|
|
@@ -80,7 +80,7 @@ class Period extends \common\components\ActiveRecord
|
|
|
{
|
|
|
return [
|
|
|
[['PERIOD_NUM', 'CALC_MONTH', 'CALC_YEAR', 'START_TIME', 'END_TIME', 'CREATED_AT'], 'required'],
|
|
|
- [['PERIOD_NUM', 'CALC_MONTH', 'CALC_YEAR', 'START_TIME', 'END_TIME', 'IS_MONTH', 'IS_YEAR', 'IS_CLOSED', 'IS_PERFED', 'IS_CALCULATED', 'IS_SENT', 'IS_PERFING', 'IS_CALCING', 'IS_SENDING', 'CALC_PERCENT', 'SENT_PERCENT', 'CLOSED_AT', 'PERF_STARTED_AT', 'PERFED_AT', 'CALCULATE_STARTED_AT', 'CALCULATED_AT', 'SEND_STARTED_AT', 'SENT_AT', 'CREATED_AT'], 'integer'],
|
|
|
+ [['PERIOD_NUM', 'CALC_MONTH', 'CALC_YEAR', 'START_TIME', 'END_TIME', 'IS_MONTH', 'IS_YEAR', 'IS_PERFED', 'IS_CALCULATED', 'IS_SENT', 'IS_PERFING', 'IS_CALCING', 'IS_SENDING', 'CALC_PERCENT', 'SENT_PERCENT', 'CLOSED_AT', 'PERF_STARTED_AT', 'PERFED_AT', 'CALCULATE_STARTED_AT', 'CALCULATED_AT','CREATED_AT'], 'integer'],
|
|
|
[['ID', 'PERF_ADMIN_ID', 'CLOSE_ADMIN_ID', 'CALC_ADMIN_ID', 'SENT_ADMIN_ID'], 'string', 'max' => 32],
|
|
|
[['PERIOD_NUM'], 'unique'],
|
|
|
[['ID'], 'unique'],
|
|
|
@@ -133,7 +133,6 @@ class Period extends \common\components\ActiveRecord
|
|
|
public function setPeriodNum($periodNum = null){
|
|
|
if (empty($periodNum)) {
|
|
|
$this->nowPeriodArr = static::find()
|
|
|
- ->where('IS_CLOSED=0')
|
|
|
->where('IS_PREPARE=1')
|
|
|
->orderBy('PERIOD_NUM ASC')
|
|
|
->asArray()
|
|
|
@@ -145,7 +144,10 @@ class Period extends \common\components\ActiveRecord
|
|
|
$this->periodArr = $this->nowPeriodArr;
|
|
|
$periodNum = $this->nowPeriodArr['PERIOD_NUM'];
|
|
|
} else {
|
|
|
- $this->periodArr = static::findOneAsArray('PERIOD_NUM=:PERIOD_NUM AND IS_CLOSED=0 AND IS_PREPARE=1', [':PERIOD_NUM'=>$periodNum]);
|
|
|
+ $this->periodArr = static::findOneAsArray(
|
|
|
+ 'PERIOD_NUM=:PERIOD_NUM AND IS_PREPARE=1',
|
|
|
+ [':PERIOD_NUM'=>$periodNum]
|
|
|
+ );
|
|
|
if (empty($this->periodArr)) {
|
|
|
|
|
|
return false;
|
|
|
@@ -580,289 +582,23 @@ class Period extends \common\components\ActiveRecord
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取上月的年月
|
|
|
- * @param $periodNum
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getLastMonth($periodNum = null){
|
|
|
- $period = $this->setPeriodNum($periodNum);
|
|
|
- if($period){
|
|
|
- $year = $period['CALC_YEAR'];
|
|
|
- $month = $period['CALC_MONTH'];
|
|
|
- $lastYear = Date::lastMonth($year.'-'.$month, 'Y');
|
|
|
- $lastMonth = Date::lastMonth($year.'-'.$month, 'm');
|
|
|
- return [
|
|
|
- 'year' => $lastYear,
|
|
|
- 'month' => intval($lastMonth),
|
|
|
- 'yearMonth' => $lastYear.Tool::numFix($lastMonth, 2),
|
|
|
- ];
|
|
|
- } else {
|
|
|
- return [
|
|
|
- 'year' => 0,
|
|
|
- 'month' => 0,
|
|
|
- 'yearMonth' => 0,
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 上几个月的年月
|
|
|
- * @param int $num
|
|
|
- * @param null $periodNum
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getLastNumMonth($num=1,$periodNum = null){
|
|
|
- $period = $this->setPeriodNum($periodNum);
|
|
|
- if($period){
|
|
|
- $year = $period['CALC_YEAR'];
|
|
|
- $month = $period['CALC_MONTH'];
|
|
|
- $lastYear = Date::lastNumMonth($num,$year.'-'.$month, 'Y');
|
|
|
- $lastMonth = Date::lastNumMonth($num,$year.'-'.$month, 'm');
|
|
|
- return [
|
|
|
- 'year' => $lastYear,
|
|
|
- 'month' => intval($lastMonth),
|
|
|
- 'yearMonth' => $lastYear.Tool::numFix($lastMonth, 2),
|
|
|
- ];
|
|
|
- } else {
|
|
|
- return [
|
|
|
- 'year' => 0,
|
|
|
- 'month' => 0,
|
|
|
- 'yearMonth' => 0,
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 下月的年月
|
|
|
- * @param null $periodNum
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getNextMonth($periodNum = null){
|
|
|
- $period = $this->setPeriodNum($periodNum);
|
|
|
- if($period){
|
|
|
- $year = $period['CALC_YEAR'];
|
|
|
- $month = $period['CALC_MONTH'];
|
|
|
- $nextYear = Date::nextMonth($year.'-'.$month, 'Y');
|
|
|
- $nextMonth = Date::nextMonth($year.'-'.$month, 'm');
|
|
|
- return [
|
|
|
- 'year' => $nextYear,
|
|
|
- 'month' => intval($nextMonth),
|
|
|
- 'yearMonth' => $nextYear.Tool::numFix($nextMonth, 2),
|
|
|
- ];
|
|
|
- } else {
|
|
|
- return [
|
|
|
- 'year' => 0,
|
|
|
- 'month' => 0,
|
|
|
- 'yearMonth' => 0,
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 通过时间戳获取期
|
|
|
- * @param $time
|
|
|
- * @return array|null|\yii\db\ActiveRecord
|
|
|
- */
|
|
|
- public static function getPeriodFromTime($time){
|
|
|
- return static::find()->where('START_TIME<=:TIME AND END_TIME>:TIME', [':TIME'=>$time])->asArray()->one();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 通过时间戳范围获取期间内的期
|
|
|
- * @param $minTime
|
|
|
- * @param $maxTime
|
|
|
- * @return array|\yii\db\ActiveRecord[]
|
|
|
- */
|
|
|
- public static function getPeriodFromTimeRange($minTime, $maxTime){
|
|
|
- return static::find()->where('END_TIME>:MIN_TIME AND START_TIME<:MAX_TIME', [':MIN_TIME'=>$minTime, ':MAX_TIME'=>$maxTime])->orderBy('PERIOD_NUM ASC')->asArray()->all();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取近几期的期数
|
|
|
- * @param $num
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public static function getNearlyPeriodNum($num){
|
|
|
- // 获取当前期
|
|
|
- $period = self::instance();
|
|
|
- $periodNum = $period->getNowPeriodNum();
|
|
|
- // 获取前$num期的期数
|
|
|
- $periodNums = [
|
|
|
- $periodNum
|
|
|
- ];
|
|
|
- for($i=0;$i<$num;$i++){
|
|
|
- if($periodNum - $i > 0){
|
|
|
- // 查看该期是否存在
|
|
|
- if(self::isExistsPeriodNum($periodNum - $i)){
|
|
|
- $periodNums[] = $periodNum - $i;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return array_reverse($periodNums);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取近几期的挂网期数
|
|
|
- * @param $num
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public static function getNearlySendPeriodNum($num){
|
|
|
- // 获取当前期
|
|
|
- $period = self::instance();
|
|
|
- $periodNum = $period->sentMaxPeriodNum();
|
|
|
- // 获取前$num期的期数
|
|
|
- $periodNums = [
|
|
|
- $periodNum
|
|
|
- ];
|
|
|
- for($i=0;$i<$num;$i++){
|
|
|
- if($periodNum - $i > 0){
|
|
|
- // 查看该期是否存在
|
|
|
- if(self::isExistsPeriodNum($periodNum - $i)){
|
|
|
- $periodNums[] = $periodNum - $i;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return array_reverse($periodNums);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取近几期的年月
|
|
|
- * @param $num
|
|
|
- * @return array
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- public static function getNearlyPeriodYearMonth($num){
|
|
|
- // 获取当前期
|
|
|
- $period = self::instance();
|
|
|
- $periodNum = $period->getNowPeriodNum();
|
|
|
- $nowYearMonth = $period->getNowYearMonth();
|
|
|
- // 获取前$num期的期数
|
|
|
- $periodYearMonths = [];
|
|
|
- for($i=1;$i<=$num;$i++){
|
|
|
- if($periodNum - $i > 0){
|
|
|
- // 查看该期是否存在
|
|
|
- if(self::isExistsPeriodNum($periodNum - $i)){
|
|
|
- $yearMonth = $period->getYearMonth($periodNum - $i);
|
|
|
- $periodYearMonths[] = [
|
|
|
- 'yearMonth' => $yearMonth,
|
|
|
- 'periodNum' => $periodNum - $i,
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return array_reverse($periodYearMonths);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取本月所有已经挂网的期数
|
|
|
- * @param $yearMonth
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public static function monthSentAllPeriodNum($yearMonth){
|
|
|
- $year = intval(substr($yearMonth, 0, 4));
|
|
|
- $month = intval(substr($yearMonth, 4, 2));
|
|
|
- $allPeriod = Period::find()->where('CALC_YEAR=:CALC_YEAR AND CALC_MONTH=:CALC_MONTH AND IS_SENT=1', [':CALC_YEAR'=>$year, ':CALC_MONTH'=>$month])->select('PERIOD_NUM')->asArray()->all();
|
|
|
- $result = [];
|
|
|
- if($allPeriod){
|
|
|
- foreach($allPeriod as $period){
|
|
|
- $result[] = $period['PERIOD_NUM'];
|
|
|
- }
|
|
|
- }
|
|
|
- return $result;
|
|
|
- }
|
|
|
+ // 奖金计算,更新业绩表,进度百分比
|
|
|
+ public static function updatePercent($percent, $periodNum) {
|
|
|
+ $result = Period::updateAll(
|
|
|
+ ['PERF_PERCENT' => $percent],
|
|
|
+ 'PERIOD_NUM=:PERIOD_NUM',
|
|
|
+ [':PERIOD_NUM' => $periodNum]
|
|
|
+ );
|
|
|
|
|
|
- /**
|
|
|
- * 所传月份所有已结算的期数
|
|
|
- * @param $yearMonth
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public static function monthCalcAllPeriodNum($yearMonth){
|
|
|
- $year = intval(substr($yearMonth, 0, 4));
|
|
|
- $month = intval(substr($yearMonth, 4, 2));
|
|
|
- $allPeriod = Period::find()->where('CALC_YEAR=:CALC_YEAR AND CALC_MONTH=:CALC_MONTH AND IS_CALCING=1', [':CALC_YEAR'=>$year, ':CALC_MONTH'=>$month])->select('PERIOD_NUM')->asArray()->all();
|
|
|
- $result = [];
|
|
|
- if($allPeriod){
|
|
|
- foreach($allPeriod as $period){
|
|
|
- $result[] = $period['PERIOD_NUM'];
|
|
|
- }
|
|
|
- }
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取已结算的最大期数
|
|
|
- * @return mixed
|
|
|
+ * 更新计算进度
|
|
|
*/
|
|
|
- public static function calculatedMaxPeriodNum(){
|
|
|
- return static::find()->where('IS_CALCULATED=1')->max('PERIOD_NUM');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 已挂网的最大期数
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
- public static function sentMaxPeriodNum(){
|
|
|
- return static::find()->where('IS_SENT=1')->max('PERIOD_NUM');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 期数结束时间
|
|
|
- * @param $periodNum
|
|
|
- * @return int|mixed
|
|
|
- */
|
|
|
- public static function getEndTime($periodNum) {
|
|
|
- $endTime = static::find()->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $periodNum])->select('END_TIME')->asArray()->one();
|
|
|
- return $endTime['END_TIME'] ?? 0;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 到年底的剩余月份
|
|
|
- * @param null $periodNum
|
|
|
- * @return int
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- public static function getMonthLeft($periodNum = null) {
|
|
|
- $period = self::instance();
|
|
|
- if ($periodNum) {
|
|
|
- $nowMonth = $period->getMonth($periodNum);
|
|
|
- } else {
|
|
|
- $nowMonth = $period->getNowMonth();
|
|
|
- }
|
|
|
- return 12 - (int)$nowMonth + 1;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 起始期数和结束期数几个月
|
|
|
- * @param $startPeriodNum
|
|
|
- * @param $endPeriodNum
|
|
|
- * @return int|string
|
|
|
- */
|
|
|
- public static function getMonthNum($startPeriodNum,$endPeriodNum){
|
|
|
- return self::find()->select('CALC_MONTH')->groupBy('CALC_MONTH')->where('PERIOD_NUM>=:START_PERIOD AND PERIOD_NUM<=:END_PERIOD',[':START_PERIOD'=>$startPeriodNum,':END_PERIOD'=>$endPeriodNum])->count();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 从期数获取当前月的所有期
|
|
|
- *
|
|
|
- */
|
|
|
- public static function getCurrentMonthPeriodByPeriodNum($periodNum){
|
|
|
- $currentPeriod = self::getInfoByPeriodNum($periodNum);
|
|
|
- $currentYear = $currentPeriod['CALC_YEAR'];
|
|
|
- $currentMonth = $currentPeriod['CALC_MONTH'];
|
|
|
- $periodsArray = self::findAllAsArray(['CALC_YEAR'=>$currentYear,'CALC_MONTH'=>$currentMonth]);
|
|
|
- $periods = [];
|
|
|
- foreach ($periodsArray as $p){
|
|
|
- $periods[] = $p['PERIOD_NUM'];
|
|
|
- }
|
|
|
-
|
|
|
- return $periods;
|
|
|
- }
|
|
|
-
|
|
|
- // 奖金计算,更新业绩表,进度百分比
|
|
|
- public static function updatePercent($percent, $periodNum) {
|
|
|
+ public static function updateCalcProcess($perpare, $periodNum) {
|
|
|
$result = Period::updateAll(
|
|
|
- ['PERF_PERCENT' => $percent],
|
|
|
+ ['IS_PREPARE' => $perpare],
|
|
|
'PERIOD_NUM=:PERIOD_NUM',
|
|
|
[':PERIOD_NUM' => $periodNum]
|
|
|
);
|