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 ?? [];