feat(worker): 我的订单新增待提交打手资料筛选

- 仅筛 3 天(72h)好友赠送单,口径与提交资料接口一致

- 加法式页签,仍保留在代练中;问题单纳入

- 概览与实时 workerStatuses 同步,提交/重置资料后自动移出/移入

- 显式单号检索忽略该展示筛选
This commit is contained in:
2026-11-17 18:35:18 +08:00
parent 4abc8b39d0
commit 5d0be12476
16 changed files with 399 additions and 20 deletions
@@ -223,6 +223,25 @@ test('内部现货不再因上一手 last_assigned 进入打手可见集', async
assert.equal(calls.length, 2, '列表和概览必须共用同一条历史可见条件')
})
test('「待提交打手资料」只筛本人名下 3 天赠送的 material_required 单', () => {
const query = buildWorkOrderWhere({ workerSharingId: 7, giftMaterialPending: true })
assert.match(query.whereClause, /wo\.acceptance_mode = 'friend_gift'/)
assert.match(query.whereClause, /wo\.gift_phase = 'material_required'/)
assert.match(query.whereClause, /wo\.status IN \('in_progress', 'problem'\)/)
// 必须锁死当前接单人:可见集合里的超时历史单可能是别人正在做的单
assert.match(query.whereClause, /wo\.assigned_worker_id = \$1::bigint/)
assert.match(query.whereClause, /gift_cooldown_hours/)
assert.match(query.whereClause, /gift_cooldown_minutes/)
assert.match(query.whereClause, /\) = 4320/)
// 复用 worker_visible 的打手参数,不额外占位
assert.deepEqual(query.params, [7])
// 普通状态筛选不产生赠送资料条件
const plain = buildWorkOrderWhere({ workerSharingId: 7, statuses: ['in_progress'] })
assert.doesNotMatch(plain.whereClause, /gift_phase = 'material_required'/)
})
test('后台接单人员筛选把寄售供货人的绑定工单纳入可见集合', () => {
const query = buildWorkOrderWhere({
workerSharingId: 1494,
@@ -548,6 +548,11 @@ export type ListInput = {
excludeFilledSharing?: boolean
/** VIP 免审核后仍在补图期限内的订单;与状态筛选取并集 */
vipEvidencePending?: boolean
/**
* 打手端「待提交打手资料」筛选:3 天(72h)好友赠送单,且当前接单人就是该打手、
* 仍停在 material_required 阶段。必须与 workerSharingId 一起使用,否则会跨打手。
*/
giftMaterialPending?: boolean
/** 验收模式筛选:standard / friend_gift。 */
acceptanceMode?: string
/** 好友赠送阶段筛选:material_required / material_submitted / friend_countdown / gift_ready。 */
@@ -2,7 +2,9 @@ import { query } from '../../db/client.js'
import type { ListInput, WorkOrderRow, WorkOrderStatistics } from './types.js'
import type { PoolClient } from 'pg'
import {
DEFAULT_GIFT_COOLDOWN_HOURS,
normalizeWorkOrderAcceptanceMode,
THREE_DAY_GIFT_COOLDOWN_MINUTES,
WORK_ORDER_ACCEPTANCE_MODE,
WORK_ORDER_GIFT_PHASE,
} from '../../domain/work-order-acceptance-mode.js'
@@ -80,6 +82,8 @@ type WorkerOrderOverviewRow = {
settlement_amount: number
vip_evidence_pending_count: number
vip_evidence_pending_settlement_amount: number
gift_material_pending_count: number
gift_material_pending_settlement_amount: number
}
type WorkOrderStatisticsRow = {
@@ -398,6 +402,7 @@ export async function listWorkOrders({
visibleAfterIso = '',
excludeFilledSharing = false,
vipEvidencePending = false,
giftMaterialPending = false,
acceptanceMode = '',
giftPhase = '',
useOperationalStatus = false,
@@ -424,6 +429,7 @@ export async function listWorkOrders({
visibleAfterIso,
excludeFilledSharing,
vipEvidencePending,
giftMaterialPending,
acceptanceMode,
giftPhase,
// 无状态筛选时运营状态不影响列表入选,不应为此聚合整张拼单表。
@@ -657,9 +663,27 @@ export async function getWorkerOrderOverview(workerId: number | string): Promise
settlementAmount: number
vipEvidencePendingCount: number
vipEvidencePendingSettlementAmount: number
giftMaterialPendingCount: number
giftMaterialPendingSettlementAmount: number
}>
> {
const normalizedWorkerId = Number(workerId)
// 「待提交打手资料」概览口径:与列表筛选、提交资料接口完全一致,
// 只统计当前打手名下仍停在 material_required 的 3 天好友赠送单。
const giftMaterialPendingFilter = `
status IN ('in_progress', 'problem')
AND is_assigned_to_me
AND acceptance_mode = 'friend_gift'
AND gift_phase = 'material_required'
AND (
CASE
WHEN COALESCE(gift_cooldown_hours, 0) = 0
AND COALESCE(gift_cooldown_minutes, 0) = 0
THEN ${DEFAULT_GIFT_COOLDOWN_HOURS * 60}
ELSE COALESCE(gift_cooldown_hours, 0) * 60 + COALESCE(gift_cooldown_minutes, 0)
END
) = ${THREE_DAY_GIFT_COOLDOWN_MINUTES}
`
const result = await query<WorkerOrderOverviewRow>(
`
WITH visible_orders AS (
@@ -687,6 +711,10 @@ export async function getWorkerOrderOverview(workerId: number | string): Promise
wo.status AS wo_status,
wo.reward_amount,
wo.acceptance_json,
wo.acceptance_mode,
wo.gift_phase,
wo.gift_cooldown_hours,
wo.gift_cooldown_minutes,
wo.assigned_worker_id = $1 AS is_assigned_to_me,
EXISTS (
SELECT 1 FROM work_order_events we
@@ -739,14 +767,21 @@ export async function getWorkerOrderOverview(workerId: number | string): Promise
WHEN wos.status = 'accepted' THEN 'accepted'
END AS status,
SUM(wos.share_reward)::int AS amount,
(ARRAY_AGG(wos.acceptance_json ORDER BY wos.id DESC))[1] AS acceptance_json
(ARRAY_AGG(wos.acceptance_json ORDER BY wos.id DESC))[1] AS acceptance_json,
f.acceptance_mode AS acceptance_mode,
f.gift_phase AS gift_phase,
f.gift_cooldown_hours AS gift_cooldown_hours,
f.gift_cooldown_minutes AS gift_cooldown_minutes,
f.is_assigned_to_me AS is_assigned_to_me
FROM work_order_shares wos
INNER JOIN order_flags f ON f.id = wos.work_order_id
WHERE wos.worker_id = $1
AND wos.status IN ('joined', 'submitted', 'accepted')
AND f.wo_status NOT IN ('accepted', 'cancelled', 'problem')
GROUP BY wos.work_order_id, wos.status, f.has_pending_handling,
(wos.problem_marked_at IS NOT NULL)
(wos.problem_marked_at IS NOT NULL),
f.acceptance_mode, f.gift_phase, f.gift_cooldown_hours, f.gift_cooldown_minutes,
f.is_assigned_to_me
),
order_status_rows AS (
SELECT
@@ -754,6 +789,11 @@ export async function getWorkerOrderOverview(workerId: number | string): Promise
status,
amount,
acceptance_json,
acceptance_mode,
gift_phase,
gift_cooldown_hours,
gift_cooldown_minutes,
is_assigned_to_me,
TRUE AS is_worker_share
FROM share_status_rows
@@ -778,6 +818,11 @@ export async function getWorkerOrderOverview(workerId: number | string): Promise
ELSE 0
END AS amount,
f.acceptance_json,
f.acceptance_mode,
f.gift_phase,
f.gift_cooldown_hours,
f.gift_cooldown_minutes,
f.is_assigned_to_me,
f.is_worker_share
FROM order_flags f
WHERE
@@ -813,7 +858,13 @@ export async function getWorkerOrderOverview(workerId: number | string): Promise
AND NULLIF(acceptance_json->>'evidenceDueAt', '')::timestamptz > NOW()
),
0
)::int AS vip_evidence_pending_settlement_amount
)::int AS vip_evidence_pending_settlement_amount,
COUNT(*) FILTER (WHERE ${giftMaterialPendingFilter})::int
AS gift_material_pending_count,
COALESCE(
SUM(amount) FILTER (WHERE ${giftMaterialPendingFilter}),
0
)::int AS gift_material_pending_settlement_amount
FROM order_status_rows
GROUP BY status
@@ -847,7 +898,13 @@ export async function getWorkerOrderOverview(workerId: number | string): Promise
AND NULLIF(acceptance_json->>'evidenceDueAt', '')::timestamptz > NOW()
),
0
)::int AS vip_evidence_pending_settlement_amount
)::int AS vip_evidence_pending_settlement_amount,
COUNT(*) FILTER (WHERE ${giftMaterialPendingFilter})::int
AS gift_material_pending_count,
COALESCE(
SUM(amount) FILTER (WHERE ${giftMaterialPendingFilter}),
0
)::int AS gift_material_pending_settlement_amount
FROM order_status_rows
`,
[normalizedWorkerId],
@@ -858,6 +915,8 @@ export async function getWorkerOrderOverview(workerId: number | string): Promise
settlementAmount: Number(row.settlement_amount || 0),
vipEvidencePendingCount: Number(row.vip_evidence_pending_count || 0),
vipEvidencePendingSettlementAmount: Number(row.vip_evidence_pending_settlement_amount || 0),
giftMaterialPendingCount: Number(row.gift_material_pending_count || 0),
giftMaterialPendingSettlementAmount: Number(row.gift_material_pending_settlement_amount || 0),
}))
}
@@ -1221,6 +1280,7 @@ export function buildWorkOrderWhere({
visibleAfterIso = '',
excludeFilledSharing = false,
vipEvidencePending = false,
giftMaterialPending = false,
acceptanceMode = '',
giftPhase = '',
useOperationalStatus = false,
@@ -1428,6 +1488,27 @@ export function buildWorkOrderWhere({
}
}
}
if (giftMaterialPending) {
// 与「提交本人资料」接口同口径:只有当前接单人、仍停在 material_required 的赠送单
// 才需要他补资料。3 天口径按实际生效的总冷却分钟数判断,0/0 为历史默认 72 小时。
const workerScope = workerSharingId
? `AND wo.assigned_worker_id = ${workerSharePlaceholder}::bigint`
: ''
filters.push(`(
wo.acceptance_mode = '${WORK_ORDER_ACCEPTANCE_MODE.FRIEND_GIFT}'
AND wo.gift_phase = '${WORK_ORDER_GIFT_PHASE.MATERIAL_REQUIRED}'
AND wo.status IN ('in_progress', 'problem')
AND (
CASE
WHEN COALESCE(wo.gift_cooldown_hours, 0) = 0
AND COALESCE(wo.gift_cooldown_minutes, 0) = 0
THEN ${DEFAULT_GIFT_COOLDOWN_HOURS * 60}
ELSE COALESCE(wo.gift_cooldown_hours, 0) * 60 + COALESCE(wo.gift_cooldown_minutes, 0)
END
) = ${THREE_DAY_GIFT_COOLDOWN_MINUTES}
${workerScope}
)`)
}
if (workOrderId) {
params.push(workOrderId)
filters.push(`wo.id = $${params.length}`)