Преглед изворни кода

计算服务,季度相关推送

theo пре 3 година
родитељ
комит
9cfbd175a6

+ 9 - 0
common/helpers/bonus/Calc/BaseBusiness.php

@@ -77,4 +77,13 @@ class BaseBusiness
         $calcMonth2 = date('Ym', strtotime('+' . ($this->_calcMonth - 2) . ' month', $startTime));
         return [$calcMonth1, $calcMonth2];
     }
+
+    public function getMonthsByPeriodNum($periodNum) {
+        $currentPeriod = Period::getInfoByPeriodNum($periodNum);
+        $currentYear = $currentPeriod['CALC_YEAR'];
+        $currentMonth = $currentPeriod['CALC_MONTH'];
+        $calcMonth1 = $currentYear . str_pad($currentMonth - 2,2,"0",STR_PAD_LEFT);
+        $calcMonth2 = $currentYear . str_pad($currentMonth - 1,2,"0",STR_PAD_LEFT);
+        return [$calcMonth1, $calcMonth2];
+    }
 }

+ 7 - 2
common/helpers/bonus/Calc/PushBaseDataToCalc.php

@@ -482,7 +482,11 @@ class PushBaseDataToCalc extends BaseBusiness
         $currentPeriod = Period::getInfoByPeriodNum($periodNum);
         //判断是否月节点
         if ($currentPeriod['IS_MONTH']) {
-            $periodNum = Period::getCurrentMonthPeriodByPeriodNum($periodNum);
+            if (in_array($periodNum, [3,6,9,12])){ // 如果是季度尾
+                $periodNum = Period::getCurrentQuarterPeriodByPeriodNum($periodNum);
+            }else{
+                $periodNum = Period::getCurrentMonthPeriodByPeriodNum($periodNum);
+            }
         }
         $field = implode(',', $fieldArray);
         $data  = CalcBonusQY::find()->select($field)->where(['PERIOD_NUM' => $periodNum])->asArray()->all();
@@ -641,7 +645,8 @@ class PushBaseDataToCalc extends BaseBusiness
         $_offset = 0;
         $field   = implode(',', $fieldArray);
 
-        $months = $this->getMonthsForQuarterly();
+        $months = $this->getMonthsByPeriodNum($this->_periodNum);
+        print_r($months);
 
         //结算月
         perfMonth:

+ 16 - 0
common/models/Period.php

@@ -854,6 +854,22 @@ class Period extends \common\components\ActiveRecord
         return $periods;
     }
 
+    public static function getCurrentQuarterPeriodByPeriodNum($periodNum){
+        $currentPeriod = self::getInfoByPeriodNum($periodNum);
+        $currentYear = $currentPeriod['CALC_YEAR'];
+        $currentMonth = $currentPeriod['CALC_MONTH'];
+        $periodsArray = self::find()->select("*")
+            ->where(['CALC_YEAR'=>$currentYear,'CALC_MONTH'=>$currentMonth])
+            ->where(['in', 'CALC_MONTH', [$currentMonth-2, $currentMonth-1, $currentMonth]])
+            ->asArray()->all();
+        $periods = [];
+        foreach ($periodsArray as $p){
+            $periods[] = $p['PERIOD_NUM'];
+        }
+
+        return $periods;
+    }
+
     public static function updatePeriodIsAutoExec($periodNum, $isAutoExec = 0): int
     {
         return Period::updateAll(['AUTO_EXEC' => $isAutoExec], ['PERIOD_NUM' => $periodNum]);