|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|