fix(finance): 收敛内部 SKU 履约路由与载体状态
统一内部 SKU 与渠道主/兜底解析,禁止并列主渠道。 运营指定渠道改为先创建真实载体,失败保持明确 pending。 历史缺载体、多载体冲突和自动发货兜底统一由管道修复。 迁移人工配置与旧 sku_code 规则,补充严格预检和集成测试。
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
type ChannelCandidateItem,
|
||||
type ChannelRule,
|
||||
} from './channel-assign-service.js'
|
||||
import type { InternalSkuChannelRow } from './internal-sku-channel-service.js'
|
||||
|
||||
function buildItem(patch: Partial<ChannelCandidateItem> = {}): ChannelCandidateItem {
|
||||
return {
|
||||
@@ -20,12 +21,26 @@ function buildItem(patch: Partial<ChannelCandidateItem> = {}): ChannelCandidateI
|
||||
has_work_order: false,
|
||||
has_affiliate_task: false,
|
||||
has_manual_task: false,
|
||||
capability_channel: null,
|
||||
channels: [],
|
||||
basis_date: '2026-10-31',
|
||||
...patch,
|
||||
}
|
||||
}
|
||||
|
||||
function buildChannel(patch: Partial<InternalSkuChannelRow> = {}): InternalSkuChannelRow {
|
||||
return {
|
||||
internal_sku: '套装-测试',
|
||||
channel: 'manual',
|
||||
priority: 10,
|
||||
is_fallback: false,
|
||||
enabled: true,
|
||||
canonical_product_id: null,
|
||||
config_json: {},
|
||||
source: 'test',
|
||||
...patch,
|
||||
}
|
||||
}
|
||||
|
||||
function buildRule(patch: Partial<ChannelRule> = {}): ChannelRule {
|
||||
return {
|
||||
id: 1,
|
||||
@@ -40,13 +55,13 @@ function buildRule(patch: Partial<ChannelRule> = {}): ChannelRule {
|
||||
}
|
||||
}
|
||||
|
||||
test('渠道判定:精确 SKU 规则优先于载体证据', () => {
|
||||
test('渠道判定:真实载体优先于冲突的旧规则', () => {
|
||||
const decision = resolveChannelDecision(buildItem({ has_work_order: true }), [
|
||||
buildRule({ channel: 'third_party_voucher', priority: 10 }),
|
||||
])
|
||||
|
||||
assert.equal(decision.channel, 'third_party_voucher')
|
||||
assert.equal(decision.source, 'auto_rule')
|
||||
assert.equal(decision.channel, 'work_order')
|
||||
assert.equal(decision.source, 'carrier_evidence')
|
||||
assert.equal(decision.conflict, false)
|
||||
})
|
||||
|
||||
@@ -79,19 +94,19 @@ test('渠道判定:同优先级多渠道判为冲突,不静默选择', () =>
|
||||
|
||||
test('渠道判定:不同优先级时取优先级更小的', () => {
|
||||
const decision = resolveChannelDecision(buildItem(), [
|
||||
buildRule({ id: 1, channel: 'affiliate_dash', priority: 60 }),
|
||||
buildRule({ id: 1, channel: 'third_party_voucher', priority: 60 }),
|
||||
buildRule({ id: 2, channel: 'manual', priority: 70 }),
|
||||
])
|
||||
|
||||
assert.equal(decision.channel, 'affiliate_dash')
|
||||
assert.equal(decision.channel, 'third_party_voucher')
|
||||
})
|
||||
|
||||
test('渠道判定:provider / shop 限定生效,空串表示不限', () => {
|
||||
const scoped = buildRule({ provider: 'pdd', shop_id: 'shop-b' })
|
||||
assert.equal(resolveChannelDecision(buildItem(), [scoped]).channel, null)
|
||||
|
||||
const wide = buildRule({ provider: '', shop_id: '' })
|
||||
assert.equal(resolveChannelDecision(buildItem(), [wide]).channel, 'affiliate_dash')
|
||||
const wide = buildRule({ provider: '', shop_id: '', channel: 'third_party_voucher' })
|
||||
assert.equal(resolveChannelDecision(buildItem(), [wide]).channel, 'third_party_voucher')
|
||||
})
|
||||
|
||||
test('渠道判定:内部 SKU 与 SKU 名称两种键都能命中', () => {
|
||||
@@ -125,23 +140,50 @@ test('渠道判定:停用的规则不参与', () => {
|
||||
|
||||
test('渠道判定:卡券/人工能力可兜底,自动发货/接单必须靠载体', () => {
|
||||
const voucher = resolveChannelDecision(
|
||||
buildItem({ capability_channel: 'third_party_voucher' }),
|
||||
buildItem({ channels: [buildChannel({ channel: 'third_party_voucher' })] }),
|
||||
[],
|
||||
)
|
||||
assert.equal(voucher.channel, 'third_party_voucher')
|
||||
assert.equal(voucher.source, 'auto_mapping')
|
||||
|
||||
const manual = resolveChannelDecision(buildItem({ capability_channel: 'manual' }), [])
|
||||
const manual = resolveChannelDecision(buildItem({ channels: [buildChannel()] }), [])
|
||||
assert.equal(manual.channel, 'manual')
|
||||
assert.equal(manual.source, 'auto_mapping')
|
||||
|
||||
const affiliate = resolveChannelDecision(buildItem({ capability_channel: 'affiliate_dash' }), [])
|
||||
const affiliate = resolveChannelDecision(
|
||||
buildItem({ channels: [buildChannel({ channel: 'affiliate_dash' })] }),
|
||||
[],
|
||||
)
|
||||
assert.equal(affiliate.channel, null, '自动发货能力没有任务时不能只改财务口径')
|
||||
|
||||
const workOrder = resolveChannelDecision(buildItem({ capability_channel: 'work_order' }), [])
|
||||
const workOrder = resolveChannelDecision(
|
||||
buildItem({ channels: [buildChannel({ channel: 'work_order' })] }),
|
||||
[],
|
||||
)
|
||||
assert.equal(workOrder.channel, null, '接单能力没有工单时不能只改财务口径')
|
||||
})
|
||||
|
||||
test('渠道判定:内部 SKU 配置优先于旧 sku_code 规则', () => {
|
||||
const decision = resolveChannelDecision(
|
||||
buildItem({ channels: [buildChannel({ channel: 'third_party_voucher' })] }),
|
||||
[buildRule({ channel: 'manual' })],
|
||||
)
|
||||
assert.equal(decision.channel, 'third_party_voucher')
|
||||
assert.equal(decision.source, 'auto_mapping')
|
||||
})
|
||||
|
||||
test('渠道判定:内部 SKU 同级多渠道判为冲突', () => {
|
||||
const decision = resolveChannelDecision(
|
||||
buildItem({
|
||||
channels: [buildChannel({ channel: 'work_order' }), buildChannel({ channel: 'manual' })],
|
||||
}),
|
||||
[],
|
||||
)
|
||||
assert.equal(decision.channel, null)
|
||||
assert.equal(decision.conflict, true)
|
||||
assert.deepEqual(decision.conflictChannels.sort(), ['manual', 'work_order'])
|
||||
})
|
||||
|
||||
test('渠道判定:人工任务作为人工载体证据', () => {
|
||||
const decision = resolveChannelDecision(buildItem({ has_manual_task: true }), [])
|
||||
assert.equal(decision.channel, 'manual')
|
||||
|
||||
Reference in New Issue
Block a user