shish 2 月之前
父节点
当前提交
d8bc341de9
共有 1 个文件被更改,包括 36 次插入10 次删除
  1. 36 10
      console/controllers/CustomDistController.php

+ 36 - 10
console/controllers/CustomDistController.php

@@ -155,17 +155,11 @@ class CustomDistController extends Controller
                     continue;
                 }
 
-                $where = [
-                    'mainId' => $mainId,
-                    'shopId' => $shopId,
-                    'customId' => $customId,
-                ];
-                if (!$this->all) {
-                    $where['customDistId!='] = $distId;
-                }
+                $countWhere = $this->buildOrderCountWhere($mainId, $shopId, $customId, $distId);
+                $updateWhere = $this->buildOrderUpdateWhere($mainId, $shopId, $customId, $distId);
 
                 if ($this->dryRun) {
-                    $count = (int)OrderClass::getCount($where);
+                    $count = (int)OrderClass::getCount($countWhere);
                     if ($count > 0) {
                         $customName = $custom['name'] ?? '';
                         $this->stdout("[dryRun] mainId={$mainId} shopId={$shopId} customId={$customId} {$customName} distId={$distId} 订单 {$count} 条\n");
@@ -174,7 +168,7 @@ class CustomDistController extends Controller
                     continue;
                 }
 
-                $affected = OrderClass::updateByCondition($where, ['customDistId' => $distId]);
+                $affected = Order::updateAll(['customDistId' => $distId], $updateWhere);
                 if ($affected > 0) {
                     $updated += (int)$affected;
                 }
@@ -191,4 +185,36 @@ class CustomDistController extends Controller
 
         return $updated;
     }
+
+    /**
+     * updateAll 用的 Yii 标准条件
+     */
+    private function buildOrderUpdateWhere($mainId, $shopId, $customId, $distId)
+    {
+        $base = [
+            'mainId' => $mainId,
+            'shopId' => $shopId,
+            'customId' => $customId,
+        ];
+        if ($this->all) {
+            return $base;
+        }
+        return ['and', $base, ['!=', 'customDistId', $distId]];
+    }
+
+    /**
+     * conditionQuery 用的等值/不等条件(仅 dryRun 统计)
+     */
+    private function buildOrderCountWhere($mainId, $shopId, $customId, $distId)
+    {
+        $where = [
+            'mainId' => $mainId,
+            'shopId' => $shopId,
+            'customId' => $customId,
+        ];
+        if (!$this->all) {
+            $where['customDistId!='] = $distId;
+        }
+        return $where;
+    }
 }