fix(consignment): 修复寄售仓库无法搜索供货打手

This commit is contained in:
yml2213
2026-11-04 21:30:50 +08:00
parent 3a557e8bda
commit 517d763f17
2 changed files with 54 additions and 3 deletions
@@ -21,6 +21,39 @@ test('寄卖仓库按关键字搜索必须能搜到"寄卖单号"(SUB…),
)
})
test('寄卖仓库搜索必须覆盖供货打手姓名、打手电话与页面展示的卖家电话', async () => {
const source = await readFile(new URL('./consignment-repo.ts', import.meta.url), 'utf8')
const inventoryListStart = source.indexOf('export async function listConsignmentInventories')
const inventoryListBody = source.slice(
inventoryListStart,
source.indexOf('\n}\n', inventoryListStart),
)
for (const field of [
'ci.worker_name',
'ci.worker_phone',
'ci.seller_phone',
'cs.worker_name',
'cs.worker_phone',
'cs.seller_phone',
'supplier_worker.display_name',
'supplier_worker.phone',
]) {
assert.ok(inventoryListBody.includes(field), `寄售仓库搜索缺少字段:${field}`)
}
const countSqlLine = inventoryListBody
.split('\n')
.find((line) =>
line.includes('SELECT COUNT(*)::integer AS total FROM consignment_inventories ci'),
)
assert.ok(countSqlLine, '未找到寄售仓库计数 SQL')
assert.ok(
countSqlLine!.includes('LEFT JOIN worker_users supplier_worker'),
'计数 SQL 缺少供货打手 join,按姓名/电话搜索会报错',
)
})
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')
@@ -181,13 +181,30 @@ export async function listConsignmentInventories(filters: {
if (filters.keyword) {
values.push(`%${filters.keyword.trim()}%`)
conditions.push(
`(ci.item_name ILIKE $${values.length} OR ci.inventory_no ILIKE $${values.length} OR ci.bound_platform_order_id ILIKE $${values.length} OR ci.seller_contact ILIKE $${values.length} OR ci.seller_game_id ILIKE $${values.length} OR ci.seller_payment_info ILIKE $${values.length} OR ci.remark ILIKE $${values.length} OR cs.submission_no ILIKE $${values.length} OR ccs.name ILIKE $${values.length})`,
`(ci.item_name ILIKE $${values.length}
OR ci.inventory_no ILIKE $${values.length}
OR ci.bound_platform_order_id ILIKE $${values.length}
OR ci.seller_contact ILIKE $${values.length}
OR ci.seller_game_id ILIKE $${values.length}
OR ci.seller_phone ILIKE $${values.length}
OR ci.seller_payment_info ILIKE $${values.length}
OR ci.worker_name ILIKE $${values.length}
OR ci.worker_phone ILIKE $${values.length}
OR ci.remark ILIKE $${values.length}
OR cs.submission_no ILIKE $${values.length}
OR cs.seller_phone ILIKE $${values.length}
OR cs.worker_name ILIKE $${values.length}
OR cs.worker_phone ILIKE $${values.length}
OR supplier_worker.display_name ILIKE $${values.length}
OR supplier_worker.username ILIKE $${values.length}
OR supplier_worker.phone ILIKE $${values.length}
OR ccs.name ILIKE $${values.length})`,
)
}
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''
// 计数也要带上提报单 / 对接客服 join:关键字现在包含 cs.submission_no 与 ccs.name
const countSql = `SELECT COUNT(*)::integer AS total FROM consignment_inventories ci LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id LEFT JOIN consignment_contact_supporters ccs ON ccs.id = ci.contact_supporter_id ${whereClause}`
// 计数与列表必须使用同一组 join,否则新增的提报单 / 供货打手关键字会直接报错。
const countSql = `SELECT COUNT(*)::integer AS total FROM consignment_inventories ci LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id LEFT JOIN worker_users supplier_worker ON supplier_worker.id = ci.worker_id LEFT JOIN consignment_contact_supporters ccs ON ccs.id = ci.contact_supporter_id ${whereClause}`
const countRes = await query<{ total: number }>(countSql, values)
const total = countRes.rows[0]?.total || 0
@@ -213,6 +230,7 @@ export async function listConsignmentInventories(filters: {
FROM consignment_inventories ci
LEFT JOIN work_categories wc ON wc.id = ci.category_id
LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id
LEFT JOIN worker_users supplier_worker ON supplier_worker.id = ci.worker_id
LEFT JOIN consignment_contact_supporters ccs ON ccs.id = ci.contact_supporter_id
LEFT JOIN work_orders wo ON wo.id = ci.bound_work_order_id
${whereClause}