From 517d763f1719dd138ece670c6c1194e422c23884 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Wed, 4 Nov 2026 21:30:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(consignment):=20=E4=BF=AE=E5=A4=8D=E5=AF=84?= =?UTF-8?q?=E5=94=AE=E4=BB=93=E5=BA=93=E6=97=A0=E6=B3=95=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E4=BE=9B=E8=B4=A7=E6=89=93=E6=89=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worker-platform/consignment-repo.test.ts | 33 +++++++++++++++++++ .../worker-platform/consignment-repo.ts | 24 ++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/apps/backend/src/repositories/worker-platform/consignment-repo.test.ts b/apps/backend/src/repositories/worker-platform/consignment-repo.test.ts index 1f36ce65..c3a4ac3a 100644 --- a/apps/backend/src/repositories/worker-platform/consignment-repo.test.ts +++ b/apps/backend/src/repositories/worker-platform/consignment-repo.test.ts @@ -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') diff --git a/apps/backend/src/repositories/worker-platform/consignment-repo.ts b/apps/backend/src/repositories/worker-platform/consignment-repo.ts index 221bc013..bf3c41a8 100644 --- a/apps/backend/src/repositories/worker-platform/consignment-repo.ts +++ b/apps/backend/src/repositories/worker-platform/consignment-repo.ts @@ -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}