refactor(douyin-mashida)!: 纠偏——删掉自建的皮肤通道,改回复用 affiliate_dash
上一轮我把皮肤交付做成了「另建一套执行器 + 独立领取接口 + 只提交账号就结束」, 跟买家实际要走的过程不一致(真正的完成信号是「扫码绑定后的 UID == 买家填的 UID」), 而且核销还触发了老通知逻辑,给买家**又发了一条 /redeem** —— 买家收到两条链接。 本次按用户要求改回**完全复用仓库现成的 affiliate_dash 通道**(= 旧的快手皮肤自动发货)。 **删掉** - 执行器 `douyin_mashida_skin`(含 registry/types/planner/bootstrap/路由白名单注册) - `services/claim/claim-skin-service.ts`、`routes/claim-skin.ts`、`/api/v1/claim-skin` 挂载 - 迁移 096 的 `claim_submission_json` 全链路(task-repo / rows / inputs / task-detail / admin-read-service 的 claimSubmission),并新增 **097 兜底迁移**把该列 DROP 掉 - 顺带清掉上一轮专为已删接口加的死代码(utils/http.ts 的 buildMessageSuccessPayload 等) **改回复用** - `resolveOrderItemClaimLink`:通用解析(只看订单项、不看执行器)→ `buildConfiguredClaimUrl(claimLinkBase, token)`;多履约单元取 task id 最小并告警; **绝不回退** hash 形态的 `buildClaimUrl` - `cert_link` 与付款后那条**唯一**消息共用同一个解析结果 - **核销后不再给抖音买家发第二条消息**(`shouldNotifyBuyerAfterVerify` 只放行非抖音 provider) - 买家侧走既有流程:输 UID → 二维码 → 扫码绑定 → 比对 UID → delivered/REDEEMED; 在 delivered 分支 best-effort 核销平台券(幂等、失败只 warn,不拖慢买家响应) - 后台回显链接改按 **order.provider** 判断(抖音用 `claimLinkBase`) **SQL 守卫**:允许「删除历史迁移」,但强制要求「同时新增兜底迁移」配对 (修改历史迁移仍禁止),并把改动来源换成 `git status --porcelain`(否则未跟踪的新迁移看不见) `npm run check`:tests 671 / pass 668 / fail 0 / skipped 3(含新增的物品图回退用例)
This commit is contained in:
@@ -1,157 +0,0 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
douyinMashidaSkinExecutor,
|
||||
resolveSkinTaskClaimToken,
|
||||
} from './douyin-mashida-skin-executor.js'
|
||||
import { getFulfillmentExecutor } from './registry.js'
|
||||
import type { FulfillmentPrepareDeps } from './types.js'
|
||||
import type { TaskRow } from '../../../types/repository/rows.js'
|
||||
|
||||
const FIXED_NOW = '2026-10-10T00:00:00.000Z'
|
||||
|
||||
function createTask(overrides: Partial<TaskRow> = {}): TaskRow {
|
||||
return {
|
||||
id: 9,
|
||||
order_id: 1,
|
||||
order_item_id: 11,
|
||||
unit_index: 1,
|
||||
platform_order_id: '6930318258716179555',
|
||||
profile_id: 3,
|
||||
task_no: 'DT-1',
|
||||
executor_key: 'douyin_mashida_skin',
|
||||
task_status: 'paid',
|
||||
delivery_status: 'pending',
|
||||
result_code: '',
|
||||
result_message: '',
|
||||
automation_mode: 'manual',
|
||||
requires_claim: true,
|
||||
user_action_status: 'pending_claim',
|
||||
attempt_count: 0,
|
||||
runtime_session_id: '',
|
||||
login_type: '',
|
||||
nickname: '',
|
||||
role_name: '',
|
||||
role_id: '',
|
||||
area: '',
|
||||
partition_name: '',
|
||||
claim_token: '',
|
||||
claim_expires_at: null,
|
||||
primary_claim_token: '',
|
||||
primary_claim_token_id: null,
|
||||
primary_claim_token_status: '',
|
||||
primary_claim_expires_at: null,
|
||||
artifacts_json: {},
|
||||
context_json: {},
|
||||
screenshot_path: '',
|
||||
last_error: '',
|
||||
retry_count: 0,
|
||||
created_at: FIXED_NOW,
|
||||
updated_at: FIXED_NOW,
|
||||
claimed_at: null,
|
||||
role_confirmed_at: null,
|
||||
redeemed_at: null,
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
function createDeps(overrides: Partial<FulfillmentPrepareDeps> = {}) {
|
||||
const updates: Array<{ taskId: number | string; patch: Record<string, unknown> }> = []
|
||||
const tokenRequests: Array<number | string> = []
|
||||
|
||||
const deps: FulfillmentPrepareDeps = {
|
||||
updateTask: async (taskId, patch) => {
|
||||
updates.push({ taskId, patch: { ...patch } })
|
||||
return { ...createTask(), ...patch }
|
||||
},
|
||||
createTaskClaimToken: async (taskId) => {
|
||||
tokenRequests.push(taskId)
|
||||
return { token: 'skin-token', expired_at: null }
|
||||
},
|
||||
notifyTaskAutoManualReview: async () => null,
|
||||
nowIso: () => FIXED_NOW,
|
||||
...overrides,
|
||||
}
|
||||
|
||||
return { deps, updates, tokenRequests }
|
||||
}
|
||||
|
||||
test('皮肤执行器已注册到 registry', () => {
|
||||
assert.equal(getFulfillmentExecutor('douyin_mashida_skin'), douyinMashidaSkinExecutor)
|
||||
})
|
||||
|
||||
test('preparePaidTask:无 token 时生成 claim token 并置为待领取', async () => {
|
||||
const { deps, updates, tokenRequests } = createDeps()
|
||||
|
||||
const result = await douyinMashidaSkinExecutor.preparePaidTask?.(createTask(), deps)
|
||||
|
||||
assert.deepEqual(tokenRequests, [9])
|
||||
assert.equal(updates.length, 2)
|
||||
assert.deepEqual(updates[0]?.patch, {
|
||||
claim_token: 'skin-token',
|
||||
claim_expires_at: null,
|
||||
updated_at: FIXED_NOW,
|
||||
})
|
||||
assert.deepEqual(updates[1]?.patch, {
|
||||
task_status: 'link_generated',
|
||||
user_action_status: 'pending_claim',
|
||||
last_error: '',
|
||||
updated_at: FIXED_NOW,
|
||||
})
|
||||
assert.equal(result?.task_status, 'link_generated')
|
||||
})
|
||||
|
||||
test('preparePaidTask:已有 token 且已是待领取时完全幂等(不重复建 token)', async () => {
|
||||
const { deps, updates, tokenRequests } = createDeps()
|
||||
|
||||
const result = await douyinMashidaSkinExecutor.preparePaidTask?.(
|
||||
createTask({
|
||||
claim_token: 'skin-token',
|
||||
primary_claim_token: 'skin-token',
|
||||
primary_claim_token_id: 5,
|
||||
task_status: 'link_generated',
|
||||
user_action_status: 'pending_claim',
|
||||
}),
|
||||
deps,
|
||||
)
|
||||
|
||||
assert.deepEqual(tokenRequests, [])
|
||||
assert.deepEqual(updates, [])
|
||||
assert.equal(result?.task_status, 'link_generated')
|
||||
})
|
||||
|
||||
test('preparePaidTask:已有 token 但状态未就绪时只补状态', async () => {
|
||||
const { deps, updates, tokenRequests } = createDeps()
|
||||
|
||||
await douyinMashidaSkinExecutor.preparePaidTask?.(
|
||||
createTask({ claim_token: 'skin-token', primary_claim_token: 'skin-token' }),
|
||||
deps,
|
||||
)
|
||||
|
||||
assert.deepEqual(tokenRequests, [])
|
||||
assert.equal(updates.length, 1)
|
||||
assert.equal(updates[0]?.patch.task_status, 'link_generated')
|
||||
})
|
||||
|
||||
test('preparePaidTask:买家已领取的任务不会被降级回待领取', async () => {
|
||||
const { deps, updates, tokenRequests } = createDeps()
|
||||
|
||||
const claimed = createTask({
|
||||
claim_token: 'skin-token',
|
||||
primary_claim_token: 'skin-token',
|
||||
task_status: 'claimed',
|
||||
user_action_status: 'not_required',
|
||||
})
|
||||
const result = await douyinMashidaSkinExecutor.preparePaidTask?.(claimed, deps)
|
||||
|
||||
assert.deepEqual(tokenRequests, [])
|
||||
assert.deepEqual(updates, [])
|
||||
assert.equal(result?.task_status, 'claimed')
|
||||
})
|
||||
|
||||
test('resolveSkinTaskClaimToken 优先 primary_claim_token', () => {
|
||||
assert.equal(resolveSkinTaskClaimToken({ claim_token: 'a' }), 'a')
|
||||
assert.equal(resolveSkinTaskClaimToken({ claim_token: 'a', primary_claim_token: 'b' }), 'b')
|
||||
assert.equal(resolveSkinTaskClaimToken(null), '')
|
||||
})
|
||||
@@ -1,134 +0,0 @@
|
||||
import { TASK_STATUS } from '../../../domain/task-status.js'
|
||||
import { listTasksByOrderId } from '../../../repositories/task-repo.js'
|
||||
import { logWarn } from '../../../utils/logger.js'
|
||||
import { resolveDouyinMashidaSkinClaimUrl } from '../../platforms/douyin-mashida/claim-link.js'
|
||||
import type { DouyinMashidaSourceConfig } from '../../platforms/douyin-mashida/source-config-service.js'
|
||||
import {
|
||||
FULFILLMENT_EXECUTOR_KEYS,
|
||||
type FulfillmentDeliveryLink,
|
||||
type FulfillmentExecutor,
|
||||
type FulfillmentPrepareDeps,
|
||||
} from './types.js'
|
||||
import type { TaskRow } from '../../../types/repository/rows.js'
|
||||
|
||||
/**
|
||||
* 抖音码速达「皮肤自动发货」执行器。
|
||||
*
|
||||
* 与 affiliate-dash 执行器的最大区别:**不打任何外部平台**。
|
||||
* 付款后我们只需要「确保任务有 claim token」并把任务置为待领取(`link_generated` + `pending_claim`),
|
||||
* 领取链接(`claimLinkBase/token`)由调用方拿去做两件事:
|
||||
* 1. 写进 `coupons.syncV2` 的 `cert_link`(见 redeem/certificate-service.ts);
|
||||
* 2. 通过 `order.message` 按模板发给买家(见 douyin-mashida/notify-service.ts)。
|
||||
*/
|
||||
export const douyinMashidaSkinExecutor: FulfillmentExecutor = {
|
||||
key: FULFILLMENT_EXECUTOR_KEYS.DOUYIN_MASHIDA_SKIN,
|
||||
preparePaidTask,
|
||||
resolveDeliveryLink,
|
||||
}
|
||||
|
||||
export function resolveSkinTaskClaimToken(task: Partial<TaskRow> | null | undefined): string {
|
||||
return String(task?.primary_claim_token || task?.claim_token || '').trim()
|
||||
}
|
||||
|
||||
export type OrderItemSkinClaimLink = {
|
||||
/** 领取链接;未配置 claimLinkBase、或该订单项没有皮肤任务/token 时为空串 */
|
||||
claimUrl: string
|
||||
token: string
|
||||
/** 该订单项下的皮肤履约单元数量(数量 > 1 时会有多个 token) */
|
||||
taskCount: number
|
||||
pickedTaskId: number | null
|
||||
}
|
||||
|
||||
/**
|
||||
* 取某订单项的皮肤领取链接。
|
||||
*
|
||||
* 一个订单项按数量会拆成 N 个履约单元(`fulfillment_tasks`),每个单元一个 token
|
||||
* (`claim_tokens.task_id` 唯一);这里固定取 task id 最小的那个,保证同一张券每次解析结果一致。
|
||||
* 调用方(certificate-service / notify-service)据 `taskCount` 打 warn 留痕。
|
||||
*/
|
||||
export async function resolveOrderItemSkinClaimLink(input: {
|
||||
orderId: number | string
|
||||
orderItemId: number | string
|
||||
config?: DouyinMashidaSourceConfig | undefined
|
||||
}): Promise<OrderItemSkinClaimLink> {
|
||||
const skinTasks = (await listTasksByOrderId(input.orderId))
|
||||
.filter(
|
||||
(task) =>
|
||||
Number(task.order_item_id) === Number(input.orderItemId) &&
|
||||
String(task.executor_key || '').trim() === FULFILLMENT_EXECUTOR_KEYS.DOUYIN_MASHIDA_SKIN,
|
||||
)
|
||||
.sort((left, right) => Number(left.id) - Number(right.id))
|
||||
|
||||
const pickedTask = skinTasks[0] || null
|
||||
const token = resolveSkinTaskClaimToken(pickedTask)
|
||||
|
||||
return {
|
||||
claimUrl: resolveDouyinMashidaSkinClaimUrl(token, input.config),
|
||||
token,
|
||||
taskCount: skinTasks.length,
|
||||
pickedTaskId: pickedTask ? Number(pickedTask.id) : null,
|
||||
}
|
||||
}
|
||||
|
||||
async function preparePaidTask(
|
||||
task: TaskRow,
|
||||
deps: FulfillmentPrepareDeps,
|
||||
): Promise<TaskRow | null> {
|
||||
let workingTask = task
|
||||
|
||||
// 幂等:已有 token 不重复生成(claim_tokens.task_id 唯一,重复插入只会覆盖)。
|
||||
if (!resolveSkinTaskClaimToken(task)) {
|
||||
const claimToken = await deps.createTaskClaimToken(task.id)
|
||||
workingTask =
|
||||
(await deps.updateTask(task.id, {
|
||||
claim_token: claimToken.token,
|
||||
claim_expires_at: claimToken.expired_at,
|
||||
updated_at: deps.nowIso(),
|
||||
})) || task
|
||||
}
|
||||
|
||||
// 买家已提交过(claimed)的任务不允许被降级回待领取。
|
||||
if (
|
||||
workingTask.task_status === TASK_STATUS.CLAIMED ||
|
||||
workingTask.task_status === TASK_STATUS.REDEEMED ||
|
||||
workingTask.task_status === TASK_STATUS.COMPLETED
|
||||
) {
|
||||
return workingTask
|
||||
}
|
||||
|
||||
if (
|
||||
workingTask.task_status !== TASK_STATUS.LINK_GENERATED ||
|
||||
workingTask.user_action_status !== 'pending_claim'
|
||||
) {
|
||||
workingTask =
|
||||
(await deps.updateTask(task.id, {
|
||||
task_status: TASK_STATUS.LINK_GENERATED,
|
||||
user_action_status: 'pending_claim',
|
||||
last_error: '',
|
||||
updated_at: deps.nowIso(),
|
||||
})) || workingTask
|
||||
}
|
||||
|
||||
return workingTask
|
||||
}
|
||||
|
||||
/** 对外统一返回本站皮肤领取链接;基址未配置时返回 null(不猜、不回退 hash 版领取页)。 */
|
||||
async function resolveDeliveryLink(task: TaskRow): Promise<FulfillmentDeliveryLink | null> {
|
||||
const token = resolveSkinTaskClaimToken(task)
|
||||
if (!token) {
|
||||
return null
|
||||
}
|
||||
|
||||
const claimUrl = resolveDouyinMashidaSkinClaimUrl(token)
|
||||
if (!claimUrl) {
|
||||
logWarn('[douyin-mashida/skin]', '未配置领取链接基址(claimLinkBase),无法生成皮肤领取链接', {
|
||||
taskId: task.id,
|
||||
taskNo: task.task_no,
|
||||
platformOrderId: task.platform_order_id,
|
||||
})
|
||||
return null
|
||||
}
|
||||
|
||||
const expireTime = String(task.primary_claim_expires_at || task.claim_expires_at || '').trim()
|
||||
return expireTime ? { claimUrl, expireTime } : { claimUrl }
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import { isPaidPreparationStableStatus } from '../../../domain/task-status.js'
|
||||
import { affiliateDashExecutor } from './affiliate-dash-executor.js'
|
||||
import { douyinMashidaSkinExecutor } from './douyin-mashida-skin-executor.js'
|
||||
import { legacyFeifeiExecutor, legacyLewanExecutor } from './legacy-retired-executor.js'
|
||||
import { manualDispatchExecutor } from './manual-executor.js'
|
||||
import {
|
||||
@@ -15,7 +14,6 @@ import type { TaskRow } from '../../../types/repository/rows.js'
|
||||
|
||||
const EXECUTORS = new Map<string, FulfillmentExecutor>([
|
||||
[FULFILLMENT_EXECUTOR_KEYS.AFFILIATE_DASH, affiliateDashExecutor],
|
||||
[FULFILLMENT_EXECUTOR_KEYS.DOUYIN_MASHIDA_SKIN, douyinMashidaSkinExecutor],
|
||||
[FULFILLMENT_EXECUTOR_KEYS.MANUAL_DISPATCH, manualDispatchExecutor],
|
||||
[FULFILLMENT_EXECUTOR_KEYS.KUAISHOU_CLOUD, legacyLewanExecutor],
|
||||
[FULFILLMENT_EXECUTOR_KEYS.KUAISHOU_FEIFEI, legacyFeifeiExecutor],
|
||||
|
||||
@@ -4,8 +4,6 @@ import type { TaskRow } from '../../../types/repository/rows.js'
|
||||
export const FULFILLMENT_EXECUTOR_KEYS = {
|
||||
MANUAL_DISPATCH: 'manual_dispatch',
|
||||
AFFILIATE_DASH: 'affiliate_dash',
|
||||
/** 抖音码速达「皮肤自动发货」:只发本站领取链接,不打 affiliate-dash 平台 */
|
||||
DOUYIN_MASHIDA_SKIN: 'douyin_mashida_skin',
|
||||
/** @deprecated 已下线,仅历史任务 / stub 识别 */
|
||||
KUAISHOU_CLOUD: 'kuaishou_ct_assisted',
|
||||
/** @deprecated 已下线,仅历史任务识别 */
|
||||
@@ -70,10 +68,6 @@ export function isManualDispatchExecutor(value: unknown): boolean {
|
||||
return normalizeExecutorKey(value) === FULFILLMENT_EXECUTOR_KEYS.MANUAL_DISPATCH
|
||||
}
|
||||
|
||||
export function isDouyinMashidaSkinExecutor(value: unknown): boolean {
|
||||
return normalizeExecutorKey(value) === FULFILLMENT_EXECUTOR_KEYS.DOUYIN_MASHIDA_SKIN
|
||||
}
|
||||
|
||||
export function isRetiredFulfillmentExecutor(value: unknown): boolean {
|
||||
const executorKey = normalizeExecutorKey(value)
|
||||
return (
|
||||
|
||||
@@ -109,25 +109,26 @@ test('planFulfillmentTaskForOrderItem affiliate 缺 sku 时返回 null', async (
|
||||
assert.equal(plan, null)
|
||||
})
|
||||
|
||||
test('planFulfillmentTaskForOrderItem 为抖音皮肤商品生成领取链接履约计划', async () => {
|
||||
test('planFulfillmentTaskForOrderItem 为抖音命中商品生成 affiliate_dash 履约计划', async () => {
|
||||
const plan = await planFulfillmentTaskForOrderItem({
|
||||
order: createOrder({ provider: 'douyin_mashida', platform: 'doudian' }),
|
||||
item: createOrderItem({
|
||||
sku_code: '幸运币2个',
|
||||
sku_name: '【测试专用】和平精英皮肤小店入口',
|
||||
item_snapshot_json: {
|
||||
fulfillmentRoute: { selectedExecutorKey: 'douyin_mashida_skin' },
|
||||
douyinSkin: {
|
||||
internalSku: '幸运币2个',
|
||||
fulfillmentRoute: { selectedExecutorKey: 'affiliate_dash' },
|
||||
affiliateDash: {
|
||||
matchMode: 'affiliate_dash_sku_mapping',
|
||||
productNo: '幸运币2个',
|
||||
sku: 'lucky_coin_x2',
|
||||
productTitle: '【测试专用】和平精英皮肤小店入口',
|
||||
skuName: '幸运币2个',
|
||||
},
|
||||
},
|
||||
}),
|
||||
getProfileByKey: async (profileKey) => ({
|
||||
id: 21,
|
||||
profile_key: profileKey,
|
||||
name: '抖音皮肤自动发货',
|
||||
name: 'affiliate-dash 履约',
|
||||
executor_key: profileKey,
|
||||
requires_claim: false,
|
||||
auto_dispatch: false,
|
||||
@@ -135,33 +136,31 @@ test('planFulfillmentTaskForOrderItem 为抖音皮肤商品生成领取链接履
|
||||
})
|
||||
|
||||
assert.ok(plan)
|
||||
assert.equal(plan.executorKey, 'douyin_mashida_skin')
|
||||
assert.equal(plan.profileKey, 'douyin_mashida_skin')
|
||||
assert.equal(plan.executorKey, 'affiliate_dash')
|
||||
assert.equal(plan.profileKey, 'affiliate_dash')
|
||||
assert.equal(plan.requiresClaim, true)
|
||||
assert.equal(plan.autoDispatch, false)
|
||||
assert.equal(plan.context.affiliateDash, null)
|
||||
|
||||
const douyinSkin = plan.context.douyinSkin as Record<string, unknown> | null
|
||||
assert.ok(douyinSkin)
|
||||
assert.equal(douyinSkin.internalSku, '幸运币2个')
|
||||
assert.equal(douyinSkin.sku, 'lucky_coin_x2')
|
||||
assert.equal(douyinSkin.imageUrl, '/images/products/lucky_coin_x2.webp')
|
||||
const affiliateDash = plan.context.affiliateDash as Record<string, unknown> | null
|
||||
assert.ok(affiliateDash)
|
||||
assert.equal(affiliateDash.sku, 'lucky_coin_x2')
|
||||
assert.equal(affiliateDash.productName, '幸运币2个')
|
||||
})
|
||||
|
||||
test('planFulfillmentTaskForOrderItem 抖音皮肤缺内部 SKU 时返回 null', async () => {
|
||||
test('planFulfillmentTaskForOrderItem 抖音订单缺 affiliate_dash sku 时返回 null', async () => {
|
||||
const plan = await planFulfillmentTaskForOrderItem({
|
||||
order: createOrder({ provider: 'douyin_mashida', platform: 'doudian' }),
|
||||
item: createOrderItem({
|
||||
sku_code: '',
|
||||
sku_name: '无内部 SKU',
|
||||
item_snapshot_json: {
|
||||
fulfillmentRoute: { selectedExecutorKey: 'douyin_mashida_skin' },
|
||||
fulfillmentRoute: { selectedExecutorKey: 'affiliate_dash' },
|
||||
},
|
||||
}),
|
||||
getProfileByKey: async (profileKey) => ({
|
||||
id: 21,
|
||||
profile_key: profileKey,
|
||||
name: '抖音皮肤自动发货',
|
||||
name: 'affiliate-dash 履约',
|
||||
executor_key: profileKey,
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { getFulfillmentProfileByKey } from '../../repositories/fulfillment-profile-repo.js'
|
||||
import { resolveProductImageUrl } from '../platforms/affiliate-dash/product-image.js'
|
||||
import type { JsonObject } from '../../types/json.js'
|
||||
import type { OrderItemRow, OrderRow } from '../../types/repository/rows.js'
|
||||
import {
|
||||
FULFILLMENT_EXECUTOR_KEYS,
|
||||
isAffiliateDashExecutor,
|
||||
isDouyinMashidaSkinExecutor,
|
||||
} from './executors/types.js'
|
||||
import { FULFILLMENT_EXECUTOR_KEYS, isAffiliateDashExecutor } from './executors/types.js'
|
||||
|
||||
export type FulfillmentBindingLike = {
|
||||
id: number
|
||||
@@ -96,7 +91,6 @@ function buildFulfillmentTaskContext({
|
||||
fulfillmentConfig: JsonObject
|
||||
}) {
|
||||
const affiliateDashConfig = parseJsonObject(fulfillmentConfig.affiliateDash)
|
||||
const douyinSkinConfig = parseJsonObject(fulfillmentConfig.douyinSkin)
|
||||
|
||||
return {
|
||||
profileKey,
|
||||
@@ -128,17 +122,6 @@ function buildFulfillmentTaskContext({
|
||||
lastSyncedAt: null,
|
||||
}
|
||||
: null,
|
||||
// 皮肤自动发货:任务上下文只放「怎么发货」的静态信息;买家提交的游戏账号
|
||||
// 属于隐私数据,落在 fulfillment_tasks.claim_submission_json,不进这里、更不进打手工单。
|
||||
douyinSkin: isDouyinMashidaSkinExecutor(executorKey)
|
||||
? {
|
||||
flowType: 'douyin_mashida_skin',
|
||||
internalSku: String(douyinSkinConfig.internalSku || item.sku_code || '').trim(),
|
||||
sku: String(douyinSkinConfig.sku || '').trim(),
|
||||
productTitle: String(douyinSkinConfig.productTitle || item.sku_name || '').trim(),
|
||||
imageUrl: resolveProductImageUrl(douyinSkinConfig.internalSku || item.sku_code),
|
||||
}
|
||||
: null,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,10 +134,6 @@ async function resolveDynamicFulfillmentProfile(
|
||||
return resolveDynamicAffiliateDashProfile(item, getProfileByKey)
|
||||
}
|
||||
|
||||
if (selectedExecutorKey === FULFILLMENT_EXECUTOR_KEYS.DOUYIN_MASHIDA_SKIN) {
|
||||
return resolveDynamicDouyinMashidaSkinProfile(item, getProfileByKey)
|
||||
}
|
||||
|
||||
if (selectedExecutorKey === FULFILLMENT_EXECUTOR_KEYS.MANUAL_DISPATCH) {
|
||||
return resolveDynamicManualDispatchProfile(item, getProfileByKey)
|
||||
}
|
||||
@@ -202,46 +181,8 @@ async function resolveDynamicAffiliateDashProfile(
|
||||
}
|
||||
|
||||
/**
|
||||
* 皮肤自动发货:内部 SKU 命中权威映射表时使用。
|
||||
* `requires_claim=true` 让任务要求领取链接;`auto_dispatch=false` 表示不需要打手抢单。
|
||||
* 人工履约:路由规则明确指定人工、或未命中任何自动通道时使用。
|
||||
*/
|
||||
async function resolveDynamicDouyinMashidaSkinProfile(
|
||||
item: OrderItemRow,
|
||||
getProfileByKey: FulfillmentProfileResolver,
|
||||
): Promise<FulfillmentBindingLike | null> {
|
||||
const snapshot = parseJsonObject(item.item_snapshot_json)
|
||||
const douyinSkin = parseJsonObject(snapshot.douyinSkin)
|
||||
const internalSku = String(douyinSkin.internalSku || item.sku_code || '').trim()
|
||||
if (!internalSku) {
|
||||
return null
|
||||
}
|
||||
|
||||
const profile = await getProfileByKey(FULFILLMENT_EXECUTOR_KEYS.DOUYIN_MASHIDA_SKIN)
|
||||
if (!profile) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
...profile,
|
||||
profile_id: Number(profile.id || profile.profile_id || 0),
|
||||
profile_key: FULFILLMENT_EXECUTOR_KEYS.DOUYIN_MASHIDA_SKIN,
|
||||
profile_name: String(profile.profile_name || profile.name || '抖音皮肤自动发货').trim(),
|
||||
executor_key: FULFILLMENT_EXECUTOR_KEYS.DOUYIN_MASHIDA_SKIN,
|
||||
requires_claim: true,
|
||||
auto_dispatch: false,
|
||||
config_json: {
|
||||
flowType: 'douyin_mashida_skin',
|
||||
configId: `${FULFILLMENT_EXECUTOR_KEYS.DOUYIN_MASHIDA_SKIN}:${internalSku}`,
|
||||
douyinSkin: {
|
||||
internalSku,
|
||||
sku: String(douyinSkin.sku || '').trim(),
|
||||
productTitle: String(douyinSkin.productTitle || item.sku_name || '').trim(),
|
||||
},
|
||||
notes: '抖音码速达皮肤商品自动发货(本站领取链接)',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveDynamicManualDispatchProfile(
|
||||
item: OrderItemRow,
|
||||
getProfileByKey: FulfillmentProfileResolver,
|
||||
|
||||
@@ -4,7 +4,7 @@ import test from 'node:test'
|
||||
import {
|
||||
matchAffiliateDashSku,
|
||||
matchAffiliateDashSkuPassthrough,
|
||||
matchDouyinMashidaSkinSku,
|
||||
matchDouyinMashidaAffiliateDashSku,
|
||||
normalizeAffiliateDashMappingKey,
|
||||
resolveOrderItemForFulfillment,
|
||||
} from './product-resolution-service.js'
|
||||
@@ -100,7 +100,7 @@ test('reverseAffiliateDashSkuToProductNo 未命中返回空串', () => {
|
||||
assert.equal(reverseAffiliateDashSkuToProductNo(''), '')
|
||||
})
|
||||
|
||||
// ---- 抖音码速达(抖店)皮肤商品分流 ----
|
||||
// ---- 抖音码速达(抖店)订单分流:复用 affiliate_dash 通道 ----
|
||||
|
||||
const DOUYIN_SKIN_TITLE = '【测试专用】和平精英皮肤小店入口出售返场吃鸡皮肤浪漫天命专用'
|
||||
|
||||
@@ -126,14 +126,14 @@ function selectedExecutorKeyOf(
|
||||
return String(route?.selectedExecutorKey || '')
|
||||
}
|
||||
|
||||
test('matchDouyinMashidaSkinSku 只认权威映射表并做归一化', () => {
|
||||
assert.equal(matchDouyinMashidaSkinSku('幸运币2个'), 'lucky_coin_x2')
|
||||
assert.equal(matchDouyinMashidaSkinSku(' 幸运币2个 '), 'lucky_coin_x2')
|
||||
assert.equal(matchDouyinMashidaSkinSku('不存在的皮肤'), '')
|
||||
assert.equal(matchDouyinMashidaSkinSku(''), '')
|
||||
test('matchDouyinMashidaAffiliateDashSku 只认权威映射表并做归一化', () => {
|
||||
assert.equal(matchDouyinMashidaAffiliateDashSku('幸运币2个'), 'lucky_coin_x2')
|
||||
assert.equal(matchDouyinMashidaAffiliateDashSku(' 幸运币2个 '), 'lucky_coin_x2')
|
||||
assert.equal(matchDouyinMashidaAffiliateDashSku('不存在的皮肤'), '')
|
||||
assert.equal(matchDouyinMashidaAffiliateDashSku(''), '')
|
||||
})
|
||||
|
||||
test('抖音订单:内部 SKU 命中映射表 → 皮肤自动发货', async () => {
|
||||
test('抖音订单:内部 SKU 命中映射表 → 复用 affiliate_dash 通道自动发货', async () => {
|
||||
const item = await resolveOrderItemForFulfillment({
|
||||
provider: 'douyin_mashida',
|
||||
platform: 'doudian',
|
||||
@@ -141,16 +141,18 @@ test('抖音订单:内部 SKU 命中映射表 → 皮肤自动发货', async (
|
||||
})
|
||||
|
||||
assert.equal(item.isConfigured, true)
|
||||
assert.equal(selectedExecutorKeyOf(item), 'douyin_mashida_skin')
|
||||
assert.equal(item.skuCode, '幸运币2个')
|
||||
assert.equal(item.skuName, DOUYIN_SKIN_TITLE)
|
||||
assert.deepEqual(item.snapshot.douyinSkin, {
|
||||
assert.equal(selectedExecutorKeyOf(item), 'affiliate_dash')
|
||||
// 走 affiliate_dash 通道后与 91 同口径:skuCode 是英文 sku、skuName 是中文商品名
|
||||
assert.equal(item.skuCode, 'lucky_coin_x2')
|
||||
assert.equal(item.skuName, '幸运币2个')
|
||||
// 快照里的 affiliateDash 就是 affiliate_dash 执行器/规划器要用的映射结果
|
||||
assert.deepEqual(item.snapshot.affiliateDash, {
|
||||
matchMode: 'affiliate_dash_sku_mapping',
|
||||
internalSku: '幸运币2个',
|
||||
productNo: '幸运币2个',
|
||||
sku: 'lucky_coin_x2',
|
||||
productTitle: DOUYIN_SKIN_TITLE,
|
||||
skuName: '幸运币2个',
|
||||
})
|
||||
assert.equal(resolveProductImageUrl(item.skuCode), '/images/products/lucky_coin_x2.webp')
|
||||
assert.equal(resolveProductImageUrl('幸运币2个'), '/images/products/lucky_coin_x2.webp')
|
||||
})
|
||||
|
||||
test('抖音订单:内部 SKU 未命中映射表 → 回退 manual_dispatch', async () => {
|
||||
@@ -161,7 +163,7 @@ test('抖音订单:内部 SKU 未命中映射表 → 回退 manual_dispatch',
|
||||
})
|
||||
|
||||
assert.equal(selectedExecutorKeyOf(item), 'manual_dispatch')
|
||||
assert.equal(item.snapshot.douyinSkin, null)
|
||||
assert.equal(item.snapshot.affiliateDash, null)
|
||||
// 引流长标题作为 skuName,内部 SKU 作为 skuCode
|
||||
assert.equal(item.skuCode, '不存在的皮肤')
|
||||
assert.equal(item.skuName, DOUYIN_SKIN_TITLE)
|
||||
|
||||
@@ -44,14 +44,6 @@ export type AffiliateDashSkuMatch = {
|
||||
matchMode: 'affiliate_dash_sku_mapping' | 'affiliate_dash_sku_passthrough'
|
||||
}
|
||||
|
||||
/** 抖音码速达「皮肤」命中信息:内部 SKU → 英文 sku(图片文件名同一套映射)。 */
|
||||
export type DouyinMashidaSkinMatch = {
|
||||
sku: string
|
||||
internalSku: string
|
||||
productTitle: string
|
||||
matchMode: 'affiliate_dash_sku_mapping'
|
||||
}
|
||||
|
||||
type FulfillmentItemCandidate = {
|
||||
externalItemId: string
|
||||
externalSkuCode: string
|
||||
@@ -59,7 +51,6 @@ type FulfillmentItemCandidate = {
|
||||
externalSkuNameNormalized: string
|
||||
resolvedSkuCode: string
|
||||
affiliateDashMatch: AffiliateDashSkuMatch | null
|
||||
douyinSkinMatch: DouyinMashidaSkinMatch | null
|
||||
fulfillmentRoute: FulfillmentRouteResult | null
|
||||
isConfigured: boolean
|
||||
}
|
||||
@@ -91,7 +82,6 @@ export async function resolveOrderItemForFulfillment({
|
||||
externalSkuName,
|
||||
externalSkuNameNormalized,
|
||||
affiliateDashMatch,
|
||||
douyinSkinMatch,
|
||||
fulfillmentRoute,
|
||||
} = candidate
|
||||
|
||||
@@ -130,14 +120,6 @@ export async function resolveOrderItemForFulfillment({
|
||||
skuName: affiliateDashMatch.skuName,
|
||||
}
|
||||
: null,
|
||||
douyinSkin: douyinSkinMatch
|
||||
? {
|
||||
matchMode: douyinSkinMatch.matchMode,
|
||||
internalSku: douyinSkinMatch.internalSku,
|
||||
sku: douyinSkinMatch.sku,
|
||||
productTitle: douyinSkinMatch.productTitle,
|
||||
}
|
||||
: null,
|
||||
isConfigured: candidate.isConfigured,
|
||||
}
|
||||
|
||||
@@ -231,7 +213,6 @@ async function resolveConfiguredItemCandidate({
|
||||
externalSkuNameNormalized,
|
||||
resolvedSkuCode,
|
||||
affiliateDashMatch,
|
||||
douyinSkinMatch: null,
|
||||
fulfillmentRoute,
|
||||
isConfigured: Boolean(selectedExecutorKey),
|
||||
}
|
||||
@@ -256,7 +237,6 @@ async function resolveConfiguredItemCandidate({
|
||||
externalSkuNameNormalized,
|
||||
resolvedSkuCode,
|
||||
affiliateDashMatch: null,
|
||||
douyinSkinMatch: null,
|
||||
fulfillmentRoute: null,
|
||||
isConfigured: false,
|
||||
}
|
||||
@@ -267,8 +247,9 @@ async function resolveConfiguredItemCandidate({
|
||||
*
|
||||
* 平台字段口径:`sku_order_list[].code` = **内部 SKU**(如「幸运币2个」,才是真正的商品),
|
||||
* `product_name` = 引流长标题(如「【测试专用】和平精英皮肤小店入口…」)。
|
||||
* 因此分流与图片都按内部 SKU 走:
|
||||
* - 内部 SKU 命中权威表 `AFFILIATE_DASH_SKU_MAPPING` → 皮肤自动发货(本站领取链接);
|
||||
* 因此分流都按内部 SKU 走:
|
||||
* - 内部 SKU 命中权威表 `AFFILIATE_DASH_SKU_MAPPING` → 复用现成的 `affiliate_dash` 通道
|
||||
* (买家输 UID → 二维码 → 扫码绑定 → 比对 UID → 发货完成);
|
||||
* - 未命中 → 显式映射拿不到通道,按现有语义回退 `manual_dispatch`(接单平台/人工)。
|
||||
*/
|
||||
function resolveDouyinMashidaItemCandidate({
|
||||
@@ -286,29 +267,33 @@ function resolveDouyinMashidaItemCandidate({
|
||||
}): FulfillmentItemCandidate {
|
||||
const internalSku = pickFirstNonEmpty([externalSkuCode, externalItemId])
|
||||
const productTitle = pickFirstNonEmpty([externalSkuName, internalSku])
|
||||
const skinSku = matchDouyinMashidaSkinSku(internalSku)
|
||||
const douyinSkinMatch: DouyinMashidaSkinMatch | null = skinSku
|
||||
// 内部 SKU(平台 code,如「幸运币2个」)→ affiliate-dash 英文 SKU(与商品图同一张权威表)。
|
||||
// 皮肤/礼包类商品的交付**直接复用现成的 affiliate_dash 通道**:
|
||||
// 买家输 UID → 出二维码 → 扫码绑定 → 比对「绑定 UID == 填的 UID」→ 发货完成。
|
||||
// 不另建执行器、不另做一套页面(与旧快手皮肤自动发货完全一致)。
|
||||
const dashSku = matchDouyinMashidaAffiliateDashSku(internalSku)
|
||||
const affiliateDashMatch: AffiliateDashSkuMatch | null = dashSku
|
||||
? {
|
||||
sku: skinSku,
|
||||
internalSku,
|
||||
productTitle,
|
||||
sku: dashSku,
|
||||
productNo: internalSku,
|
||||
skuName: internalSku,
|
||||
matchMode: 'affiliate_dash_sku_mapping',
|
||||
}
|
||||
: null
|
||||
const fulfillmentRoute = resolveFulfillmentRoute({
|
||||
productName: productTitle,
|
||||
internalSku,
|
||||
// 命中皮肤 → 皮肤自动发货;未命中 → **显式**回落人工(接单平台)。
|
||||
// 命中 → 自动发货;未命中 → **显式**回落人工(接单平台)。
|
||||
// 不依赖全局 `unmatchedExecutorKey`:线上/联调环境该值可能是空串(dev 库就是空串),
|
||||
// 那样未命中的抖音订单会既不建任务、也不进人工,等于静默漏单。
|
||||
preferredExecutorKey: douyinSkinMatch
|
||||
? FULFILLMENT_EXECUTOR_KEYS.DOUYIN_MASHIDA_SKIN
|
||||
preferredExecutorKey: affiliateDashMatch
|
||||
? FULFILLMENT_EXECUTOR_KEYS.AFFILIATE_DASH
|
||||
: FULFILLMENT_EXECUTOR_KEYS.MANUAL_DISPATCH,
|
||||
candidates: [
|
||||
{
|
||||
executorKey: FULFILLMENT_EXECUTOR_KEYS.DOUYIN_MASHIDA_SKIN,
|
||||
available: Boolean(douyinSkinMatch),
|
||||
reason: douyinSkinMatch ? '' : '内部 SKU 未命中皮肤商品映射',
|
||||
executorKey: FULFILLMENT_EXECUTOR_KEYS.AFFILIATE_DASH,
|
||||
available: Boolean(affiliateDashMatch),
|
||||
reason: affiliateDashMatch ? '' : '内部 SKU 未命中商品映射',
|
||||
},
|
||||
{
|
||||
executorKey: FULFILLMENT_EXECUTOR_KEYS.MANUAL_DISPATCH,
|
||||
@@ -323,20 +308,19 @@ function resolveDouyinMashidaItemCandidate({
|
||||
externalSkuCode,
|
||||
externalSkuName,
|
||||
externalSkuNameNormalized,
|
||||
// 内部 SKU 就是「商品」:保留中文内部 SKU 作为 skuCode,领取页图片与展示都靠它。
|
||||
// 内部 SKU 就是「商品」:保留中文内部 SKU 作为 skuCode,展示与商品图都靠它。
|
||||
resolvedSkuCode: internalSku || pickFirstNonEmpty([externalItemId, item.itemId]),
|
||||
affiliateDashMatch: null,
|
||||
douyinSkinMatch,
|
||||
affiliateDashMatch,
|
||||
fulfillmentRoute,
|
||||
isConfigured: Boolean(fulfillmentRoute.selectedExecutorKey),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部 SKU → 英文 sku:只查权威表(与领取页图片 `resolveProductImageUrl` 同一套来源),
|
||||
* 保证「能路由到皮肤执行器」与「能取到商品图」永远一致。
|
||||
* 内部 SKU → affiliate-dash 英文 sku:只查权威表(与商品图 `resolveProductImageUrl` 同一套来源),
|
||||
* 保证「能路由到 affiliate-dash 自动发货」与「能取到商品图」永远一致。
|
||||
*/
|
||||
export function matchDouyinMashidaSkinSku(internalSku: unknown): string {
|
||||
export function matchDouyinMashidaAffiliateDashSku(internalSku: unknown): string {
|
||||
const raw = String(internalSku ?? '').trim()
|
||||
if (!raw) {
|
||||
return ''
|
||||
|
||||
@@ -12,11 +12,7 @@ test('normalizeFulfillmentRoutingConfig drops retired executors and keeps affili
|
||||
})
|
||||
|
||||
assert.deepEqual(config.defaultExecutorPriority, ['affiliate_dash'])
|
||||
assert.deepEqual(Object.keys(config.executors).sort(), [
|
||||
'affiliate_dash',
|
||||
'douyin_mashida_skin',
|
||||
'manual_dispatch',
|
||||
])
|
||||
assert.deepEqual(Object.keys(config.executors).sort(), ['affiliate_dash', 'manual_dispatch'])
|
||||
assert.equal(config.unmatchedExecutorKey, 'manual_dispatch')
|
||||
})
|
||||
|
||||
@@ -186,7 +182,7 @@ test('normalizeFulfillmentRoutingConfig 支持按内部 SKU 的规则维度', ()
|
||||
rules: [
|
||||
{
|
||||
internalSku: '幸运币2个',
|
||||
executorKey: 'douyin_mashida_skin',
|
||||
executorKey: 'affiliate_dash',
|
||||
priority: 500,
|
||||
},
|
||||
],
|
||||
@@ -201,7 +197,7 @@ test('normalizeFulfillmentRoutingConfig 支持按内部 SKU 的规则维度', ()
|
||||
assert.equal(rule.normalizedProductName, '')
|
||||
assert.equal(rule.internalSku, '幸运币2个')
|
||||
assert.equal(rule.normalizedInternalSku, '幸运币2个')
|
||||
assert.equal(rule.id, '幸运币2个:douyin_mashida_skin')
|
||||
assert.equal(rule.id, '幸运币2个:affiliate_dash')
|
||||
})
|
||||
|
||||
test('旧商品名规则归一化后带 matchField=product_name,语义不变', () => {
|
||||
@@ -221,13 +217,13 @@ test('resolveFulfillmentRoute 命中内部 SKU 规则', () => {
|
||||
const result = resolveFulfillmentRoute({
|
||||
productName: '【测试专用】和平精英皮肤小店入口',
|
||||
internalSku: '幸运币2个',
|
||||
candidates: [{ executorKey: 'douyin_mashida_skin', available: true }],
|
||||
candidates: [{ executorKey: 'affiliate_dash', available: true }],
|
||||
config: normalizeFulfillmentRoutingConfig({
|
||||
rules: [{ internalSku: '幸运币2个', executorKey: 'douyin_mashida_skin', priority: 500 }],
|
||||
rules: [{ internalSku: '幸运币2个', executorKey: 'affiliate_dash', priority: 500 }],
|
||||
}),
|
||||
})
|
||||
|
||||
assert.equal(result.selectedExecutorKey, 'douyin_mashida_skin')
|
||||
assert.equal(result.selectedExecutorKey, 'affiliate_dash')
|
||||
assert.equal(result.reason, '命中商品路由规则')
|
||||
assert.equal(result.matchedRule?.productName, '幸运币2个')
|
||||
})
|
||||
@@ -238,7 +234,7 @@ test('resolveFulfillmentRoute 内部 SKU 规则支持归一化与 contains', ()
|
||||
{
|
||||
internalSku: '幸运币',
|
||||
matchType: 'contains',
|
||||
executorKey: 'douyin_mashida_skin',
|
||||
executorKey: 'affiliate_dash',
|
||||
priority: 500,
|
||||
},
|
||||
],
|
||||
@@ -247,15 +243,15 @@ test('resolveFulfillmentRoute 内部 SKU 规则支持归一化与 contains', ()
|
||||
const exactFullWidth = resolveFulfillmentRoute({
|
||||
productName: '',
|
||||
internalSku: ' 幸运币2个 ',
|
||||
candidates: [{ executorKey: 'douyin_mashida_skin', available: true }],
|
||||
candidates: [{ executorKey: 'affiliate_dash', available: true }],
|
||||
config,
|
||||
})
|
||||
assert.equal(exactFullWidth.selectedExecutorKey, 'douyin_mashida_skin')
|
||||
assert.equal(exactFullWidth.selectedExecutorKey, 'affiliate_dash')
|
||||
|
||||
const miss = resolveFulfillmentRoute({
|
||||
productName: '',
|
||||
internalSku: '荣耀勋章2个',
|
||||
candidates: [{ executorKey: 'douyin_mashida_skin', available: true }],
|
||||
candidates: [],
|
||||
config,
|
||||
})
|
||||
assert.equal(miss.selectedExecutorKey, 'manual_dispatch')
|
||||
@@ -269,7 +265,7 @@ test('resolveFulfillmentRoute 未命中内部 SKU 规则时商品名规则仍然
|
||||
config: normalizeFulfillmentRoutingConfig({
|
||||
rules: [
|
||||
{ productName: '荣耀套装', executorKey: 'affiliate_dash', priority: 200 },
|
||||
{ internalSku: '幸运币2个', executorKey: 'douyin_mashida_skin', priority: 900 },
|
||||
{ internalSku: '幸运币2个', executorKey: 'affiliate_dash', priority: 900 },
|
||||
],
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -75,7 +75,6 @@ const FULFILLMENT_ROUTING_CONFIG_FILE_PATH = path.join(
|
||||
|
||||
const ROUTABLE_EXECUTOR_KEYS: string[] = [
|
||||
FULFILLMENT_EXECUTOR_KEYS.AFFILIATE_DASH,
|
||||
FULFILLMENT_EXECUTOR_KEYS.DOUYIN_MASHIDA_SKIN,
|
||||
FULFILLMENT_EXECUTOR_KEYS.MANUAL_DISPATCH,
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user