Эх сурвалжийг харах

fix:完善季度相关代码

brook 3 жил өмнө
parent
commit
46baa3360c

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

@@ -28,8 +28,8 @@ class BaseBusiness
 //            $periodDataArr = $periodObj->setPeriodNum($periodNum);
 //            $this->_periodId = $periodDataArr['ID'];
             $this->_isCalcMonth = $periodObj->isCalcMonth($periodNum);
-//            $this->_calcYear = $periodObj->getYear($periodNum);
-//            $this->_calcMonth     = $periodObj->getMonth($periodNum);
+            $this->_calcYear = $periodObj->getYear($periodNum);
+            $this->_calcMonth     = $periodObj->getMonth($periodNum);
             $this->_calcYearMonth = $periodObj->getYearMonth($periodNum);
         } else {
             //todo
@@ -70,4 +70,11 @@ class BaseBusiness
         return \Yii::$app->$db->createCommand("SELECT * FROM AR_PERIOD where PERIOD_NUM = $this->_periodNum")->queryOne();
     }
 
+    public function getMonthsForQuarterly()
+    {
+        $startTime  = strtotime(date('Y') . '0101');
+        $calcMonth1 = date("Y-m", strtotime('+' . ($this->_calcMonth - 1) . ' month', $startTime));
+        $calcMonth2 = date("Y-m", strtotime('+' . ($this->_calcMonth - 2) . ' month', $startTime));
+        return [$calcMonth1, $calcMonth2];
+    }
 }

+ 2 - 2
common/helpers/bonus/Calc/PullCalcBonusData.php

@@ -132,7 +132,7 @@ class PullCalcBonusData extends BaseBusiness
 
         $_offset      = 0;
         $this->_limit = 2000;
-        calcMonth:
+        calcBonus:
 
         $offset = $_offset * $this->_limit;
 
@@ -178,7 +178,7 @@ class PullCalcBonusData extends BaseBusiness
             \Yii::$app->db->createCommand()->batchInsert($table, $fieldArray, $data)->execute();
             $userInfo = null;
             $data     = null;
-            goto calcMonth;
+            goto calcBonus;
         }
         $data = null;
         return true;

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

@@ -272,6 +272,28 @@ class PushBaseDataToCalc extends BaseBusiness
             'CALCULATED_AT',
             'CREATED_AT',
         ]],
+        //--- 月业绩表 只有当前结算月为季度最终月时才推
+        'perfMonth'        => ['separately' => true, 'table' => 'AR_PERF_MONTH', 'field' => [
+            'ID',
+            'USER_ID',
+            'FX_AMOUNT_CASH',
+            'PV_PCS',
+            'PV_PCS_FX',
+            'PV_1L',
+            'PV_2L',
+            'PV_3L',
+            'PV_4L',
+            'PV_5L',
+            'PV_1L_TOTAL',
+            'PV_2L_TOTAL',
+            'PV_3L_TOTAL',
+            'PV_4L_TOTAL',
+            'PV_5L_TOTAL',
+            'CALC_MONTH',
+            'CREATED_AT',
+            'PV_PSS',
+            'PV_PSS_TOTAL',
+        ]],
         //--- 推荐网络表
         'userRelation'     => ['table' => 'AR_USER_RELATION_NEW', 'field' => [
             'ID',
@@ -379,8 +401,18 @@ class PushBaseDataToCalc extends BaseBusiness
     public function period($table, $fieldArray, $db)
     {
         $field = implode(',', $fieldArray);
-        $data  = Period::find()->select($field)
-            ->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum])
+
+        $where = ['PERIOD_NUM' => $this->_periodNum];
+
+        if ($this->_isCalcMonth) {
+            $where = ['CALC_YEAR' => $this->_calcYear, 'CALC_MONTH' => $this->_calcMonth];
+            if (in_array($this->_calcMonth, [3, 6, 9, 12])) {
+                $where['CALC_MONTH'] = [$this->_calcMonth, $this->_calcMonth - 1, $this->_calcMonth - 2];
+            }
+        }
+
+        $data = Period::find()->select($field)
+            ->where($where)
             ->asArray()->all();
         if (!empty($data)) {
             \Yii::$app->$db->createCommand()->batchInsert($table, $fieldArray, $data)->execute();
@@ -596,4 +628,31 @@ class PushBaseDataToCalc extends BaseBusiness
         $fieldArray = self::BASE_INFO_METHODS['perfOrder']['field'] ?? [];
         \Yii::$app->$db->createCommand()->batchInsert($table, $fieldArray, $data)->execute();
     }
+
+    public function perfMonth($table, $fieldArray, $db)
+    {
+        if (!$this->_isCalcMonth && !in_array($this->_calcMonth, [3, 6, 9, 12])) {
+            return true;
+        }
+        $_offset = 0;
+        $field   = implode(',', $fieldArray);
+
+        $months = $this->getMonthsForQuarterly();
+
+        //结算月
+        perfMonth:
+        $offset = $_offset * $this->_limit;
+        $data   = PerfMonth::find()->where(['CALC_MONTH' => $months])
+            ->offset($offset)->limit($this->_limit)->select($field)->asArray()->all();
+
+        if (!empty($data)) {
+            $_offset    += 1;
+            $fieldArray = array_keys(current($data));
+            \Yii::$app->$db->createCommand()->batchInsert($table, $fieldArray, $data)->execute();
+            $data = null;
+            goto perfMonth;
+        }
+        $data = null;
+        return true;
+    }
 }