修复:寄售登记人改名后显示与筛选同步
This commit is contained in:
@@ -223,6 +223,22 @@ test('内部现货不再因上一手 last_assigned 进入打手可见集', async
|
||||
assert.equal(calls.length, 2, '列表和概览必须共用同一条历史可见条件')
|
||||
})
|
||||
|
||||
test('后台接单人员筛选把寄售供货人的绑定工单纳入可见集合', () => {
|
||||
const query = buildWorkOrderWhere({
|
||||
workerSharingId: 1494,
|
||||
consignmentSupplierWorkerId: 1494,
|
||||
})
|
||||
assert.match(query.joins, /FROM consignment_inventories supplier_ci/)
|
||||
assert.match(query.joins, /supplier_ci\.worker_id = \$2::bigint/)
|
||||
assert.match(query.joins, /supplier_ci\.bound_work_order_id IS NOT NULL/)
|
||||
assert.deepEqual(query.params, [1494, 1494])
|
||||
|
||||
// 打手端「我的订单」不传扩展口径,可见范围必须保持原样
|
||||
const plain = buildWorkOrderWhere({ workerSharingId: 1494 })
|
||||
assert.doesNotMatch(plain.joins, /supplier_ci/)
|
||||
assert.deepEqual(plain.params, [1494])
|
||||
})
|
||||
|
||||
test('「仅问题单」检索走短路分支,从 pending 表反查而非枚举可见集', () => {
|
||||
const query = buildWorkOrderWhere({ workerSharingId: 7, statuses: ['problem'] })
|
||||
|
||||
|
||||
@@ -54,6 +54,52 @@ test('寄卖仓库搜索必须覆盖供货打手姓名、打手电话与页面
|
||||
)
|
||||
})
|
||||
|
||||
test('寄卖提报单搜索必须能搜打手,列表与计数 SQL 都带实时打手关联', async () => {
|
||||
const source = await readFile(new URL('./consignment-repo.ts', import.meta.url), 'utf8')
|
||||
const start = source.indexOf('export async function listConsignmentSubmissions')
|
||||
assert.ok(start > 0, '未找到寄卖提报单列表查询')
|
||||
const body = source.slice(start, source.indexOf('\n}\n', start))
|
||||
|
||||
for (const field of [
|
||||
'cs.worker_name',
|
||||
'cs.worker_phone',
|
||||
'supplier_worker.display_name',
|
||||
'supplier_worker.username',
|
||||
'supplier_worker.phone',
|
||||
]) {
|
||||
assert.ok(body.includes(field), `提报单搜索缺少字段:${field}`)
|
||||
}
|
||||
assert.ok(body.includes('AS live_worker_name'), '列表必须带出实时打手昵称')
|
||||
assert.ok(body.includes('AS live_worker_phone'), '列表必须带出实时打手电话')
|
||||
|
||||
const countSqlLine = body
|
||||
.split('\n')
|
||||
.find((line) =>
|
||||
line.includes('SELECT COUNT(*)::integer AS total FROM consignment_submissions cs'),
|
||||
)
|
||||
assert.ok(countSqlLine, '未找到提报单计数 SQL')
|
||||
assert.ok(
|
||||
countSqlLine!.includes('LEFT JOIN worker_users supplier_worker'),
|
||||
'计数 SQL 缺少打手 join,按姓名/电话搜索会报错',
|
||||
)
|
||||
})
|
||||
|
||||
test('寄售库存详情/批量/匹配候选查询都带出实时打手昵称', async () => {
|
||||
const source = await readFile(new URL('./consignment-repo.ts', import.meta.url), 'utf8')
|
||||
for (const fn of [
|
||||
'getConsignmentInventoryById',
|
||||
'listConsignmentInventoriesByIds',
|
||||
'getConsignmentInventoryBySubmissionId',
|
||||
'listActiveConsignmentInventoriesForMatching',
|
||||
]) {
|
||||
const start = source.indexOf(`export async function ${fn}`)
|
||||
assert.ok(start > 0, `未找到查询:${fn}`)
|
||||
const body = source.slice(start, source.indexOf('\n}\n', start))
|
||||
assert.ok(body.includes('LEFT JOIN worker_users supplier_worker'), `${fn} 缺少实时打手 join`)
|
||||
assert.ok(body.includes('AS live_worker_name'), `${fn} 缺少实时打手昵称字段`)
|
||||
}
|
||||
})
|
||||
|
||||
test('寄卖仓库按通过审核入库时间筛选,结束日期必须包含当天全天', async () => {
|
||||
const source = await readFile(new URL('./consignment-repo.ts', import.meta.url), 'utf8')
|
||||
const inventoryListStart = source.indexOf('export async function listConsignmentInventories')
|
||||
|
||||
@@ -48,6 +48,10 @@ export type ConsignmentInventoryRow = {
|
||||
worker_id?: string | number | null
|
||||
worker_name?: string
|
||||
worker_phone?: string
|
||||
/** 当前打手昵称(实时 join worker_users,优先于入库时的快照) */
|
||||
live_worker_name?: string | null
|
||||
/** 当前打手电话(实时 join worker_users,优先于入库时的快照) */
|
||||
live_worker_phone?: string | null
|
||||
assigned_worker_id?: string | number | null
|
||||
deposit_amount_fen?: number
|
||||
/** 对接客服(发布/审核入库时选定,用于提成归属与联系) */
|
||||
@@ -81,6 +85,10 @@ export type ConsignmentSubmissionRow = {
|
||||
worker_id?: string | number | null
|
||||
worker_name?: string
|
||||
worker_phone?: string
|
||||
/** 当前打手昵称(实时 join worker_users,优先于提报时的快照) */
|
||||
live_worker_name?: string | null
|
||||
/** 当前打手电话(实时 join worker_users,优先于提报时的快照) */
|
||||
live_worker_phone?: string | null
|
||||
deposit_amount_fen?: number
|
||||
/** 对接客服(发布时选定,用于提成归属与联系) */
|
||||
contact_supporter_id?: string | number | null
|
||||
@@ -233,6 +241,8 @@ export async function listConsignmentInventories(filters: {
|
||||
wc.name AS category_name,
|
||||
cs.submission_no AS source_submission_no,
|
||||
cs.screenshots_json AS submission_screenshots_json,
|
||||
COALESCE(NULLIF(supplier_worker.display_name, ''), supplier_worker.username) AS live_worker_name,
|
||||
supplier_worker.phone AS live_worker_phone,
|
||||
wo.acceptance_json AS gift_evidence_json,
|
||||
wo.work_order_no AS gift_work_order_no,
|
||||
wo.status AS gift_work_order_status,
|
||||
@@ -355,6 +365,8 @@ export async function getConsignmentInventoryById(
|
||||
wc.name AS category_name,
|
||||
cs.submission_no AS source_submission_no,
|
||||
cs.screenshots_json AS submission_screenshots_json,
|
||||
COALESCE(NULLIF(supplier_worker.display_name, ''), supplier_worker.username) AS live_worker_name,
|
||||
supplier_worker.phone AS live_worker_phone,
|
||||
wo.acceptance_json AS gift_evidence_json,
|
||||
wo.work_order_no AS gift_work_order_no,
|
||||
wo.status AS gift_work_order_status,
|
||||
@@ -366,6 +378,7 @@ export async function getConsignmentInventoryById(
|
||||
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
|
||||
WHERE ci.id = $1
|
||||
@@ -387,10 +400,13 @@ export async function listConsignmentInventoriesByIds(
|
||||
wc.name AS category_name,
|
||||
cs.submission_no AS source_submission_no,
|
||||
cs.screenshots_json AS submission_screenshots_json,
|
||||
COALESCE(NULLIF(supplier_worker.display_name, ''), supplier_worker.username) AS live_worker_name,
|
||||
supplier_worker.phone AS live_worker_phone,
|
||||
ccs.name AS contact_supporter_name
|
||||
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
|
||||
WHERE ci.id = ANY($1::bigint[])
|
||||
`
|
||||
@@ -933,9 +949,12 @@ export async function listActiveConsignmentInventoriesForMatching(options?: {
|
||||
SELECT
|
||||
ci.*,
|
||||
cs.submission_no AS source_submission_no,
|
||||
COALESCE(NULLIF(supplier_worker.display_name, ''), supplier_worker.username) AS live_worker_name,
|
||||
supplier_worker.phone AS live_worker_phone,
|
||||
ccs.name AS contact_supporter_name
|
||||
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
|
||||
WHERE ${conditions.join(' AND ')}
|
||||
ORDER BY ci.id ASC
|
||||
@@ -967,12 +986,22 @@ export async function listConsignmentSubmissions(filters: {
|
||||
if (filters.keyword) {
|
||||
values.push(`%${filters.keyword.trim()}%`)
|
||||
conditions.push(
|
||||
`(cs.item_name ILIKE $${values.length} OR cs.submission_no ILIKE $${values.length} OR cs.contact_info ILIKE $${values.length} OR cs.seller_game_id ILIKE $${values.length} OR cs.seller_phone ILIKE $${values.length} OR ccs.name ILIKE $${values.length})`,
|
||||
`(cs.item_name ILIKE $${values.length}
|
||||
OR cs.submission_no ILIKE $${values.length}
|
||||
OR cs.contact_info ILIKE $${values.length}
|
||||
OR cs.seller_game_id 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 ')}` : ''
|
||||
const countSql = `SELECT COUNT(*)::integer AS total FROM consignment_submissions cs LEFT JOIN consignment_contact_supporters ccs ON ccs.id = cs.contact_supporter_id ${whereClause}`
|
||||
const countSql = `SELECT COUNT(*)::integer AS total FROM consignment_submissions cs LEFT JOIN worker_users supplier_worker ON supplier_worker.id = cs.worker_id LEFT JOIN consignment_contact_supporters ccs ON ccs.id = cs.contact_supporter_id ${whereClause}`
|
||||
const countRes = await query<{ total: number }>(countSql, values)
|
||||
const total = countRes.rows[0]?.total || 0
|
||||
|
||||
@@ -989,9 +1018,12 @@ export async function listConsignmentSubmissions(filters: {
|
||||
wo.acceptance_json AS gift_evidence_json,
|
||||
wo.work_order_no AS gift_work_order_no,
|
||||
wo.status AS gift_work_order_status,
|
||||
COALESCE(NULLIF(supplier_worker.display_name, ''), supplier_worker.username) AS live_worker_name,
|
||||
supplier_worker.phone AS live_worker_phone,
|
||||
ccs.name AS contact_supporter_name
|
||||
FROM consignment_submissions cs
|
||||
LEFT JOIN work_categories wc ON wc.id = cs.category_id
|
||||
LEFT JOIN worker_users supplier_worker ON supplier_worker.id = cs.worker_id
|
||||
LEFT JOIN consignment_contact_supporters ccs ON ccs.id = cs.contact_supporter_id
|
||||
LEFT JOIN consignment_inventories rinv ON (rinv.id = cs.result_inventory_id OR rinv.source_submission_id = cs.id)
|
||||
LEFT JOIN work_orders wo ON wo.id = rinv.bound_work_order_id
|
||||
@@ -1209,9 +1241,12 @@ export async function listConsignmentSubmissionsByIds(
|
||||
wo.acceptance_json AS gift_evidence_json,
|
||||
wo.work_order_no AS gift_work_order_no,
|
||||
wo.status AS gift_work_order_status,
|
||||
COALESCE(NULLIF(supplier_worker.display_name, ''), supplier_worker.username) AS live_worker_name,
|
||||
supplier_worker.phone AS live_worker_phone,
|
||||
ccs.name AS contact_supporter_name
|
||||
FROM consignment_submissions cs
|
||||
LEFT JOIN work_categories wc ON wc.id = cs.category_id
|
||||
LEFT JOIN worker_users supplier_worker ON supplier_worker.id = cs.worker_id
|
||||
LEFT JOIN consignment_contact_supporters ccs ON ccs.id = cs.contact_supporter_id
|
||||
LEFT JOIN consignment_inventories rinv
|
||||
ON (rinv.id = cs.result_inventory_id OR rinv.source_submission_id = cs.id)
|
||||
@@ -1238,10 +1273,13 @@ export async function getConsignmentInventoryBySubmissionId(
|
||||
ci.*,
|
||||
wc.name AS category_name,
|
||||
cs.submission_no AS source_submission_no,
|
||||
COALESCE(NULLIF(supplier_worker.display_name, ''), supplier_worker.username) AS live_worker_name,
|
||||
supplier_worker.phone AS live_worker_phone,
|
||||
ccs.name AS contact_supporter_name
|
||||
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
|
||||
WHERE ci.source_submission_id = $1
|
||||
ORDER BY ci.id DESC
|
||||
@@ -1262,9 +1300,12 @@ export async function getConsignmentSubmissionById(
|
||||
wo.acceptance_json AS gift_evidence_json,
|
||||
wo.work_order_no AS gift_work_order_no,
|
||||
wo.status AS gift_work_order_status,
|
||||
COALESCE(NULLIF(supplier_worker.display_name, ''), supplier_worker.username) AS live_worker_name,
|
||||
supplier_worker.phone AS live_worker_phone,
|
||||
ccs.name AS contact_supporter_name
|
||||
FROM consignment_submissions cs
|
||||
LEFT JOIN work_categories wc ON wc.id = cs.category_id
|
||||
LEFT JOIN worker_users supplier_worker ON supplier_worker.id = cs.worker_id
|
||||
LEFT JOIN consignment_contact_supporters ccs ON ccs.id = cs.contact_supporter_id
|
||||
LEFT JOIN consignment_inventories rinv ON (rinv.id = cs.result_inventory_id OR rinv.source_submission_id = cs.id)
|
||||
LEFT JOIN work_orders wo ON wo.id = rinv.bound_work_order_id
|
||||
|
||||
@@ -514,6 +514,14 @@ export type ListInput = {
|
||||
/** 后台打手列表按提现黑名单筛选。 */
|
||||
isWithdrawalBlacklisted?: boolean | null | undefined
|
||||
workerSharingId?: number
|
||||
/**
|
||||
* 后台「接单人员」筛选的扩展口径:同时把该打手作为寄售供货人的工单纳入可见集合。
|
||||
*
|
||||
* 内部寄售直接履约不写 assigned_worker_id,供货关系只存在
|
||||
* consignment_inventories.worker_id;仅靠 workerSharingId 会漏掉这些单。
|
||||
* 该字段只由后台筛选使用,打手端「我的订单」不传,避免改变打手可见范围。
|
||||
*/
|
||||
consignmentSupplierWorkerId?: number
|
||||
/** 大厅候选集合的总展示上限;筛选与分页在候选集合内执行。 */
|
||||
hallCandidateLimit?: number
|
||||
hallCategoryLimits?: Record<string, number>
|
||||
|
||||
@@ -391,6 +391,7 @@ export async function listWorkOrders({
|
||||
workerLevelIds = [],
|
||||
categoryId = 0,
|
||||
workerSharingId = 0,
|
||||
consignmentSupplierWorkerId = 0,
|
||||
hallCandidateLimit = 0,
|
||||
hallCategoryLimits = {},
|
||||
visibleAfterIso = '',
|
||||
@@ -416,6 +417,7 @@ export async function listWorkOrders({
|
||||
...(resolvedWorkerIds ? { workerIds: resolvedWorkerIds } : {}),
|
||||
categoryId,
|
||||
workerSharingId,
|
||||
consignmentSupplierWorkerId,
|
||||
hallCandidateLimit,
|
||||
hallCategoryLimits,
|
||||
visibleAfterIso,
|
||||
@@ -1205,6 +1207,7 @@ export function buildWorkOrderWhere({
|
||||
workerIds,
|
||||
categoryId = 0,
|
||||
workerSharingId = 0,
|
||||
consignmentSupplierWorkerId = 0,
|
||||
hallCandidateLimit = 0,
|
||||
hallCategoryLimits = {},
|
||||
visibleAfterIso = '',
|
||||
@@ -1234,6 +1237,7 @@ export function buildWorkOrderWhere({
|
||||
)
|
||||
}
|
||||
let workerSharePlaceholder = ''
|
||||
let consignmentSupplierUnion = ''
|
||||
|
||||
// 旧的 excludeFilledSharing 写法:LEFT JOIN 一份「整张 work_order_shares 的聚合」
|
||||
// (GROUP BY work_order_id)再在 WHERE 里比较。列表/计数每次调用都要重算这份全局聚合,
|
||||
@@ -1245,6 +1249,22 @@ export function buildWorkOrderWhere({
|
||||
if (workerSharingId) {
|
||||
params.push(workerSharingId)
|
||||
workerSharePlaceholder = `$${params.length}`
|
||||
const normalizedSupplierWorkerId = Math.max(
|
||||
0,
|
||||
Math.floor(Number(consignmentSupplierWorkerId) || 0),
|
||||
)
|
||||
if (normalizedSupplierWorkerId > 0) {
|
||||
// 内部寄售直接履约不写 assigned_worker_id:供货关系只存在
|
||||
// consignment_inventories.worker_id,这里按库存回查绑定工单,补进可见集合。
|
||||
params.push(normalizedSupplierWorkerId)
|
||||
const supplierPlaceholder = `$${params.length}`
|
||||
consignmentSupplierUnion = `
|
||||
UNION
|
||||
SELECT supplier_ci.bound_work_order_id AS work_order_id
|
||||
FROM consignment_inventories supplier_ci
|
||||
WHERE supplier_ci.worker_id = ${supplierPlaceholder}::bigint
|
||||
AND supplier_ci.bound_work_order_id IS NOT NULL`
|
||||
}
|
||||
joins.push(`
|
||||
INNER JOIN (
|
||||
SELECT assigned.id AS work_order_id
|
||||
@@ -1263,7 +1283,7 @@ export function buildWorkOrderWhere({
|
||||
SELECT timeout_ev.work_order_id
|
||||
FROM work_order_events timeout_ev
|
||||
WHERE timeout_ev.event_type LIKE 'timeout_%'
|
||||
AND timeout_ev.payload_json->>'workerId' = ${workerSharePlaceholder}::text
|
||||
AND timeout_ev.payload_json->>'workerId' = ${workerSharePlaceholder}::text${consignmentSupplierUnion}
|
||||
) worker_visible ON worker_visible.work_order_id = wo.id
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT wos.status, wos.created_at
|
||||
|
||||
Reference in New Issue
Block a user