feat(finance): 下单入口补内部 SKU,卡券/人工按商品能力兜底

- 纯数字/空内部 SKU 入口查 internal_sku_mappings,补 spec.skuNick
- 快照记录 internalSku/source,便于审计
- 财务 channel_assign 对卡券/人工使用商品渠道能力兜底(source=auto_mapping)
- 自动发货/接单仍要求真实任务/工单载体,避免只改口径
This commit is contained in:
yml2213
2026-11-02 13:52:40 +08:00
parent a501f9f2e0
commit 531a23d78b
4 changed files with 94 additions and 1 deletions
@@ -63,6 +63,7 @@ export type ChannelCandidateItem = {
normalized_sku_name: string | null
has_work_order: boolean
has_affiliate_task: boolean
capability_channel: FulfillmentChannel | null
basis_date: string
}
@@ -144,6 +145,18 @@ export function resolveChannelDecision(
}
}
// 卡券/人工没有必须创建的履约任务,可直接用商品渠道能力兜底;
// 自动发货/接单平台仍要求真实载体,避免只改口径不派单。
if (item.capability_channel === 'third_party_voucher' || item.capability_channel === 'manual') {
return {
channel: item.capability_channel,
source: 'auto_mapping',
conflict: false,
conflictChannels: [],
matchedRuleIds: [],
}
}
return { channel: null, source: '', conflict: false, conflictChannels: [], matchedRuleIds: [] }
}
@@ -208,9 +221,28 @@ export async function assignPendingOrderItemChannels(
EXISTS (
SELECT 1 FROM fulfillment_tasks ft
WHERE ft.order_item_id = oi.id AND ft.executor_key = 'affiliate_dash'
) AS has_affiliate_task
) AS has_affiliate_task,
cap.channel AS capability_channel
FROM order_items oi
JOIN orders o ON o.id = oi.order_id
LEFT JOIN LATERAL (
SELECT c.channel
FROM product_catalog p
JOIN product_channel_capabilities c
ON c.product_id = p.id AND c.enabled = TRUE
WHERE p.status = 'active'
AND btrim(p.canonical_name) = ${INTERNAL_SKU_SQL}
ORDER BY
CASE c.channel
WHEN 'affiliate_dash' THEN 1
WHEN 'work_order' THEN 2
WHEN 'third_party_voucher' THEN 3
WHEN 'manual' THEN 4
ELSE 9
END,
c.priority ASC
LIMIT 1
) cap ON TRUE
WHERE oi.fulfillment_status = 'pending'
AND oi.fulfillment_locked = FALSE
AND oi.id > $1