feat(fulfillment): 增加未命中渠道兜底核销
This commit is contained in:
@@ -34,7 +34,10 @@ import { ensureCarrierForOrderItem } from './carrier-creation-service.js'
|
||||
import { reconcilePendingCarriers } from './carrier-reconciliation-service.js'
|
||||
import { TASK_STATUS } from '../../domain/task-status.js'
|
||||
import { canonicalizeInternalSku, containsCjk } from './internal-sku-resolver.js'
|
||||
import { scheduleVoucherConsumeForOrderItems } from './voucher-consume-queue-service.js'
|
||||
import {
|
||||
scheduleVoucherConsumeFallbackForOrderItems,
|
||||
scheduleVoucherConsumeForOrderItems,
|
||||
} from './voucher-consume-queue-service.js'
|
||||
import {
|
||||
assignFulfillmentChannelsWithExecutor,
|
||||
attachFulfillmentConfigurations,
|
||||
@@ -359,6 +362,7 @@ export async function assignPendingOrderItemChannels(
|
||||
channel: FulfillmentChannel
|
||||
source: FulfillmentSource
|
||||
}> = []
|
||||
const unmatchedVoucherItemIds: number[] = []
|
||||
|
||||
const channelsByInternalSku = await loadInternalSkuChannelsForKeys(
|
||||
rows.rows.map((item) => item.internal_sku),
|
||||
@@ -410,6 +414,9 @@ export async function assignPendingOrderItemChannels(
|
||||
eventType: 'routing_pending',
|
||||
reason: pending.reason,
|
||||
})
|
||||
if (pending.reason === 'no_channel_capability') {
|
||||
unmatchedVoucherItemIds.push(Number(item.id))
|
||||
}
|
||||
continue
|
||||
}
|
||||
assignments.push({ id: item.id, channel: decision.channel, source: decision.source })
|
||||
@@ -447,6 +454,18 @@ export async function assignPendingOrderItemChannels(
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
if (unmatchedVoucherItemIds.length > 0) {
|
||||
await scheduleVoucherConsumeFallbackForOrderItems(
|
||||
unmatchedVoucherItemIds,
|
||||
'order_received',
|
||||
).catch((error) => {
|
||||
logWarn('[channel-assign]', '未命中渠道后安排兜底核销失败', {
|
||||
orderItemIds: unmatchedVoucherItemIds,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
result.nextCursor = reachedEnd ? 0 : cursor
|
||||
|
||||
Reference in New Issue
Block a user