fix(consignment): 匹配弹窗改用寄卖单号,客服界面不再展示内部仓库号
问题:内部寄售库存匹配弹窗显示的是「寄卖单号 INV26091711253394」——候选现货走的 是另一个查询 listActiveConsignmentInventoriesForMatching,它没 join 提报单, sourceSubmissionNo 取不到,前端就回退显示内部仓库号;客服拿这个号去寄卖仓库又搜不到。 - 匹配候选查询补 LEFT JOIN consignment_submissions 带出 source_submission_no; 该查询原本是 SELECT * 且列名无前缀,而 consignment_submissions 同样有 status/game_name/category_id,加 join 会让条件变成 ambiguous column 直接 500, 故列名统一加 ci. 前缀并显式列字段(加静态守卫测试钉住) - 客服界面只展示寄卖单号:匹配弹窗候选卡片、工单寄售标识、工单详情、寄卖仓库列表与详情 全部去掉内部仓库号;手工入库现货写「客服手工入库(无提报单号)」, 历史老单写「老单无提报单号」,不再抛内部编号 - 内部仓库号保留:数据/接口/按它搜索都还在,撤销解绑等链路未动 真实库验证:仓库层候选查询与 checkWorkOrderInventoryMatches 都带出了寄卖单号。临时数据已清理。
This commit is contained in:
@@ -18,3 +18,22 @@ test('寄卖仓库按关键字搜索必须能搜到"寄卖单号"(SUB…),
|
||||
'计数 SQL 缺少提报单 join,会导致按寄卖单号搜索时报 500',
|
||||
)
|
||||
})
|
||||
|
||||
test('匹配候选要带出寄卖单号,并且 join 之后所有列名都必须加 ci. 前缀', async () => {
|
||||
const source = await readFile(new URL('./consignment-repo.ts', import.meta.url), 'utf8')
|
||||
const start = source.indexOf('export async function listActiveConsignmentInventoriesForMatching')
|
||||
assert.ok(start > 0, '未找到匹配候选查询')
|
||||
const body = source.slice(start, source.indexOf('\n}\n', start))
|
||||
|
||||
// 客服界面只展示寄卖单号(SUB…),候选里必须带出来,否则又回退显示内部仓库号
|
||||
assert.ok(body.includes('cs.submission_no AS source_submission_no'))
|
||||
assert.ok(body.includes('LEFT JOIN consignment_submissions cs'))
|
||||
// consignment_submissions 也有 status/game_name/category_id:不加前缀会 ambiguous column 直接 500
|
||||
assert.ok(
|
||||
!/WHERE[^`]*[^.]\bstatus = /.test(body.replace(/ci\.status/g, 'X')),
|
||||
'存在未加前缀的 status',
|
||||
)
|
||||
assert.ok(body.includes("ci.status = 'in_stock'"))
|
||||
assert.ok(body.includes('ci.allow_matching = TRUE'))
|
||||
assert.ok(!body.includes('SELECT *'), 'SELECT * 会把两表同名列搞乱,必须显式列出')
|
||||
})
|
||||
|
||||
@@ -902,23 +902,29 @@ export async function listActiveConsignmentInventoriesForMatching(options?: {
|
||||
gameName?: string
|
||||
categoryId?: number | null
|
||||
}): Promise<ConsignmentInventoryRow[]> {
|
||||
const conditions: string[] = ["status = 'in_stock'", 'allow_matching = TRUE']
|
||||
// 客服看到的匹配候选要显示「寄卖单号」(提报单号),所以必须带出提报单号;
|
||||
// 注意列名一律加 ci. 前缀:consignment_submissions 也有 status/game_name/category_id,
|
||||
// 加了 join 之后不加前缀会直接撞成 ambiguous column。
|
||||
const conditions: string[] = ["ci.status = 'in_stock'", 'ci.allow_matching = TRUE']
|
||||
const values: unknown[] = []
|
||||
|
||||
if (options?.gameName) {
|
||||
values.push(options.gameName)
|
||||
conditions.push(`game_name = $${values.length}`)
|
||||
conditions.push(`ci.game_name = $${values.length}`)
|
||||
}
|
||||
if (options?.categoryId) {
|
||||
values.push(options.categoryId)
|
||||
conditions.push(`category_id = $${values.length}`)
|
||||
conditions.push(`ci.category_id = $${values.length}`)
|
||||
}
|
||||
|
||||
const sql = `
|
||||
SELECT *
|
||||
FROM consignment_inventories
|
||||
SELECT
|
||||
ci.*,
|
||||
cs.submission_no AS source_submission_no
|
||||
FROM consignment_inventories ci
|
||||
LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id
|
||||
WHERE ${conditions.join(' AND ')}
|
||||
ORDER BY id ASC
|
||||
ORDER BY ci.id ASC
|
||||
`
|
||||
const res = await query<ConsignmentInventoryRow>(sql, values)
|
||||
return res.rows
|
||||
|
||||
Reference in New Issue
Block a user