修复接单模板动态匹配并移除冗余运维文档

This commit is contained in:
yml
2026-11-15 00:00:04 +08:00
parent 572c43ce0e
commit 36f52a7f68
20 changed files with 627 additions and 1330 deletions
@@ -136,11 +136,9 @@ function resolvePendingReason(item: ChannelCandidateItem): {
const carrierIssue =
primary.channel === 'manual' && !Number(primaryConfig.manualConfigId || 0)
? 'manual_config_missing'
: primary.channel === 'work_order' && !String(primaryConfig.workRuleKey || '').trim()
? 'work_rule_missing'
: primary.channel === 'affiliate_dash' && !String(primaryConfig.affiliateSku || '').trim()
? 'affiliate_mapping_missing'
: 'carrier_not_attempted'
: primary.channel === 'affiliate_dash' && !String(primaryConfig.affiliateSku || '').trim()
? 'affiliate_mapping_missing'
: 'carrier_not_attempted'
return {
reason: 'no_carrier',
detail: {
@@ -793,8 +791,11 @@ export async function switchChannelForOrderItems(input: {
})
}
const targetInternalSku = switchInternalSkus[0]!
const draftProductId = await ensureDraftProductForChannel(targetInternalSku, input.channel)
if (!draftProductId) {
const draftProductId =
input.channel === 'work_order'
? null
: await ensureDraftProductForChannel(targetInternalSku, input.channel)
if (input.channel !== 'work_order' && !draftProductId) {
throw createHttpError('渠道标准商品创建或启用失败,请先在商品配置中处理', {
statusCode: 409,
errorCode: 'channel_standard_product_required',
@@ -980,6 +981,8 @@ export async function switchChannelForOrderItems(input: {
source: 'operator',
note: input.note,
adminUserId: input.adminUserId,
clearCanonicalProduct: input.channel === 'work_order',
replaceConfig: input.channel === 'work_order',
})
}
return {
@@ -2021,8 +2024,11 @@ export async function assignChannelByInternalSku(input: {
],
)
const draftProductId = await ensureDraftProductForChannel(internalSku, input.channel)
if (!draftProductId) {
const draftProductId =
input.channel === 'work_order'
? null
: await ensureDraftProductForChannel(internalSku, input.channel)
if (input.channel !== 'work_order' && !draftProductId) {
throw createHttpError('渠道标准商品创建或启用失败,请先在商品配置中处理', {
statusCode: 409,
errorCode: 'channel_standard_product_required',
@@ -2040,6 +2046,8 @@ export async function assignChannelByInternalSku(input: {
},
note: input.note,
adminUserId: input.adminUserId,
clearCanonicalProduct: input.channel === 'work_order',
replaceConfig: input.channel === 'work_order',
})
const ruleCreated = true
@@ -2238,6 +2246,7 @@ async function ensureDraftProductForChannel(
internalSku: string,
channel: FulfillmentChannel,
): Promise<number | null> {
if (channel === 'work_order') return null
const key = canonicalizeInternalSku(internalSku)
if (!key) return null
const definition = {
@@ -2247,7 +2256,6 @@ async function ensureDraftProductForChannel(
unit: '件',
sourceKind: 'affiliate_dash',
},
work_order: { prefix: 'tpl:', category: '接单', unit: '件', sourceKind: 'work_order' },
manual: { prefix: 'man:', category: '人工', unit: '件', sourceKind: 'manual' },
on_account: { prefix: 'man:', category: '统一结算', unit: '件', sourceKind: 'manual' },
third_party_voucher: {
@@ -2342,14 +2350,14 @@ async function resolveInternalSkuCarrierConfig(
}
}
if (channel === 'work_order') {
// 接单模板按真实订单匹配,不能把内部 SKU 伪造成 workRuleKey。
// 空配置表示动态匹配;生成工单后再把实际模板商品写回正式履约。
return { canonicalProductId: null, configJson: { templateSelection: 'dynamic' } }
}
const prefixes =
channel === 'affiliate_dash'
? ['aff:']
: channel === 'work_order'
? ['tpl:', 'wo:']
: channel === 'on_account'
? ['man:']
: ['tpv:']
channel === 'affiliate_dash' ? ['aff:'] : channel === 'on_account' ? ['man:'] : ['tpv:']
const product = await query<{ id: number; canonical_sku: string }>(
`SELECT id, canonical_sku
FROM product_catalog
@@ -2385,11 +2393,9 @@ async function resolveInternalSkuCarrierConfig(
configJson:
channel === 'affiliate_dash'
? { affiliateSku: carrierKey }
: channel === 'work_order'
? { workRuleKey: carrierKey }
: channel === 'on_account'
? { settlementSku: carrierKey }
: { voucherSku: carrierKey },
: channel === 'on_account'
? { settlementSku: carrierKey }
: { voucherSku: carrierKey },
}
}
@@ -2422,8 +2428,11 @@ export async function upsertChannelRule(input: {
})
}
const draftProductId = await ensureDraftProductForChannel(matchKey, input.channel)
if (!draftProductId) {
const draftProductId =
input.channel === 'work_order'
? null
: await ensureDraftProductForChannel(matchKey, input.channel)
if (input.channel !== 'work_order' && !draftProductId) {
throw createHttpError('渠道标准商品创建或启用失败,请先在商品配置中处理', {
statusCode: 409,
errorCode: 'channel_standard_product_required',
@@ -2443,8 +2452,10 @@ export async function upsertChannelRule(input: {
note: String(input.note || '').slice(0, 300),
adminUserId: input.adminUserId,
replacePriority: true,
canonicalProductId: draftProductId,
canonicalProductId: carrier.canonicalProductId ?? draftProductId,
configJson: carrier.configJson,
clearCanonicalProduct: input.channel === 'work_order',
replaceConfig: input.channel === 'work_order',
})
return { id }
}