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