feat(finance): 商品渠道能力、自动发货转人工与成本异常收口

- 商品可同时支持自动发货/人工,新增渠道能力与成本冲销字段
- 卡券缺商品时按内部中文 SKU 自动建 tpv: 商品并补渠道规则
- 自动发货失败转人工并冲销原渠道成本
- 配置成本后按最早缺失订单生效并立即补算、关闭异常
- tpv: 商品来源计入第三方卡券
This commit is contained in:
yml2213
2026-11-02 13:17:15 +08:00
parent 86b5347e40
commit 3c4c81003f
16 changed files with 532 additions and 34 deletions
@@ -177,7 +177,7 @@ export async function createAdminCostSnapshot(payload: JsonObject = {}, _session
WHERE subject_type = 'order_item'
AND subject_id = $1
AND cost_item_id = $2
AND superseded_at IS NULL
AND superseded_at IS NULL AND reversed_at IS NULL
FOR UPDATE
`,
[orderItemId, line.costItemId],
@@ -194,7 +194,7 @@ export async function createAdminCostSnapshot(payload: JsonObject = {}, _session
continue
}
await client.query(
`UPDATE cost_snapshots SET superseded_at = $1 WHERE id = $2 AND superseded_at IS NULL`,
`UPDATE cost_snapshots SET superseded_at = $1 WHERE id = $2 AND superseded_at IS NULL AND reversed_at IS NULL`,
[now, current.id],
)
supersededCount += 1
@@ -212,7 +212,7 @@ export async function createAdminCostSnapshot(payload: JsonObject = {}, _session
$7, $8, $9, $10, 'resolved', $11::jsonb, $12, $13, $13
)
ON CONFLICT (subject_type, subject_id, cost_item_id)
WHERE superseded_at IS NULL
WHERE superseded_at IS NULL AND reversed_at IS NULL
DO NOTHING
RETURNING *
`,