fix(consignment): 打通寄卖权限鉴权、指派占库竞态与撤销守卫
- 后台权限白名单补齐 consignment.view/manage/review/fulfill, 避免在「角色权限」页保存任意角色时静默清除寄卖权限 - 寄卖后台 19 个接口由 requireAdminRoles 改为 requireAdminPermission, 使 view/manage/review/fulfill 四个权限真正生效 - 指派打手履约改为先原子占库(WHERE status = 'in_stock'), 失败自动回滚库存,消除并发下同一件现货被两张工单同时认领 - 撤销寄售履约拒绝押金履约模式(worker_deposit), 避免打手押金不释放造成资金挂账;前端同步隐藏该入口 - 撤销回库不再强制覆盖 allow_matching,保留运营手动关闭的匹配开关 - 新增 4 个回归测试:权限白名单与迁移一致性、占库/回滚条件、撤销守卫
This commit is contained in:
@@ -542,6 +542,81 @@ export async function updateConsignmentInventory(
|
||||
return res.rows[0] || null
|
||||
}
|
||||
|
||||
/**
|
||||
* 以“条件更新”方式原子占用在库物品(指派打手押金履约)。
|
||||
*
|
||||
* 必须在指派打手之前调用:并发下只有一个调用能拿到 `status = 'in_stock'` 的那一行,
|
||||
* 避免同一件现货被两张工单同时认领。
|
||||
* 返回 null 表示物品已被其他操作占用。
|
||||
*/
|
||||
export async function claimConsignmentInventoryForWorkerWithClient(
|
||||
client: PoolClient,
|
||||
id: number | string,
|
||||
input: { workerId: number; now: string; allocationStatus?: string },
|
||||
): Promise<ConsignmentInventoryRow | null> {
|
||||
const res = await client.query<ConsignmentInventoryRow>(
|
||||
`
|
||||
UPDATE consignment_inventories
|
||||
SET
|
||||
status = 'consumed',
|
||||
allocation_status = $1,
|
||||
worker_id = $2,
|
||||
consumed_at = $3,
|
||||
updated_at = $3
|
||||
WHERE id = $4 AND status = 'in_stock'
|
||||
RETURNING *
|
||||
`,
|
||||
[input.allocationStatus || '已指派打手(押金履约中)', input.workerId, input.now, id],
|
||||
)
|
||||
return res.rows[0] || null
|
||||
}
|
||||
|
||||
export async function claimConsignmentInventoryForWorker(
|
||||
id: number | string,
|
||||
input: { workerId: number; now: string; allocationStatus?: string },
|
||||
): Promise<ConsignmentInventoryRow | null> {
|
||||
return withTransaction((client) =>
|
||||
claimConsignmentInventoryForWorkerWithClient(client, id, input),
|
||||
)
|
||||
}
|
||||
|
||||
export async function releaseConsignmentInventoryClaimWithClient(
|
||||
client: PoolClient,
|
||||
id: number | string,
|
||||
input: { now: string; reason?: string },
|
||||
): Promise<ConsignmentInventoryRow | null> {
|
||||
const res = await client.query<ConsignmentInventoryRow>(
|
||||
`
|
||||
UPDATE consignment_inventories
|
||||
SET
|
||||
status = 'in_stock',
|
||||
allocation_status = '待安排',
|
||||
worker_id = NULL,
|
||||
bound_order_id = NULL,
|
||||
bound_work_order_id = NULL,
|
||||
bound_platform_order_id = '',
|
||||
shop_name = '',
|
||||
consumed_at = NULL,
|
||||
remark = CASE
|
||||
WHEN $2 = '' THEN remark
|
||||
ELSE remark || ' [指派回滚: ' || $2 || ']'
|
||||
END,
|
||||
updated_at = $1
|
||||
WHERE id = $3 AND status = 'consumed'
|
||||
RETURNING *
|
||||
`,
|
||||
[input.now, input.reason || '', id],
|
||||
)
|
||||
return res.rows[0] || null
|
||||
}
|
||||
|
||||
export async function releaseConsignmentInventoryClaim(
|
||||
id: number | string,
|
||||
input: { now: string; reason?: string },
|
||||
): Promise<ConsignmentInventoryRow | null> {
|
||||
return withTransaction((client) => releaseConsignmentInventoryClaimWithClient(client, id, input))
|
||||
}
|
||||
|
||||
export async function archiveConsignmentInventoryWithClient(
|
||||
client: PoolClient,
|
||||
id: number | string,
|
||||
|
||||
Reference in New Issue
Block a user