Преглед на файлове

fix:完善计算完成后业绩单拉取功能,完善自动合格相关订单生成

brook преди 3 години
родител
ревизия
e1c18fc58a

+ 27 - 11
common/helpers/bonus/BonusSend.php

@@ -131,7 +131,6 @@ class BonusSend extends BaseObject {
     public function putFakeOrder() {
         echo('开始处理-假订单' . PHP_EOL);
         $fakeOrder= Order::find()->where(['PERIOD_NUM'=>$this->_periodNum, 'IS_AUTO'=>'1'])->asArray()->all();
-//        print_r($fakeOrder);exit;
         foreach($fakeOrder as $fOrder){
             $oRemainPv=RemainPv::findOne(["USER_ID"=>$fOrder['USER_ID']]);
             $transactionRemain = \Yii::$app->db->beginTransaction();
@@ -412,7 +411,8 @@ class BonusSend extends BaseObject {
         echo sprintf("时间:[%s]数据库发奖,当前page为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()), $page);
         $periodNum = $this->_periodNum;
         // 从奖金结算表中获取当期未发放的所有数据
-        $allData = CalcBonus::findUseDbCalc()
+//        $allData = CalcBonus::findUseDbCalc()
+        $allData = CalcBonus::find()
         ->yearMonth($this->_calcYearMonth)
         ->where(
             '(IS_SENT=0 OR IS_SENT=2) AND CALC_MONTH=:CALC_MONTH AND PERIOD_NUM=:PERIOD_NUM', 
@@ -564,7 +564,8 @@ class BonusSend extends BaseObject {
     public function updateEmpLevel(int $offset = 0) {
         if ($this->_isCalcMonth) {
             $empLv = EmployLevel::getIdConvertLevelSortCache();
-            $allData = CalcBonus::findUseDbCalc()
+//            $allData = CalcBonus::findUseDbCalc()
+            $allData = CalcBonus::find()
             ->yearMonth($this->_calcYearMonth)
             ->where(
                 'CALC_MONTH=:CALC_MONTH AND PERIOD_NUM=:PERIOD_NUM', 
@@ -621,7 +622,8 @@ class BonusSend extends BaseObject {
     public function updateCrownLevel(int $offset = 0)
     {
         $starCrownLv = StarCrownLevel::getIdConvertLevelSortCache();
-        $allData = CalcBonusQY::findUseDbCalc()
+//        $allData = CalcBonusQY::findUseDbCalc()
+        $allData = CalcBonusQY::find()
             ->yearMonth($this->_calcYearMonth)
             ->where(
                 'CALC_MONTH=:CALC_MONTH AND PERIOD_NUM=:PERIOD_NUM',
@@ -743,15 +745,21 @@ class BonusSend extends BaseObject {
      * @throws \yii\db\Exception
      */
     public function updateUserPerf(int $offset = 0) {
-        $allData = PerfPeriod::findUseDbCalc()->yearMonth($this->_calcYearMonth)->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum])->orderBy('ID ASC')->offset($offset)->limit($this->_limit)->all();
+//        $allData = PerfPeriod::findUseDbCalc()
+        $allData = PerfPeriod::find()
+            ->yearMonth($this->_calcYearMonth)->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum])->orderBy('ID ASC')->offset($offset)->limit($this->_limit)->all();
         if ($allData) {
             $transaction = Yii::$app->db->beginTransaction();
             try {
                 foreach ($allData as $data) {
                     $isUpdate = false;
-                    if (UserPerf::findUseDbCalc()->where('USER_ID=:USER_ID', [':USER_ID' => $data['USER_ID']])->exists()) {
+//                    if (UserPerf::findUseDbCalc()
+                    if (UserPerf::find()
+                        ->where('USER_ID=:USER_ID', [':USER_ID' => $data['USER_ID']])->exists()) {
                         // 判断本期是否已经更新过业绩
-                        if (!UserPerfUpdate::findUseDbCalc()->yearMonth($this->_calcYearMonth)->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [':USER_ID' => $data['USER_ID'], ':PERIOD_NUM' => $this->_periodNum])->exists()) {
+//                        if (!UserPerfUpdate::findUseDbCalc()
+                        if (!UserPerfUpdate::find()
+                            ->yearMonth($this->_calcYearMonth)->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [':USER_ID' => $data['USER_ID'], ':PERIOD_NUM' => $this->_periodNum])->exists()) {
                             $isUpdate = true;
                             // 更新业绩
                             UserPerf::updateAll([
@@ -851,15 +859,21 @@ class BonusSend extends BaseObject {
         if (!$this->_isCalcMonth) {
             return true;
         }
-        $allData = PerfMonth::findUseDbCalc()->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])->orderBy('ID ASC')->offset($offset)->limit($this->_limit)->all();
+//        $allData = PerfMonth::findUseDbCalc()
+        $allData = PerfMonth::find()
+            ->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])->orderBy('ID ASC')->offset($offset)->limit($this->_limit)->all();
         if ($allData) {
             $transaction = Yii::$app->db->beginTransaction();
             try {
                 foreach ($allData as $data) {
                     $isUpdate = false;
-                    if (UserPerf::findUseDbCalc()->where('USER_ID=:USER_ID', [':USER_ID' => $data['USER_ID']])->exists()) {
+//                    if (UserPerf::findUseDbCalc()
+                    if (UserPerf::find()
+                        ->where('USER_ID=:USER_ID', [':USER_ID' => $data['USER_ID']])->exists()) {
                         // 判断本期是否已经更新过业绩
-                        if (!UserPerfMonthUpdate::findUseDbCalc()->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', [':USER_ID' => $data['USER_ID'], ':CALC_MONTH' => $this->_calcYearMonth])->exists()) {
+//                        if (!UserPerfMonthUpdate::findUseDbCalc()
+                        if (!UserPerfMonthUpdate::find()
+                            ->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', [':USER_ID' => $data['USER_ID'], ':CALC_MONTH' => $this->_calcYearMonth])->exists()) {
                             $isUpdate = true;
                             // 更新业绩
                             UserPerf::updateAll([
@@ -1091,7 +1105,9 @@ class BonusSend extends BaseObject {
      * @throws \yii\db\Exception
      */
     public function sendSmsLoop(int $offset = 0) {
-        $allData = UserInfo::findUseDbCalc()->select('USER_ID,ALLOW_RECONSUME_SMS_TO')->where('ALLOW_RECONSUME_SMS=1')->offset($offset)->limit($this->_limit)->all();
+//        $allData = UserInfo::findUseDbCalc()
+        $allData = UserInfo::find()
+            ->select('USER_ID,ALLOW_RECONSUME_SMS_TO')->where('ALLOW_RECONSUME_SMS=1')->offset($offset)->limit($this->_limit)->all();
         if ($allData) {
             $smsWallet = explode(",", $this->_sysConfig['smsWallet']['VALUE']);
             $smsFee = $this->_sysConfig['smsFee']['VALUE'];

+ 3 - 1
common/helpers/bonus/Calc/BaseBusiness.php

@@ -17,6 +17,8 @@ class BaseBusiness
 
     protected $_limit = 10000;
 
+    //最小生成自动合格订单的业绩
+    public static $automaticEntitlementPerf = 30;
 
     public function __construct($periodNum)
     {
@@ -44,7 +46,7 @@ class BaseBusiness
         if (empty($periodNum) || !is_numeric($periodNum)) {
             return 0;
         }
-        $db     = self::CALC_DB_NAME;
+        $db = self::CALC_DB_NAME;
         //同步字段去掉 IS_CALCULATED, 否则自动拉取的轮询间隔之间奖金计算完成后更新该字段则会认为已经拉取过奖金数据
         $period = \Yii::$app->$db->createCommand("SELECT 
                 PERIOD_NUM,

+ 27 - 1
common/helpers/bonus/Calc/GeneratePerfOrder.php

@@ -8,10 +8,13 @@ use common\helpers\Date;
 use common\helpers\snowflake\SnowFake;
 use common\models\DecOrder;
 use common\models\forms\DeclarationForm;
+use common\models\forms\OrderForm;
 use common\models\Order;
 use common\models\OrderDec;
 use common\models\OrderShop;
 use common\models\PerfOrder;
+use common\models\Period;
+use common\models\RemainPv;
 
 
 class GeneratePerfOrder extends BasePerfBusiness
@@ -54,8 +57,10 @@ class GeneratePerfOrder extends BasePerfBusiness
     {
 //        $this->setCalcStatus('start');
         try {
-            //清业务系统本地数据(业绩相关)
+            //清业务系统本地数据(业绩相关)
             $this->clearPerfOrderBusinessData();
+            //清除并重新生成自动合格相关订单
+            $this->_createFakeOrder($this->_periodNum, $this->_isCalcMonth);
             //生成业绩单
             $this->perfOrder();
             //todo 更新进度
@@ -437,5 +442,26 @@ class GeneratePerfOrder extends BasePerfBusiness
         $fieldArray = array_keys($data[0]);
         return \Yii::$app->db->createCommand()->batchInsert($table, $fieldArray, $data)->execute();
     }
+
+    public static function _createFakeOrder($periodNum, $isCalcMonth)
+    {
+        if ($isCalcMonth) {
+            $periods = Period::getCurrentMonthPeriodByPeriodNum($periodNum);
+            //先清除本期的假订单
+//            echo('首先,清除上次尝试生成业绩单时所创建的虚假订单' . date('Y-m-d  H:i:s', time()) . PHP_EOL);
+            Order::deleteAll(['IS_AUTO' => '1', 'PERIOD_NUM' => $periodNum]);
+//            echo('检查有结余PV的用户,如果他当月PV不足30,则为其创建假订单' . PHP_EOL);
+            $userHaveRemain = RemainPv::findAllAsArray('REMAIN_PV >0');
+            foreach ($userHaveRemain as $uR) {
+                $myPv = Order::find()->where(['PERIOD_NUM' => $periods, 'USER_ID' => $uR['USER_ID']])->SUM('PV');
+                if ($myPv < self::$automaticEntitlementPerf) {
+                    //制造虚拟订单
+//                    echo('不足30了,生成假订单' . PHP_EOL);
+                    $newOrderForm = new OrderForm();
+                    $newOrderForm->addFakeOrder($uR['USER_ID'], $periodNum);
+                }
+            }
+        }
+    }
 }
 

+ 6 - 0
common/helpers/bonus/Calc/PullCalcBonusData.php

@@ -18,6 +18,7 @@ use common\models\CalcBonusVilla;
 use common\models\CalcBonusVIP;
 use common\models\CalcBonusYC;
 use common\models\CalcBonusYJ;
+use common\models\CalcRecord;
 use common\models\ScoreMonth;
 use common\models\User;
 use common\models\UserBonus;
@@ -93,6 +94,11 @@ class PullCalcBonusData extends BaseBusiness
                     continue;//必要,避免增加逻辑代码后忘记此处
                 }
             }
+            //拉取期业绩
+            $res = (new PullPerfDataFromCalc($this->_periodNum))->start();
+            if (200 != $res['code']) {
+                CalcRecord::record($this->_periodNum, '第' . $this->_periodNum . '期的奖金计算后的期业绩数据获取失败,原因:' . $res['msg']);
+            }
         } catch (\Exception $e) {
             return $this->fail('msg:' . $e->getMessage() . 'line:' . $e->getLine());
         }