shish 4 месяцев назад
Родитель
Сommit
faf2c2a80f
1 измененных файлов с 15 добавлено и 0 удалено
  1. 15 0
      console/controllers/CustomController.php

+ 15 - 0
console/controllers/CustomController.php

@@ -152,6 +152,8 @@ class CustomController extends Controller
         ini_set('memory_limit', '2045M');
         set_time_limit(0);
 
+        $redisKey = 'refresh_custom_data_processed_shops';
+
         // 1. 查询 xhShop 表,获取所有 ptStyle = 1 的门店数据,每次取出500个进行处理
         $query = \bizHd\shop\models\Shop::find()
             ->select('id, mainId')
@@ -165,6 +167,13 @@ class CustomController extends Controller
                 foreach ($allShops as $shop) {
                     $shopId = $shop['id'];
                     $mainId = $shop['mainId'];
+
+                    // 判断是否已经执行过,执行过则跳过
+                    $hasProcessed = Yii::$app->redis->executeCommand('SISMEMBER', [$redisKey, $shopId]);
+                    if ($hasProcessed) {
+                        continue;
+                    }
+
                     $customs = CustomClass::getAllByCondition(['shopId' => $shopId], null, 'id, userId, buyAmount, growth, member, memberName', null, true);
                     $levelDatas = MemberLevelClass::getAllByCondition(['mainId' => $mainId], 'amount DESC', 'id, name, level, amount');
                     if (!empty($customs) && !empty($levelDatas)) {
@@ -199,10 +208,16 @@ class CustomController extends Controller
                             HdClass::updateByCondition(['shopId' => $shopId, 'userId' => $c->userId], ['expendAmount' => $buyAmount]);
                         }
                     }
+
+                    // 记录该 shopId 已经执行完成
+                    Yii::$app->redis->executeCommand('SADD', [$redisKey, $shopId]);
                 }
             }
         }
 
+        // 脚本执行完之后,清除缓存
+        Yii::$app->redis->executeCommand('DEL', [$redisKey]);
+
     }
 
     //批量创建客户