feat(admin): 收口人工履约入口并修复履约筛选
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
} from '../../repositories/order-item-repo.js'
|
||||
import { getOrderById, listOrders } from '../../repositories/order-repo.js'
|
||||
import { listOrderRefunds } from '../finance/order-refund-service.js'
|
||||
import { getManualFulfillmentCountsByOrderIds } from '../finance/manual-fulfillment-service.js'
|
||||
import {
|
||||
getTaskById,
|
||||
listTasks,
|
||||
@@ -104,6 +105,7 @@ export async function getAdminOrders(
|
||||
keyword: String(query.keyword || '').trim(),
|
||||
provider: String(query.provider || '').trim(),
|
||||
executorKey: String(query.executorKey || '').trim(),
|
||||
fulfillmentMode: normalizeOrderFulfillmentModeFilter(query.fulfillmentMode),
|
||||
platformOrderId: String(query.platformOrderId || '').trim(),
|
||||
payStatus: String(query.payStatus || '').trim(),
|
||||
taskStatus: String(query.taskStatus || '').trim(),
|
||||
@@ -114,11 +116,12 @@ export async function getAdminOrders(
|
||||
|
||||
const orderIds = items.map((item) => Number(item.id)).filter((id) => id > 0)
|
||||
const oids = items.map((item) => item.platform_order_id).filter(Boolean)
|
||||
const [orderItems, tasks, vouchers, workOrders] = await Promise.all([
|
||||
const [orderItems, tasks, vouchers, workOrders, manualCounts] = await Promise.all([
|
||||
listOrderItemsByOrderIds(orderIds),
|
||||
listTasksByOrderIds(orderIds),
|
||||
listKuaishouIndustryVouchersByOids(oids),
|
||||
listWorkOrdersByOrderIds(orderIds),
|
||||
getManualFulfillmentCountsByOrderIds(orderIds),
|
||||
])
|
||||
const orderItemsByOrderId = groupRowsByOrderId(orderItems)
|
||||
const tasksByOrderId = groupRowsByOrderId(tasks)
|
||||
@@ -136,12 +139,29 @@ export async function getAdminOrders(
|
||||
tasks: orderTasks,
|
||||
vouchers: orderVouchers,
|
||||
workOrderCount: orderWorkOrders.length,
|
||||
manualConfig: manualCounts.get(orderId) || { pending: 0, unconfigured: 0 },
|
||||
})
|
||||
}),
|
||||
pagination: { page, pageSize, total },
|
||||
}
|
||||
}
|
||||
|
||||
const ADMIN_ORDER_FULFILLMENT_MODES = new Set([
|
||||
'work_order',
|
||||
'affiliate_dash',
|
||||
'legacy_platform',
|
||||
'manual',
|
||||
'mixed',
|
||||
'pending',
|
||||
])
|
||||
|
||||
function normalizeOrderFulfillmentModeFilter(value: unknown): string {
|
||||
const mode = String(value || '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
return ADMIN_ORDER_FULFILLMENT_MODES.has(mode) ? mode : ''
|
||||
}
|
||||
|
||||
function groupRowsByOrderId<T extends { order_id?: number | string | null }>(
|
||||
rows: T[],
|
||||
): Map<number, T[]> {
|
||||
@@ -182,12 +202,14 @@ export async function getAdminOrderDetail(
|
||||
})
|
||||
}
|
||||
|
||||
const [items, tasks, workOrders, refunds] = await Promise.all([
|
||||
const [items, tasks, workOrders, refunds, manualCounts] = await Promise.all([
|
||||
listOrderItemsByOrderId(order.id),
|
||||
listTasksByOrderId(order.id),
|
||||
listWorkOrdersByOrderId(order.id),
|
||||
listOrderRefunds(order.id),
|
||||
getManualFulfillmentCountsByOrderIds([order.id]),
|
||||
])
|
||||
const manualConfig = manualCounts.get(Number(order.id)) || { pending: 0, unconfigured: 0 }
|
||||
const kuaishouIndustryVouchers = await listKuaishouIndustryVouchersByOid(order.platform_order_id)
|
||||
const itemSummary = summarizeOrderItems(items, order, kuaishouIndustryVouchers)
|
||||
const orderItemTitle = resolveOrderItemTitle(items[0], order, kuaishouIndustryVouchers)
|
||||
@@ -233,6 +255,8 @@ export async function getAdminOrderDetail(
|
||||
fulfillmentMode: fulfillment.fulfillmentMode,
|
||||
manualItemCount: fulfillment.manualItemCount,
|
||||
pendingItemCount: fulfillment.pendingItemCount,
|
||||
manualPendingCount: manualConfig.pending,
|
||||
manualUnconfiguredCount: manualConfig.unconfigured,
|
||||
hasVoucher: fulfillment.hasVoucher,
|
||||
voucherState: fulfillment.voucherState,
|
||||
workOrderCount: workOrders.length,
|
||||
|
||||
Reference in New Issue
Block a user