merge: 合并 dev_match 寄卖匹配看板改造到 dev

# Conflicts:
#	apps/backend/src/services/worker-platform/consignment-matching.integration.test.ts
This commit is contained in:
2026-11-12 15:35:01 +08:00
18 changed files with 961 additions and 758 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)