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
@@ -511,7 +511,6 @@ export async function assignOrderItemsAfterCarrierReady(input: {
item,
channel: input.channel,
retryInactiveCarrier: true,
allowInactiveTaskRetry: true,
})
} catch (error) {
carrier = {
@@ -1216,9 +1215,16 @@ export type RetryPendingCarrierGroupResult = {
remaining: number
}
/** 运营确认后重试整组载体:允许重开已关闭的历史尝试,并包含运营锁定的订单项。 */
/**
* 运营确认后重试整组载体。
*
* 默认只处理未锁定且没有历史终态任务的订单;重开旧任务必须显式传入
* retryInactiveCarrier。锁定项需要先解除锁定,避免一次操作误伤整组。
*/
export async function retryPendingCarrierGroup(input: {
internalSku: string
retryInactiveCarrier?: boolean
includeLocked?: boolean
}): Promise<RetryPendingCarrierGroupResult> {
const internalSku = canonicalizeInternalSku(input.internalSku)
if (!internalSku || !containsCjk(internalSku)) {
@@ -1247,8 +1253,8 @@ export async function retryPendingCarrierGroup(input: {
const carrier = await reconcilePendingCarriers({
orderItemIds: batchIds,
limit: batchIds.length,
includeLocked: true,
retryInactiveCarrier: true,
includeLocked: input.includeLocked === true,
retryInactiveCarrier: input.retryInactiveCarrier === true,
})
workOrdersCreated += carrier.workOrdersCreated
affiliateTasksCreated += carrier.affiliateTasksCreated
@@ -1258,7 +1264,7 @@ export async function retryPendingCarrierGroup(input: {
batchSize: batchIds.length,
maxBatches: 1,
afterId: 0,
includeLocked: true,
includeLocked: input.includeLocked === true,
})
assignedItemIds.push(...applied.assignedItemIds)
}
@@ -1303,6 +1309,40 @@ export async function retryPendingCarrierGroup(input: {
}
}
/** 解除一个待分类分组中的运营锁定,让自动路由或后续修复重新接管。 */
export async function unlockPendingChannelGroup(input: {
groupKey?: string
internalSku?: string
}): Promise<{ updated: number }> {
const scope = resolvePendingGroupScopeInput(input)
if (!scope) {
throw createHttpError('缺少待分类队列分组标识', {
statusCode: 400,
errorCode: 'pending_group_key_required',
})
}
const params: unknown[] = []
const where = ["oi.fulfillment_status = 'pending'", 'oi.fulfillment_locked = TRUE']
if (scope.type === 'internal_sku') {
params.push(scope.internalSku)
where.push(`${INTERNAL_SKU_SQL} = $${params.length}`)
} else {
params.push(scope.provider, scope.shopId, scope.skuCode)
where.push(`o.provider = $1 AND o.shop_id = $2 AND oi.sku_code = $3`)
}
const result = await query(
`UPDATE order_items oi
SET fulfillment_locked = FALSE,
updated_at = NOW()
FROM orders o
WHERE o.id = oi.order_id
AND ${where.join(' AND ')}`,
params,
)
return { updated: result.rowCount || 0 }
}
export type DeletePendingChannelGroupResult = {
archivedItems: number
preservedOrders: number