shish 4 months ago
parent
commit
64db27fc11
1 changed files with 15 additions and 13 deletions
  1. 15 13
      console/controllers/CustomController.php

+ 15 - 13
console/controllers/CustomController.php

@@ -109,7 +109,7 @@ class CustomController extends Controller
     //每天凌晨3点35分执行,取出所有 lunar==1 的 且 birthdayTime 小于当前时间的客户,然后把他们的阴历转阳历,然后更新他们的 birthdayTime
     public function actionUpdateBirthday()
     {
-        try{
+        try {
             $calendar = new Calendar();
             $customList = CustomClass::getAllByCondition(['lunar' => 1, 'birthdayTime<' => time()], null, 'id, userId, birthday, birthdayTime, birthdayMonth, birthdayDate', null, true);
             foreach ($customList as $custom) {
@@ -140,8 +140,8 @@ class CustomController extends Controller
                 ]);
             }
             Yii::info('阴历转阳历脚本成功执行');
-        }catch(\Exception $e){
-            Yii::error('阴历转阳历脚本执行失败,原因:'.$e->getMessage());
+        } catch (\Exception $e) {
+            Yii::error('阴历转阳历脚本执行失败,原因:' . $e->getMessage());
         }
     }
 
@@ -152,10 +152,15 @@ class CustomController extends Controller
         ini_set('memory_limit', '2045M');
         set_time_limit(0);
 
-        try{
-            // 1. 查询 xhShop 表,获取所有 ptStyle = 1 的门店数据
-            $allShops = \bizHd\shop\classes\ShopClass::getAllByCondition(['ptStyle'=>1, 'status'=>1], 'id ASC', 'id, mainId');
-            // 2. 把每个门店下的所有用户进行遍历,刷新他们的累计消费和成长值、积分
+        // 1. 查询 xhShop 表,获取所有 ptStyle = 1 的门店数据,每次取出500个进行处理
+        $query = \bizHd\shop\models\Shop::find()
+            ->select('id, mainId')
+            ->where(['ptStyle' => 1])
+            ->orderBy('id DESC')
+            ->asArray();
+
+        // 2. 把每个门店下的所有用户进行遍历,刷新他们的累计消费和成长值、积分
+        foreach ($query->batch(500) as $allShops) {
             if (!empty($allShops)) {
                 foreach ($allShops as $shop) {
                     $shopId = $shop['id'];
@@ -174,7 +179,7 @@ class CustomController extends Controller
                                     } elseif ($order['forward'] == 1) { //1 售后付款单(红冲)
                                         $buyAmount = bcsub($buyAmount, $order['actPrice'], 2);
                                     } else {
-                                        Yii::info('订单类型不存在,订单ID:'.$order['id']);
+                                        Yii::info('订单类型不存在,订单ID:' . $order['id']);
                                         continue;
                                     }
                                 }
@@ -191,16 +196,13 @@ class CustomController extends Controller
                             $c->save();
 
                             // 更新客户所对应花店的消费金额
-                            HdClass::updateByCondition(['shopId'=>$shopId, 'userId'=>$c->userId], ['expendAmount'=>$buyAmount]);
+                            HdClass::updateByCondition(['shopId' => $shopId, 'userId' => $c->userId], ['expendAmount' => $buyAmount]);
                         }
                     }
                 }
             }
-
-            Yii::info('客户的累计消费和成长值、积分刷新脚本成功执行');
-        }catch(\Exception $e){
-            Yii::error('客户的累计消费和成长值、积分刷新脚本执行失败,原因:'.$e->getMessage());
         }
+
     }
 
     //批量创建客户