feat(order): 快递策略漏斗支持外部编码开启时仅匹配纯货主维度策略
This commit is contained in:
parent
fbd9ac2326
commit
a6d67a17fe
@ -797,22 +797,18 @@ class DeliveryOrderService extends Service {
|
||||
};
|
||||
|
||||
// ===== 快递绑定策略漏斗匹配(items 处理后 weight 可用) =====
|
||||
// enable_external_express_code 开启时以外部快递匹配结果为准(匹配不到已在 resolveExpressSnapshot 兜底默认快递),跳过策略漏斗覆盖
|
||||
// enable_external_express_code 开启时仅"纯货主维度"策略参与漏斗,命中后覆盖外部快递匹配结果;
|
||||
// 关闭时全维度策略参与,沿用原有逻辑
|
||||
try {
|
||||
const funnelPolicyConfig = await this.getStoreWarehousePolicyConfig(info.storeId, info.warehouseId);
|
||||
const enableExternalExpressCode = this.resolveEnableExternalExpressCode(funnelPolicyConfig, funnelPolicyConfig);
|
||||
if (enableExternalExpressCode) {
|
||||
ctx.logger.info('[ExpressPolicyMatch] enable_external_express_code 开启,跳过快递策略漏斗,保留外部快递匹配或兜底结果', {
|
||||
orderId,
|
||||
orderCode: deliveryOrder.deliveryOrderCode,
|
||||
logisticsCode: orderData.logistics_code,
|
||||
sysLogisticsCode: orderData.sys_logistics_code,
|
||||
});
|
||||
}
|
||||
const receiverInfo = deliveryOrder.receiverInfo;
|
||||
const shopNick = deliveryOrder.shopNick;
|
||||
const hasEnoughData = !enableExternalExpressCode
|
||||
&& (shopNick || (receiverInfo && (receiverInfo.province || receiverInfo.city)));
|
||||
// 外部编码开启:仅需货主ID即可参与漏斗(只匹配纯货主维度策略);
|
||||
// 外部编码关闭:需 shopNick 或收货省/市信息
|
||||
const hasEnoughData = enableExternalExpressCode
|
||||
? Boolean(info.storeId)
|
||||
: Boolean(shopNick || (receiverInfo && (receiverInfo.province || receiverInfo.city)));
|
||||
|
||||
if (hasEnoughData) {
|
||||
const address = [
|
||||
@ -834,6 +830,10 @@ class DeliveryOrderService extends Service {
|
||||
prohibitedTypeIds: itemsInfo && Array.isArray(itemsInfo.prohibited_type_ids)
|
||||
? itemsInfo.prohibited_type_ids
|
||||
: null,
|
||||
},
|
||||
{
|
||||
// 启用外部编码时仅匹配纯货主维度策略,命中后覆盖外部快递映射结果
|
||||
onlyStoreDimension: enableExternalExpressCode,
|
||||
}
|
||||
);
|
||||
|
||||
@ -904,7 +904,9 @@ class DeliveryOrderService extends Service {
|
||||
this.appendOrderOperationLog(
|
||||
operationLogs,
|
||||
ORDER_OPERATION_CODES.EXPRESS_FALLBACK,
|
||||
`未命中快递策略,使用默认快递: ${fallbackName || fallbackCode}`
|
||||
enableExternalExpressCode
|
||||
? `未命中货主快递策略,保留外部快递: ${fallbackName || fallbackCode}`
|
||||
: `未命中快递策略,使用默认快递: ${fallbackName || fallbackCode}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,6 +177,27 @@ class ExpressPolicyService extends Service {
|
||||
return policyArray.some(v => Number(v) === Number(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断策略是否为"纯货主维度"策略:
|
||||
* store_ids 非空,且 shop_name / prohibited_type_id / regions / exclude_regions / 重量区间全部未限定。
|
||||
*
|
||||
* @param {Object} policy 策略行
|
||||
* @return {boolean} 是否为纯货主策略
|
||||
*/
|
||||
_isStoreOnlyPolicy(policy = {}) {
|
||||
const asArray = v => (Array.isArray(v) ? v : []);
|
||||
if (asArray(policy.store_ids).length === 0) {
|
||||
return false;
|
||||
}
|
||||
const hasOtherDimension = asArray(policy.shop_name).length > 0
|
||||
|| asArray(policy.prohibited_type_id).length > 0
|
||||
|| asArray(policy.regions).length > 0
|
||||
|| asArray(policy.exclude_regions).length > 0
|
||||
|| (policy.min_weight_g !== null && policy.min_weight_g !== undefined)
|
||||
|| (policy.max_weight_g !== null && policy.max_weight_g !== undefined);
|
||||
return !hasOtherDimension;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按策略优先级漏斗筛选,返回命中策略的快递编码与重量段类型。
|
||||
*
|
||||
@ -195,9 +216,11 @@ class ExpressPolicyService extends Service {
|
||||
* @param {Array<number>} [params.prohibitedTypeIds] 商品违禁品类型 ID 数组
|
||||
* @param {string} [params.address] 省市区详细地址(单个字符串)
|
||||
* @param {number} [params.weight] 重量(克)
|
||||
* @return {Promise<{expressCode: string|null, weightType: number|null}>}
|
||||
* @param {Object} [options] 匹配选项
|
||||
* @param {boolean} [options.onlyStoreDimension=false] 仅匹配"纯货主维度"策略(store_ids 非空且其它维度全空)
|
||||
* @return {Promise<{expressCode: string|null, weightType: number|null}>} 命中策略的快递编码与重量段类型,未命中时 expressCode 为 null
|
||||
*/
|
||||
async matchPolicy(warehouseId, params = {}) {
|
||||
async matchPolicy(warehouseId, params = {}, options = {}) {
|
||||
const {
|
||||
storeId,
|
||||
customShopName,
|
||||
@ -205,6 +228,7 @@ class ExpressPolicyService extends Service {
|
||||
address,
|
||||
weight,
|
||||
} = params;
|
||||
const { onlyStoreDimension = false } = options;
|
||||
|
||||
const policies = await this.getWarehousePolicies(warehouseId);
|
||||
if (!Array.isArray(policies) || policies.length === 0) {
|
||||
@ -212,6 +236,11 @@ class ExpressPolicyService extends Service {
|
||||
}
|
||||
|
||||
for (const policy of policies) {
|
||||
// 0) 维度白名单:onlyStoreDimension 开启时跳过非纯货主策略
|
||||
if (onlyStoreDimension && !this._isStoreOnlyPolicy(policy)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 1) store_ids — 未限定(NULL)视为不限;否则传入 storeId 必须在范围内
|
||||
if (!this._matchValueInArray(policy.store_ids, storeId)) {
|
||||
continue;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user