feat(consignment): 统一寄卖匹配看板口径并收口占用与重匹配

- 看板与引擎统一数量、模板规格、正向规格信号判定,纳入 internal_matching/unassigned

- 库存侧改走新引擎匹配,移除旧 /fulfill 手动入口与旧弹窗

- 验收时将 reserved allocation 收口为 consumed,补份额级收口

- 拼单重新匹配通过 material 排除全部原库存/原卖家

- 开发/测试环境放宽迁移顺序校验,生产保持严格;修正集成测试份额报酬口径
This commit is contained in:
2026-11-12 15:17:09 +08:00
parent 229eef31a8
commit e39f640dac
18 changed files with 962 additions and 759 deletions
@@ -281,6 +281,20 @@ export async function markConsignmentAllocationsConsumedWithClient(
)
}
/** 单个拼单份额验收:只收口这一份占用的库存,避免整单尚在履约时提前标记。 */
export async function markConsignmentAllocationConsumedForShareWithClient(
client: PoolClient,
shareId: number,
now: string,
): Promise<void> {
await client.query(
`UPDATE consignment_inventory_allocations
SET status = 'consumed', updated_at = $1
WHERE work_order_share_id = $2 AND status = 'reserved'`,
[now, shareId],
)
}
/**
* 一条库存当前的有效占用(一库存可拆给多张订单)。
* 卖家操作必须据此定位具体订单/份额,不能再只看 bound_work_order_id。
@@ -30,6 +30,8 @@ import {
settleConsignmentSupplierPayoutByWorkOrderWithClient,
} from './consignment-deposit-repo.js'
import {
markConsignmentAllocationConsumedForShareWithClient,
markConsignmentAllocationsConsumedWithClient,
releaseConsignmentAllocationForShareWithClient,
releaseConsignmentAllocationsForWorkOrderWithClient,
} from './consignment-allocation-repo.js'
@@ -240,6 +242,9 @@ export async function acceptWorkOrderAndSettle(input: {
now: input.now,
})
}
// 验收即交付完成:占用从 reserved 收口为 consumed,
// 否则卖家端会一直显示「占用中」,售后释放路径也可能把已交付的货退回可匹配池。
await markConsignmentAllocationsConsumedWithClient(client, input.workOrderId, input.now)
if (shares.length > 0) {
// 单独验收过的份额已经完成资金结算,统一验收时只处理尚未结算的份额。
@@ -787,6 +792,8 @@ export async function acceptWorkOrderShareAndSettle(input: {
`UPDATE work_order_shares SET status = 'accepted', accepted_at = $1, updated_at = $1 WHERE id = $2`,
[input.now, input.shareId],
)
// 份额验收即这一份交付完成:只收口该份额的占用,母单剩余份额仍按 reserved 统计。
await markConsignmentAllocationConsumedForShareWithClient(client, input.shareId, input.now)
if (workerId > 0) {
// 等级升级要跑全量已验收订单计数,挪到事务提交后执行,避免拖垮验收事务。
upgradeWorkerIds.push(workerId)