From a6d67a17fe161890b63b01118af088407c1974ee Mon Sep 17 00:00:00 2001 From: liufumingren Date: Wed, 26 Aug 2026 17:24:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(order):=20=E5=BF=AB=E9=80=92=E7=AD=96?= =?UTF-8?q?=E7=95=A5=E6=BC=8F=E6=96=97=E6=94=AF=E6=8C=81=E5=A4=96=E9=83=A8?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E5=BC=80=E5=90=AF=E6=97=B6=E4=BB=85=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E7=BA=AF=E8=B4=A7=E4=B8=BB=E7=BB=B4=E5=BA=A6=E7=AD=96?= =?UTF-8?q?=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/systems/delivery_order.js | 26 +++++++++++---------- app/service/systems/express_policy.js | 33 +++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/app/service/systems/delivery_order.js b/app/service/systems/delivery_order.js index be919f2..8cb969c 100644 --- a/app/service/systems/delivery_order.js +++ b/app/service/systems/delivery_order.js @@ -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}` ); } } diff --git a/app/service/systems/express_policy.js b/app/service/systems/express_policy.js index 0df2b1f..19107f6 100644 --- a/app/service/systems/express_policy.js +++ b/app/service/systems/express_policy.js @@ -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} [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;