fix(express-policy): 违禁品策略无法命中——订单创建时聚合商品违禁品类型参与匹配
- addOrderLines 批量查询 StockWarehouse 增加 prohibited_id 字段并聚合去重 - itemsInfo 返回 prohibited_type_ids,matchPolicy 由写死 null 改为传入真实值 - 修复限定违禁品类型的快递策略此前永远被跳过、订单降级默认快递的问题
This commit is contained in:
parent
bb676f941e
commit
9894e15ccd
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user