From 9894e15ccdc45a4d43b26e91f8d05625b6163bd0 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Fri, 21 Aug 2026 22:56:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(express-policy):=20=E8=BF=9D=E7=A6=81?= =?UTF-8?q?=E5=93=81=E7=AD=96=E7=95=A5=E6=97=A0=E6=B3=95=E5=91=BD=E4=B8=AD?= =?UTF-8?q?=E2=80=94=E2=80=94=E8=AE=A2=E5=8D=95=E5=88=9B=E5=BB=BA=E6=97=B6?= =?UTF-8?q?=E8=81=9A=E5=90=88=E5=95=86=E5=93=81=E8=BF=9D=E7=A6=81=E5=93=81?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=8F=82=E4=B8=8E=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - addOrderLines 批量查询 StockWarehouse 增加 prohibited_id 字段并聚合去重 - itemsInfo 返回 prohibited_type_ids,matchPolicy 由写死 null 改为传入真实值 - 修复限定违禁品类型的快递策略此前永远被跳过、订单降级默认快递的问题 --- app/service/systems/delivery_order.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/service/systems/delivery_order.js b/app/service/systems/delivery_order.js index a893e93..7d1110f 100644 --- a/app/service/systems/delivery_order.js +++ b/app/service/systems/delivery_order.js @@ -830,7 +830,10 @@ class DeliveryOrderService extends Service { customShopName: shopNick || '', address: address || '', weight: itemsInfo.total_weight || null, - prohibitedTypeIds: null, // TODO: 后续从商品 StockWarehouse.prohibited_id 聚合 + // 从订单商品聚合的违禁品类型ID(StockWarehouse.prohibited_id 去重) + prohibitedTypeIds: itemsInfo && Array.isArray(itemsInfo.prohibited_type_ids) + ? itemsInfo.prohibited_type_ids + : null, } ); @@ -1345,7 +1348,7 @@ class DeliveryOrderService extends Service { enableExternalExpressCode, }, operationLogs); const resolvedOperatorName = await this.resolveOperatorName(operatorName, createChannel, info); - + const fromKey = this.normalizeOrderFromKey(info.appKey); return { delivery_order_code: deliveryOrderCode, pre_delivery_order_code: preDeliveryOrderCode || '', @@ -1405,7 +1408,7 @@ class DeliveryOrderService extends Service { extend_props: requestExtendProps || null, store_id: info.storeId, warehouse_id: info.warehouseId, - from_key: this.normalizeOrderFromKey(info.appKey), + from_key: fromKey, }; } @@ -1547,13 +1550,14 @@ class DeliveryOrderService extends Service { // ===== Sort: 按 stockId 升序排序,保证所有事务加锁顺序一致,从根本上消除死锁 ===== resolvedItems.sort((a, b) => a.stockId - b.stockId); - // ===== 批量查询 wms_stock_warehouse 获取仓库侧称重毛重 ===== + // ===== 批量查询 wms_stock_warehouse 获取仓库侧称重毛重 & 违禁品类型 ===== const stockIds = [ ...new Set(resolvedItems.map(item => item.stockId).filter(Boolean)) ]; const warehouseWeightMap = new Map(); + const stockProhibitedMap = new Map(); // stock_id -> 违禁品类型ID if (stockIds.length > 0) { const warehouseRecords = await app.model.StockWarehouse.findAll({ where: { id: stockIds }, - attributes: [ 'id', 'gross_weight' ], + attributes: [ 'id', 'gross_weight', 'prohibited_id' ], transaction, raw: true, }); @@ -1562,6 +1566,10 @@ class DeliveryOrderService extends Service { if (gw > 0) { warehouseWeightMap.set(record.id, gw); } + const prohibitedId = Number(record.prohibited_id) || 0; + if (prohibitedId > 0) { + stockProhibitedMap.set(record.id, prohibitedId); + } } } @@ -1705,6 +1713,7 @@ class DeliveryOrderService extends Service { stock_quantity_map: Object.fromEntries(stockQuantityMap), // stock_id -> 数量 stock_weight_map: Object.fromEntries(stockWeightMap), // stock_id -> 单件重量 line_data: lineData, // 创建的明细数据 + prohibited_type_ids: [ ...new Set(stockProhibitedMap.values()) ], // 违禁品类型ID去重数组(快递策略匹配用) stats: { // 统计信息汇总 unique_items: stock_count, total_items: item_total_count,