fix(pdd): 无店铺上下文时跳过快手结构化匹配,按模板名/out_sku_sn 命中

模板残留的 match_json.sellerId 等字段会让拼多多订单误入结构化分支并直接未命中;仅快手有 sellerId 时才走该路径。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
yml2213
2026-09-15 11:18:27 +08:00
co-authored by Cursor
parent 30b547cbbe
commit d09cce5050
2 changed files with 39 additions and 1 deletions
@@ -270,7 +270,10 @@ function scoreWorkProductRule(order: OrderRow, item: OrderItemRow, rule: WorkPro
!['itemTitleMatchType', 'skuNickMatchType'].includes(key) && String(value || '').trim(),
)
if (hasStructuredMatch) {
// 结构化 match_json(sellerId/skuNick 等)是快手发码路径;拼多多等无店铺上下文的订单
// 若误入该分支,常因缺 sellerId 直接失败,且不会回退到模板名/out_sku_sn。
// 仅当订单带有店铺上下文时才走结构化匹配。
if (hasStructuredMatch && context.sellerId) {
let score = 100
if (!matchCondition(context.sellerId, match.sellerId)) return null
if (match.sellerId) score += 1000
@@ -631,6 +631,41 @@ test('拼多多订单在结构化 match_json 下仍可用 out_sku_sn 命中', ()
assert.equal(decision.rule?.id, rule.id)
})
test('拼多多订单忽略模板残留的快手结构化 match_json,按 out_sku_sn 命中模板名', () => {
const rule = buildProductRule({
provider: '',
platform: '',
product_name: '安卓怒嚎1钻',
match_type: 'contains',
// 历史保存残留的快手字段:若强制走结构化会因缺 sellerId 直接未命中
match_json: {
sellerId: '2174663396',
relItemId: '961856378217',
skuNick: '安卓怒嚎1钻',
skuNickMatchType: 'exact',
},
})
const order = { ...buildOrderRow(), provider: 'pdd', platform: 'pdd', shop_id: 'pdd_shop_1' }
const item = {
...buildOrderItemRow(),
sku_code: '安卓怒嚎1钻',
sku_name: '安卓怒嚎1钻',
item_snapshot_json: {
goodsId: '961856378217',
goods_id: '961856378217',
spec: '安卓区(qv互通),苏尔南-怒嚎1钻',
outSkuSn: '安卓怒嚎1钻',
out_sku_sn: '安卓怒嚎1钻',
},
}
const decision = resolveMatchingProductRuleDecision(order, item, [rule], [], {
legacyFallbackEnabled: false,
})
assert.equal(decision.reason, 'matched')
assert.equal(decision.rule?.id, rule.id)
})
test('拼多多订单缺少 out_sku_sn 且 spec 不含规则名时不命中', () => {
const rule = buildProductRule({
provider: 'pdd',