fix(fulfillment): 修复载体重试并完善核销任务列表

This commit is contained in:
yml2213
2026-11-05 18:36:10 +08:00
parent 89a68b5734
commit e8b76b3b73
19 changed files with 945 additions and 104 deletions
@@ -22,6 +22,8 @@ import { attachKuaishouIndustryVoucherToTask } from '../platforms/kuaishou-indus
import { verifyCertificate } from '../redeem/certificate-service.js'
import { logIntegration, logWarn } from '../../utils/logger.js'
import {
VOUCHER_CONSUME_CHANNELS,
VOUCHER_CONSUME_PROVIDERS,
getVoucherConsumePolicy,
resolveVoucherConsumePolicy,
type VoucherConsumeChannel,
@@ -99,6 +101,13 @@ type VoucherOrderItemTargetRow = {
const RETRY_DELAYS_SECONDS = [10, 30, 60, 300, 600, 900, 1800]
const PROCESSING_LOCK_SECONDS = 120
const VOUCHER_CONSUME_JOB_STATUSES = [
'pending',
'processing',
'succeeded',
'failed',
'cancelled',
] as const
export async function scheduleVoucherConsumeForTask(
task: TaskRow,
@@ -443,6 +452,9 @@ export async function runVoucherConsumeDispatchJob(
export async function listVoucherConsumeJobs(
input: {
keyword?: string
provider?: string
channel?: string
status?: string
page?: number
pageSize?: number
@@ -450,10 +462,43 @@ export async function listVoucherConsumeJobs(
) {
const page = clampInteger(input.page, 1, 1, Number.MAX_SAFE_INTEGER)
const pageSize = clampInteger(input.pageSize, 20, 1, 100)
const status = String(input.status || '').trim()
const keyword = String(input.keyword || '')
.trim()
.slice(0, 100)
const providerInput = String(input.provider || '').trim()
const provider = (VOUCHER_CONSUME_PROVIDERS as readonly string[]).includes(providerInput)
? providerInput
: ''
const channel = (VOUCHER_CONSUME_CHANNELS as readonly string[]).includes(
String(input.channel || '').trim(),
)
? String(input.channel).trim()
: ''
const status = (VOUCHER_CONSUME_JOB_STATUSES as readonly string[]).includes(
String(input.status || '').trim(),
)
? String(input.status).trim()
: ''
const params: unknown[] = []
const where: string[] = []
if (keyword) {
params.push(`%${keyword}%`)
where.push(
`(CAST(id AS TEXT) ILIKE $${params.length}
OR platform_order_id ILIKE $${params.length}
OR target_key ILIKE $${params.length}
OR CAST(order_id AS TEXT) ILIKE $${params.length})`,
)
}
if (provider) {
params.push(provider)
where.push(`provider = $${params.length}`)
}
if (channel) {
params.push(channel)
where.push(`channel = $${params.length}`)
}
if (status) {
params.push(status)
where.push(`status = $${params.length}`)