feat(consignment): 寄售仓库新增对接客服多选筛选

This commit is contained in:
2026-11-19 11:28:30 +08:00
parent 587ac1cd00
commit a6e15f582e
5 changed files with 122 additions and 2 deletions
@@ -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')
@@ -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) {