修复历史电子凭证任务操作入口
This commit is contained in:
@@ -63,6 +63,10 @@ import type {
|
||||
AdminTaskListQueryInput,
|
||||
AdminViewerSessionInput,
|
||||
} from '../../types/admin/read-inputs.js'
|
||||
import type {
|
||||
KuaishouIndustryVoucherRow,
|
||||
TaskRow,
|
||||
} from '../../types/repository/rows.js'
|
||||
|
||||
type JsonRecord = Record<string, any>
|
||||
|
||||
@@ -220,11 +224,14 @@ export async function getAdminTaskDetail(
|
||||
}
|
||||
|
||||
const primaryClaimTokenId = getTaskPrimaryClaimTokenId(task)
|
||||
const [order, claimToken, taskEvents, taskKuaishouIndustryVouchers] = await Promise.all([
|
||||
const [order, claimToken, taskEvents, taskKuaishouIndustryVouchers, oidKuaishouIndustryVouchers] = await Promise.all([
|
||||
getOrderById(task.order_id),
|
||||
primaryClaimTokenId ? getClaimTokenById(primaryClaimTokenId) : Promise.resolve(null),
|
||||
listTaskEventsByTaskId(task.id),
|
||||
listKuaishouIndustryVouchersByTaskId(task.id),
|
||||
task.platform_order_id
|
||||
? listKuaishouIndustryVouchersByOid(task.platform_order_id)
|
||||
: Promise.resolve([]),
|
||||
])
|
||||
const orderItems = order ? await listOrderItemsByOrderId(order.id) : []
|
||||
const orderItem = orderItems.find((item) => item.id === task.order_item_id) || null
|
||||
@@ -241,7 +248,12 @@ export async function getAdminTaskDetail(
|
||||
mapKuaishouCloudFulfillmentContext(taskContext.kuaishouCloudFulfillment, {
|
||||
cloudSourceLabelMap,
|
||||
}) || mapKuaishouCloudTaskStateProjection(task, { cloudSourceLabelMap })
|
||||
const firstKuaishouIndustryVoucher = taskKuaishouIndustryVouchers[0] || null
|
||||
const firstKuaishouIndustryVoucher = resolveKuaishouIndustryVoucherForTask(
|
||||
task,
|
||||
taskContext,
|
||||
taskKuaishouIndustryVouchers,
|
||||
oidKuaishouIndustryVouchers,
|
||||
)
|
||||
const kuaishouIndustryVoucher =
|
||||
firstKuaishouIndustryVoucher
|
||||
? mapAdminKuaishouIndustryVoucher(firstKuaishouIndustryVoucher)
|
||||
@@ -375,6 +387,46 @@ function mapKuaishouIndustryVoucherContext(value: unknown): JsonRecord | null {
|
||||
}
|
||||
}
|
||||
|
||||
function resolveKuaishouIndustryVoucherForTask(
|
||||
task: TaskRow,
|
||||
taskContext: JsonRecord,
|
||||
taskVouchers: KuaishouIndustryVoucherRow[],
|
||||
oidVouchers: KuaishouIndustryVoucherRow[],
|
||||
): KuaishouIndustryVoucherRow | null {
|
||||
const linkedVoucher = taskVouchers[0] || null
|
||||
if (linkedVoucher) {
|
||||
return linkedVoucher
|
||||
}
|
||||
|
||||
const voucherContext =
|
||||
taskContext.kuaishouIndustryVoucher &&
|
||||
typeof taskContext.kuaishouIndustryVoucher === 'object' &&
|
||||
!Array.isArray(taskContext.kuaishouIndustryVoucher)
|
||||
? taskContext.kuaishouIndustryVoucher as JsonRecord
|
||||
: {}
|
||||
const voucherCode = String(voucherContext.voucherCode || voucherContext.eticketId || '').trim()
|
||||
if (voucherCode) {
|
||||
const matchedByCode = oidVouchers.find(
|
||||
(voucher) => String(voucher.voucher_code || '').trim() === voucherCode,
|
||||
)
|
||||
if (matchedByCode) {
|
||||
return matchedByCode
|
||||
}
|
||||
}
|
||||
|
||||
const unitIndex = Number(task.unit_index || 0) || 0
|
||||
if (unitIndex > 0) {
|
||||
const matchedByUnit = oidVouchers.find(
|
||||
(voucher) => Number(voucher.unit_index || 0) === unitIndex,
|
||||
)
|
||||
if (matchedByUnit) {
|
||||
return matchedByUnit
|
||||
}
|
||||
}
|
||||
|
||||
return oidVouchers.length === 1 ? (oidVouchers[0] || null) : null
|
||||
}
|
||||
|
||||
function buildCloudSourceLabelMap() {
|
||||
const labelMap = new Map<string, string>()
|
||||
|
||||
|
||||
@@ -969,6 +969,30 @@ async function getRequiredIndustryVoucherForTask(task: TaskRow): Promise<Kuaisho
|
||||
}
|
||||
}
|
||||
|
||||
const oidVouchers = await resolveIndustryVouchersForOrder(task.platform_order_id)
|
||||
if (voucherCode) {
|
||||
const matchedByCode = oidVouchers.find(
|
||||
(voucher) => String(voucher.voucher_code || '').trim() === voucherCode,
|
||||
)
|
||||
if (matchedByCode) {
|
||||
return matchedByCode
|
||||
}
|
||||
}
|
||||
|
||||
const unitIndex = Number(task.unit_index || 0) || 0
|
||||
if (unitIndex > 0) {
|
||||
const matchedByUnit = oidVouchers.find(
|
||||
(voucher) => Number(voucher.unit_index || 0) === unitIndex,
|
||||
)
|
||||
if (matchedByUnit) {
|
||||
return matchedByUnit
|
||||
}
|
||||
}
|
||||
|
||||
if (oidVouchers.length === 1 && oidVouchers[0]) {
|
||||
return oidVouchers[0]
|
||||
}
|
||||
|
||||
throw createHttpError('当前任务没有关联电子凭证,无法执行该操作', {
|
||||
statusCode: 409,
|
||||
errorCode: 'admin_task_kuaishou_industry_voucher_missing',
|
||||
|
||||
Reference in New Issue
Block a user