优化打手接单上限统计
This commit is contained in:
@@ -2324,10 +2324,19 @@ async function enqueueDepositUnfreezeWithClient(
|
|||||||
export async function countWorkerActiveOrders(workerId: number | string): Promise<number> {
|
export async function countWorkerActiveOrders(workerId: number | string): Promise<number> {
|
||||||
const result = await query<{ total: number }>(
|
const result = await query<{ total: number }>(
|
||||||
`
|
`
|
||||||
SELECT COUNT(*)::int AS total
|
SELECT (
|
||||||
FROM work_orders
|
SELECT COUNT(*)::int
|
||||||
WHERE assigned_worker_id = $1
|
FROM work_orders
|
||||||
AND status IN ('in_progress', 'pending_acceptance', 'problem')
|
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)],
|
[Number(workerId)],
|
||||||
)
|
)
|
||||||
@@ -2443,10 +2452,19 @@ async function getOutstandingDepositAmountWithClient(
|
|||||||
async function countWorkerActiveOrdersWithClient(client: PoolClient, workerId: number): Promise<number> {
|
async function countWorkerActiveOrdersWithClient(client: PoolClient, workerId: number): Promise<number> {
|
||||||
const result = await client.query<{ total: number }>(
|
const result = await client.query<{ total: number }>(
|
||||||
`
|
`
|
||||||
SELECT COUNT(*)::int AS total
|
SELECT (
|
||||||
FROM work_orders
|
SELECT COUNT(*)::int
|
||||||
WHERE assigned_worker_id = $1
|
FROM work_orders
|
||||||
AND status IN ('in_progress', 'pending_acceptance', 'problem')
|
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],
|
[workerId],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -494,9 +494,10 @@ export function requireActiveWorkerSession(session: WorkerSession | null | undef
|
|||||||
|
|
||||||
export async function getWorkerProfile(session: WorkerSession) {
|
export async function getWorkerProfile(session: WorkerSession) {
|
||||||
const worker = await getRequiredWorker(session.workerId)
|
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),
|
getWorkerFinanceRequestSummary(session.workerId),
|
||||||
countWorkerAcceptedOrders(session.workerId),
|
countWorkerAcceptedOrders(session.workerId),
|
||||||
|
countWorkerActiveOrders(session.workerId),
|
||||||
countWorkerTimeoutEvents(session.workerId),
|
countWorkerTimeoutEvents(session.workerId),
|
||||||
Promise.resolve(getWorkerFinanceConfig()),
|
Promise.resolve(getWorkerFinanceConfig()),
|
||||||
])
|
])
|
||||||
@@ -507,6 +508,7 @@ export async function getWorkerProfile(session: WorkerSession) {
|
|||||||
permissions,
|
permissions,
|
||||||
summary: {
|
summary: {
|
||||||
acceptedOrderCount,
|
acceptedOrderCount,
|
||||||
|
activeOrderCount,
|
||||||
timeoutOrderCount,
|
timeoutOrderCount,
|
||||||
pendingWithdrawAmount: financeSummary.pendingWithdrawAmount,
|
pendingWithdrawAmount: financeSummary.pendingWithdrawAmount,
|
||||||
approvedWithdrawAmount: financeSummary.approvedWithdrawAmount,
|
approvedWithdrawAmount: financeSummary.approvedWithdrawAmount,
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import type { CollectField, WorkOrder, WorkerUser } from '@/types/worker-platfor
|
|||||||
import { formatDateTime } from '@/utils/date-time'
|
import { formatDateTime } from '@/utils/date-time'
|
||||||
|
|
||||||
type HallSummary = {
|
type HallSummary = {
|
||||||
activeCount: number
|
|
||||||
pendingAcceptanceCount: number
|
pendingAcceptanceCount: number
|
||||||
problemCount: number
|
problemCount: number
|
||||||
}
|
}
|
||||||
@@ -82,34 +81,24 @@ export default function WorkerHallPage() {
|
|||||||
const hallSummaryQuery = useQuery({
|
const hallSummaryQuery = useQuery({
|
||||||
queryKey: ['worker-hall-summary'],
|
queryKey: ['worker-hall-summary'],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const [inProgressResponse, pendingAcceptanceResponse, problemResponse] =
|
const [pendingAcceptanceResponse, problemResponse] = await Promise.all([
|
||||||
await Promise.all([
|
fetchWorkerMyOrders({
|
||||||
fetchWorkerMyOrders({
|
status: 'pending_acceptance',
|
||||||
status: 'in_progress',
|
page: 1,
|
||||||
page: 1,
|
pageSize: 1,
|
||||||
pageSize: 1,
|
}),
|
||||||
}),
|
fetchWorkerMyOrders({
|
||||||
fetchWorkerMyOrders({
|
status: 'problem',
|
||||||
status: 'pending_acceptance',
|
page: 1,
|
||||||
page: 1,
|
pageSize: 1,
|
||||||
pageSize: 1,
|
}),
|
||||||
}),
|
])
|
||||||
fetchWorkerMyOrders({
|
|
||||||
status: 'problem',
|
|
||||||
page: 1,
|
|
||||||
pageSize: 1,
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
|
|
||||||
const pendingAcceptanceCount =
|
const pendingAcceptanceCount =
|
||||||
pendingAcceptanceResponse.data.pagination.total
|
pendingAcceptanceResponse.data.pagination.total
|
||||||
const problemCount = problemResponse.data.pagination.total
|
const problemCount = problemResponse.data.pagination.total
|
||||||
|
|
||||||
return {
|
return {
|
||||||
activeCount:
|
|
||||||
inProgressResponse.data.pagination.total +
|
|
||||||
pendingAcceptanceCount +
|
|
||||||
problemCount,
|
|
||||||
pendingAcceptanceCount,
|
pendingAcceptanceCount,
|
||||||
problemCount,
|
problemCount,
|
||||||
} satisfies HallSummary
|
} satisfies HallSummary
|
||||||
@@ -121,7 +110,7 @@ export default function WorkerHallPage() {
|
|||||||
const pagination = ordersQuery.data?.data.pagination
|
const pagination = ordersQuery.data?.data.pagination
|
||||||
const categories = ordersQuery.data?.data.categories || []
|
const categories = ordersQuery.data?.data.categories || []
|
||||||
const worker = profileQuery.data?.data.worker
|
const worker = profileQuery.data?.data.worker
|
||||||
const activeCount = hallSummaryQuery.data?.activeCount || 0
|
const activeCount = Number(profileQuery.data?.data.summary.activeOrderCount || 0)
|
||||||
const pendingAcceptanceCount = hallSummaryQuery.data?.pendingAcceptanceCount || 0
|
const pendingAcceptanceCount = hallSummaryQuery.data?.pendingAcceptanceCount || 0
|
||||||
const problemCount = hallSummaryQuery.data?.problemCount || 0
|
const problemCount = hallSummaryQuery.data?.problemCount || 0
|
||||||
const maxActiveOrders = Number(worker?.level?.permissions.maxActiveOrders || 0)
|
const maxActiveOrders = Number(worker?.level?.permissions.maxActiveOrders || 0)
|
||||||
@@ -215,7 +204,7 @@ export default function WorkerHallPage() {
|
|||||||
note:
|
note:
|
||||||
remainingSlots === null
|
remainingSlots === null
|
||||||
? '当前等级待配置'
|
? '当前等级待配置'
|
||||||
: `待验收 ${pendingAcceptanceCount} 单 / 问题单 ${problemCount} 单`,
|
: `待验收 ${pendingAcceptanceCount} 单 / 问题单 ${problemCount} 单(不占上限)`,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export type WorkerUser = {
|
|||||||
|
|
||||||
export type WorkerProfileSummary = {
|
export type WorkerProfileSummary = {
|
||||||
acceptedOrderCount: number
|
acceptedOrderCount: number
|
||||||
|
activeOrderCount: number
|
||||||
timeoutOrderCount: number
|
timeoutOrderCount: number
|
||||||
pendingWithdrawAmount: number
|
pendingWithdrawAmount: number
|
||||||
approvedWithdrawAmount: number
|
approvedWithdrawAmount: number
|
||||||
|
|||||||
Reference in New Issue
Block a user