超时订单按打手统计,抢单大厅标注限时任务
This commit is contained in:
@@ -1425,6 +1425,7 @@ export async function settleOverdueWorkOrder(input: {
|
||||
payloadJson: JSON.stringify({
|
||||
policy: input.policy,
|
||||
depositAmount: resolvedDepositAmount,
|
||||
workerId: workerId > 0 ? workerId : null,
|
||||
}),
|
||||
now: input.now,
|
||||
})
|
||||
@@ -1449,6 +1450,36 @@ export async function countWorkerActiveOrders(workerId: number | string): Promis
|
||||
return Number(result.rows[0]?.total || 0)
|
||||
}
|
||||
|
||||
export async function countTimeoutEventsByWorkerIds(workerIds: number[]): Promise<Map<number, number>> {
|
||||
const counts = new Map<number, number>()
|
||||
const uniqueIds = [...new Set(workerIds.map((id) => Number(id)).filter((id) => id > 0))]
|
||||
if (uniqueIds.length === 0) return counts
|
||||
const result = await query<{ worker_id: string; total: number }>(
|
||||
`
|
||||
SELECT payload_json->>'workerId' AS worker_id, COUNT(*)::int AS total
|
||||
FROM work_order_events
|
||||
WHERE event_type LIKE 'timeout_%'
|
||||
AND payload_json->>'workerId' IS NOT NULL
|
||||
AND payload_json->>'workerId' != ''
|
||||
AND payload_json->>'workerId' = ANY($1::text[])
|
||||
GROUP BY payload_json->>'workerId'
|
||||
`,
|
||||
[uniqueIds.map(String)],
|
||||
)
|
||||
for (const row of result.rows) {
|
||||
const workerId = Number(row.worker_id)
|
||||
if (Number.isFinite(workerId) && workerId > 0) {
|
||||
counts.set(workerId, Number(row.total || 0))
|
||||
}
|
||||
}
|
||||
return counts
|
||||
}
|
||||
|
||||
export async function countWorkerTimeoutEvents(workerId: number | string): Promise<number> {
|
||||
const counts = await countTimeoutEventsByWorkerIds([Number(workerId)])
|
||||
return counts.get(Number(workerId)) || 0
|
||||
}
|
||||
|
||||
export async function createWorkOrderEvent(input: {
|
||||
workOrderId: number
|
||||
actorType: string
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
countWorkCategoryUsages,
|
||||
countWorkerLevelUsages,
|
||||
countWorkOrderPendingSharingSubmissions,
|
||||
countTimeoutEventsByWorkerIds,
|
||||
cancelWorkerWorkOrder,
|
||||
countWorkerCancellationsSince,
|
||||
createWorkOrder,
|
||||
@@ -299,8 +300,17 @@ export async function listAdminWorkerUsers(query: JsonObject = {}) {
|
||||
status: String(query.status || '').trim(),
|
||||
keyword: String(query.keyword || '').trim(),
|
||||
})
|
||||
const timeoutCounts = await countTimeoutEventsByWorkerIds(
|
||||
items.map((item) => Number(item.id)),
|
||||
)
|
||||
return {
|
||||
items: items.map(mapWorkerUser),
|
||||
items: items.map((item) => {
|
||||
const worker = mapWorkerUser(item)
|
||||
return {
|
||||
...worker,
|
||||
timeoutOrderCount: timeoutCounts.get(Number(item.id)) || 0,
|
||||
}
|
||||
}),
|
||||
pagination: { page, pageSize, total },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
addWorkerWalletCredit,
|
||||
countWorkerAcceptedOrders,
|
||||
countWorkerActiveOrders,
|
||||
countWorkerTimeoutEvents,
|
||||
countWorkCategoryUsages,
|
||||
countWorkerLevelUsages,
|
||||
countWorkOrderPendingSharingSubmissions,
|
||||
@@ -347,9 +348,10 @@ export function requireActiveWorkerSession(session: WorkerSession | null | undef
|
||||
|
||||
export async function getWorkerProfile(session: WorkerSession) {
|
||||
const worker = await getRequiredWorker(session.workerId)
|
||||
const [financeSummary, acceptedOrderCount, financeConfig] = await Promise.all([
|
||||
const [financeSummary, acceptedOrderCount, timeoutOrderCount, financeConfig] = await Promise.all([
|
||||
getWorkerFinanceRequestSummary(session.workerId),
|
||||
countWorkerAcceptedOrders(session.workerId),
|
||||
countWorkerTimeoutEvents(session.workerId),
|
||||
Promise.resolve(getWorkerFinanceConfig()),
|
||||
])
|
||||
const permissions = resolveWorkerPermissions(worker)
|
||||
@@ -359,6 +361,7 @@ export async function getWorkerProfile(session: WorkerSession) {
|
||||
permissions,
|
||||
summary: {
|
||||
acceptedOrderCount,
|
||||
timeoutOrderCount,
|
||||
pendingWithdrawAmount: financeSummary.pendingWithdrawAmount,
|
||||
approvedWithdrawAmount: financeSummary.approvedWithdrawAmount,
|
||||
pendingRechargeAmount: financeSummary.pendingRechargeAmount,
|
||||
|
||||
Reference in New Issue
Block a user