拆分工单押金查询
This commit is contained in:
@@ -8,6 +8,7 @@ export * from './worker-finance-repo.js'
|
|||||||
export * from './worker-ranking-repo.js'
|
export * from './worker-ranking-repo.js'
|
||||||
export * from './work-order-repo.js'
|
export * from './work-order-repo.js'
|
||||||
export * from './work-order-query-repo.js'
|
export * from './work-order-query-repo.js'
|
||||||
|
export * from './work-order-deposit-query-repo.js'
|
||||||
export * from './work-order-event-repo.js'
|
export * from './work-order-event-repo.js'
|
||||||
export * from './work-order-share-repo.js'
|
export * from './work-order-share-repo.js'
|
||||||
export * from './work-category-repo.js'
|
export * from './work-category-repo.js'
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { query } from '../../db/client.js'
|
||||||
|
|
||||||
|
/** 汇总仍在等待解冻的押金,供订单详情和实时通知展示。 */
|
||||||
|
export async function sumPendingUnfreezeByOrderIds(
|
||||||
|
workOrderIds: number[],
|
||||||
|
): Promise<Map<number, number>> {
|
||||||
|
const totals = new Map<number, number>()
|
||||||
|
const uniqueIds = [...new Set(workOrderIds.map(Number).filter((id) => id > 0))]
|
||||||
|
if (uniqueIds.length === 0) return totals
|
||||||
|
const result = await query<{ work_order_id: number; total: number }>(
|
||||||
|
`
|
||||||
|
SELECT work_order_id, SUM(amount)::int AS total
|
||||||
|
FROM worker_deposit_unfreezes
|
||||||
|
WHERE work_order_id = ANY($1::bigint[])
|
||||||
|
AND status = 'pending'
|
||||||
|
GROUP BY work_order_id
|
||||||
|
`,
|
||||||
|
[uniqueIds],
|
||||||
|
)
|
||||||
|
for (const row of result.rows) {
|
||||||
|
totals.set(Number(row.work_order_id), Number(row.total || 0))
|
||||||
|
}
|
||||||
|
return totals
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@ import type { PoolClient } from 'pg'
|
|||||||
import { maybeUpgradeWorkerLevelWithClient } from './worker-ranking-repo.js'
|
import { maybeUpgradeWorkerLevelWithClient } from './worker-ranking-repo.js'
|
||||||
|
|
||||||
export * from './work-order-query-repo.js'
|
export * from './work-order-query-repo.js'
|
||||||
|
export { sumPendingUnfreezeByOrderIds } from './work-order-deposit-query-repo.js'
|
||||||
|
|
||||||
export async function createWorkOrder(input: CreateWorkOrderInput): Promise<WorkOrderRow | null> {
|
export async function createWorkOrder(input: CreateWorkOrderInput): Promise<WorkOrderRow | null> {
|
||||||
const result = await query<{ id: number }>(
|
const result = await query<{ id: number }>(
|
||||||
@@ -1882,28 +1883,6 @@ export async function settleOverdueWorkOrder(input: {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sumPendingUnfreezeByOrderIds(
|
|
||||||
workOrderIds: number[],
|
|
||||||
): Promise<Map<number, number>> {
|
|
||||||
const totals = new Map<number, number>()
|
|
||||||
const uniqueIds = [...new Set(workOrderIds.map(Number).filter((id) => id > 0))]
|
|
||||||
if (uniqueIds.length === 0) return totals
|
|
||||||
const result = await query<{ work_order_id: number; total: number }>(
|
|
||||||
`
|
|
||||||
SELECT work_order_id, SUM(amount)::int AS total
|
|
||||||
FROM worker_deposit_unfreezes
|
|
||||||
WHERE work_order_id = ANY($1::bigint[])
|
|
||||||
AND status = 'pending'
|
|
||||||
GROUP BY work_order_id
|
|
||||||
`,
|
|
||||||
[uniqueIds],
|
|
||||||
)
|
|
||||||
for (const row of result.rows) {
|
|
||||||
totals.set(Number(row.work_order_id), Number(row.total || 0))
|
|
||||||
}
|
|
||||||
return totals
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function deductPendingDepositUnfreeze(input: {
|
export async function deductPendingDepositUnfreeze(input: {
|
||||||
workOrderId: number
|
workOrderId: number
|
||||||
amount: number
|
amount: number
|
||||||
|
|||||||
Reference in New Issue
Block a user