修复核销提前导致的链接不初始化错误
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
* 把「核销时间」提前到链接交付时刻,降低「拿链即退」误退窗口。
|
||||
*
|
||||
* 语义:核销 = 领取链接已交付(售出闭环),≠ 游戏内道具已到账。
|
||||
*
|
||||
* 交付后会 best-effort 自动准备 Cloud 绑定资源(取号/绑链),避免
|
||||
* 「已核销却停在待准备资源」只能靠后台手动点「准备资源」。
|
||||
*/
|
||||
import {
|
||||
attachKuaishouIndustryVoucherToTask,
|
||||
@@ -11,8 +14,11 @@ import {
|
||||
import {
|
||||
consumeKuaishouIndustryVoucher,
|
||||
} from '../platforms/kuaishou-industry/voucher-service.js'
|
||||
import { prepareFulfillmentBinding } from '../fulfillment/executors/registry.js'
|
||||
import { normalizeKuaishouCloudFlow } from '../fulfillment/kuaishou-cloud/index.js'
|
||||
import { listKuaishouIndustryVouchersByOid } from '../../repositories/kuaishou-industry-voucher-repo.js'
|
||||
import { logIntegration, logWarn } from '../../utils/logger.js'
|
||||
import { parseTaskContext } from '../../utils/task-json.js'
|
||||
import type {
|
||||
KuaishouIndustryVoucherRow,
|
||||
OrderRow,
|
||||
@@ -130,8 +136,18 @@ export async function consumeIndustryVouchersBeforeOpen91Deliver(options: {
|
||||
continue
|
||||
}
|
||||
|
||||
await attachKuaishouIndustryVoucherToTask(task, result.voucher, {
|
||||
const attachedTask =
|
||||
(await attachKuaishouIndustryVoucherToTask(task, result.voucher, {
|
||||
source,
|
||||
})) || task
|
||||
|
||||
// 核销后立刻补准备绑定资源;失败不阻断 cards(领取页仍会再兜底 prepare)
|
||||
await ensureBindingPreparedAfterDeliver({
|
||||
task: attachedTask,
|
||||
source,
|
||||
requestId: options.requestId || '',
|
||||
orderId: options.order.id,
|
||||
orderNo: oid,
|
||||
})
|
||||
|
||||
if (alreadyConsumed) {
|
||||
@@ -179,3 +195,50 @@ export async function consumeIndustryVouchersBeforeOpen91Deliver(options: {
|
||||
alreadyConsumedTaskIds,
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureBindingPreparedAfterDeliver(options: {
|
||||
task: TaskRow
|
||||
source: string
|
||||
requestId: string
|
||||
orderId: number
|
||||
orderNo: string
|
||||
}) {
|
||||
const executorKey = String(options.task.executor_key || '').trim()
|
||||
// lewan / 行业凭证任务才需要 Cloud 绑定资源
|
||||
if (
|
||||
executorKey !== 'kuaishou_ct_assisted' &&
|
||||
executorKey !== 'kuaishou-industry' &&
|
||||
!parseTaskContext(options.task).kuaishouCloudFulfillment
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const flow = normalizeKuaishouCloudFlow(
|
||||
parseTaskContext(options.task).kuaishouCloudFulfillment,
|
||||
)
|
||||
if (flow.binding.prepareStatus === 'ready' && String(flow.binding.bindUrl || '').trim()) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await prepareFulfillmentBinding(options.task, {
|
||||
source: `${options.source}_prepare_binding`,
|
||||
actor: { source: options.source },
|
||||
})
|
||||
logIntegration('[open-91/query]', '91交付后自动准备绑定资源成功', {
|
||||
requestId: options.requestId,
|
||||
orderId: options.orderId,
|
||||
orderNo: options.orderNo,
|
||||
taskId: options.task.id,
|
||||
source: options.source,
|
||||
})
|
||||
} catch (error) {
|
||||
logWarn('[open-91/query]', '91交付后自动准备绑定资源失败(不阻断 cards,领取页将再试)', {
|
||||
requestId: options.requestId,
|
||||
orderId: options.orderId,
|
||||
orderNo: options.orderNo,
|
||||
taskId: options.task.id,
|
||||
error: error instanceof Error ? error.message : String(error || ''),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user