shish 8 месяцев назад
Родитель
Сommit
89e947dbf6
1 измененных файлов с 7 добавлено и 7 удалено
  1. 7 7
      console/controllers/TestController.php

+ 7 - 7
console/controllers/TestController.php

@@ -39,14 +39,14 @@ class TestController extends Controller
         $query = new \yii\db\Query();
         $query->select(['id', 'sendStatus']);
         $query->from(Order::tableName());
-        foreach ($query->batch() as $batch) {
-            foreach ($batch as $order) {
-                $id = $order['id'];
-                \bizGhs\order\classes\OrderClass::updateById($id, ['sendStatus' => -4]);
-                //echo $id . "\n";
+        $totalCount = 0;
+        foreach ($query->batch(3000) as $batch) {
+            $ids = array_column($batch, 'id');
+            \bizGhs\order\classes\OrderClass::updateByIds($ids, ['sendStatus' => -4]);
+            $totalCount += count($ids);
+            echo "已处理 " . $totalCount . " 条记录\n";
             }
-        }
-
+        echo "全部完成!共处理 " . $totalCount . " 条记录\n";
     }
 
     public function actionSend()