fix(consignment): 复核修复——占库撞 080 CHECK 必 500、指派非卖家双付货款、手动匹配权限门控

- 占库默认 allocation_status 从自由文本改为「已安排」,不再撞 080 的
  CHECK ('待安排','已安排');加静态守卫测试(剥注释断言枚举内默认值)
- resolveConsignmentAssignRewardFen 加 assigneeIsSupplier:指派供货卖家本人
  → 报酬=结算价(货款走报酬渠道);指派别的打手 → 报酬保持原值(货款走
  供货货款渠道),两条渠道互斥,封住平台双付;补行为级测试 + 调用点钉住
- 手动匹配两处入口(库存面板行内按钮、拦截弹窗 footer)统一按
  consignment.fulfill 门控,编辑/作废仍为 manage,与后端权限一一对应
- docs/寄卖系统优化方案.md 记录批次 U

后端 473(+3)/ 前端 49(+1)测试全绿,typecheck / lint / format / check:sql / build 通过
This commit is contained in:
yml2213
2026-09-17 12:36:12 +08:00
parent 0476339ec4
commit 63837e473b
8 changed files with 176 additions and 36 deletions
@@ -37,3 +37,21 @@ test('匹配候选要带出寄卖单号,并且 join 之后所有列名都必
assert.ok(body.includes('ci.allow_matching = TRUE'))
assert.ok(!body.includes('SELECT *'), 'SELECT * 会把两表同名列搞乱,必须显式列出')
})
test('占库写入的 allocation_status 默认值必须在 080 CHECK 枚举(待安排/已安排)内', async () => {
const source = await readFile(new URL('./consignment-repo.ts', import.meta.url), 'utf8')
const start = source.indexOf('export async function claimConsignmentInventoryForWorkerWithClient')
assert.ok(start > 0, '未找到打手指派占库函数')
const body = source.slice(start, source.indexOf('\n}\n', start))
// 080 给 allocation_status 加了 CHECK ('待安排','已安排')。默认值以前是一段自由文本描述,
// 真实库一占库就撞约束 500 —— 假 client 单测跑不出真 SQL,只能静态钉住。
// 先剥掉注释再断言,防止注释里引用旧值(历史说明)误伤。
const code = body.replace(/^\s*\/\/.*$/gm, '')
const match = code.match(/input\.allocationStatus \|\| '([^']+)'/)
assert.ok(match, '占库必须给 allocation_status 一个枚举内的默认值')
assert.ok(
match![1] === '待安排' || match![1] === '已安排',
`默认值「${match![1]}」违反 080 的 CHECK 约束,真实库必 500`,
)
})
@@ -495,7 +495,9 @@ export async function claimConsignmentInventoryForWorkerWithClient(
RETURNING *
`,
[
input.allocationStatus || '已指派打手(押金履约中)',
// 080 给 allocation_status 加了 CHECK ('待安排','已安排'):默认值必须是枚举内的值,
// 以前默认写「已指派打手(押金履约中)」会在真实库直接撞约束 500(假 client 单测跑不出来)。
input.allocationStatus || '已安排',
input.workerId,
input.now,
input.boundOrderId ?? null,