diff --git a/apps/backend/src/routes/customer-fulfillment.ts b/apps/backend/src/routes/customer-fulfillment.ts index e6d80f07..5e331430 100644 --- a/apps/backend/src/routes/customer-fulfillment.ts +++ b/apps/backend/src/routes/customer-fulfillment.ts @@ -10,6 +10,7 @@ import { pollPublicBinding, pollPublicLogin, pollPublicWeiboQrLogin, + resetPublicBinding, savePublicTaskProfile, sendPublicHuyaSmsCode, sendPublicWeiboSmsCode, @@ -98,6 +99,16 @@ router.post( ), ) +router.post( + '/:orderNo/tasks/:taskId/binding/reset', + writeLimit, + createRouteHandler((req) => resetPublicBinding(req.params.orderNo, req.params.taskId), { + successMessage: '已返回修改资料', + errorMessage: '重置换绑状态失败', + scope: '[customer-fulfillment/:orderNo/tasks/:taskId/binding/reset]', + }), +) + router.post( '/:orderNo/tasks/:taskId/binding/start', writeLimit, diff --git a/apps/backend/src/services/semi-auto/huya-connector-client.ts b/apps/backend/src/services/semi-auto/huya-connector-client.ts index ec40ad26..e4e8c001 100644 --- a/apps/backend/src/services/semi-auto/huya-connector-client.ts +++ b/apps/backend/src/services/semi-auto/huya-connector-client.ts @@ -487,6 +487,23 @@ export async function confirmHuyaBinding( ) } +/** + * 客户返回上一步修改资料:只重置绑定/换绑状态,不注销登录会话、不删除客户资料。 + * 外部 Connector 通过独立 reset 端点实现;未提供时由调用方决定是否继续。 + */ +export async function resetHuyaBinding( + sessionId: string, + mode: SemiAutoConnectorMode = defaultSemiAutoConnectorMode(), +): Promise { + if (mode === 'embedded') return huyaNativeConnector.resetBinding(sessionId) + if (mode === 'mock') return startHuyaBinding(sessionId, mode, {}) + return callConnector( + `/api/internal/huya-semi-auto/sessions/${encodeURIComponent(sessionId)}/binding/reset`, + { method: 'POST', body: {} }, + mode, + ) +} + /** * 扫码后由项目侧主动向虎牙提交换绑确认。 * 外部 Connector 暂未提供独立端点时复用 confirm 端点(语义一致,幂等)。 diff --git a/apps/backend/src/services/semi-auto/huya-native/huya-native-connector.ts b/apps/backend/src/services/semi-auto/huya-native/huya-native-connector.ts index d762fd33..8be34662 100644 --- a/apps/backend/src/services/semi-auto/huya-native/huya-native-connector.ts +++ b/apps/backend/src/services/semi-auto/huya-native/huya-native-connector.ts @@ -1152,6 +1152,20 @@ export class HuyaNativeConnector { ) } + /** + * 客户点「上一步修改资料」:清空本次绑定/换绑状态,保留登录会话。 + * 重新提交资料后会重新查询平台角色,按新资料重新比对,不会继承旧的换绑失败状态。 + */ + async resetBinding(sessionId: string): Promise { + return this.withLock(sessionId, async () => { + const session = this.requireAuthenticatedSession(sessionId) + session.binding = defaultBindingState() + session.binding.account = session.nickname + session.binding.message = '已返回上一步修改资料,提交后会重新识别平台角色' + return this.bindingView(session) + }) + } + /** * 客户点「确认绑定」:只做本地状态流转,不调用虎牙接口。 * 虎牙侧的绑定已由扫码(小程序/弹窗)完成,确认绑定只是核对三项后落库; diff --git a/apps/backend/src/services/semi-auto/semi-auto-binding-role.test.ts b/apps/backend/src/services/semi-auto/semi-auto-binding-role.test.ts index bbb09d7a..d68ab66a 100644 --- a/apps/backend/src/services/semi-auto/semi-auto-binding-role.test.ts +++ b/apps/backend/src/services/semi-auto/semi-auto-binding-role.test.ts @@ -44,20 +44,26 @@ describe('待确认角色 UID 取数(huyaUid)', () => { }) it('虎牙加密串角色 ID 改用 huyaUid 参与比对', () => { - const result = compareBindingRole(task('1199608910400', '大鲨鱼伊塞53', '1199608910400'), { - bindGameRole: '大鲨鱼伊塞53', - bindGameRoleId: '834ee3e75a1bfc9f65fb6b966bac7ef318e68ea', - }) + const result = compareBindingRole( + task('1199608910400', '大鲨鱼伊塞53', '1199608910400', '安卓V区'), + { + bindGameRole: '大鲨鱼伊塞53', + bindGameRoleId: '834ee3e75a1bfc9f65fb6b966bac7ef318e68ea', + bindGameChannel: '安卓(android) · 微信', + }, + ) assert.equal(result.verdict, 'match') assert.equal(result.boundRoleId, '1199608910400') }) - it('没有 huyaUid 时保留原始加密串,仍判不一致', () => { - const result = compareBindingRole(task('1199608910400', '大鲨鱼伊塞53'), { + it('没有 huyaUid 时无法核对加密角色 ID,判 unknown', () => { + const result = compareBindingRole(task('1199608910400', '大鲨鱼伊塞53', '', '安卓V区'), { bindGameRole: '大鲨鱼伊塞53', bindGameRoleId: '834ee3e75a1bfc9f65fb6b966bac7ef318e68ea', + bindGameChannel: '安卓(android) · 微信', }) - assert.equal(result.verdict, 'mismatch') + assert.equal(result.verdict, 'unknown') + assert.match(result.message, /平台可核对角色ID/) assert.equal(result.boundRoleId, '834ee3e75a1bfc9f65fb6b966bac7ef318e68ea') }) }) @@ -157,7 +163,7 @@ describe('客户填写角色与平台识别角色比对', () => { assert.equal(result.boundZone, '安卓V区') }) - it('渠道解析不出区服时跳过区服比对', () => { + it('渠道解析不出区服时判 unknown,不允许提交', () => { const result = compareBindingRole( task('1199608910400', '大鲨鱼伊塞53', '1199608910400', '苹果Q区'), { @@ -166,41 +172,51 @@ describe('客户填写角色与平台识别角色比对', () => { bindGameChannel: '微信用户', }, ) - assert.equal(result.verdict, 'match') + assert.equal(result.verdict, 'unknown') + assert.match(result.message, /平台区服/) assert.equal(result.boundZone, '') }) - it('两侧角色 ID 一致时允许确认', () => { - const result = compareBindingRole(task('1192083858', '巫师基尔斯84'), { + it('客户区服未填时判 unknown,不允许提交', () => { + const result = compareBindingRole(task('1199608910400', '大鲨鱼伊塞53', '1199608910400', ''), { + bindGameRole: '大鲨鱼伊塞53', + bindGameRoleId: '1199608910400', + bindGameChannel: '安卓(android) · 微信', + }) + assert.equal(result.verdict, 'unknown') + assert.match(result.message, /客户区服/) + }) + + it('三项一致时允许提交平台绑定', () => { + const result = compareBindingRole(task('1192083858', '巫师基尔斯84', '1192083858', '安卓Q区'), { bindGameRole: '巫师基尔斯84', bindGameRoleId: '1192083858', + bindGameChannel: '安卓(android) · QQ', }) assert.equal(result.verdict, 'match') assert.equal(result.customerRoleId, '1192083858') assert.equal(result.boundRoleId, '1192083858') + assert.match(result.message, /可提交平台绑定/) }) - it('两侧角色 ID 不一致时禁止确认', () => { - const result = compareBindingRole(task('1192083858', '巫师基尔斯84'), { + it('两侧角色 ID 不一致时禁止提交', () => { + const result = compareBindingRole(task('1192083858', '巫师基尔斯84', '', '安卓V区'), { bindGameRole: '我是火星人2222', bindGameRoleId: '166909256', + bindGameChannel: '安卓(android) · 微信', }) assert.equal(result.verdict, 'mismatch') assert.match(result.message, /不一致/) }) - it('缺少角色 ID 时退回角色名称比对', () => { - const matched = compareBindingRole(task('', '巫师基尔斯84'), { + it('任一侧缺少角色 ID 时判 unknown,不退化为只比角色名', () => { + const result = compareBindingRole(task('', '巫师基尔斯84'), { bindGameRole: '巫师基尔斯84', bindGameRoleId: '', }) - assert.equal(matched.verdict, 'match') - - const mismatched = compareBindingRole(task('', '巫师基尔斯84'), { - bindGameRole: '我是火星人2222', - bindGameRoleId: '', - }) - assert.equal(mismatched.verdict, 'mismatch') + assert.equal(result.verdict, 'unknown') + assert.match(result.message, /客户游戏编号/) + assert.match(result.message, /平台可核对角色ID/) }) it('两侧都没有可核对信息时标记为 unknown', () => { diff --git a/apps/backend/src/services/semi-auto/semi-auto-task-service.ts b/apps/backend/src/services/semi-auto/semi-auto-task-service.ts index 1048e7de..5d06c1b2 100644 --- a/apps/backend/src/services/semi-auto/semi-auto-task-service.ts +++ b/apps/backend/src/services/semi-auto/semi-auto-task-service.ts @@ -25,6 +25,7 @@ import { getHuyaBindingSnapshot, getHuyaLoginSession, loginHuyaSms, + resetHuyaBinding, revokeHuyaSession, sendHuyaSmsCode, startHuyaBinding, @@ -178,6 +179,17 @@ function normalizeOrderNo(value: unknown): string { return text } +/** 客户资料以 TASK_SELECT 合并后的字段为准:优先任务表,回退工单资料。 */ +export function hasCustomerProfile( + task: Pick, +): boolean { + return Boolean( + String(task.customer_game_id || '').trim() && + String(task.customer_game_role || '').trim() && + String(task.customer_server_zone || '').trim(), + ) +} + function displayStatus(task: TaskRow) { if (task.execution_status === 'completed') return { key: 'completed', label: '已完成' } if (task.execution_status === 'cancelled') return { key: 'cancelled', label: '已取消' } @@ -192,6 +204,9 @@ function displayStatus(task: TaskRow) { if (task.platform === 'weibo' || task.binding_status === 'confirmed') { return { key: 'waiting_operator', label: '等待客服处理' } } + if (task.platform === 'huya' && !hasCustomerProfile(task)) { + return { key: 'waiting_profile', label: '待客户填写资料' } + } if (task.binding_status === 'role_ready') { return { key: 'binding_confirm', label: '待确认绑定角色' } } @@ -413,16 +428,13 @@ function assertHuyaTask(task: TaskRow) { } /** - * 半自动订单没有工单,资料页 /c/<订单号>(虎牙)或 /d/<订单号>(微博)是唯一入口。 - * 未提交区服 / 游戏编号 / 角色名时,不允许开始登录,避免后续无法比对角色。 + * 半自动订单没有工单时,客户资料在登录后由 /c/<订单号> 收集; + * 任务表为空但工单素材已有资料时,TASK_SELECT 会合并回退字段。 + * 进入绑定/确认/换绑前必须已有完整三项资料。 */ function assertCustomerProfileReady(task: TaskRow) { if (task.platform !== 'huya') return - if ( - !String(task.customer_game_server_zone || '').trim() || - !String(task.customer_game_role_id || '').trim() || - !String(task.customer_game_role_name || '').trim() - ) { + if (!hasCustomerProfile(task)) { throw createHttpError('请先提交游戏角色资料', { statusCode: 409, errorCode: 'semi_auto_profile_required', @@ -824,6 +836,13 @@ export async function savePublicTaskProfile( errorCode: 'semi_auto_profile_locked', }) } + // 客户页流程固定为「登录 → 填写资料 → 绑定角色」;未登录不允许提前写资料。 + if (task.login_status !== 'authenticated') { + throw createHttpError('请先完成虎牙登录后再填写资料', { + statusCode: 409, + errorCode: 'semi_auto_login_required', + }) + } const profile = normalizeCustomerProfile(payload) await withTransaction(async (client) => { await client.query( @@ -1003,7 +1022,7 @@ function normalizeServerZone(value: unknown): string { /** * 从虎牙渠道串解析区服,例如「安卓(android) · 微信」→ 安卓V区。 - * 解析不出平台或登录方式时返回空串,调用方跳过区服比对。 + * 解析不出平台或登录方式时返回空串,比对时按「平台区服缺失」处理(判 unknown)。 */ export function detectServerZone(channel: unknown): string { const text = String(channel ?? '') @@ -1022,13 +1041,14 @@ export function detectServerZone(channel: unknown): string { } /** - * 客户填写角色与平台识别角色必须一致才允许确认绑定。 + * 客户填写角色与平台识别角色必须完全一致才允许提交平台绑定。 * - * 区服、角色名、角色 ID 三项都要一致: - * ① 两侧都有 ID 时 ID 必须相等; - * ② 两侧都有角色名时名称必须相等(不能因为 ID 相同就放行改名); - * ③ 平台渠道能解析出区服且客户有填时,区服必须相等。 - * 任一侧缺某字段时跳过该字段比对;三项都取不到才判 unknown,转客服核对。 + * 区服、角色名、角色 ID 三项必须全部存在且一致: + * ① 客户游戏编号 = 虎牙账号 UID,与平台可核对角色 ID 相等; + * ② 角色名按规范化文本相等(忽略空白与大小写差异不能放行改名); + * ③ 平台渠道能解析出区服且与客户所填区服相等。 + * 任一侧缺任一项(含平台只给加密 roleId 且拿不到 UID)判 unknown,转客服核对; + * 任一项不等判 mismatch,不允许提交平台绑定。 */ export function compareBindingRole( task: Pick< @@ -1060,40 +1080,38 @@ export function compareBindingRole( boundZone, } - if (customerRoleId && boundRoleId && customerRoleId !== boundRoleId) { - return { ...base, verdict: 'mismatch', message: '两侧角色 ID 不一致,无法确认绑定' } - } - - if ( - customerRoleName && - boundRoleName && - normalizeRoleText(customerRoleName) !== normalizeRoleText(boundRoleName) - ) { - return { ...base, verdict: 'mismatch', message: '两侧角色名称不一致,无法确认绑定' } - } - - if (customerZone && boundZone && customerZone !== boundZone) { - return { ...base, verdict: 'mismatch', message: '两侧区服不一致,无法确认绑定' } - } - - const matchedFields = [ - customerRoleId && boundRoleId ? '角色 ID' : '', - customerRoleName && boundRoleName ? '角色名称' : '', - customerZone && boundZone ? '区服' : '', - ].filter(Boolean) - - if (matchedFields.length > 0) { + // 客户确认的口径:区服、角色名、角色 ID 三项必须全部存在且一致。 + const missing: string[] = [] + if (!customerRoleId) missing.push('客户游戏编号') + if (!customerRoleName) missing.push('客户角色名') + if (!customerZone) missing.push('客户区服') + if (!boundRoleId || !isNumericBindingRoleId(boundRoleId)) missing.push('平台可核对角色ID') + if (!boundRoleName) missing.push('平台角色名') + if (!boundZone) missing.push('平台区服') + if (missing.length > 0) { return { ...base, - verdict: 'match', - message: `两侧${matchedFields.join('、')}一致,可确认绑定`, + verdict: 'unknown', + message: `缺少${missing.join('、')},无法核对绑定角色,请联系客服`, } } + if (customerRoleId !== boundRoleId) { + return { ...base, verdict: 'mismatch', message: '两侧角色 ID 不一致,无法提交平台绑定' } + } + + if (normalizeRoleText(customerRoleName) !== normalizeRoleText(boundRoleName)) { + return { ...base, verdict: 'mismatch', message: '两侧角色名称不一致,无法提交平台绑定' } + } + + if (customerZone !== boundZone) { + return { ...base, verdict: 'mismatch', message: '两侧区服不一致,无法提交平台绑定' } + } + return { ...base, - verdict: 'unknown', - message: '未获取到可核对的两侧角色信息,请联系客服核对后再确认', + verdict: 'match', + message: '两侧区服、角色名称、角色 ID 一致,可提交平台绑定', } } @@ -1206,7 +1224,6 @@ export async function startPublicLogin(orderNoInput: unknown, taskIdInput: unkno const taskId = normalizeId(taskIdInput) await ensureSemiAutoTasksForOrder(orderNo) const task = await loadTaskForOrder(orderNo, taskId) - assertCustomerProfileReady(task) if (task.execution_status === 'completed' || task.execution_status === 'cancelled') { throw createHttpError('当前订单已结束,不能重新登录', { statusCode: 409, @@ -1340,6 +1357,7 @@ export async function startPublicBinding( errorCode: 'semi_auto_login_required', }) } + assertCustomerProfileReady(task) const session = task.platform === 'weibo' ? await getWeiboBinding(task.connector_session_id, task.connector_mode) @@ -1351,6 +1369,81 @@ export async function startPublicBinding( return { task: mapTask(updated), binding } } +/** + * 客户在失败/不一致页面点「上一步修改资料」: + * 清空绑定/换绑状态,保留登录会话和客户资料;重新提交资料后重新走绑定流程。 + */ +export async function resetPublicBinding(orderNoInput: unknown, taskIdInput: unknown) { + const orderNo = normalizeOrderNo(orderNoInput) + const taskId = normalizeId(taskIdInput) + const task = await loadTaskForOrder(orderNo, taskId) + if (task.platform !== 'huya') { + throw createHttpError('当前平台不需要重置绑定状态', { + statusCode: 409, + errorCode: 'semi_auto_binding_reset_not_supported', + }) + } + if (task.execution_status === 'completed' || task.execution_status === 'cancelled') { + throw createHttpError('当前订单已结束,不能返回修改资料', { + statusCode: 409, + errorCode: 'semi_auto_task_closed', + }) + } + if (task.binding_status === 'confirmed') { + throw createHttpError('绑定已确认,不能返回修改资料', { + statusCode: 409, + errorCode: 'semi_auto_profile_locked', + }) + } + if (!task.connector_session_id || task.login_status !== 'authenticated') { + throw createHttpError('请先完成平台登录', { + statusCode: 409, + errorCode: 'semi_auto_login_required', + }) + } + + // 清空 Connector 内存里的换绑失败状态;外部 Connector 尚未提供 reset 时, + // 本地状态仍重置,客户可继续修改资料,不能被旧的失败状态卡死。 + try { + await resetHuyaBinding(task.connector_session_id, task.connector_mode) + } catch { + // 仅清理本地持久化状态;下一次绑定会重新查询平台角色。 + } + + await withTransaction(async (client) => { + await client.query( + ` + UPDATE semi_auto_tasks + SET binding_status = 'not_started', + bind_game_role = '', + bind_game_role_id = '', + bind_game_channel = '', + binding_started_at = NULL, + bound_at = NULL, + execution_status = 'waiting_customer', + last_error = '', + updated_at = NOW() + WHERE id = $1 + `, + [task.id], + ) + await appendTaskEvent(client, task.id, { + eventType: 'binding_reset', + actorType: 'customer', + fromBindingStatus: task.binding_status, + toBindingStatus: 'not_started', + fromExecutionStatus: task.execution_status, + toExecutionStatus: 'waiting_customer', + detail: { + reason: 'customer_profile_edit', + customerProfileKept: true, + }, + }) + }) + const updated = await loadTask(task.id) + return { task: mapTask(updated), binding: null } +} + export async function pollPublicBinding(orderNoInput: unknown, taskIdInput: unknown) { const orderNo = normalizeOrderNo(orderNoInput) const taskId = normalizeId(taskIdInput) @@ -1390,52 +1483,49 @@ export async function confirmPublicBinding( errorCode: 'semi_auto_binding_not_ready', }) } + assertCustomerProfileReady(task) // 确认绑定是纯本地动作:虎牙侧只读内存快照,不再触发角色查询或换绑提交。 const session = task.platform === 'huya' ? await getHuyaBindingSnapshot(task.connector_session_id, task.connector_mode) : await getBindingForTask(task, task.connector_session_id) + const comparison = compareBindingRole(task, session) + // 换绑被虎牙拒绝时平台仍返回原角色。若客户已把资料改成与原角色一致, + // 允许直接确认;否则要求重新扫码或返回上一步修改资料。 if ( task.platform === 'huya' && session.rebindUnchanged === true && - options.acceptExistingRole !== true + comparison.verdict !== 'match' ) { - // 换绑被虎牙拒绝时不直接放行,要求客户二选一:重新扫码换绑 / 仍使用原角色。 const reason = String(session.rebindConfirmMessage || '').trim() throw createHttpError( `${ reason ? `换绑未成功:${reason}。` : '换绑未生效:平台仍返回原绑定角色。' - }请重新扫码换绑,或确认继续使用原绑定角色「${session.bindGameRole || '原角色'}」`, + }请重新扫码换绑,或返回上一步修改资料,使资料与平台当前角色一致后再提交平台绑定`, { statusCode: 409, errorCode: 'semi_auto_binding_rebind_decision_required', }, ) } - // 已绑定角色但没有可核对的数字角色 ID:不能只按角色名放行,必须人工核实(客户页会提示联系客服)。 - const boundRolePresent = - Boolean(String(session.bindGameRole || '').trim()) || session.hasExistingBinding === true - if ( - task.platform === 'huya' && - boundRolePresent && - !isNumericBindingRoleId(session.bindGameRoleId) - ) { - throw createHttpError('平台未返回可核对的角色ID,请联系客服人工核实后再确认绑定', { - statusCode: 409, - errorCode: 'semi_auto_binding_role_id_missing', - }) - } - const comparison = compareBindingRole(task, session) - if (comparison.verdict === 'mismatch') { + // 三项必须全部存在且一致;信息不完整同样不能自动放行,必须转客服核实。 + if (comparison.verdict !== 'match') { throw createHttpError(comparison.message, { statusCode: 409, - errorCode: 'semi_auto_binding_role_mismatch', + errorCode: + comparison.verdict === 'mismatch' + ? 'semi_auto_binding_role_mismatch' + : 'semi_auto_binding_role_unverifiable', }) } // 必须调用 Connector 完成确认,否则会话仍是 role_ready,数据库也会停在待确认。 const confirmedSession = task.platform === 'huya' - ? await confirmHuyaBinding(task.connector_session_id, task.connector_mode, options) + ? await confirmHuyaBinding(task.connector_session_id, task.connector_mode, { + ...(options.acceptExistingRole === true || session.rebindUnchanged === true + ? { acceptExistingRole: true } + : {}), + }) : session const binding = await updateBindingTask(task, confirmedSession, 'customer') const updated = await loadTask(task.id) @@ -1468,6 +1558,7 @@ export async function submitPublicRebind(orderNoInput: unknown, taskIdInput: unk errorCode: 'semi_auto_login_required', }) } + assertCustomerProfileReady(task) const session = await submitHuyaRebind(task.connector_session_id, task.connector_mode) const binding = await updateBindingTask(task, session, 'customer') const updated = await loadTask(task.id) @@ -1483,7 +1574,6 @@ export async function sendPublicHuyaSmsCode( const taskId = normalizeId(taskIdInput) const task = await loadTaskForOrder(orderNo, taskId) assertHuyaTask(task) - assertCustomerProfileReady(task) if (task.execution_status === 'completed' || task.execution_status === 'cancelled') { throw createHttpError('当前订单已结束,不能重新登录', { statusCode: 409, @@ -1633,7 +1723,6 @@ export async function loginPublicHuyaSms( const taskId = normalizeId(taskIdInput) const task = await loadTaskForOrder(orderNo, taskId) assertHuyaTask(task) - assertCustomerProfileReady(task) if (task.execution_status === 'completed' || task.execution_status === 'cancelled') { throw createHttpError('当前订单已结束,不能重新登录', { statusCode: 409, @@ -1937,6 +2026,12 @@ export async function getAdminSemiAutoTask(taskIdInput: unknown) { ) return { task: mapTask(task), + // 管理端详情直接复用与客户页相同的三项比对口径,避免出现第二套判定。 + comparison: compareBindingRole(task, { + bindGameRole: task.bind_game_role, + bindGameRoleId: task.bind_game_role_id, + bindGameChannel: task.bind_game_channel, + }), events: events.rows.map((event) => ({ id: Number(event.id), eventType: event.event_type, diff --git a/apps/backend/src/services/semi-auto/semi-auto-task.integration.test.ts b/apps/backend/src/services/semi-auto/semi-auto-task.integration.test.ts index 28dc20aa..b8f34467 100644 --- a/apps/backend/src/services/semi-auto/semi-auto-task.integration.test.ts +++ b/apps/backend/src/services/semi-auto/semi-auto-task.integration.test.ts @@ -9,6 +9,14 @@ import test from 'node:test' const TEST_DATABASE_URL = String(process.env.SEMI_AUTO_TASK_TEST_DATABASE_URL || '').trim() +/** 断言领域服务抛出指定错误码,避免只匹配中文提示。 */ +async function expectErrorCode(fn: () => Promise, errorCode: string) { + await assert.rejects(fn, (error: { errorCode?: string }) => { + assert.equal(error.errorCode, errorCode) + return true + }) +} + test( '人工渠道半自动任务可由客户入口和后台列表幂等回填', { skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false }, @@ -16,11 +24,15 @@ test( process.env.DATABASE_URL = TEST_DATABASE_URL const { closeDb, query, withTransaction } = await import('../../db/client.js') const { + confirmPublicBinding, ensureSemiAutoTasksForOrder, exportAdminSemiAutoCredential, listAdminSemiAutoTasks, listPublicSemiAutoTasks, requestAdminSemiAutoCustomerReauth, + resetPublicBinding, + savePublicTaskProfile, + startPublicBinding, } = await import('./semi-auto-task-service.js') const suffix = `${Date.now()}_${Math.floor(Math.random() * 1_000_000)}` const orderNo = `IT-SEMI-AUTO-${suffix}` @@ -110,6 +122,17 @@ test( assert.equal(tasks[0]?.semiAutoConfig.pageTitle, '虎牙授权测试') const taskId = Number(tasks[0]?.id || 0) + // 客户页流程固定为「登录 → 填写资料 → 绑定角色」:未登录不能提前写资料或开始绑定。 + await expectErrorCode( + () => + savePublicTaskProfile(orderNo, taskId, { + roleName: '集成测试角色', + roleId: '1192083858', + serverZone: '安卓V区', + }), + 'semi_auto_login_required', + ) + await expectErrorCode(() => startPublicBinding(orderNo, taskId), 'semi_auto_login_required') const credential = await query<{ id: number }>( ` INSERT INTO semi_auto_credentials ( @@ -141,11 +164,110 @@ test( ) const authenticatedList = await listAdminSemiAutoTasks({ keyword: orderNo }) assert.equal(authenticatedList.items[0]?.loginStatus, 'authenticated') - assert.equal(authenticatedList.items[0]?.displayStatus.label, '等待客服处理') + assert.equal(authenticatedList.items[0]?.displayStatus.label, '待客户填写资料') + + // 资料未填时不能开始绑定;也不能把待确认角色直接提交为平台绑定。 + await expectErrorCode(() => startPublicBinding(orderNo, taskId), 'semi_auto_profile_required') + await query("UPDATE semi_auto_tasks SET binding_status = 'role_ready' WHERE id = $1", [ + taskId, + ]) + await expectErrorCode( + () => confirmPublicBinding(orderNo, taskId), + 'semi_auto_profile_required', + ) + await query("UPDATE semi_auto_tasks SET binding_status = 'not_started' WHERE id = $1", [ + taskId, + ]) + + const savedProfile = await savePublicTaskProfile(orderNo, taskId, { + roleName: '集成测试角色', + roleId: '1192083858', + serverZone: '安卓V区', + }) + assert.equal(savedProfile.task.customerGameRoleName, '集成测试角色') + assert.equal(savedProfile.task.customerGameRoleId, '1192083858') + assert.equal(savedProfile.task.customerServerZone, '安卓V区') + const profileReadyList = await listAdminSemiAutoTasks({ keyword: orderNo }) + assert.equal(profileReadyList.items[0]?.displayStatus.label, '等待客户绑定角色') const exported = await exportAdminSemiAutoCredential(taskId) assert.equal(exported.credentialId, credentialId) assert.equal(exported.platform, 'huya') + // 换绑失败后客户点「上一步修改资料」:清空绑定/换绑状态,保留登录与已填资料。 + await query( + ` + UPDATE semi_auto_tasks + SET binding_status = 'role_ready', + bind_game_role = '平台原角色', + bind_game_role_id = '99887766', + bind_game_channel = '微信', + binding_started_at = NOW(), + bound_at = NOW(), + last_error = '虎牙未接受本次换绑', + updated_at = NOW() + WHERE id = $1 + `, + [taskId], + ) + const reset = await resetPublicBinding(orderNo, taskId) + assert.equal(reset.task.bindingStatus, 'not_started') + assert.equal(reset.binding, null) + assert.equal(reset.task.customerGameRoleName, '集成测试角色') + assert.equal(reset.task.customerGameRoleId, '1192083858') + assert.equal(reset.task.customerServerZone, '安卓V区') + const resetRow = await query<{ + binding_status: string + bind_game_role: string + bind_game_role_id: string + bind_game_channel: string + binding_started_at: string | null + bound_at: string | null + login_status: string + credential_id: number | null + connector_session_id: string + customer_game_role_name: string + customer_game_role_id: string + customer_game_server_zone: string + last_error: string + execution_status: string + }>( + ` + SELECT binding_status, bind_game_role, bind_game_role_id, bind_game_channel, + binding_started_at, bound_at, login_status, credential_id, + connector_session_id, customer_game_role_name, customer_game_role_id, + customer_game_server_zone, last_error, execution_status + FROM semi_auto_tasks + WHERE id = $1 + `, + [taskId], + ) + const resetState = resetRow.rows[0] + assert.equal(resetState?.binding_status, 'not_started') + assert.equal(resetState?.bind_game_role, '') + assert.equal(resetState?.bind_game_role_id, '') + assert.equal(resetState?.bind_game_channel, '') + assert.equal(resetState?.binding_started_at, null) + assert.equal(resetState?.bound_at, null) + assert.equal(resetState?.last_error, '') + assert.equal(resetState?.execution_status, 'waiting_customer') + assert.equal(resetState?.login_status, 'authenticated') + assert.equal(Number(resetState?.credential_id), credentialId) + assert.equal(resetState?.connector_session_id, `it-huya-session-${suffix}`) + assert.equal(resetState?.customer_game_role_name, '集成测试角色') + assert.equal(resetState?.customer_game_role_id, '1192083858') + assert.equal(resetState?.customer_game_server_zone, '安卓V区') + const resetEvents = await query<{ detail_json: { reason?: string } | null }>( + ` + SELECT detail_json + FROM semi_auto_task_events + WHERE task_id = $1 AND event_type = 'binding_reset' + ORDER BY id DESC + LIMIT 1 + `, + [taskId], + ) + assert.equal(resetEvents.rows[0]?.detail_json?.reason, 'customer_profile_edit') + const reauthorized = await requestAdminSemiAutoCustomerReauth(taskId, { userId: 1, role: 'support', @@ -599,7 +721,7 @@ test( ) test( - '客户手动触发虎牙短信登录后保存 CK 并进入等待客服', + '客户手动触发虎牙短信登录后保存 CK 并进入填写资料步骤', { skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false }, async () => { process.env.DATABASE_URL = TEST_DATABASE_URL @@ -607,8 +729,12 @@ test( const { closeDb, query } = await import('../../db/client.js') const { createSemiAutoMock } = await import('../dev-mock/dev-mock-service.js') const { resetMockSessions } = await import('../dev-mock/mock-semi-auto-connector.js') - const { listPublicSemiAutoTasks, loginPublicHuyaSms, sendPublicHuyaSmsCode } = - await import('./semi-auto-task-service.js') + const { + listPublicSemiAutoTasks, + loginPublicHuyaSms, + savePublicTaskProfile, + sendPublicHuyaSmsCode, + } = await import('./semi-auto-task-service.js') const suffix = `${Date.now()}_${Math.floor(Math.random() * 1_000_000)}` const orderNo = `IT-HUYA-SMS-${suffix}` let orderId = 0 @@ -645,11 +771,21 @@ test( }) const tasks = await listPublicSemiAutoTasks(orderNo) assert.equal(tasks[0]?.loginStatus, 'authenticated') - assert.equal(tasks[0]?.executionStatus, 'waiting_operator') + // 虎牙登录成功后仍需客户填写资料,不能直接进入等待客服。 + assert.equal(tasks[0]?.executionStatus, 'waiting_customer') + assert.equal(tasks[0]?.displayStatus.label, '待客户填写资料') assert.equal(tasks[0]?.credentialSource, 'sms') assert.ok(tasks[0]?.huyaUid) assert.equal(tasks[0]?.platformNickname, 'Mock虎牙用户') + const saved = await savePublicTaskProfile(orderNo, result.taskId, { + roleName: 'Mock虎牙角色', + roleId: '1192083858', + serverZone: '安卓V区', + }) + assert.equal(saved.task.executionStatus, 'waiting_customer') + assert.equal(saved.task.displayStatus.label, '等待客户绑定角色') + const stored = await query<{ id: number credential_source: string diff --git a/apps/backend/src/test-support/consignment-integration-cleanup.ts b/apps/backend/src/test-support/consignment-integration-cleanup.ts new file mode 100644 index 00000000..71c1ade2 --- /dev/null +++ b/apps/backend/src/test-support/consignment-integration-cleanup.ts @@ -0,0 +1,80 @@ +/** + * 寄卖相关集成测试的收尾清理。 + * + * 集成测试会造打手、分类、寄卖配置、提报、库存、工单、钱包流水。以前跑完不带清理, + * 数据会永久留在目标库里(2026-11-10 就是这样在共享联调库留下了 CTIMEOUT 假单)。 + * + * 清理口径:所有识别字段都必须包含本次运行的 `suffix`。suffix 由测试自己生成 + * (`Date.now().toString(36)` + 随机数),真实业务数据不会命中;配合 + * `integration-db-guard` 的隔离库限制,误删风险极低。 + */ +import { query } from '../db/client.js' + +/** + * 删除本次集成测试造出的全部数据。 + * + * 必须在测试的 `finally` 里调用,删除顺序遵循外键依赖(子表 -> 主表)。 + */ +export async function cleanupIntegrationRun(suffix: string) { + const token = String(suffix || '').trim() + if (!token) throw new Error('cleanupIntegrationRun 需要 suffix') + const like = `%${token}%` + const params = [like] + + const workOrderScope = `SELECT id FROM work_orders WHERE work_order_no LIKE $1` + const inventoryScope = `SELECT id FROM consignment_inventories WHERE inventory_no LIKE $1` + const submissionScope = `SELECT id FROM consignment_submissions WHERE submission_no LIKE $1` + const workerScope = `SELECT id FROM worker_users WHERE username LIKE $1` + const categoryScope = `SELECT id FROM work_categories WHERE category_key LIKE $1` + const profileScope = `SELECT id FROM consignment_profiles + WHERE category_id IN (${categoryScope}) OR name LIKE $1` + + // 子记录:工单 / 库存维度 + await query(`DELETE FROM work_order_events WHERE work_order_id IN (${workOrderScope})`, params) + await query(`DELETE FROM work_order_shares WHERE work_order_id IN (${workOrderScope})`, params) + await query( + `DELETE FROM consignment_inventory_allocations + WHERE work_order_id IN (${workOrderScope}) OR inventory_id IN (${inventoryScope})`, + params, + ) + await query( + `DELETE FROM consignment_sms_logs + WHERE work_order_id IN (${workOrderScope}) OR inventory_id IN (${inventoryScope})`, + params, + ) + await query( + `DELETE FROM consignment_match_logs + WHERE work_order_no LIKE $1 OR payload_json::text LIKE $1`, + params, + ) + + // 钱包流水与打手会话 + await query(`DELETE FROM worker_wallet_ledgers WHERE worker_id IN (${workerScope})`, params) + await query(`DELETE FROM worker_sessions WHERE worker_id IN (${workerScope})`, params) + + // 主实体:先断开 库存 <-> 提报 的双向引用 + await query( + `UPDATE consignment_inventories SET source_submission_id = NULL WHERE inventory_no LIKE $1`, + params, + ) + await query( + `UPDATE consignment_submissions SET result_inventory_id = NULL WHERE submission_no LIKE $1`, + params, + ) + await query(`DELETE FROM work_orders WHERE work_order_no LIKE $1`, params) + await query(`DELETE FROM consignment_inventories WHERE inventory_no LIKE $1`, params) + await query(`DELETE FROM consignment_submissions WHERE submission_no LIKE $1`, params) + + // 配置、钱包、打手、分类 + await query( + `DELETE FROM consignment_profile_versions WHERE profile_id IN (${profileScope})`, + params, + ) + await query(`DELETE FROM consignment_profiles WHERE id IN (${profileScope})`, params) + await query(`DELETE FROM worker_wallets WHERE worker_id IN (${workerScope})`, params) + await query(`DELETE FROM worker_users WHERE username LIKE $1`, params) + await query(`DELETE FROM work_product_rules WHERE rule_key LIKE $1`, params) + await query(`DELETE FROM consignment_contact_supporters WHERE name LIKE $1`, params) + await query(`DELETE FROM admin_users WHERE username LIKE $1`, params) + await query(`DELETE FROM work_categories WHERE category_key LIKE $1`, params) +} diff --git a/apps/backend/src/test-support/integration-db-guard.test.ts b/apps/backend/src/test-support/integration-db-guard.test.ts new file mode 100644 index 00000000..abccf34b --- /dev/null +++ b/apps/backend/src/test-support/integration-db-guard.test.ts @@ -0,0 +1,84 @@ +import assert from 'node:assert/strict' +import test from 'node:test' + +import { + isIsolatedIntegrationDatabaseName, + resolveIntegrationDatabaseOrThrow, + resolveIsolatedIntegrationDatabaseUrl, +} from './integration-db-guard.js' + +test('隔离库命名:_ctest / _itest / _test 段才放行', () => { + assert.equal(isIsolatedIntegrationDatabaseName('order_site_ctest'), true) + assert.equal(isIsolatedIntegrationDatabaseName('order_site_ctest_fresh'), true) + assert.equal(isIsolatedIntegrationDatabaseName('order_site_itest'), true) + assert.equal(isIsolatedIntegrationDatabaseName('order_site_test'), true) + assert.equal(isIsolatedIntegrationDatabaseName('ctest'), true) +}) + +test('共享库与系统库一律拒绝(防止再污染联调/生产)', () => { + assert.equal(isIsolatedIntegrationDatabaseName('order_site'), false) + assert.equal(isIsolatedIntegrationDatabaseName('postgres'), false) + assert.equal(isIsolatedIntegrationDatabaseName('template1'), false) + assert.equal(isIsolatedIntegrationDatabaseName(''), false) +}) + +test('库存名只是包含 test 字样但没有独立段时不放行', () => { + assert.equal(isIsolatedIntegrationDatabaseName('order_site_contest'), false) + assert.equal(isIsolatedIntegrationDatabaseName('latest_orders'), false) +}) + +test('未设置环境变量时返回 null,调用方据此跳过测试', () => { + delete process.env.ORDER_SITE_GUARD_TEST_URL + assert.equal(resolveIntegrationDatabaseOrThrow('ORDER_SITE_GUARD_TEST_URL'), null) +}) + +test('两个连接串不一致时直接抛错', () => { + process.env.ORDER_SITE_GUARD_TEST_URL = 'postgres://u:p@127.0.0.1:5432/order_site_ctest' + process.env.DATABASE_URL = 'postgres://u:p@127.0.0.1:5432/order_site' + assert.throws( + () => resolveIntegrationDatabaseOrThrow('ORDER_SITE_GUARD_TEST_URL'), + /必须与 DATABASE_URL 完全一致/, + ) + delete process.env.ORDER_SITE_GUARD_TEST_URL + delete process.env.DATABASE_URL +}) + +test('指向共享库时即使两个变量一致也要拒绝', () => { + process.env.ORDER_SITE_GUARD_TEST_URL = 'postgres://u:p@192.168.10.9:5432/order_site' + process.env.DATABASE_URL = 'postgres://u:p@192.168.10.9:5432/order_site' + assert.throws( + () => resolveIntegrationDatabaseOrThrow('ORDER_SITE_GUARD_TEST_URL'), + /拒绝在非隔离库/, + ) + delete process.env.ORDER_SITE_GUARD_TEST_URL + delete process.env.DATABASE_URL +}) + +test('指向隔离库且两值一致时返回库名', () => { + process.env.ORDER_SITE_GUARD_TEST_URL = 'postgres://u:p@127.0.0.1:5432/order_site_ctest' + process.env.DATABASE_URL = 'postgres://u:p@127.0.0.1:5432/order_site_ctest' + assert.deepEqual(resolveIntegrationDatabaseOrThrow('ORDER_SITE_GUARD_TEST_URL'), { + databaseUrl: 'postgres://u:p@127.0.0.1:5432/order_site_ctest', + databaseName: 'order_site_ctest', + }) + delete process.env.ORDER_SITE_GUARD_TEST_URL + delete process.env.DATABASE_URL +}) + +test('只校验库名的版本:未设置返回空串,共享库抛错,隔离库原样返回', () => { + delete process.env.ORDER_SITE_GUARD_TEST_URL + assert.equal(resolveIsolatedIntegrationDatabaseUrl('ORDER_SITE_GUARD_TEST_URL'), '') + + process.env.ORDER_SITE_GUARD_TEST_URL = 'postgres://u:p@192.168.10.9:5432/order_site' + assert.throws( + () => resolveIsolatedIntegrationDatabaseUrl('ORDER_SITE_GUARD_TEST_URL'), + /拒绝在非隔离库/, + ) + + process.env.ORDER_SITE_GUARD_TEST_URL = 'postgres://u:p@127.0.0.1:5432/order_site_ctest' + assert.equal( + resolveIsolatedIntegrationDatabaseUrl('ORDER_SITE_GUARD_TEST_URL'), + 'postgres://u:p@127.0.0.1:5432/order_site_ctest', + ) + delete process.env.ORDER_SITE_GUARD_TEST_URL +}) diff --git a/apps/backend/src/test-support/integration-db-guard.ts b/apps/backend/src/test-support/integration-db-guard.ts new file mode 100644 index 00000000..2589c68f --- /dev/null +++ b/apps/backend/src/test-support/integration-db-guard.ts @@ -0,0 +1,100 @@ +/** + * 集成测试数据库守卫。 + * + * 背景:2026-11-10 寄卖超时集成测试误跑在共享联调库 `order_site` 上,留下 7 条 + * `CTIMEOUT-WO-*` 假工单和 8 个假打手,后台把它们当成真实订单展示。 + * + * 原来的守卫只校验 `DATABASE_URL === CONSIGNMENT_MATCHING_TEST_DATABASE_URL`, + * 两边都被指到联调库时形同虚设。这里加两道硬约束: + * 1. 目标库名必须带隔离测试标记(`_ctest` / `_itest` / `_test`); + * 2. 显式拒绝 `order_site`、`postgres` 这类共享库。 + */ + +/** 明确禁止运行集成测试的库名(生产/联调/系统库)。 */ +const FORBIDDEN_DATABASE_NAMES = new Set([ + 'order_site', + 'order_site_ctest_prod', + 'postgres', + 'template0', + 'template1', +]) + +/** 允许的隔离库命名:包含 _ctest / _itest / _test 段(可带 _fresh 等后缀)。 */ +const ISOLATED_DATABASE_PATTERN = /(^|_)(ctest|itest|test)($|_)/i + +export type IntegrationDatabaseCheck = { + databaseUrl: string + databaseName: string +} + +function readDatabaseName(databaseUrl: string): string { + try { + return decodeURIComponent(new URL(databaseUrl).pathname.replace(/^\/+/, '')).trim() + } catch { + return '' + } +} + +/** 判断库名是否为隔离测试库;导出便于单测覆盖命名规则。 */ +export function isIsolatedIntegrationDatabaseName(name: string): boolean { + const normalized = String(name || '').trim() + if (!normalized) return false + if (FORBIDDEN_DATABASE_NAMES.has(normalized.toLowerCase())) return false + return ISOLATED_DATABASE_PATTERN.test(normalized) +} + +/** + * 校验并返回集成测试库地址。 + * + * - 未设置 `envName` 对应变量时返回 null(调用方据此 skip); + * - 设置后要求与 `DATABASE_URL` 完全一致,且库名必须是隔离测试库,否则直接抛错中断测试。 + */ +export function resolveIntegrationDatabaseOrThrow( + envName: string, +): IntegrationDatabaseCheck | null { + const databaseUrl = String(process.env[envName] || '').trim() + if (!databaseUrl) return null + + const runtimeUrl = String(process.env.DATABASE_URL || '').trim() + if (runtimeUrl !== databaseUrl) { + throw new Error( + `${envName} 必须与 DATABASE_URL 完全一致,避免测试绕过连接配置连到别的库:\n` + + ` ${envName}=${databaseUrl}\n DATABASE_URL=${runtimeUrl || '(未设置)'}`, + ) + } + + const databaseName = readDatabaseName(databaseUrl) + if (!isIsolatedIntegrationDatabaseName(databaseName)) { + throw new Error( + `拒绝在非隔离库 "${databaseName || databaseUrl}" 上运行集成测试。\n` + + '请使用专门的测试库(库名需包含 _ctest / _itest / _test,例如 order_site_ctest),' + + '否则测试会往共享环境写假工单、假打手。', + ) + } + + return { databaseUrl, databaseName } +} + +/** + * 只校验库名、不要求和 `DATABASE_URL` 一致的版本。 + * + * 给「测试自己把 `process.env.DATABASE_URL` 改写成测试库」的那批集成测试用: + * 它们在模块顶层读不到最终连接串,但仍必须保证目标库是隔离库。 + * + * 未设置环境变量时返回空串(调用方据此 skip);库名不合法时直接抛错。 + */ +export function resolveIsolatedIntegrationDatabaseUrl(envName: string): string { + const databaseUrl = String(process.env[envName] || '').trim() + if (!databaseUrl) return '' + + const databaseName = readDatabaseName(databaseUrl) + if (!isIsolatedIntegrationDatabaseName(databaseName)) { + throw new Error( + `拒绝在非隔离库 "${databaseName || databaseUrl}" 上运行集成测试(${envName})。\n` + + '请使用专门的测试库(库名需包含 _ctest / _itest / _test,例如 order_site_ctest),' + + '否则测试中途失败时会把假工单、假打手留在共享环境。', + ) + } + + return databaseUrl +} diff --git a/apps/frontend/index.html b/apps/frontend/index.html index 94870c37..12817a76 100644 --- a/apps/frontend/index.html +++ b/apps/frontend/index.html @@ -2,7 +2,7 @@ - + { + document.documentElement.classList.add('customer-mobile-html') + document.body.classList.add('customer-mobile-body') + return () => { + document.documentElement.classList.remove('customer-mobile-html') + document.body.classList.remove('customer-mobile-body') + } + }, []) // 非标准子路径也按首段路径绑定平台,避免 /c/.../extra 这类地址绕过严格绑定。 const prefix = window.location.pathname.split('/').filter(Boolean)[0] const wildcardPlatform = prefix === 'c' ? 'huya' : prefix === 'd' ? 'weibo' : undefined diff --git a/apps/frontend/src/pages/admin/AdminSemiAutoTasksPage.tsx b/apps/frontend/src/pages/admin/AdminSemiAutoTasksPage.tsx index 42bbdc42..72be1359 100644 --- a/apps/frontend/src/pages/admin/AdminSemiAutoTasksPage.tsx +++ b/apps/frontend/src/pages/admin/AdminSemiAutoTasksPage.tsx @@ -53,6 +53,7 @@ import { resolvePostInjectionUrl } from '@/utils/semi-auto-injection' const { Text } = Typography const STATUS_COLORS: Record = { + waiting_profile: 'gold', waiting_customer: 'blue', waiting_login: 'blue', login_scanned: 'cyan', @@ -773,19 +774,49 @@ export default function AdminSemiAutoTasksPage() { ? '微博登录即授权' : BINDING_STATUS_LABELS[detail.task.bindingStatus] || detail.task.bindingStatus} - - {detail.task.bindGameRole - ? `${detail.task.bindGameRole}${detail.task.bindGameRoleId ? `(${detail.task.bindGameRoleId})` : '(无角色ID)'}` - : '-'} + + {detail.task.bindGameRole || '-'} + + + {detail.task.bindGameRoleId || detail.task.huyaUid || '-'} + + + {[ + detail.task.bindGameChannel, + detail.comparison?.boundZone ? `识别区服 ${detail.comparison.boundZone}` : '', + ] + .filter(Boolean) + .join(' · ') || '-'} - {detail.task.customerGameRoleName - ? `${detail.task.customerGameRoleName}${detail.task.customerGameRoleId ? `(${detail.task.customerGameRoleId})` : ''}` - : '-'} + {detail.task.customerGameRoleName || '-'} - + + {detail.task.customerGameRoleId || '-'} + + {detail.task.customerServerZone || '-'} + + + + {detail.comparison?.verdict === 'match' + ? '三项一致,可提交平台绑定' + : detail.comparison?.verdict === 'mismatch' + ? '资料与平台角色不一致' + : '信息不完整,需人工核实'} + + {detail.comparison?.message || '-'} + + {detail.task.assignedAdminName || '未领取'} diff --git a/apps/frontend/src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx b/apps/frontend/src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx index 04ea4d4f..262a3eac 100644 --- a/apps/frontend/src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx +++ b/apps/frontend/src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx @@ -19,6 +19,7 @@ import { pollCustomerBinding, pollCustomerLogin, pollCustomerWeiboQrLogin, + resetCustomerBinding, saveCustomerTaskProfile, sendCustomerHuyaSmsCode, sendCustomerWeiboSmsCode, @@ -56,7 +57,7 @@ export default function CustomerFulfillmentPage({ }: { expectedPlatform?: CustomerFulfillmentPlatform }) { - const { message, modal } = App.useApp() + const { message } = App.useApp() const { orderNo: routeOrderNo } = useParams<{ orderNo?: string }>() const navigate = useNavigate() const { search, hash } = useLocation() @@ -86,8 +87,8 @@ export default function CustomerFulfillmentPage({ const [profileServerZone, setProfileServerZone] = useState('') const [profileSaving, setProfileSaving] = useState(false) const [profileEditing, setProfileEditing] = useState(false) - const [rebindFailureDismissed, setRebindFailureDismissed] = useState(false) const startingBindingRef = useRef(false) + const resettingBindingRef = useRef(false) const hydratingBindingRef = useRef(false) const autoOpenedRoleRef = useRef('') const redirectingRef = useRef(false) @@ -100,6 +101,13 @@ export default function CustomerFulfillmentPage({ [selectedTaskId, tasks], ) const isWeibo = selectedTask?.platform === 'weibo' + // 虎牙流程:登录 → 填写资料(区服/游戏编号/角色名)→ 绑定角色。 + // 三项资料齐全前不生成绑定二维码,避免客户在资料缺失时先绑错角色。 + const profileComplete = Boolean( + String(selectedTask?.customerServerZone || '').trim() && + String(selectedTask?.customerGameRoleId || '').trim() && + String(selectedTask?.customerGameRoleName || '').trim(), + ) const load = useCallback( async (silent = false) => { @@ -171,7 +179,6 @@ export default function CustomerFulfillmentPage({ autoOpenedRoleRef.current = '' setBindingSessionExpired(false) setBindingLoadError('') - setRebindFailureDismissed(false) }, [selectedTask?.id]) useEffect(() => { @@ -263,10 +270,12 @@ export default function CustomerFulfillmentPage({ return () => window.clearInterval(timer) }, [orderNo, selectedTask?.id, selectedTask?.loginStatus, selectedTask?.platform]) - // 登录成功后自动进入绑定阶段;失败或过期时由客户点按钮重试,避免页面来回跳。 + // 登录并填写完整资料后才自动进入绑定阶段;资料不全或客户正在返回修改资料时停留在资料步骤。 + // 失败或过期时由客户点按钮重试,避免页面来回跳。 useEffect(() => { if (!selectedTask || !orderNo || selectedTask.platform !== 'huya') return if (selectedTask.loginStatus !== 'authenticated') return + if (!profileComplete || profileEditing) return if (selectedTask.bindingStatus === 'confirmed') return if (selectedTask.bindingStatus !== 'not_started' || startingBindingRef.current) return startingBindingRef.current = true @@ -293,6 +302,8 @@ export default function CustomerFulfillmentPage({ }, [ message, orderNo, + profileComplete, + profileEditing, selectedTask?.bindingStatus, selectedTask?.id, selectedTask?.loginStatus, @@ -374,7 +385,9 @@ export default function CustomerFulfillmentPage({ if (!bindingInfo?.comparison) return // 换绑后仍是原角色时只展示失败原因,不能自动弹出确认框。 if (bindingInfo.rebindUnchanged) return - // 识别到角色(含与资料不一致)都要弹出对比框,由客户选择修改资料或同步平台角色。 + // 只有三项完全一致才自动弹出核对框,让客户直接提交平台绑定; + // 不一致时不弹框,由下方「重新扫码换绑 / 上一步修改资料」两个按钮处理。 + if (bindingInfo.comparison.verdict !== 'match') return const key = `${selectedTask.id}:${bindingInfo.bindGameRoleId || ''}` if (autoOpenedRoleRef.current === key) return autoOpenedRoleRef.current = key @@ -509,7 +522,7 @@ export default function CustomerFulfillmentPage({ ) setLoginInfo(response.data.login) setHuyaChallenge(null) - message.success(isWeibo ? '微博登录成功,等待客服处理' : '登录成功,请继续绑定游戏角色') + message.success(isWeibo ? '微博登录成功,等待客服处理' : '登录成功,请填写游戏角色资料') } catch (error) { const errorCode = (error as { errorCode?: string } | null)?.errorCode || '' if (errorCode === 'weibo_sms_mfa_required') { @@ -597,13 +610,21 @@ export default function CustomerFulfillmentPage({ } return } - // 资料不一致同样打开对比框,客户可在弹窗内修改资料或同步平台角色。 - setBindingConfirmOpen(true) + // 只有三项完全一致才打开核对框;不一致由页面按钮引导换绑或修改资料。 + if (nextBinding?.comparison?.verdict === 'match') { + setBindingConfirmOpen(true) + } else { + setBindingConfirmOpen(false) + message.warning( + nextBinding?.comparison?.message || + '平台角色与已填资料不一致,请重新扫码换绑或修改资料', + ) + } return } if (nextTask.bindingStatus === 'confirmed') { setBindingConfirmOpen(false) - message.success('绑定已确认,等待客服处理') + message.success('已提交平台绑定,等待客服处理') return } // 弹窗内点「刷新」:角色不再是待确认状态时收起弹窗,避免展示过期比对。 @@ -661,7 +682,7 @@ export default function CustomerFulfillmentPage({ return } if (nextTask.bindingStatus === 'role_ready') { - message.success('换绑已生效,请核对角色后确认绑定') + message.success('换绑已生效,请核对角色后提交平台绑定') return } message.info('已向虎牙提交换绑,正在等待角色生效') @@ -680,55 +701,17 @@ export default function CustomerFulfillmentPage({ } } - async function handleSyncBindingProfile() { - if (!selectedTask) return - const comparison = bindingInfo?.comparison - if (!comparison) return - const roleName = comparison.boundRoleName - const roleId = comparison.boundRoleId - const serverZone = comparison.boundZone - if (!roleName || !roleId || !/^\d+$/.test(roleId) || !serverZone) { - message.warning('平台角色信息不完整,请点「修改资料」手动填写') - return - } - setProfileSaving(true) - try { - const response = await saveCustomerTaskProfile(orderNo, selectedTask.id, { - roleName, - roleId, - serverZone, - }) - setTasks((current) => - current.map((task) => (task.id === response.data.task.id ? response.data.task : task)), - ) - const bindingResponse = await pollCustomerBinding(orderNo, selectedTask.id) - if (bindingResponse.data.binding) setBindingInfo(bindingResponse.data.binding) - reopenBindingConfirm(bindingResponse.data.task, bindingResponse.data.binding) - message.success('资料已按平台角色同步,请核对后确认绑定') - } catch (error) { - message.error(error instanceof Error ? error.message : '同步角色资料失败') - } finally { - setProfileSaving(false) - } - } - - async function handleConfirmBinding(acceptExistingRole = false) { + async function handleConfirmBinding() { if (!selectedTask) return setBindingLoading(true) try { - const response = await confirmCustomerBinding( - orderNo, - selectedTask.id, - acceptExistingRole ? { acceptExistingRole: true } : {}, - ) + const response = await confirmCustomerBinding(orderNo, selectedTask.id) setTasks((current) => current.map((task) => (task.id === response.data.task.id ? response.data.task : task)), ) setBindingInfo(response.data.binding) setBindingConfirmOpen(false) - message.success( - acceptExistingRole ? '已按原绑定角色确认,等待客服处理' : '绑定已确认,等待客服处理', - ) + message.success('已提交平台绑定,等待客服处理') } catch (error) { if (isHuyaSessionExpired(error)) { setBindingSessionExpired(true) @@ -736,48 +719,62 @@ export default function CustomerFulfillmentPage({ message.warning('虎牙登录会话已过期,请重新登录') return } - message.error(error instanceof Error ? error.message : '确认绑定失败') + message.error(error instanceof Error ? error.message : '提交平台绑定失败') } finally { setBindingLoading(false) } } - /** 换绑被虎牙拒绝时的二次确认:客户可以选择继续使用原绑定角色。 */ - function handleAcceptExistingRole() { - if (!selectedTask || bindingLoading) return - const reason = String(bindingInfo?.rebindConfirmMessage || '').trim() - modal.confirm({ - title: '确认使用原角色?', - content: `本次换绑未成功${reason ? `(${reason})` : ''},平台仍返回原绑定角色「${ - bindingRoleName || '当前角色' - }」。确认后本次换绑作废,直接使用该角色继续履约。`, - okText: '确认使用原角色', - cancelText: '先不确认', - onOk: () => handleConfirmBinding(true), - }) - } - - /** 资料变更后重新打开对比弹窗,让客户基于最新两侧信息再次核对。 */ + /** 资料变更后重新打开核对弹窗:只有三项完全一致才让客户直接提交平台绑定。 */ function reopenBindingConfirm( nextTask: CustomerSemiAutoTask, nextBinding: CustomerBindingInfo | null | undefined, ) { if (nextTask.bindingStatus !== 'role_ready') return false if (!nextBinding?.comparison || nextBinding.rebindUnchanged) return false + if (nextBinding.comparison.verdict !== 'match') return false autoOpenedRoleRef.current = `${nextTask.id}:${nextBinding.bindGameRoleId || ''}` setBindingConfirmOpen(true) return true } - /** 从对比弹窗回到资料表单,保存成功后会自动重新打开对比。 */ - function openProfileEditor() { + /** + * 返回第二步修改资料: + * 立即切回资料表单(步骤条高亮第 2 步、隐藏绑定/换绑结果),同时调后端清空虎牙 + * 绑定与换绑失败状态;登录状态和已填资料保留,客户提交资料后重新走绑定流程。 + */ + async function openProfileEditor() { + if (!selectedTask) return + if (resettingBindingRef.current) return setBindingConfirmOpen(false) setProfileEditing(true) + // 资料步骤会隐藏绑定二维码与比对区,等 React 完成切换后再回到第二步顶部。 window.setTimeout(() => { document - .getElementById('customer-profile-form') - ?.scrollIntoView({ behavior: 'smooth', block: 'center' }) - }, 0) + .getElementById('customer-binding-stage') + ?.scrollIntoView({ behavior: 'smooth', block: 'start' }) + }, 60) + if (selectedTask.platform !== 'huya' || selectedTask.bindingStatus === 'not_started') return + resettingBindingRef.current = true + try { + const response = await resetCustomerBinding(orderNo, selectedTask.id) + setTasks((current) => + current.map((task) => (task.id === response.data.task.id ? response.data.task : task)), + ) + // 换绑失败原因(rebindUnchanged / rebindConfirmState 等)随绑定详情一并清掉。 + setBindingInfo(response.data.binding) + setBindingLoadError('') + message.success('已返回上一步,请修改资料后重新提交') + } catch (error) { + if (isHuyaSessionExpired(error)) { + setBindingSessionExpired(true) + } else { + // 重置失败不阻断客户改资料,保存后会重新识别平台角色。 + message.error(error instanceof Error ? error.message : '重置绑定状态失败,请稍后重试') + } + } finally { + resettingBindingRef.current = false + } } async function handleSaveProfile() { @@ -790,6 +787,10 @@ export default function CustomerFulfillmentPage({ message.warning('请选择区服') return } + if (!/^\d+$/.test(profileRoleId.trim())) { + message.warning('游戏编号只能是数字') + return + } setProfileSaving(true) try { const response = await saveCustomerTaskProfile(orderNo, selectedTask.id, { @@ -809,7 +810,7 @@ export default function CustomerFulfillmentPage({ } catch { // 绑定尚未开始时没有 binding,可忽略。 } - message.success(reopened ? '角色资料已保存,请重新核对绑定角色' : '角色资料已保存') + message.success(reopened ? '资料已保存且与平台角色一致,请提交平台绑定' : '资料已保存') } catch (error) { message.error(error instanceof Error ? error.message : '保存角色资料失败') } finally { @@ -846,7 +847,6 @@ export default function CustomerFulfillmentPage({ } } - const config = selectedTask?.semiAutoConfig || {} const displayTitle = isWeibo ? '微博账号登录授权' : '绑定游戏角色' const loginQrVisible = Boolean(selectedTask) && ['qr_pending', 'scanned'].includes(selectedTask.loginStatus) @@ -857,9 +857,9 @@ export default function CustomerFulfillmentPage({ selectedTask.executionStatus !== 'completed' && selectedTask.executionStatus !== 'cancelled', ) - const bindingQrVisible = ['not_started', 'qr_pending', 'scanned'].includes( - selectedTask?.bindingStatus || '', - ) + const bindingQrVisible = + profileComplete && + ['not_started', 'qr_pending', 'scanned'].includes(selectedTask?.bindingStatus || '') const bindingComparison = bindingInfo?.comparison || null const bindingRoleId = bindingInfo?.bindGameRoleId || selectedTask?.bindGameRoleId || '' // 虎牙 gameRole.roleId 是加密串,客户侧统一展示数值 UID(huyaUid)。 @@ -871,8 +871,9 @@ export default function CustomerFulfillmentPage({ })() const bindingRoleName = bindingInfo?.bindGameRole || selectedTask?.bindGameRole || '' const rebindUnchanged = bindingInfo?.rebindUnchanged === true - // 换绑失败视图可返回「已识别角色 + 资料不一致」的核对界面;后端 rebindUnchanged 保持不变。 - const showRebindFailure = rebindUnchanged && !rebindFailureDismissed + // 换绑被虎牙拒绝或未生效时展示失败原因;若客户已把资料改成与平台当前角色一致, + // 比对为 match,则回到正常提交流程,不再显示换绑失败。 + const showRebindFailure = rebindUnchanged && bindingComparison?.verdict !== 'match' const rebindConfirmState = bindingInfo?.rebindConfirmState || 'idle' const rebindRejected = rebindConfirmState === 'rejected' const rebindAccepted = rebindConfirmState === 'accepted' @@ -886,12 +887,18 @@ export default function CustomerFulfillmentPage({ (bindingInfo?.requiresSupport ?? (Boolean(bindingInfo?.bindGameRole || bindingRoleName) && !bindingRoleIdNumeric)) // 绑定阶段顶部状态条:按 bindingStatus 显式映射,已确认/已过期/失败不再显示(各自有卡片)。 + const comparisonMismatch = + selectedTask?.bindingStatus === 'role_ready' && bindingComparison?.verdict === 'mismatch' + const comparisonUnknown = + selectedTask?.bindingStatus === 'role_ready' && bindingComparison?.verdict === 'unknown' + // 平台没给出可核对角色或比对缺项时,都只能转客服人工核实。 + const bindingNeedsSupport = bindingRequiresSupport || comparisonUnknown const bindingBanner = (() => { if (bindingSessionExpired) return null - if (bindingRequiresSupport && selectedTask?.bindingStatus !== 'confirmed') { + if (bindingNeedsSupport && selectedTask?.bindingStatus !== 'confirmed') { return { tone: 'is-warning', - text: '已登录,但平台未返回可核对的角色ID,请联系客服人工核实', + text: '已登录,但两侧角色信息不完整,无法自动核对,请联系客服人工核实', } } if (showRebindFailure) { @@ -900,8 +907,12 @@ export default function CustomerFulfillmentPage({ text: rebindRejected ? '虎牙未接受本次换绑,请查看下方原因' : '换绑未生效,请查看下方原因', } } + if (comparisonMismatch) { + return { tone: 'is-warning', text: '平台角色与已填资料不一致,请重新扫码换绑或修改资料' } + } if (selectedTask?.bindingStatus === 'role_ready') { - return { tone: 'is-info', text: '已识别绑定角色,请核对后确认' } + if (!bindingComparison) return { tone: 'is-info', text: '正在核对平台角色,请稍候' } + return { tone: 'is-info', text: '平台角色与已填资料一致,请提交平台绑定' } } if ( selectedTask?.bindingStatus === 'confirmed' || @@ -921,27 +932,8 @@ export default function CustomerFulfillmentPage({ const nextRebindText = bindingInfo?.nextRebindAt ? formatAdminDateTime(bindingInfo.nextRebindAt) : '' - const comparisonMismatch = - selectedTask?.bindingStatus === 'role_ready' && bindingComparison?.verdict === 'mismatch' - const showProfileForm = showBindingStage && profileEditing - const bindingCustomerReady = Boolean( - bindingComparison?.customerRoleId || bindingComparison?.customerRoleName, - ) - // 平台角色名、数字角色 ID、区服齐全时,才支持一键同步为平台角色。 - const canSyncBindingProfile = Boolean( - bindingComparison?.boundRoleName && - /^\d+$/.test(String(bindingComparison?.boundRoleId || '').trim()) && - bindingComparison?.boundZone, - ) - const needsProfileCollection = Boolean( - selectedTask && - selectedTask.platform === 'huya' && - selectedTask.executionStatus !== 'completed' && - selectedTask.bindingStatus !== 'confirmed' && - (!selectedTask.customerServerZone || - !selectedTask.customerGameRoleId || - !selectedTask.customerGameRoleName), - ) + // 登录后资料不全时自动展开资料表单;资料齐全后才展示绑定二维码。 + const showProfileForm = showBindingStage && (profileEditing || !profileComplete) const renderLoginForm = (options: { platformLabel: string @@ -1060,17 +1052,6 @@ export default function CustomerFulfillmentPage({ ) } - if (needsProfileCollection && selectedTask) { - return ( - - setTasks((current) => current.map((item) => (item.id === task.id ? task : item))) - } - /> - ) - } - return (
@@ -1096,6 +1077,20 @@ export default function CustomerFulfillmentPage({ + {selectedTask?.platform === 'huya' ? ( + + ) : null} + {selectedTask?.loginStatus === 'waiting_login' || selectedTask?.loginStatus === 'failed' || selectedTask?.loginStatus === 'expired' || @@ -1177,21 +1172,23 @@ export default function CustomerFulfillmentPage({ {showBindingStage ? (
-
-

- 绑定信息 (已登录虎牙账号) -

-
- 登录账号 - - {bindingInfo?.bindGameAccount || selectedTask.bindGameAccount || '未获取'} - + {profileComplete && !profileEditing ? ( +
+

+ 绑定信息 (已登录虎牙账号) +

+
+ 登录账号 + + {bindingInfo?.bindGameAccount || selectedTask.bindGameAccount || '未获取'} + +
+
+ 绑定角色 + {bindingRoleName || '未识别到角色'} +
-
- 绑定角色 - {bindingRoleName || '未识别到角色'} -
-
+ ) : null} {bindingSessionExpired ? (
@@ -1211,7 +1208,7 @@ export default function CustomerFulfillmentPage({
) : null} - {bindingBanner ? ( + {bindingBanner && !profileEditing ? (
{bindingBanner.text}
@@ -1219,7 +1216,11 @@ export default function CustomerFulfillmentPage({ {showProfileForm && !bindingSessionExpired ? (
-

修改资料后会重新核对平台识别角色。

+

+ {profileComplete + ? '第二步:修改资料后会用最新资料重新核对平台角色,三项完全一致才能提交平台绑定。' + : '第二步:请填写游戏角色资料:区服、游戏编号(虎牙账号 UID)与角色名,提交后才能生成绑定二维码。'} +

) : null} - {bindingQrVisible && !bindingSessionExpired ? ( + {bindingQrVisible && !bindingSessionExpired && !profileEditing ? (

游戏角色绑定二维码

{bindingInfo?.qrImage || bindingQrImage ? ( @@ -1301,7 +1312,7 @@ export default function CustomerFulfillmentPage({ : '请使用微信APP扫码进行游戏角色绑定'}

- 扫码后系统会核对平台角色与已填资料;不一致时可修改资料或同步平台角色。 + 扫码后系统会核对平台角色与已填资料;三项完全一致才能提交平台绑定。

{selectedTask?.bindingStatus === 'scanned' @@ -1311,7 +1322,7 @@ export default function CustomerFulfillmentPage({ ? '已向虎牙提交绑定,正在等待角色生效,请稍候刷新。' : bindingInfo?.rebindRequested ? '扫码后请在虎牙弹窗中选中目标角色;选好后点下方「已选好角色,提交换绑」。' - : '请在微信中完成角色绑定确认,再点击下方按钮进入下一步。' + : '请在微信中完成角色绑定确认,再点击下方按钮核对平台角色。' : '扫码后请在微信确认框中核对目标角色。'}

{nextRebindText ? ( @@ -1354,13 +1365,13 @@ export default function CustomerFulfillmentPage({ > {rebindAccepted || bindConfirmPending ? '刷新绑定状态' - : '已扫码绑定,点击进入下一步'} + : '已扫码绑定,点击核对平台角色'} )}
) : null} - {selectedTask?.bindingStatus === 'expired' ? ( + {selectedTask?.bindingStatus === 'expired' && !profileEditing ? ( ) : null} - {selectedTask?.bindingStatus === 'failed' ? ( + {selectedTask?.bindingStatus === 'failed' && !profileEditing ? ( ) : null} - {selectedTask?.bindingStatus === 'role_ready' && !bindingSessionExpired ? ( + {selectedTask?.bindingStatus === 'role_ready' && + !bindingSessionExpired && + !profileEditing ? ( - {bindingRequiresSupport ? ( + {bindingNeedsSupport ? ( ) : showRebindFailure ? ( } /> - ) : ( - - )} - {!bindingRequiresSupport && - !showRebindFailure && - comparisonMismatch && - bindingComparison ? ( + ) : comparisonMismatch && bindingComparison ? ( @@ -1457,12 +1457,23 @@ export default function CustomerFulfillmentPage({ {bindingComparison.customerRoleName || '角色未填'}(ID{' '} {bindingComparison.customerRoleId || '未填'}) - 三项一致后才能提交确认;可一键同步平台角色。 + + 三项完全一致才能提交平台绑定;请重新扫码换绑,或上一步修改资料。 + } /> - ) : null} - {bindingRequiresSupport ? ( + ) : ( + + )} + {bindingNeedsSupport ? (
- ) : showRebindFailure ? ( + ) : showRebindFailure || comparisonMismatch ? (
- - - -
- ) : comparisonMismatch ? ( -
- - -
- ) : rebindUnchanged ? ( -
- - + {comparisonMismatch && rebindAccepted ? ( + <> + + + + ) : ( + <> + + + + )}
) : (
@@ -1574,26 +1552,17 @@ export default function CustomerFulfillmentPage({ size="large" className="customer-binding-confirm" loading={bindingLoading} + disabled={!bindingComparison} onClick={() => setBindingConfirmOpen(true)} > - 确认绑定角色 - -
)} ) : null} - {selectedTask?.bindingStatus === 'confirmed' ? ( + {selectedTask?.bindingStatus === 'confirmed' && !profileEditing ? (

绑定状态需要平台人工核实,请联系客服处理

- -
- {bindingComparison?.verdict === 'mismatch' ? ( -
- - {canSyncBindingProfile ? ( - - ) : null} + {bindingComparison?.verdict === 'match' ? ( +
+ +
- ) : null} + ) : ( +
+ + +
+ )} {bindingComparison?.verdict === 'mismatch' ? (

- {bindingComparison?.message || '两侧角色信息不一致,无法确认绑定'} + {bindingComparison?.message || '两侧角色信息不一致,无法提交平台绑定'}

) : bindingComparison?.verdict === 'unknown' ? (

两侧角色信息不完整,请联系客服核实

@@ -1684,12 +1653,14 @@ export default function CustomerFulfillmentPage({ destroyOnClose > -

检测到待确认的绑定角色,请核对两侧角色是否一致。

+

+ 请核对两侧区服、角色名称与角色 ID,三项完全一致才能提交平台绑定。 +

您填写的角色 -
@@ -1698,7 +1669,7 @@ export default function CustomerFulfillmentPage({
- 待确认角色 + 平台识别角色 -
-
+
    + {HUYA_FLOW_STEPS.map((label, index) => { + const step = index + 1 + const state = step < current ? 'is-done' : step === current ? 'is-active' : '' + return ( +
  1. + {step < current ? '✓' : step} + {label} +
  2. + ) + })} +
) } diff --git a/apps/frontend/src/pages/customer-fulfillment/HuyaChallengeModal.tsx b/apps/frontend/src/pages/customer-fulfillment/HuyaChallengeModal.tsx index 66e8794d..8664ed8f 100644 --- a/apps/frontend/src/pages/customer-fulfillment/HuyaChallengeModal.tsx +++ b/apps/frontend/src/pages/customer-fulfillment/HuyaChallengeModal.tsx @@ -113,6 +113,7 @@ export default function HuyaChallengeModal(input: Props) { return ( ( + `/api/v1/customer-fulfillment/${encodeURIComponent(orderNo)}/tasks/${taskId}/binding/reset`, + {}, + ) +} + export function confirmCustomerBinding( orderNo: string, taskId: number, diff --git a/apps/frontend/src/styles/client.css b/apps/frontend/src/styles/client.css index 1b341f6d..06422524 100644 --- a/apps/frontend/src/styles/client.css +++ b/apps/frontend/src/styles/client.css @@ -1465,29 +1465,24 @@ } .customer-auth-hero { - min-height: auto; + position: relative; + min-height: clamp(112px, 15vw, 136px); display: flex; - align-items: center; - justify-content: center; - padding: 38px 16px 10px; - background: none; -} - -/* 微博登录页顶部 KV:与资料页共用 inside-kv.jpg,叠加深色渐变保证标题可读。 */ -.customer-auth-page.is-weibo .customer-auth-hero { - min-height: 134px; - align-items: flex-start; + align-items: flex-end; justify-content: flex-start; - padding: 26px 20px 20px; + padding: 12px 20px 14px; + overflow: hidden; + text-align: left; background-color: #0b1220; background-image: - linear-gradient(180deg, rgba(11, 18, 32, 0.12) 0%, rgba(11, 18, 32, 0.72) 72%, #232936 100%), + linear-gradient(180deg, rgba(11, 18, 32, 0.06) 0%, rgba(11, 18, 32, 0.62) 72%, #232936 100%), url('/images/customer/inside-kv.jpg'); background-repeat: no-repeat; background-position: center 38%; background-size: cover; } +/* 微博与虎牙客户页统一使用同一套顶部 KV,不再单独覆盖背景。 */ .customer-auth-page.is-weibo .customer-auth-brand { width: 100%; justify-content: flex-start; @@ -1499,17 +1494,18 @@ } @media (max-width: 640px) { - .customer-auth-page.is-weibo .customer-auth-hero { - min-height: 118px; - padding: 20px 16px 14px; + .customer-auth-hero { + min-height: 112px; + padding: 12px 16px 14px; background-position: center 42%; } } .customer-auth-brand { + width: 100%; display: flex; align-items: center; - justify-content: center; + justify-content: flex-start; gap: 0; min-width: 0; } @@ -1535,7 +1531,8 @@ line-height: 1.4; font-weight: 700; letter-spacing: 0; - text-align: center; + text-align: left; + text-shadow: 0 2px 12px rgba(0, 0, 0, 0.72); white-space: normal; overflow-wrap: anywhere; } @@ -2184,19 +2181,19 @@ /* 资料页顶部 KV:原图 https://game.gtimg.cn/images/gp/web201908/inside_kv.jpg(本地 1600×510 q82) */ .customer-collect-hero { position: relative; - min-height: clamp(190px, 24vw, 240px); + min-height: clamp(132px, 18vw, 160px); display: flex; align-items: flex-end; justify-content: center; - padding: 0 20px 16px; + padding: 0 18px 12px; overflow: hidden; text-align: center; background-color: #0b1220; background-image: - linear-gradient(180deg, rgba(11, 18, 32, 0) 45%, rgba(11, 18, 32, 0.55) 72%, #0b1220 100%), + linear-gradient(180deg, rgba(11, 18, 32, 0) 38%, rgba(11, 18, 32, 0.55) 72%, #0b1220 100%), url('/images/customer/inside-kv.jpg'); background-repeat: no-repeat; - background-position: center 38%; + background-position: center 40%; background-size: cover; } @@ -2211,8 +2208,8 @@ @media (max-width: 640px) { .customer-collect-hero { - min-height: 180px; - padding: 0 16px 14px; + min-height: 132px; + padding: 0 16px 12px; background-position: center 42%; } @@ -2497,6 +2494,72 @@ font-size: 16px; } +.customer-huya-steps { + display: flex; + gap: 8px; + margin: 12px 16px 0; + padding: 12px 14px; + list-style: none; + border: 1px solid #3a4150; + border-radius: 12px; + background: #1b212c; +} + +.customer-huya-step { + display: flex; + flex: 1 1 0; + align-items: center; + gap: 7px; + min-width: 0; + color: #64748b; + font-size: 13px; + line-height: 1.3; +} + +.customer-huya-step-index { + display: inline-flex; + flex: 0 0 auto; + align-items: center; + justify-content: center; + width: 22px; + height: 22px; + border: 1px solid #3a4150; + border-radius: 50%; + color: #94a3b8; + font-size: 12px; + font-weight: 600; + background: #212733; +} + +.customer-huya-step-label { + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.customer-huya-step.is-active { + color: #f8fafc; + font-weight: 600; +} + +.customer-huya-step.is-active .customer-huya-step-index { + color: #fff; + border-color: #2563eb; + background: #2563eb; + box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18); +} + +.customer-huya-step.is-done { + color: #6ee7b7; +} + +.customer-huya-step.is-done .customer-huya-step-index { + color: #6ee7b7; + border-color: #065f46; + background: rgba(6, 78, 59, 0.4); +} + .customer-order-card { margin: 10px 16px 0; padding: 16px; @@ -3088,9 +3151,9 @@ } .customer-auth-hero { - min-height: auto; - padding: 38px 16px 10px; - background: none; + min-height: 112px; + padding: 12px 16px 14px; + background-position: center 42%; } .customer-auth-brand h1 { @@ -3111,6 +3174,23 @@ min-height: 0; } + .customer-huya-steps { + gap: 6px; + margin: 10px 16px 0; + padding: 10px 12px; + } + + .customer-huya-step { + gap: 5px; + font-size: 11px; + } + + .customer-huya-step-index { + width: 19px; + height: 19px; + font-size: 10px; + } + .customer-auth-facts { padding-inline: 20px; } @@ -3231,3 +3311,244 @@ line-height: 1.45; } } + +/* ========================================================================== + 客户履约页(半自动)固定移动端 + 窄屏自适应 + -------------------------------------------------------------------------- + 全局 base.css 给 body 设了 min-width:320px,worker.css 又用 overflow-x:hidden + 裁掉横向溢出。应用内浏览器 / 分屏 / 系统显示放大时实际视口可能小于 320px, + 页面右侧(输入框、商品值、提示文案)会被直接裁掉。 + 下面只作用于客户履约页(body.customer-mobile-body),不影响后台与打手端。 + ========================================================================== */ + +html.customer-mobile-html, +body.customer-mobile-body { + min-width: 0; + width: 100%; + max-width: 100%; + overflow-x: hidden; +} + +body.customer-mobile-body #root { + width: 100%; + min-width: 0; + max-width: 100%; +} + +body.customer-mobile-body .customer-collect-page, +body.customer-mobile-body .customer-auth-page { + width: 100%; + min-width: 0; + max-width: 100%; + min-height: 100vh; + min-height: 100dvh; + overflow-x: hidden; +} + +body.customer-mobile-body .customer-collect-hero { + width: min(480px, 100%); + margin: 0 auto; +} + +body.customer-mobile-body .customer-collect-body { + width: 100%; + max-width: 480px; + margin: 0 auto; + padding: 20px clamp(12px, 4vw, 20px) calc(40px + env(safe-area-inset-bottom)); + padding-left: max(clamp(12px, 4vw, 20px), env(safe-area-inset-left)); + padding-right: max(clamp(12px, 4vw, 20px), env(safe-area-inset-right)); + gap: 10px; +} + +body.customer-mobile-body .customer-auth-shell { + width: min(480px, 100%); + min-width: 0; +} + +body.customer-mobile-body .customer-auth-main { + padding-bottom: calc(24px + env(safe-area-inset-bottom)); +} + +body.customer-mobile-body .customer-auth-content-stack, +body.customer-mobile-body .customer-auth-section, +body.customer-mobile-body .customer-auth-facts, +body.customer-mobile-body .customer-auth-facts > div, +body.customer-mobile-body .customer-auth-task-switcher, +body.customer-mobile-body .customer-login-form, +body.customer-mobile-body .customer-collect-card, +body.customer-mobile-body .customer-order-card { + min-width: 0; +} + +body.customer-mobile-body .customer-collect-card, +body.customer-mobile-body .customer-collect-readonly, +body.customer-mobile-body .customer-collect-input.ant-input, +body.customer-mobile-body .customer-collect-select.ant-select, +body.customer-mobile-body .customer-login-mobile.ant-input, +body.customer-mobile-body .customer-login-code-input.ant-input, +body.customer-mobile-body .customer-login-submit.ant-btn, +body.customer-mobile-body .customer-login-alt.ant-btn { + width: 100%; + min-width: 0; + max-width: 100%; +} + +/* 订单卡片自带左右 16px 外边距,不能用 width:100% 再加边距 */ +body.customer-mobile-body .customer-order-card { + width: auto; + max-width: 100%; +} + +body.customer-mobile-body .customer-collect-card > div, +body.customer-mobile-body .customer-order-card > div { + flex-wrap: wrap; +} + +body.customer-mobile-body .customer-collect-card > div strong, +body.customer-mobile-body .customer-order-card > div strong { + flex: 1 1 10ch; + min-width: 0; + overflow-wrap: anywhere; + word-break: break-word; +} + +/* 状态胶囊保持自身宽度,不参与长值换行规则 */ +body.customer-mobile-body .customer-order-card > div strong.customer-order-status { + flex: 0 0 auto; + max-width: 100%; + text-align: center; +} + +body.customer-mobile-body .customer-collect-readonly { + overflow-wrap: anywhere; + word-break: break-all; +} + +body.customer-mobile-body .customer-collect-card > p { + overflow-wrap: anywhere; + word-break: break-word; +} + +body.customer-mobile-body .customer-login-form, +body.customer-mobile-body .customer-login-mobile-row, +body.customer-mobile-body .customer-login-code-input.ant-input { + min-width: 0; +} + +body.customer-mobile-body .customer-auth-role-card, +body.customer-mobile-body .customer-auth-button-stack { + width: 100%; +} + +/* 登录/绑定二维码:容器与图片都不超过可用宽度,避免 232/252/260px 固定宽溢出 */ +body.customer-mobile-body .customer-auth-qr-image, +body.customer-mobile-body .customer-auth-qr-placeholder { + width: min(252px, 100%); + min-height: 0; + aspect-ratio: 1; +} + +body.customer-mobile-body .customer-auth-qr-image .ant-image, +body.customer-mobile-body .customer-auth-qr-image img, +body.customer-mobile-body .customer-binding-qr-card .ant-image, +body.customer-mobile-body .customer-binding-qr-card img { + max-width: 100%; + height: auto; +} + +/* 固定宽度弹窗(绑定确认 520 / 虎牙验证 430)在窄屏必须收到视口内 */ +@media (max-width: 640px) { + .customer-binding-modal, + .customer-huya-challenge-modal { + width: calc(100vw - 24px) !important; + max-width: 480px; + margin: 0 auto; + } + + .customer-binding-modal .ant-modal-content, + .customer-huya-challenge-modal .ant-modal-content { + max-height: calc(100vh - 32px); + overflow-y: auto; + } +} + +@media (max-width: 380px) { + body.customer-mobile-body .customer-binding-qr-actions, + body.customer-mobile-body .customer-binding-modal-actions { + grid-template-columns: minmax(0, 1fr); + } +} + +@media (max-width: 340px) { + body.customer-mobile-body .customer-collect-body { + padding-inline: 12px; + } + + /* 标签 + 长值改为上下排列,值不再被挤到屏幕外 */ + body.customer-mobile-body .customer-collect-card > div, + body.customer-mobile-body .customer-order-card > div { + flex-direction: column; + align-items: flex-start; + gap: 4px; + } + + body.customer-mobile-body .customer-collect-card > div strong, + body.customer-mobile-body .customer-order-card > div strong { + flex: 0 1 auto; + max-width: 100%; + justify-self: start; + text-align: left; + } + + body.customer-mobile-body .customer-order-card > div strong.customer-order-status { + flex: 0 0 auto; + text-align: center; + } + + body.customer-mobile-body .customer-collect-card > p { + text-align: left; + } + + body.customer-mobile-body .customer-login-mobile-row { + flex-direction: column; + gap: 10px; + } + + body.customer-mobile-body .customer-login-code-button.ant-btn { + width: 100%; + } + + body.customer-mobile-body .customer-auth-task-switcher { + flex-direction: column; + gap: 8px; + padding: 16px; + } + + body.customer-mobile-body .customer-auth-task-switcher > span { + padding-top: 0; + } + + body.customer-mobile-body .customer-auth-facts { + padding-inline: 12px; + } + + body.customer-mobile-body .customer-auth-facts > div { + grid-template-columns: minmax(0, 1fr); + gap: 4px; + min-height: 0; + padding-block: 12px; + } + + body.customer-mobile-body .customer-auth-facts > div > strong { + justify-self: start; + text-align: left; + } + + body.customer-mobile-body .customer-auth-state { + padding: 32px 16px; + } + + body.customer-mobile-body .customer-auth-privacy { + margin-inline: 16px; + } +} diff --git a/apps/frontend/src/types/admin/semi-auto.ts b/apps/frontend/src/types/admin/semi-auto.ts index 70cb6702..74a949ab 100644 --- a/apps/frontend/src/types/admin/semi-auto.ts +++ b/apps/frontend/src/types/admin/semi-auto.ts @@ -76,8 +76,21 @@ export type SemiAutoTaskListResult = { pagination: { page: number; pageSize: number; total: number } } +export type SemiAutoBindingComparison = { + verdict: 'match' | 'mismatch' | 'unknown' + customerRoleName: string + customerRoleId: string + customerZone: string + boundRoleName: string + boundRoleId: string + boundZone: string + message: string +} + export type SemiAutoTaskDetail = { task: SemiAutoTask + /** 与客户页同源的区服 / 角色名 / 角色 ID 三项比对结果。 */ + comparison: SemiAutoBindingComparison events: SemiAutoTaskEvent[] } diff --git a/apps/frontend/tests/customer-fulfillment-binding-compare.test.ts b/apps/frontend/tests/customer-fulfillment-binding-compare.test.ts index a26107fb..55ddcda7 100644 --- a/apps/frontend/tests/customer-fulfillment-binding-compare.test.ts +++ b/apps/frontend/tests/customer-fulfillment-binding-compare.test.ts @@ -11,48 +11,42 @@ const source = readFileSync( ) const styles = readFileSync(join(root, '../src/styles/client.css'), 'utf8') -test('扫码识别角色后,资料不一致也打开对比弹窗', () => { - // 自动弹窗 effect 不再因 mismatch 提前 return。 - assert.ok(source.includes('识别到角色(含与资料不一致)都要弹出对比框')) - assert.ok(!source.includes("if (bindingInfo.comparison.verdict === 'mismatch') return")) - // 手动刷新时 mismatch 同样打开弹窗,不再关闭并只弹提示。 - assert.ok(source.includes('资料不一致同样打开对比框')) - assert.ok(!source.includes('平台角色与已填资料不一致,请先同步资料')) +test('资料不一致时不自动弹核对框,由页面两个按钮处理', () => { + assert.ok(source.includes("if (bindingInfo.comparison.verdict !== 'match') return")) + assert.ok(source.includes('不一致时不弹框')) + // 手动刷新时也只有三项一致才打开核对框。 + assert.ok(source.includes("if (nextBinding?.comparison?.verdict === 'match') {")) }) -test('对比弹窗在资料不一致时提供修改资料与同步平台角色入口', () => { - assert.ok(source.includes('修改资料')) - assert.ok(source.includes('同步平台角色')) - assert.ok(source.includes('canSyncBindingProfile')) - assert.ok(source.includes('onClick={openProfileEditor}')) - assert.ok( - source.includes( - "disabled={!bindingCustomerReady || bindingComparison?.verdict === 'mismatch'}", - ), - ) - assert.ok(styles.includes('.customer-binding-modal-actions.is-mismatch')) - assert.ok(styles.includes('repeat(auto-fit, minmax(140px, 1fr))')) +test('资料不一致时固定提供重新扫码换绑与上一步修改资料', () => { + assert.ok(source.includes('showRebindFailure || comparisonMismatch')) + assert.ok(source.includes('重新扫码换绑')) + assert.ok(source.includes('上一步修改资料')) + assert.ok(source.includes('onClick={() => void openProfileEditor()}')) + // 取消同步平台角色与直接使用原角色的快捷路径。 + assert.ok(!source.includes('同步平台角色')) + assert.ok(!source.includes('确认使用原角色')) + assert.ok(styles.includes('.customer-binding-role-actions')) }) -test('保存资料或同步平台角色后会重新打开对比弹窗', () => { +test('保存资料后只有三项一致才重新打开核对弹窗', () => { assert.ok(source.includes('function reopenBindingConfirm(')) assert.ok(source.includes("if (nextTask.bindingStatus !== 'role_ready') return false")) + assert.ok(source.includes("if (nextBinding.comparison.verdict !== 'match') return false")) assert.ok(source.includes('reopened = reopenBindingConfirm(')) - assert.ok( - source.includes( - 'reopenBindingConfirm(bindingResponse.data.task, bindingResponse.data.binding)', - ), - ) - assert.ok(source.includes('角色资料已保存,请重新核对绑定角色')) + assert.ok(source.includes('资料已保存且与平台角色一致,请提交平台绑定')) }) -test('资料不一致时仍保持后端严格比对:确认按钮禁用并显示原因', () => { - assert.ok(source.includes('两侧角色信息不一致,无法确认绑定')) +test('三项一致才出现提交平台绑定,不一致时展示原因', () => { + assert.ok(source.includes('提交平台绑定')) + assert.ok(source.includes("bindingComparison?.verdict === 'match'")) + assert.ok(source.includes('两侧角色信息不一致,无法提交平台绑定')) assert.ok(source.includes('customer-binding-modal-error')) }) test('二维码区提示扫码后会核对平台角色与已填资料', () => { assert.ok(source.includes('扫码后系统会核对平台角色与已填资料')) + assert.ok(source.includes('三项完全一致才能提交平台绑定')) }) test('换绑流程刷新二维码必须带 forceRebind,避免直接返回已有角色', () => { diff --git a/apps/frontend/tests/customer-fulfillment-mobile.test.ts b/apps/frontend/tests/customer-fulfillment-mobile.test.ts new file mode 100644 index 00000000..c262210e --- /dev/null +++ b/apps/frontend/tests/customer-fulfillment-mobile.test.ts @@ -0,0 +1,50 @@ +import assert from 'node:assert/strict' +import { readFile } from 'node:fs/promises' +import test from 'node:test' + +function source(relativePath: string) { + return new URL(`../src/${relativePath}`, import.meta.url) +} + +/** + * 半自动履约客户页是公开 H5 页面,可能被应用内浏览器、分屏或系统显示放大打开。 + * 全局 base.css 的 body { min-width:320px } + worker.css 的 overflow-x:hidden + * 会在实际视口小于 320px 时把页面右侧直接裁掉(输入框/商品值/提示文案)。 + * 这里锁住客户页专属移动端根类和 480px 移动壳,防止以后被全局样式改回去。 + */ +test('客户履约页必须覆盖 body 320px 最小宽度并使用 480px 移动端壳', async () => { + const [app, css] = await Promise.all([ + readFile(source('App.tsx'), 'utf8'), + readFile(source('styles/client.css'), 'utf8'), + ]) + + assert.match(app, /customer-mobile-html/) + assert.match(app, /customer-mobile-body/) + assert.match( + css, + /html\.customer-mobile-html,\s*body\.customer-mobile-body\s*\{[^}]*min-width:\s*0/s, + ) + assert.match( + css, + /body\.customer-mobile-body \.customer-collect-body\s*\{[^}]*max-width:\s*480px/s, + ) + assert.match( + css, + /body\.customer-mobile-body \.customer-auth-shell\s*\{[^}]*width:\s*min\(480px,\s*100%\)/s, + ) +}) + +test('客户履约页固定宽度弹窗必须收进手机视口', async () => { + const [page, huya, css] = await Promise.all([ + readFile(source('pages/customer-fulfillment/CustomerFulfillmentPage.tsx'), 'utf8'), + readFile(source('pages/customer-fulfillment/HuyaChallengeModal.tsx'), 'utf8'), + readFile(source('styles/client.css'), 'utf8'), + ]) + + assert.match(page, /className="customer-binding-modal"/) + assert.match(huya, /className="customer-huya-challenge-modal"/) + assert.match( + css, + /\.customer-binding-modal,\s*\.customer-huya-challenge-modal\s*\{[^}]*width:\s*calc\(100vw - 24px\)\s*!important/s, + ) +}) diff --git a/apps/frontend/tests/customer-fulfillment-rebind-return.test.ts b/apps/frontend/tests/customer-fulfillment-rebind-return.test.ts index 59feacda..a2b9cb7b 100644 --- a/apps/frontend/tests/customer-fulfillment-rebind-return.test.ts +++ b/apps/frontend/tests/customer-fulfillment-rebind-return.test.ts @@ -12,20 +12,47 @@ const source = readFileSync( 'utf8', ) -test('换绑失败页用「返回上一步」替换「仍使用原角色」', () => { - assert.ok(source.includes('rebindFailureDismissed')) - assert.ok(source.includes('返回上一步')) - assert.ok(!source.includes('仍使用原角色')) +test('换绑失败页提供重新扫码换绑与上一步修改资料,不再直接使用原角色', () => { + assert.ok(source.includes('showRebindFailure || comparisonMismatch')) + assert.ok(source.includes('重新扫码换绑')) + assert.ok(source.includes('上一步修改资料')) + assert.ok(!source.includes('确认使用原角色')) + assert.ok(!source.includes('handleAcceptExistingRole')) + assert.ok(!source.includes('rebindFailureDismissed')) }) -test('返回后展示资料不一致核对界面', () => { - assert.ok(source.includes('showRebindFailure')) - assert.ok(source.includes('!showRebindFailure &&')) - assert.ok(source.includes('同步平台角色并继续')) +test('换绑后仍不一致时以修改资料为主,同时保留重新扫码入口', () => { + const panelStart = source.indexOf('showRebindFailure || comparisonMismatch') + assert.ok(panelStart > 0) + const panel = source.slice(panelStart, panelStart + 1600) + assert.ok(panel.includes('重新扫码换绑')) + assert.ok(panel.includes('上一步修改资料')) assert.ok(source.includes('id="customer-binding-stage"')) }) -test('资料同步后提供确认使用原角色', () => { - assert.ok(source.includes('确认使用原角色')) - assert.ok(source.includes('handleAcceptExistingRole')) +test('取消直接使用原角色的快捷确认路径', () => { + assert.ok(!source.includes('acceptExistingRole')) + assert.ok(!source.includes('modal.confirm')) +}) + +test('点击上一步修改资料会回到第二步并隐藏绑定区', () => { + // 步骤条把编辑资料视为第二步,即使资料原本已完整。 + assert.ok(source.includes(': profileEditing || !profileComplete')) + assert.ok(source.includes("'第二步:请填写游戏角色资料")) + assert.ok(source.includes('返回绑定角色')) + // 资料步骤隐藏二维码、失败提示和比对操作,避免与第二步混在一起。 + assert.ok(source.includes('!profileEditing')) + assert.ok(source.includes("getElementById('customer-binding-stage')")) +}) + +test('上一步修改资料会清空换绑状态并保留已填资料', () => { + // 进入资料编辑时同步调用重置接口,清掉虎牙未接受换绑等失败痕迹。 + assert.ok(source.includes('async function openProfileEditor()')) + assert.ok(source.includes('await resetCustomerBinding(orderNo, selectedTask.id)')) + assert.ok(source.includes('setBindingInfo(response.data.binding)')) + assert.ok(source.includes("message.success('已返回上一步,请修改资料后重新提交')")) + // 已登录且有绑定结果时才重置,资料表单本身不受影响。 + assert.ok(source.includes("selectedTask.bindingStatus === 'not_started'")) + // 重置失败不阻断客户修改资料。 + assert.ok(source.includes('重置绑定状态失败,请稍后重试')) }) diff --git a/apps/frontend/tests/customer-fulfillment-weibo-ui.test.ts b/apps/frontend/tests/customer-fulfillment-weibo-ui.test.ts index b399112e..6bce0e2b 100644 --- a/apps/frontend/tests/customer-fulfillment-weibo-ui.test.ts +++ b/apps/frontend/tests/customer-fulfillment-weibo-ui.test.ts @@ -51,8 +51,12 @@ test('微博订单卡只展示订单号/商品/平台/状态,不含游戏和 assert.ok(!weiboBranch.includes('游戏名称')) }) -test('微博顶部使用 inside-kv 背景,虎牙保持纯色', () => { - assert.ok(styles.includes('.customer-auth-page.is-weibo .customer-auth-hero')) - assert.ok(styles.includes("url('/images/customer/inside-kv.jpg')")) +test('客户登录/绑定页顶部统一显示 inside-kv 背景,不再按平台区分', () => { + assert.match( + styles, + /\.customer-auth-hero \{[^}]*url\('\/images\/customer\/inside-kv\.jpg'\)[^}]*\}/s, + ) + assert.ok(!styles.includes('.customer-auth-page.is-weibo .customer-auth-hero')) assert.ok(!styles.includes('.customer-auth-page.is-huya .customer-auth-hero')) + assert.ok(styles.includes('.customer-auth-page.is-weibo .customer-auth-brand')) })