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) {
@@ -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,
@@ -149,6 +149,8 @@ export default function ConsignmentInventoryPanel() {
const [categoryExpandedKeys, setCategoryExpandedKeys] = useState<Array<string | number>>([])
const [specFilters, setSpecFilters] = useState<Record<string, string>>({})
const [allowMatching, setAllowMatching] = useState<string>('')
// 对接客服多选:0 作为「未指定」哨兵值,与真实客服 id 分开。
const [contactSupporterIds, setContactSupporterIds] = useState<number[]>([])
const [inboundRange, setInboundRange] = useState<[string, string] | null>(null)
const [keyword, setKeyword] = useState<string>('')
const [page, setPage] = useState<number>(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 匹配,与寄售人严格分开。 */}
<Select
mode="multiple"
allowClear
showSearch
optionFilterProp="label"
maxTagCount="responsive"
style={{ width: 220, maxWidth: '100%' }}
value={contactSupporterIds}
placeholder="对接客服(可多选)"
onChange={(values) => {
setContactSupporterIds(values)
setPage(1)
}}
options={[{ label: '未指定', value: 0 }, ...contactSupporterOptions]}
/>
<Input.Search
placeholder="搜索物品名/编号/收购人/店铺/卖家"
allowClear
@@ -0,0 +1,40 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import test from 'node:test'
const source = readFileSync(
join(
dirname(fileURLToPath(import.meta.url)),
'../src/pages/admin/panels/ConsignmentInventoryPanel.tsx',
),
'utf8',
)
test('寄售仓库提供对接客服多选筛选,并与未指定取并集', () => {
assert.ok(source.includes('mode="multiple"'))
assert.ok(source.includes('placeholder="对接客服(可多选)"'))
assert.ok(source.includes('optionFilterProp="label"'))
assert.ok(source.includes('contactSupporterIdsParam'))
assert.ok(source.includes('contactSupporterIds: contactSupporterIdsParam'))
assert.ok(
source.includes('contactSupporterUnassigned: includeUnassignedContactSupporter || undefined'),
)
assert.ok(source.includes("{ label: '未指定', value: 0 }"))
// 对接客服筛选必须排在搜索框前面。
const contactIndex = source.indexOf('placeholder="对接客服(可多选)"')
const searchIndex = source.indexOf('placeholder="搜索物品名/编号/收购人/店铺/卖家"')
assert.ok(contactIndex > 0 && searchIndex > 0 && contactIndex < searchIndex)
})
test('对接客服筛选进入列表 queryKey,统计卡片不跟随', () => {
assert.ok(source.includes('includeUnassignedContactSupporter,'))
const statsStart = source.indexOf("'admin-consignment-stats'")
assert.ok(statsStart > 0, '未找到寄售统计查询')
const statsBlock = source.slice(statsStart, statsStart + 600)
assert.ok(
!statsBlock.includes('contactSupporterIdsParam'),
'统计卡片不应跟随对接客服筛选,保持原有统计口径',
)
})