优化打手接单上限统计
This commit is contained in:
@@ -2324,10 +2324,19 @@ async function enqueueDepositUnfreezeWithClient(
|
||||
export async function countWorkerActiveOrders(workerId: number | string): Promise<number> {
|
||||
const result = await query<{ total: number }>(
|
||||
`
|
||||
SELECT COUNT(*)::int AS total
|
||||
FROM work_orders
|
||||
WHERE assigned_worker_id = $1
|
||||
AND status IN ('in_progress', 'pending_acceptance', 'problem')
|
||||
SELECT (
|
||||
SELECT COUNT(*)::int
|
||||
FROM work_orders
|
||||
WHERE assigned_worker_id = $1
|
||||
AND status = 'in_progress'
|
||||
) + (
|
||||
SELECT COUNT(*)::int
|
||||
FROM work_order_shares wos
|
||||
INNER JOIN work_orders wo ON wo.id = wos.work_order_id
|
||||
WHERE wos.worker_id = $1
|
||||
AND wos.status = 'joined'
|
||||
AND wo.status = 'open'
|
||||
) AS total
|
||||
`,
|
||||
[Number(workerId)],
|
||||
)
|
||||
@@ -2443,10 +2452,19 @@ async function getOutstandingDepositAmountWithClient(
|
||||
async function countWorkerActiveOrdersWithClient(client: PoolClient, workerId: number): Promise<number> {
|
||||
const result = await client.query<{ total: number }>(
|
||||
`
|
||||
SELECT COUNT(*)::int AS total
|
||||
FROM work_orders
|
||||
WHERE assigned_worker_id = $1
|
||||
AND status IN ('in_progress', 'pending_acceptance', 'problem')
|
||||
SELECT (
|
||||
SELECT COUNT(*)::int
|
||||
FROM work_orders
|
||||
WHERE assigned_worker_id = $1
|
||||
AND status = 'in_progress'
|
||||
) + (
|
||||
SELECT COUNT(*)::int
|
||||
FROM work_order_shares wos
|
||||
INNER JOIN work_orders wo ON wo.id = wos.work_order_id
|
||||
WHERE wos.worker_id = $1
|
||||
AND wos.status = 'joined'
|
||||
AND wo.status = 'open'
|
||||
) AS total
|
||||
`,
|
||||
[workerId],
|
||||
)
|
||||
|
||||
@@ -494,9 +494,10 @@ export function requireActiveWorkerSession(session: WorkerSession | null | undef
|
||||
|
||||
export async function getWorkerProfile(session: WorkerSession) {
|
||||
const worker = await getRequiredWorker(session.workerId)
|
||||
const [financeSummary, acceptedOrderCount, timeoutOrderCount, financeConfig] = await Promise.all([
|
||||
const [financeSummary, acceptedOrderCount, activeOrderCount, timeoutOrderCount, financeConfig] = await Promise.all([
|
||||
getWorkerFinanceRequestSummary(session.workerId),
|
||||
countWorkerAcceptedOrders(session.workerId),
|
||||
countWorkerActiveOrders(session.workerId),
|
||||
countWorkerTimeoutEvents(session.workerId),
|
||||
Promise.resolve(getWorkerFinanceConfig()),
|
||||
])
|
||||
@@ -507,6 +508,7 @@ export async function getWorkerProfile(session: WorkerSession) {
|
||||
permissions,
|
||||
summary: {
|
||||
acceptedOrderCount,
|
||||
activeOrderCount,
|
||||
timeoutOrderCount,
|
||||
pendingWithdrawAmount: financeSummary.pendingWithdrawAmount,
|
||||
approvedWithdrawAmount: financeSummary.approvedWithdrawAmount,
|
||||
|
||||
Reference in New Issue
Block a user