优化订单履约分流与后台筛选
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
import { buildClaimUrl } from '../claim/claim-service.js'
|
||||
import { buildClaimIdentityAdminSummary } from '../claim/claim-identity.js'
|
||||
import { getClaimTokenById } from '../../repositories/claim-token-repo.js'
|
||||
import { listOrderItemsByOrderId } from '../../repositories/order-item-repo.js'
|
||||
import {
|
||||
listOrderItemsByOrderId,
|
||||
listOrderItemsByOrderIds,
|
||||
} from '../../repositories/order-item-repo.js'
|
||||
import { getOrderById, listOrders } from '../../repositories/order-repo.js'
|
||||
import { getTaskById, listTasks, listTasksByOrderId } from '../../repositories/task-repo.js'
|
||||
import {
|
||||
getTaskById,
|
||||
listTasks,
|
||||
listTasksByOrderId,
|
||||
listTasksByOrderIds,
|
||||
} from '../../repositories/task-repo.js'
|
||||
import { listTaskEventsByTaskId } from '../../repositories/task-event-repo.js'
|
||||
import type { JsonRecord } from '../../types/json.js'
|
||||
import {
|
||||
@@ -76,19 +84,46 @@ export async function getAdminOrders(
|
||||
const { items, total } = await listOrders({
|
||||
page,
|
||||
pageSize,
|
||||
keyword: String(query.keyword || '').trim(),
|
||||
provider: String(query.provider || '').trim(),
|
||||
executorKey: String(query.executorKey || '').trim(),
|
||||
platformOrderId: String(query.platformOrderId || '').trim(),
|
||||
payStatus: String(query.payStatus || '').trim(),
|
||||
taskStatus: String(query.taskStatus || '').trim(),
|
||||
skuCode: String(query.skuCode || '').trim(),
|
||||
dateFrom: normalizeDateQuery(query.dateFrom),
|
||||
dateTo: normalizeDateQuery(query.dateTo, true),
|
||||
})
|
||||
|
||||
const orderIds = items.map((item) => item.id)
|
||||
const [orderItems, tasks] = await Promise.all([
|
||||
listOrderItemsByOrderIds(orderIds),
|
||||
listTasksByOrderIds(orderIds),
|
||||
])
|
||||
const orderItemsByOrderId = groupRowsByOrderId(orderItems)
|
||||
const tasksByOrderId = groupRowsByOrderId(tasks)
|
||||
|
||||
return {
|
||||
items: await Promise.all(items.map((item) => mapAdminOrderListItem(item))),
|
||||
items: items.map((item) =>
|
||||
mapAdminOrderListItem(item, {
|
||||
orderItems: orderItemsByOrderId.get(item.id) || [],
|
||||
tasks: tasksByOrderId.get(item.id) || [],
|
||||
}),
|
||||
),
|
||||
pagination: { page, pageSize, total },
|
||||
}
|
||||
}
|
||||
|
||||
function groupRowsByOrderId<T extends { order_id: number }>(rows: T[]): Map<number, T[]> {
|
||||
const grouped = new Map<number, T[]>()
|
||||
for (const row of rows) {
|
||||
const group = grouped.get(row.order_id) || []
|
||||
group.push(row)
|
||||
grouped.set(row.order_id, group)
|
||||
}
|
||||
return grouped
|
||||
}
|
||||
|
||||
export async function getAdminOrderDetail(
|
||||
orderId: AdminEntityIdInput,
|
||||
session: AdminViewerSessionInput | null = null,
|
||||
@@ -196,6 +231,8 @@ export async function getAdminTasks(
|
||||
const { items, total } = await listTasks({
|
||||
page,
|
||||
pageSize,
|
||||
keyword: String(query.keyword || '').trim(),
|
||||
executorKey: String(query.executorKey || '').trim(),
|
||||
status: String(query.status || '').trim(),
|
||||
platformOrderId: String(query.platformOrderId || '').trim(),
|
||||
taskNo: String(query.taskNo || '').trim(),
|
||||
|
||||
Reference in New Issue
Block a user