From f2d1ed08495a66b4ac54465ee199595a992872c6 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Sat, 22 Aug 2026 17:22:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(order):=20=E5=BC=82=E6=AD=A5=E9=93=BE?= =?UTF-8?q?=E8=B7=AF=E6=98=BE=E5=BC=8F=E4=BC=A0=E9=80=92=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=EF=BC=8C=E9=81=BF=E5=85=8D=20Qimen?= =?UTF-8?q?=20=E6=97=A0=E7=99=BB=E5=BD=95=E7=94=A8=E6=88=B7=E9=9D=99?= =?UTF-8?q?=E9=BB=98=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pendingOrder/orderStorageAllocation: 优先取显式传入的 warehouse_id,缺失时回退 getWarehouseId - deliveryOrder: buildExpressAllocateRequest 携带 warehouse_id,并补充自动分配开关判定日志 --- app/service/systemMethods/order/pendingOrder.js | 7 ++++++- app/service/systems/delivery_order.js | 16 ++++++++++++++++ app/service/systems/order_storage_allocation.js | 9 ++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/service/systemMethods/order/pendingOrder.js b/app/service/systemMethods/order/pendingOrder.js index 790d9dc..c3f0fa0 100644 --- a/app/service/systemMethods/order/pendingOrder.js +++ b/app/service/systemMethods/order/pendingOrder.js @@ -1891,7 +1891,12 @@ class PendingOrderService extends OrderBaseService { }; // 快照 ctx 数据(setImmediate 回调中 ctx 可能已失效) - const warehouseId = this.getWarehouseId(); + // 显式传入的仓库ID优先:Qimen 创建订单等无登录用户上下文的异步链路 ctx.user 为空, + // 调用方必须显式传 warehouseId,否则回传任务会因"缺少仓库上下文"静默失败 + const explicitWarehouseId = Number(requestData.warehouse_id ?? requestData.warehouseId ?? 0); + const warehouseId = Number.isFinite(explicitWarehouseId) && explicitWarehouseId > 0 + ? explicitWarehouseId + : this.getWarehouseId(); const operator = this.getOrderLogOperator(); const logWarehouseId = this.getOrderLogWarehouseId(warehouseId); diff --git a/app/service/systems/delivery_order.js b/app/service/systems/delivery_order.js index 7d1110f..f261a67 100644 --- a/app/service/systems/delivery_order.js +++ b/app/service/systems/delivery_order.js @@ -1856,6 +1856,8 @@ class DeliveryOrderService extends Service { return { allow_storage_location: true, order_ids: [ Number(context && context.orderId || 0) ], + // 显式携带仓库上下文,避免依赖 ctx.user(Qimen 链路无登录用户) + warehouse_id: Number(context && context.warehouseId || 0), }; } @@ -2506,6 +2508,20 @@ class DeliveryOrderService extends Service { const isAutoAllocateExpressEnabled = !isCutoffActive && !needApproval && this.normalizePolicyFlag(policyConfig.auto_allocate_express); const isAutoAllocateStorageEnabled = !isCutoffActive && !needApproval && this.normalizePolicyFlag(policyConfig.auto_allocate_storage); + // 记录开关判定结果,便于排查自动分配快递/储位未触发的问题 + this.ctx.logger.info('[DeliveryOrderService.asyncProcessOrderCreated] 自动流程开关判定', { + warehouseId: context.warehouseId, + orderId: context.orderId, + storeId: context.storeId, + cutoffEnabled, + isCutoffActive, + needApproval, + autoAllocateExpressFlag: policyConfig && policyConfig.auto_allocate_express, + autoAllocateStorageFlag: policyConfig && policyConfig.auto_allocate_storage, + isAutoAllocateExpressEnabled, + isAutoAllocateStorageEnabled, + }); + if (isAutoAllocateExpressEnabled) { await this.runAsyncProcessStep('allocateExpress', async () => { const request = this.buildExpressAllocateRequest(context); diff --git a/app/service/systems/order_storage_allocation.js b/app/service/systems/order_storage_allocation.js index ce26e4d..f0e3f31 100644 --- a/app/service/systems/order_storage_allocation.js +++ b/app/service/systems/order_storage_allocation.js @@ -479,7 +479,14 @@ class OrderStorageAllocationService extends MainService { const progressCallback = typeof requestData.progress_callback === 'function' ? requestData.progress_callback : null; - const warehouseId = toNumber(ctx.user?.store_id ?? ctx.user?.warehouse_id, 0); + // 优先使用调用方显式传入的仓库ID(Qimen 等无登录用户上下文的链路 ctx.user 为空) + const warehouseId = toNumber( + requestData.warehouse_id + ?? requestData.warehouseId + ?? ctx.user?.store_id + ?? ctx.user?.warehouse_id, + 0 + ); const orderIds = normalizeOrderIds(requestData); const allowStorageLocation = normalizeBooleanFlag( requestData.allow_storage_location