From a6e15f582e865c699ee317b7a714529d15ea00ba Mon Sep 17 00:00:00 2001 From: zhaoxing <2558691827@qq.com> Date: Thu, 19 Nov 2026 11:28:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(consignment):=20=E5=AF=84=E5=94=AE?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E6=96=B0=E5=A2=9E=E5=AF=B9=E6=8E=A5=E5=AE=A2?= =?UTF-8?q?=E6=9C=8D=E5=A4=9A=E9=80=89=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worker-platform/consignment-repo.test.ts | 17 ++++++++ .../worker-platform/consignment-repo.ts | 19 ++++++++- .../consignment-admin-service.ts | 22 ++++++++++ .../panels/ConsignmentInventoryPanel.tsx | 26 ++++++++++++ ...nsignment-inventory-contact-filter.test.ts | 40 +++++++++++++++++++ 5 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 apps/frontend/tests/consignment-inventory-contact-filter.test.ts 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 dcc38154..4b3d520a 100644 --- a/apps/backend/src/repositories/worker-platform/consignment-repo.test.ts +++ b/apps/backend/src/repositories/worker-platform/consignment-repo.test.ts @@ -64,6 +64,23 @@ test('寄卖仓库搜索必须覆盖供货打手姓名、打手电话与页面 ) }) +test('寄卖仓库对接客服筛选按 id 多选并支持未指定,关键字不再搜对接客服', async () => { + const source = await readRepoSource() + const start = source.indexOf('export async function listConsignmentInventories') + assert.ok(start > 0, '未找到寄售仓库列表查询') + const body = source.slice(start, source.indexOf('\n}\n', start)) + + assert.ok( + body.includes('ci.contact_supporter_id = ANY($${values.length}::bigint[])'), + '对接客服多选必须按 contact_supporter_id 匹配,不能按姓名', + ) + assert.ok( + body.includes('ci.contact_supporter_id IS NULL'), + '「未指定」必须能筛出没有对接客服的库存', + ) + assert.ok(!body.includes('ccs.name ILIKE'), '关键字不能继续匹配对接客服姓名,否则会与寄售人混淆') +}) + test('寄卖提报单搜索必须能搜打手,列表与计数 SQL 都带实时打手关联', async () => { const source = await readFile(new URL('./consignment-repo.ts', import.meta.url), 'utf8') const start = source.indexOf('export async function listConsignmentSubmissions') diff --git a/apps/backend/src/repositories/worker-platform/consignment-repo.ts b/apps/backend/src/repositories/worker-platform/consignment-repo.ts index dff4dfe8..16762ab5 100644 --- a/apps/backend/src/repositories/worker-platform/consignment-repo.ts +++ b/apps/backend/src/repositories/worker-platform/consignment-repo.ts @@ -238,6 +238,10 @@ export async function listConsignmentInventories(filters: { diamondLevel?: number | undefined allowMatching?: boolean | undefined workerId?: number | undefined + /** 对接客服多选:只按 contact_supporter_id 匹配,避免与寄售人同名混淆 */ + contactSupporterIds?: number[] | undefined + /** 是否包含未指定对接客服的库存(与 contactSupporterIds 取并集) */ + includeUnassignedContactSupporter?: boolean | undefined keyword?: string | undefined dateFrom?: string | undefined dateTo?: string | undefined @@ -299,6 +303,18 @@ export async function listConsignmentInventories(filters: { values.push(filters.allowMatching) conditions.push(`ci.allow_matching = $${values.length}`) } + // 对接客服筛选按外键 id 判断:多选和「未指定」是并集关系,不能按姓名匹配。 + const contactSupporterConditions: string[] = [] + if (filters.contactSupporterIds && filters.contactSupporterIds.length > 0) { + values.push(filters.contactSupporterIds) + contactSupporterConditions.push(`ci.contact_supporter_id = ANY($${values.length}::bigint[])`) + } + if (filters.includeUnassignedContactSupporter) { + contactSupporterConditions.push('ci.contact_supporter_id IS NULL') + } + if (contactSupporterConditions.length > 0) { + conditions.push(`(${contactSupporterConditions.join(' OR ')})`) + } buildConsignmentSpecFilterConditions(filters.specFilters, values, conditions) if (filters.keyword) { values.push(`%${filters.keyword.trim()}%`) @@ -324,8 +340,7 @@ export async function listConsignmentInventories(filters: { 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})`, + OR supplier_worker.phone ILIKE $${values.length})`, ) } if (filters.dateFrom) { diff --git a/apps/backend/src/services/worker-platform/consignment-admin-service.ts b/apps/backend/src/services/worker-platform/consignment-admin-service.ts index 6b50e261..2b2d1bd6 100644 --- a/apps/backend/src/services/worker-platform/consignment-admin-service.ts +++ b/apps/backend/src/services/worker-platform/consignment-admin-service.ts @@ -391,6 +391,24 @@ export function mapConsignmentSubmission(row: ConsignmentSubmissionRow) { } } +/** 对接客服多选:兼容逗号字符串与数组,过滤 0/重复/非法 id。 */ +function normalizeContactSupporterIds(value: unknown): number[] | undefined { + const source = Array.isArray(value) ? value : String(value ?? '').split(',') + const ids = Array.from( + new Set(source.map((item) => Number(item)).filter((id) => Number.isInteger(id) && id > 0)), + ) + return ids.length > 0 ? ids : undefined +} + +function readQueryBoolean(value: unknown): boolean { + return ( + value === true || + String(value ?? '') + .trim() + .toLowerCase() === 'true' + ) +} + export async function fetchAdminConsignmentInventories(query: JsonObject = {}) { const status = query.status ? String(query.status).trim() : undefined const buyerName = query.buyerName ? String(query.buyerName).trim() : undefined @@ -405,6 +423,8 @@ export async function fetchAdminConsignmentInventories(query: JsonObject = {}) { const diamondLevel = query.diamondLevel !== undefined ? Number(query.diamondLevel) : undefined const allowMatching = query.allowMatching !== undefined ? String(query.allowMatching) === 'true' : undefined + const contactSupporterIds = normalizeContactSupporterIds(query.contactSupporterIds) + const includeUnassignedContactSupporter = readQueryBoolean(query.contactSupporterUnassigned) const keyword = query.keyword ? String(query.keyword).trim() : undefined const dateFrom = normalizeInventoryDate(query.dateFrom) const dateTo = normalizeInventoryDate(query.dateTo) @@ -423,6 +443,8 @@ export async function fetchAdminConsignmentInventories(query: JsonObject = {}) { series, diamondLevel, allowMatching, + contactSupporterIds, + includeUnassignedContactSupporter, specFilters, keyword, dateFrom, diff --git a/apps/frontend/src/pages/admin/panels/ConsignmentInventoryPanel.tsx b/apps/frontend/src/pages/admin/panels/ConsignmentInventoryPanel.tsx index 560fad3e..6008849a 100644 --- a/apps/frontend/src/pages/admin/panels/ConsignmentInventoryPanel.tsx +++ b/apps/frontend/src/pages/admin/panels/ConsignmentInventoryPanel.tsx @@ -149,6 +149,8 @@ export default function ConsignmentInventoryPanel() { const [categoryExpandedKeys, setCategoryExpandedKeys] = useState>([]) const [specFilters, setSpecFilters] = useState>({}) const [allowMatching, setAllowMatching] = useState('') + // 对接客服多选:0 作为「未指定」哨兵值,与真实客服 id 分开。 + const [contactSupporterIds, setContactSupporterIds] = useState([]) const [inboundRange, setInboundRange] = useState<[string, string] | null>(null) const [keyword, setKeyword] = useState('') const [page, setPage] = useState(1) @@ -295,6 +297,9 @@ export default function ConsignmentInventoryPanel() { }, [dynamicFilters, specFilters]) const specFilterParams = Object.keys(specFilterPayload).length > 0 ? JSON.stringify(specFilterPayload) : undefined + // 对接客服筛选只按 id 传参;未指定单独标记,后端与多选 id 取并集。 + const contactSupporterIdsParam = contactSupporterIds.filter((id) => id > 0).join(',') || undefined + const includeUnassignedContactSupporter = contactSupporterIds.includes(0) function updateSpecFilter(field: ConsignmentInventoryFilterField, value: string) { setSpecFilters((current) => { @@ -314,6 +319,8 @@ export default function ConsignmentInventoryPanel() { categoryId, specFilterParams, allowMatching, + contactSupporterIdsParam, + includeUnassignedContactSupporter, inboundRange?.[0], inboundRange?.[1], keyword, @@ -326,6 +333,8 @@ export default function ConsignmentInventoryPanel() { categoryId: categoryId ?? undefined, specFilters: specFilterParams, allowMatching: allowMatching === 'yes' ? true : allowMatching === 'no' ? false : undefined, + contactSupporterIds: contactSupporterIdsParam, + contactSupporterUnassigned: includeUnassignedContactSupporter || undefined, dateFrom: inboundRange?.[0], dateTo: inboundRange?.[1], keyword: keyword || undefined, @@ -1107,6 +1116,23 @@ export default function ConsignmentInventoryPanel() { }} /> + {/* 对接客服筛选:多选 + 未指定;只按客服 id 匹配,与寄售人严格分开。 */} +