diff --git a/apps/backend/src/services/semi-auto/semi-auto-customer-service.ts b/apps/backend/src/services/semi-auto/semi-auto-customer-service.ts index ee3a6d01..bf0b3b44 100644 --- a/apps/backend/src/services/semi-auto/semi-auto-customer-service.ts +++ b/apps/backend/src/services/semi-auto/semi-auto-customer-service.ts @@ -634,10 +634,29 @@ export async function startPublicBinding( } assertCustomerProfileReady(task) if (task.platform === 'weibo') { - const session = await startWeiboBinding(task.connector_session_id, task.connector_mode, { - channel: input.channel === 'qq' ? 'qq' : 'wx', - forceRebind: input.forceRebind === true, - }) + let session: ConnectorBindingSession + try { + session = await startWeiboBinding(task.connector_session_id, task.connector_mode, { + channel: input.channel === 'qq' ? 'qq' : 'wx', + forceRebind: input.forceRebind === true, + }) + } catch (error) { + // 微博换绑被平台冷却拒绝时同样要留证:客户页要看到天数,后台要能看到原因。 + const message = error instanceof Error ? error.message : '生成微博角色绑定二维码失败' + await withTransaction(async (client) => { + const current = await loadTaskForUpdateWithClient(client, task.id) + await convergeSemiAutoTaskState(client, current.id, { + reason: 'weibo_binding_rejected', + actor: 'customer', + patch: { lastError: message }, + event: { + eventType: 'weibo_binding_rejected', + detail: { message, channel: input.channel === 'qq' ? 'qq' : 'wx' }, + }, + }) + }) + throw error + } const binding = await updateBindingTask(task, session, 'customer') const updated = await loadTask(task.id) return { task: mapTask(updated), binding } diff --git a/apps/backend/src/services/semi-auto/semi-auto-profile-requery.test.ts b/apps/backend/src/services/semi-auto/semi-auto-profile-requery.test.ts index 83e43a01..ec922cf2 100644 --- a/apps/backend/src/services/semi-auto/semi-auto-profile-requery.test.ts +++ b/apps/backend/src/services/semi-auto/semi-auto-profile-requery.test.ts @@ -43,3 +43,14 @@ describe('改完资料后重新从平台核对一次绑定事实', () => { ) }) }) + +describe('微博换绑被拒绝也要留证', () => { + it('startPublicBinding 的微博分支会写 last_error 与事件', () => { + const start = customerService.indexOf("if (task.platform === 'weibo') {\n let session") + assert.ok(start > 0, '未找到微博分支的失败留证代码') + const body = customerService.slice(start, start + 1600) + assert.ok(body.includes("reason: 'weibo_binding_rejected'")) + assert.ok(body.includes('patch: { lastError: message }')) + assert.ok(body.includes("eventType: 'weibo_binding_rejected'")) + }) +}) diff --git a/apps/frontend/src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx b/apps/frontend/src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx index 0b6c8c26..20eb1711 100644 --- a/apps/frontend/src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx +++ b/apps/frontend/src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx @@ -66,6 +66,22 @@ const SERVER_ZONE_OPTIONS = CUSTOMER_SERVER_ZONE_OPTIONS /** antd v6 语义化 classNames:让区服下拉弹层用页面深色样式 */ const SERVER_ZONE_SELECT_CLASS_NAMES = { popup: { root: 'customer-collect-dropdown' } } +/** + * 绑定失败原因去重收集:平台原因、任务 lastError、本次请求抛错可能说的是同一句话, + * 只按出现顺序保留第一次,空值直接丢弃。 + */ +function collectBindingFailureReasons(values: Array) { + const seen = new Set() + const reasons: string[] = [] + for (const value of values) { + const text = String(value || '').trim() + if (!text || seen.has(text)) continue + seen.add(text) + reasons.push(text) + } + return reasons +} + export default function CustomerFulfillmentPage({ expectedPlatform, }: { @@ -996,6 +1012,42 @@ export default function CustomerFulfillmentPage({ } } + /** + * 「确认绑定成功」后两个平台必须给出同一段引导:同一段 JSX,只换刷新按钮的文案和动作。 + * 客户不需要猜下一步——直接截图本页连订单号一起发给客服。 + */ + const renderBindingConfirmedNotice = (options: { + refreshLabel: string + onRefresh: () => void + }) => ( +
+

绑定已确认

+

+ 请截图本页,把订单号和这张截图发给客服,客服会按截图核对并继续处理。 +

+
+ 订单号 + {orderNo || selectedTask?.orderNo || ''} + +
+ +
+ ) + const displayTitle = isWeibo ? '登录并绑定微博游戏角色' : '绑定游戏角色' const loginQrVisible = Boolean(selectedTask) && ['qr_pending', 'scanned'].includes(selectedTask.loginStatus) @@ -1077,31 +1129,36 @@ export default function CustomerFulfillmentPage({ const rebindCooldownDays = Number(bindingInfo?.rebindCooldownDays || 0) const rebindCooldownText = rebindCooldownDays > 0 ? `当前仍处于虎牙换绑冷却期,剩余约 ${rebindCooldownDays} 天` : '' - // 微博页不涉及虎牙,冷却口径相同但文案不写虎牙。 - const weiboRebindCooldownText = - rebindCooldownDays > 0 ? `当前角色仍在换绑冷却期,剩余约 ${rebindCooldownDays} 天` : '' + // 微博页不涉及虎牙,冷却口径相同但文案不写虎牙。天数只认后端 rebindCooldownDays: + // 平台在「还没有绑定角色」时允许首次绑定,这种场景不算冷却,按钮必须保持可用。 + const weiboBoundRoleName = String( + bindingInfo?.bindGameRole || selectedTask?.bindGameRole || '', + ).trim() + const weiboRebindCooldownBlocked = rebindCooldownDays > 0 && Boolean(weiboBoundRoleName) + const weiboRebindCooldownText = weiboRebindCooldownBlocked + ? `当前角色仍在换绑冷却期,剩余约 ${rebindCooldownDays} 天,冷却结束后才能换绑` + : '' // 虎牙账号/目标角色仍在换绑冷却期:后端已不再给「重新扫码换绑」,页面只提供只读刷新。 const isRebindBlocked = bindingDecision?.flowState === 'rebind_blocked_account' || bindingDecision?.flowState === 'rebind_blocked_target_role' const canRefreshBindingState = decisionCanRefreshBinding || isRebindBlocked // 失败原因按「平台确认原因 → 任务原因 → 决策消息」去重,同一句只打印一次。 - const bindingFailureReasons = (() => { - const seen = new Set() - const reasons: string[] = [] - const push = (value: string | null | undefined) => { - const text = String(value || '').trim() - if (!text || seen.has(text)) return - seen.add(text) - reasons.push(text) - } - push(bindingInfo?.bindConfirmMessage) - push(selectedTask?.bindConfirmMessage) - push(bindingInfo?.rebindConfirmMessage) - push(bindingDecision?.message) - push(selectedTask?.lastError) - return reasons - })() + const bindingFailureReasons = collectBindingFailureReasons([ + bindingInfo?.bindConfirmMessage, + selectedTask?.bindConfirmMessage, + bindingInfo?.rebindConfirmMessage, + bindingDecision?.message, + selectedTask?.lastError, + ]) + // 微博绑定区同一口径:任务 lastError 已在 bindingFailureReasons 里, + // 这里再补上本次请求抛错(例如换绑冷却拒绝)与平台给出的失败消息, + // 保证它们留在页面上的展示位,而不是只弹一条会消失的 toast。 + const weiboBindingFailureReasons = collectBindingFailureReasons([ + ...bindingFailureReasons, + bindingLoadError, + selectedTask?.bindingStatus === 'failed' ? bindingInfo?.message : '', + ]) // 只有角色名缺失时才需要人工核实;加密 role token 不再冒充客户游戏角色 UID。 const bindingRequiresSupport = Boolean( bindingDecision?.requiresSupport || bindingInfo?.requiresSupport, @@ -1570,6 +1627,25 @@ export default function CustomerFulfillmentPage({ ) : null} + {/* 失败原因与虎牙同一口径:平台原因 + 任务 lastError + 本次请求抛错,去重后逐条展示。 */} + {weiboBindingFailureReasons.length ? ( + + {weiboBindingFailureReasons.map((reason) => ( + {reason} + ))} + + } + /> + ) : null} + {/* 冷却提示放在绑定按钮上方:天数只来自后端 rebindCooldownDays。 */} + {weiboRebindCooldownText ? ( + + ) : null} {bindingInfo?.qrImage ? (
) : null} - {bindingLoadError ? ( - - ) : selectedTask.bindingStatus === 'failed' && bindingInfo?.message ? ( - - ) : null} + {/* 「刷新角色状态」始终可用:冷却只限制换绑,不限制查看当前角色。 */}
)} - {weiboRebindCooldownText ? ( - - ) : null} ) : null} @@ -2046,61 +2110,28 @@ export default function CustomerFulfillmentPage({ ) : null} - {bindingDecision?.flowState === 'confirmed' && !profileEditing ? ( -
-

绑定已确认

-

- 请截图本页,把订单号和这张截图发给客服,客服会按截图核对并继续处理。 -

-
- 订单号 - {orderNo || selectedTask?.orderNo || ''} - -
- -
- ) : null} + }, + }) + : null} ) : null} + {/* 微博确认后的引导与虎牙完全同一段渲染,只换刷新文案。 */} {isWeibo && selectedTask?.loginStatus === 'authenticated' && selectedTask.bindingStatus === 'confirmed' && - selectedTask.executionStatus !== 'completed' ? ( -
-
- -
-

客服正在安排

-

请耐心等待

- -
- ) : null} + selectedTask.executionStatus !== 'completed' + ? renderBindingConfirmedNotice({ + refreshLabel: '刷新状态', + onRefresh: () => void load(), + }) + : null} { - const block = pickSlice( + // 文案与订单号复制只写一份:两个平台共用同一个渲染函数。 + const shared = pickSlice('const renderBindingConfirmedNotice = (options: {', 'const displayTitle') + assert.ok(shared.includes('绑定已确认')) + assert.ok(shared.includes('请截图本页')) + assert.ok(shared.includes('发给客服')) + assert.ok(shared.includes('订单号')) + // 订单号直接取页面已有的 orderNo / task.orderNo,不另建字段。 + assert.ok(shared.includes('{orderNo || selectedTask?.orderNo || ')) + assert.ok(shared.includes('copyOrderNoForSupport(')) + assert.ok(shared.includes('{options.refreshLabel}')) + + // 页面里「请截图本页」只出现一次,不能再复制出第二套文案。 + assert.equal(source.split('请截图本页').length - 1, 1) + + const huyaBlock = pickSlice( "bindingDecision?.flowState === 'confirmed' && !profileEditing", '{isWeibo &&', ) - assert.ok(block.includes('绑定已确认')) - assert.ok(block.includes('截图')) - assert.ok(block.includes('发给客服')) - assert.ok(block.includes('刷新订单状态')) - assert.ok(block.includes('订单号')) - // 订单号直接取页面已有的 orderNo / task.orderNo,不另建字段。 - assert.ok(block.includes('{orderNo || selectedTask?.orderNo || ')) - assert.ok(block.includes('copyOrderNoForSupport(')) + assert.ok(huyaBlock.includes('renderBindingConfirmedNotice({')) + assert.ok(huyaBlock.includes("refreshLabel: '刷新订单状态'")) + assert.ok(!huyaBlock.includes('请截图本页')) + + // 微博 confirmed 与其他平台完全同一个渲染,只换刷新按钮文案。 + assert.equal(source.split('renderBindingConfirmedNotice({').length - 1, 2) + assert.ok(source.includes("refreshLabel: '刷新状态'")) + assert.ok(source.includes("selectedTask.bindingStatus === 'confirmed'")) + // 旧文案已被替换。 assert.ok(!source.includes('平台角色绑定已确认,客服正在处理订单')) + assert.ok(!source.includes('客服正在安排')) + assert.ok(!source.includes('请耐心等待')) }) test('确认按钮不吞掉重新扫码与修改资料两个退回入口', () => { diff --git a/apps/frontend/tests/customer-fulfillment-weibo-binding-cooldown.test.ts b/apps/frontend/tests/customer-fulfillment-weibo-binding-cooldown.test.ts new file mode 100644 index 00000000..22da9bf0 --- /dev/null +++ b/apps/frontend/tests/customer-fulfillment-weibo-binding-cooldown.test.ts @@ -0,0 +1,100 @@ +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' +import { dirname, join } from 'node:path' +import { fileURLToPath } from 'node:url' +import test from 'node:test' + +const root = dirname(fileURLToPath(import.meta.url)) +const source = readFileSync( + join(root, '../src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx'), + 'utf8', +) + +/** 取样一段源码,找不到时直接失败,避免测试静默通过。 */ +function pickSlice(startMarker: string, endMarker: string) { + const start = source.indexOf(startMarker) + assert.ok(start >= 0, `源码缺少 ${startMarker}`) + const end = source.indexOf(endMarker, start) + assert.ok(end > start, `源码缺少 ${endMarker}`) + return source.slice(start, end) +} + +const weiboBindingCard = () => pickSlice('{showWeiboBindingStage ? (', '{showBindingStage ? (') + +test('换绑冷却天数只来自后端 rebindCooldownDays,不用其它字段推算', () => { + // 页面内冷却天数只有一个来源。 + assert.ok( + source.includes('const rebindCooldownDays = Number(bindingInfo?.rebindCooldownDays || 0)'), + ) + assert.equal(source.split('rebindCooldownDays =').length - 1, 1) + // 不得从平台规则字段或原始天数推算「从现在起还剩几天」。 + assert.ok(!source.includes('rebindRemainDays')) + assert.ok(!source.includes('rebindCooldownDays + ')) + assert.ok(!source.includes('rebindCooldownDays - ')) + assert.ok(!/(platformChangeBindDay|platformChangeBindTime)[^\n]*rebindCooldownDays/.test(source)) + assert.ok(!/rebindCooldownDays[^\n]*(platformChangeBindDay|platformChangeBindTime)/.test(source)) +}) + +test('冷却天数 > 0 且已有绑定角色时微信/QQ 按钮 disabled,刷新角色状态仍可用', () => { + const cooldown = pickSlice('const weiboBoundRoleName', 'const isRebindBlocked') + // 判断条件 = 后端天数 > 0 且已经有绑定角色,天数本身直接来自 rebindCooldownDays。 + assert.ok(cooldown.includes('bindingInfo?.bindGameRole || selectedTask?.bindGameRole')) + assert.ok( + cooldown.includes( + 'const weiboRebindCooldownBlocked = rebindCooldownDays > 0 && Boolean(weiboBoundRoleName)', + ), + ) + // 文案:剩余约 N 天 + 冷却结束后才能换绑,N 只来自 rebindCooldownDays。 + assert.ok( + cooldown.includes( + '当前角色仍在换绑冷却期,剩余约 ${rebindCooldownDays} 天,冷却结束后才能换绑', + ), + ) + + const card = weiboBindingCard() + // 微信绑定 / QQ 绑定两个按钮都受冷却门禁约束。 + assert.equal( + card.split('disabled={bindingSessionExpired || weiboRebindCooldownBlocked}').length - 1, + 2, + ) + const wxStart = card.indexOf('微信绑定') + const qqStart = card.indexOf('QQ 绑定') + assert.ok(wxStart > 0 && qqStart > wxStart) + // 冷却提示必须在两个绑定按钮之前(按钮上方)。 + const cooldownNotice = card.indexOf('weiboRebindCooldownText ? (') + assert.ok(cooldownNotice > 0) + assert.ok(cooldownNotice < card.indexOf("handleStartWeiboBinding('wx')")) + // 「刷新角色状态」始终可用:只受登录会话影响,不受冷却影响。 + const refreshStart = card.lastIndexOf('刷新角色状态') + assert.ok(refreshStart > 0) + const refreshButton = card.slice(card.lastIndexOf(' void handlePollBindingNow()}')) +}) + +test('微博绑定失败原因同时展示平台原因与任务 lastError,且同一句不重复', () => { + // 任务 lastError 与平台原因统一由去重收集器完成。 + const collected = pickSlice( + 'const bindingFailureReasons = collectBindingFailureReasons([', + 'const weiboBindingFailureReasons', + ) + assert.ok(collected.includes('bindingInfo?.bindConfirmMessage')) + assert.ok(collected.includes('bindingDecision?.message')) + assert.ok(collected.includes('selectedTask?.lastError')) + + // 微信/QQ 绑定抛错(如冷却拒绝)写进 bindingLoadError,和平台原因共用同一个展示位。 + const weiboReasons = pickSlice('const weiboBindingFailureReasons', 'const bindingRequiresSupport') + assert.ok(weiboReasons.includes('...bindingFailureReasons')) + assert.ok(weiboReasons.includes('bindingLoadError')) + + const card = weiboBindingCard() + assert.ok(card.includes('weiboBindingFailureReasons.length')) + assert.ok(card.includes('weiboBindingFailureReasons.map((reason) => (')) + // 不再用单条瞬时提示代替失败原因展示。 + assert.ok(!card.includes('message={bindingLoadError}')) + assert.ok(!card.includes('description={bindingInfo?.message}')) + // 去重逻辑只有一份(页面与微博区共用同一函数)。 + assert.equal(source.split('const seen = new Set()').length - 1, 1) + assert.ok(source.includes('function collectBindingFailureReasons(')) +}) diff --git a/docs/统一订单履约与财务模型-权威版.md b/docs/统一订单履约与财务模型-权威版.md index bd1ff9c7..5d4ca14c 100644 --- a/docs/统一订单履约与财务模型-权威版.md +++ b/docs/统一订单履约与财务模型-权威版.md @@ -387,9 +387,13 @@ manual fulfillment `data.game_role.is_bound / role_name / can_rebind / rebind_remain_days / bind_url`; ③ `is_bound = false` 时使用 `bind_url` 通过来联生成微信或 QQ 小程序绑定二维码, `is_bound = true` 且角色名变化后才收敛为 `binding_status = confirmed`; - ④ 已绑定且 `can_rebind = false` 时不得生成换绑二维码,必须展示冷却剩余天数; + ④ 已绑定且 `can_rebind = false` 时不得生成换绑二维码,必须展示冷却剩余天数 + (天数只取平台 `rebind_remain_days`,客户页在冷却期内禁用「微信绑定 / QQ 绑定」,不得自行推算); ⑤ 绑定二维码是 10 分钟短期会话状态,不单独落库;Connector 重启后以账号级 CK 恢复会话并重新查询 - `game_role`,已绑定事实照常确认,未绑定事实回到重新生成二维码。 + `game_role`,已绑定事实照常确认,未绑定事实回到重新生成二维码; + ⑥ 与虎牙同口径:换绑被平台冷却拒绝时必须把原因写进 `last_error` 并追加 + `weibo_binding_rejected` 事件,客户页要能看到同一句原因;绑定确认后客户页直接展示 + 「绑定已确认 + 截图本页连同订单号发给客服」,不再展示进度文案让客户自行猜测。 - 斗鱼客户领取页只允许通过订单级 SSE 接收“需要重读”的瞬态信号,不得固定秒级轮询绑定状态。 SSE 不携带订单、角色或 CK 快照;页面收到信号或断线重连后,重新读取 `/api/v1/douyu-fulfillment/<订单号>` 的权威快照。live-hub 快照字段没有实际变化时不得重复广播,避免读接口与 SSE 自激循环。