fix(douyu): 修正绑定刷新与自动启动交互

This commit is contained in:
yml
2026-11-20 22:03:20 +08:00
parent 0982993a6d
commit 38155ca1c3
7 changed files with 128 additions and 38 deletions
@@ -4,6 +4,7 @@ import {
confirmDouyuCustomerBinding,
getDouyuCustomerFulfillmentCached,
getCustomerDouyuFulfillment,
refreshDouyuCustomerBinding,
saveDouyuCustomerProfile,
startDouyuCustomerBinding,
} from '../services/douyu-fulfillment/douyu-fulfillment-service.js'
@@ -61,6 +62,15 @@ router.get(
}),
)
router.post(
'/:orderNo/binding/refresh',
createRouteHandler((req) => refreshDouyuCustomerBinding(String(req.params.orderNo || '')), {
successMessage: '绑定状态已刷新',
errorMessage: '刷新绑定状态失败',
scope: '[douyu-fulfillment/:orderNo/binding/refresh]',
}),
)
router.post(
'/:orderNo/binding/confirm',
createRouteHandler((req) => confirmDouyuCustomerBinding(String(req.params.orderNo || '')), {
@@ -76,6 +76,10 @@ type LiveBindingState = {
platName: string
bindReadyForConfirm: boolean
bindConfirmed: boolean
queueState?: string
retryAfterMs?: number
queueLane?: string
accepted?: boolean
customerProfileReset?: boolean
resetReason?: string
stateVersion?: number | string
@@ -589,6 +593,22 @@ function isLiveBindingState(value: unknown): value is LiveBindingState {
}
function liveBindingStateFromTask(task: DouyuTaskRow): LiveBindingState {
const queueState =
task.issue_code === 'mapping_missing'
? 'mapping_missing'
: !task.live_session_id
? 'allocation_queued'
: task.status === 'role_ready'
? 'role_ready'
: ['bound', 'waiting_operator', 'processing', 'completed'].includes(task.status)
? 'confirmed'
: task.status === 'failed'
? 'failed'
: task.qr_url
? 'waiting_scan'
: task.live_execution_status === 'waiting_bind'
? 'qr_queued'
: 'preparing'
return {
sessionId: Number(task.live_session_id),
platformOrderId: task.platform_order_id,
@@ -612,6 +632,8 @@ function liveBindingStateFromTask(task: DouyuTaskRow): LiveBindingState {
platName: task.bound_plat_name || '',
bindReadyForConfirm: task.status === 'role_ready',
bindConfirmed: ['bound', 'waiting_operator', 'processing', 'completed'].includes(task.status),
queueState,
retryAfterMs: queueState === 'allocation_queued' ? 2000 : 0,
completedAt: task.completed_at,
stateVersion: Number(task.live_state_version || 0),
updatedAt: task.updated_at,
@@ -815,8 +837,10 @@ export async function saveDouyuCustomerProfile(
export async function startDouyuCustomerBinding(orderNo: string, forceRefresh = false) {
let task = await loadTaskByOrderNo(orderNo)
const session = await ensureLiveSession(task)
task = session.task
if (!task.live_session_id) {
const session = await ensureLiveSession(task)
task = session.task
}
if (!task.live_session_id) {
throw createHttpError('直播账号履约会话尚未准备完成', {
statusCode: 409,