优化发码回调,失败停止整个流程
This commit is contained in:
@@ -4,9 +4,14 @@ import {
|
||||
updateOrder,
|
||||
} from '../../repositories/order-repo.js'
|
||||
import { replaceOrderItems } from '../../repositories/order-item-repo.js'
|
||||
import { listKuaishouIndustryVouchersByOid } from '../../repositories/kuaishou-industry-voucher-repo.js'
|
||||
import { syncDeliveryTasksForOrder } from './delivery-task-service.js'
|
||||
import { resolveOrderItemForFulfillment } from './product-match-service.js'
|
||||
import { bindKuaishouIndustryVouchersToOrderTasks } from '../platforms/kuaishou-industry/voucher-binding-service.js'
|
||||
import {
|
||||
isKuaishouIndustryVoucherSendCallbackSuccess,
|
||||
resolveKuaishouIndustryVoucherSendCallbackMessage,
|
||||
} from '../platforms/kuaishou-industry/voucher-service.js'
|
||||
import { nowIso } from '../../utils/time.js'
|
||||
import { logIntegration } from '../../utils/logger.js'
|
||||
import { createHttpError } from '../../utils/http.js'
|
||||
@@ -184,6 +189,25 @@ export async function upsertOrderFromSource(
|
||||
})),
|
||||
)
|
||||
|
||||
const industryVoucherGate = await resolveKuaishouIndustryVoucherGate(order.platform_order_id)
|
||||
if (!industryVoucherGate.allowed) {
|
||||
logIntegration('[order-service]', `${sourceLabel} 订单暂停履约:电子凭证发码回调未确认`, {
|
||||
orderId: order.id,
|
||||
provider: order.provider,
|
||||
platform: order.platform,
|
||||
platformOrderId: order.platform_order_id,
|
||||
voucherCount: industryVoucherGate.voucherCount,
|
||||
reason: industryVoucherGate.reason,
|
||||
}, { level: 'warn' })
|
||||
|
||||
return {
|
||||
ignoreReason: 'kuaishou_industry_send_callback_unconfirmed',
|
||||
order,
|
||||
orderItems,
|
||||
tasks: [],
|
||||
}
|
||||
}
|
||||
|
||||
const tasks = await syncDeliveryTasksForOrder(order, orderItems)
|
||||
await bindKuaishouIndustryVouchersToOrderTasks(order, tasks, {
|
||||
source: `${sourceLabel}_order_upsert`,
|
||||
@@ -209,6 +233,36 @@ export async function upsertOrderFromSource(
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveKuaishouIndustryVoucherGate(platformOrderId: unknown) {
|
||||
const oid = String(platformOrderId || '').trim()
|
||||
if (!oid) {
|
||||
return {
|
||||
allowed: true,
|
||||
voucherCount: 0,
|
||||
reason: '',
|
||||
}
|
||||
}
|
||||
|
||||
const vouchers = await listKuaishouIndustryVouchersByOid(oid)
|
||||
if (vouchers.length === 0 || vouchers.every(isKuaishouIndustryVoucherSendCallbackSuccess)) {
|
||||
return {
|
||||
allowed: true,
|
||||
voucherCount: vouchers.length,
|
||||
reason: '',
|
||||
}
|
||||
}
|
||||
|
||||
const blockedVoucher = vouchers.find((voucher) => !isKuaishouIndustryVoucherSendCallbackSuccess(voucher))
|
||||
|
||||
return {
|
||||
allowed: false,
|
||||
voucherCount: vouchers.length,
|
||||
reason: blockedVoucher
|
||||
? resolveKuaishouIndustryVoucherSendCallbackMessage(blockedVoucher)
|
||||
: '电子凭证发码回调未确认',
|
||||
}
|
||||
}
|
||||
|
||||
const ORDER_STATUS_PRIORITY = {
|
||||
created: 0,
|
||||
paid: 1,
|
||||
|
||||
Reference in New Issue
Block a user