feifei 优化 订单编号

This commit is contained in:
yml2213
2026-07-08 14:20:42 +08:00
parent ec23eb6af6
commit 2a5080c6c4
2 changed files with 74 additions and 2 deletions
@@ -1,7 +1,11 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { resolveKuaishouFeifeiClaimUrl } from './index.js'
import {
buildFeifeiPlatformOrderNo,
resolveKuaishouFeifeiClaimUrl,
} from './index.js'
import type { TaskRow } from '../../../types/repository/rows.js'
test('resolveKuaishouFeifeiClaimUrl prefers feifei h5 url over local claim url', () => {
assert.equal(
@@ -41,3 +45,66 @@ test('resolveKuaishouFeifeiClaimUrl prefers internal short link', () => {
'https://ks.khhao.com/s/AbCd1234',
)
})
test('buildFeifeiPlatformOrderNo prefers source order number', () => {
assert.equal(
buildFeifeiPlatformOrderNo(createTask({
platform_order_id: 'KS202607080001',
task_no: 'DT600a8bd23b8',
})),
'KS202607080001',
)
})
test('buildFeifeiPlatformOrderNo falls back to task number', () => {
assert.equal(
buildFeifeiPlatformOrderNo(createTask({
platform_order_id: '',
task_no: 'DT600a8bd23b8',
})),
'DT600a8bd23b8',
)
})
function createTask(patch: Partial<TaskRow> = {}): TaskRow {
return {
id: 123,
order_id: 456,
order_item_id: 789,
unit_index: 0,
platform_order_id: '',
profile_id: 0,
task_no: '',
executor_key: 'kuaishou_feifei',
task_status: 'pending',
delivery_status: 'pending',
result_code: '',
result_message: '',
automation_mode: 'auto',
requires_claim: true,
user_action_status: 'not_required',
attempt_count: 0,
runtime_session_id: '',
login_type: '',
nickname: '',
role_name: '',
role_id: '',
area: '',
partition_name: '',
claim_token: '',
primary_claim_token: '',
primary_claim_token_id: null,
primary_claim_token_status: '',
artifacts_json: '{}',
context_json: '{}',
screenshot_path: '',
last_error: '',
retry_count: 0,
created_at: '2026-07-08T00:00:00.000Z',
updated_at: '2026-07-08T00:00:00.000Z',
claimed_at: null,
role_confirmed_at: null,
redeemed_at: null,
...patch,
}
}
@@ -343,7 +343,12 @@ function isLocalClaimUrl(value: unknown) {
return !/^https?:\/\//i.test(url) || url.includes('/#/claim/')
}
function buildFeifeiPlatformOrderNo(task: TaskRow) {
export function buildFeifeiPlatformOrderNo(task: TaskRow) {
const platformOrderId = String(task.platform_order_id || '').trim()
if (platformOrderId && platformOrderId.length <= 64) {
return platformOrderId
}
const taskNo = String(task.task_no || '').trim()
if (taskNo && taskNo.length <= 64) {
return taskNo