feat(consignment): 寄售仓库新增对接客服多选筛选
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user