fix(admin): 任务列表商品名与执行器标签改为中文展示
建单时不再把英文 sku 写入商品名,列表按映射反查中文名,并将 Affiliate Dash 等标签本地化。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -33,6 +33,11 @@ import {
|
||||
canMarkManualReviewTaskStatus,
|
||||
canRetryTaskStatus,
|
||||
} from '../../domain/task-status.js'
|
||||
import { getAffiliateDashConfig } from '../platforms/affiliate-dash/config.js'
|
||||
import {
|
||||
mergeAffiliateDashSkuMapping,
|
||||
resolveAffiliateDashDisplayProductName,
|
||||
} from '../platforms/affiliate-dash/sku-mapping.js'
|
||||
import {
|
||||
canViewerCloseTask,
|
||||
canRegenerateClaimLinkForViewer,
|
||||
@@ -361,7 +366,11 @@ export async function getAdminTaskDetail(
|
||||
? {
|
||||
orderItemId: orderItem.id,
|
||||
skuCode: orderItem.sku_code,
|
||||
skuName: orderItem.sku_name,
|
||||
skuName: resolveAffiliateDashDisplayProductName(
|
||||
String(orderItem.sku_code || ''),
|
||||
String(orderItem.sku_name || ''),
|
||||
mergeAffiliateDashSkuMapping(getAffiliateDashConfig().skuMapping),
|
||||
),
|
||||
quantity: orderItem.quantity,
|
||||
}
|
||||
: null,
|
||||
|
||||
@@ -7,6 +7,11 @@ import {
|
||||
isTaskFulfillmentCompletedStatus,
|
||||
normalizeTaskStatus,
|
||||
} from '../../domain/task-status.js'
|
||||
import { getAffiliateDashConfig } from '../platforms/affiliate-dash/config.js'
|
||||
import {
|
||||
mergeAffiliateDashSkuMapping,
|
||||
resolveAffiliateDashDisplayProductName,
|
||||
} from '../platforms/affiliate-dash/sku-mapping.js'
|
||||
import {
|
||||
createAdminViewerContext,
|
||||
getTaskPrimaryClaimTokenId,
|
||||
@@ -81,13 +86,16 @@ export function mapAdminTaskListItem(
|
||||
viewerContext: AdminViewerContext = createAdminViewerContext(),
|
||||
): AdminTaskListItem {
|
||||
const fulfillment = buildTaskFulfillmentState(task)
|
||||
const skuCode = String(task.sku_code || '').trim()
|
||||
const rawSkuName = String(task.sku_name || '').trim()
|
||||
const skuMapping = mergeAffiliateDashSkuMapping(getAffiliateDashConfig().skuMapping)
|
||||
|
||||
return {
|
||||
taskId: task.id,
|
||||
taskNo: task.task_no,
|
||||
platformOrderId: task.platform_order_id,
|
||||
skuCode: task.sku_code || '',
|
||||
skuName: task.sku_name || '',
|
||||
skuCode,
|
||||
skuName: resolveAffiliateDashDisplayProductName(skuCode, rawSkuName, skuMapping),
|
||||
status: task.task_status,
|
||||
executorKey: task.executor_key || '',
|
||||
deliveryStatus: task.delivery_status || '',
|
||||
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
import {
|
||||
AFFILIATE_DASH_SKU_MAPPING,
|
||||
mergeAffiliateDashSkuMapping,
|
||||
resolveAffiliateDashDisplayProductName,
|
||||
reverseAffiliateDashSkuToProductNo,
|
||||
} from '../platforms/affiliate-dash/sku-mapping.js'
|
||||
|
||||
test('权威表覆盖核心中文商品', () => {
|
||||
@@ -76,3 +78,21 @@ test('matchAffiliateDashSkuPassthrough 不在商品列表时未命中', () => {
|
||||
test('matchAffiliateDashSkuPassthrough 空集合未命中', () => {
|
||||
assert.equal(matchAffiliateDashSkuPassthrough('suit_alan_walker', new Set()), false)
|
||||
})
|
||||
|
||||
test('resolveAffiliateDashDisplayProductName 英文 sku 反查中文', () => {
|
||||
assert.equal(
|
||||
resolveAffiliateDashDisplayProductName('suit_romantic_destiny', 'suit_romantic_destiny'),
|
||||
'套装-浪漫天命',
|
||||
)
|
||||
assert.equal(resolveAffiliateDashDisplayProductName('bag_cute_bear', ''), '萌熊伴侣背包')
|
||||
assert.equal(
|
||||
resolveAffiliateDashDisplayProductName('suit_romantic_destiny', '套装-浪漫天命'),
|
||||
'套装-浪漫天命',
|
||||
)
|
||||
assert.equal(resolveAffiliateDashDisplayProductName('', '幸运币2个'), '幸运币2个')
|
||||
})
|
||||
|
||||
test('reverseAffiliateDashSkuToProductNo 未命中返回空串', () => {
|
||||
assert.equal(reverseAffiliateDashSkuToProductNo('not_a_real_sku'), '')
|
||||
assert.equal(reverseAffiliateDashSkuToProductNo(''), '')
|
||||
})
|
||||
|
||||
@@ -84,8 +84,11 @@ export async function resolveOrderItemForFulfillment({
|
||||
externalSkuCode,
|
||||
externalItemId,
|
||||
])
|
||||
// 运营侧展示用中文商品名;英文 sku 只写在 skuCode。
|
||||
const resolvedSkuName = pickFirstNonEmpty([
|
||||
selectedExecutorKey === FULFILLMENT_EXECUTOR_KEYS.AFFILIATE_DASH ? affiliateDashMatch?.sku : '',
|
||||
selectedExecutorKey === FULFILLMENT_EXECUTOR_KEYS.AFFILIATE_DASH
|
||||
? affiliateDashMatch?.productNo || affiliateDashMatch?.skuName
|
||||
: '',
|
||||
item.skuName,
|
||||
externalSkuName,
|
||||
resolvedSkuCode,
|
||||
|
||||
@@ -60,3 +60,42 @@ export function mergeAffiliateDashSkuMapping(
|
||||
}
|
||||
return merged
|
||||
}
|
||||
|
||||
/**
|
||||
* 英文 sku → 91 中文商品名(运营后台列表展示用)。
|
||||
* 同一 sku 若被多个中文名映射,取表中先出现的键。
|
||||
*/
|
||||
export function reverseAffiliateDashSkuToProductNo(
|
||||
sku: string,
|
||||
mapping: Readonly<Record<string, string>> = AFFILIATE_DASH_SKU_MAPPING,
|
||||
): string {
|
||||
const target = String(sku || '').trim()
|
||||
if (!target) {
|
||||
return ''
|
||||
}
|
||||
|
||||
for (const [productNo, mappedSku] of Object.entries(mapping)) {
|
||||
if (String(mappedSku || '').trim() === target) {
|
||||
return String(productNo || '').trim()
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 优先用中文商品名展示;已是中文或未命中映射时原样返回。 */
|
||||
export function resolveAffiliateDashDisplayProductName(
|
||||
skuCode: string,
|
||||
skuName = '',
|
||||
mapping?: Readonly<Record<string, string>> | null,
|
||||
): string {
|
||||
const code = String(skuCode || '').trim()
|
||||
const name = String(skuName || '').trim()
|
||||
const table = mapping || AFFILIATE_DASH_SKU_MAPPING
|
||||
return (
|
||||
reverseAffiliateDashSkuToProductNo(code, table) ||
|
||||
reverseAffiliateDashSkuToProductNo(name, table) ||
|
||||
name ||
|
||||
code
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user