From 077cbb5c723e12788cfd4b6eefd27c5ee496104e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AF=E4=B9=90=E5=8A=A0=E5=86=B0?= <11869599+addie66@user.noreply.gitee.com> Date: Fri, 9 Oct 2026 12:45:47 +0800 Subject: [PATCH] =?UTF-8?q?```=20feat(shopro=5Fwechat=5Ftrade):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E6=8F=90=E8=AE=A2=E5=8D=95=E5=87=86?= =?UTF-8?q?=E5=A4=87=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在ConfirmOrders命令中添加prepareSelfetchOrder方法,用于处理自提订单的发货逻辑 - 当订单项为自提类型且未发货时,调用checkDispatchAndSend进行发货操作 - 添加异常处理机制,确保自提订单处理失败时不会中断整体流程 - 增加dry-run模式支持,便于测试验证 - 添加日志输出,提供详细的执行状态反馈 ``` --- .../command/ConfirmOrders.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/addons/shopro_wechat_trade/command/ConfirmOrders.php b/addons/shopro_wechat_trade/command/ConfirmOrders.php index 4e77a2f..26acd7f 100644 --- a/addons/shopro_wechat_trade/command/ConfirmOrders.php +++ b/addons/shopro_wechat_trade/command/ConfirmOrders.php @@ -66,6 +66,14 @@ class ConfirmOrders extends Command continue; } + try { + $this->prepareSelfetchOrder($orderModel, $order, $dryRun, $output); + } catch (\Exception $e) { + $output->writeln(' [FAIL] 自提准备: ' . $e->getMessage()); + $fail++; + continue; + } + if (!$skipMall) { try { $this->mallConfirmItems($orderModel, $order, $dryRun, $output); @@ -161,6 +169,38 @@ class ConfirmOrders extends Command return array_values(array_unique($ids)); } + /** + * 自提/到店:未发货时先走 selfetchSendItem,便于 upload_shipping_info(logistics_type=4) + */ + protected function prepareSelfetchOrder(Order $orderModel, &$order, $dryRun, Output $output) + { + $needsShip = false; + foreach ($order->item ?? [] as $item) { + $itemArr = is_object($item) && method_exists($item, 'toArray') ? $item->toArray() : (array) $item; + if (($itemArr['dispatch_type'] ?? '') !== 'selfetch') { + continue; + } + if (intval($itemArr['dispatch_status'] ?? 0) < OrderItem::DISPATCH_STATUS_SENDED) { + $needsShip = true; + break; + } + } + if (!$needsShip) { + return; + } + if ($dryRun) { + $output->writeln(' [dry-run] 自提发货 checkDispatchAndSend'); + return; + } + $orderModel->checkDispatchAndSend($order, []); + $order = Order::with('item')->where('id', $order['id'])->find(); + if (!$order) { + throw new \RuntimeException('自提发货后订单不存在'); + } + $output->writeln(' [OK] 自提已发货(待同步微信 upload_shipping_info)'); + sleep(2); + } + protected function mallConfirmItems(Order $orderModel, $order, $dryRun, Output $output) { $items = $order->item ?? [];