调整(虎牙客户资料): 增加游戏主页截图、UID 纯数字与角色名混入校验
- 迁移 191:semi_auto_tasks 增加客户游戏主页截图 5 个正式字段
(object_key / url / thumbnail_url / filename / uploaded_at)。
- 新增 POST /customer-fulfillment/:orderNo/tasks/:taskId/homepage-screenshot
(writeLimit + 单文件上传),场景 semi-auto-homepage-screenshot、
归属 semi-auto-task-{taskId},与斗鱼同一套 file_assets 校验口径。
- 保存资料改为四要素必填:区服 / 游戏角色 UID / 角色名 / 游戏主页截图;
截图须在同一事务内校验归属与类型,缺失或越权直接 400。
- 游戏角色 UID 改为 1..20 位纯数字校验(semi_auto_profile_role_id_invalid);
角色名新增「不得混入 UID/区服/登录方式」校验,规则与斗鱼一致并在后端再实现一份。
- 客户页:UID 提示改为「请输入游戏角色 UID,纯数字uid」、只接受数字输入并实时提示;
角色名加斗鱼同款提示与混入警告;新增「游戏主页截图(必填)」上传区 + 示例图 + 说明文案;
已保存截图按 DTO 的 objectKey 回填预览,不再从文件链接反解。
- 角色名规则收敛到共享 game-role-name(删除 douyu-role-name 转发层,斗鱼页面与文案不变)。
- 「资料已完成」判断仍只看已保存三要素:截图在保存时强制,
避免本次改造前已填好资料的历史任务被卡回第一步。
- 权威文档同步虎牙资料四要素、UID 纯数字、角色名混入校验与截图用途,并补迁移 191 记录。
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
-- 191_semi_auto_homepage_screenshot.sql
|
||||
--
|
||||
-- 虎牙客户授权页增加必填「游戏主页截图」,与斗鱼客户资料收集口径一致:
|
||||
-- 1. 截图对象、展示地址、缩略图、原始文件名和提交时间作为半自动任务正式字段保存;
|
||||
-- 2. 图片台账与归属校验以 file_assets 为准,任务表只保存已校验通过的结果;
|
||||
-- 3. 客服据此核对客户填写的角色名 / 游戏角色 UID 与账号绑定是否正确。
|
||||
|
||||
ALTER TABLE semi_auto_tasks
|
||||
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_object_key TEXT NOT NULL DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_url TEXT NOT NULL DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_thumbnail_url TEXT NOT NULL DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_filename TEXT NOT NULL DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_uploaded_at TIMESTAMPTZ;
|
||||
|
||||
COMMENT ON COLUMN semi_auto_tasks.customer_homepage_screenshot_object_key IS
|
||||
'客户上传的游戏主页截图对象 key;文件台账和归属校验以 file_assets 为准';
|
||||
COMMENT ON COLUMN semi_auto_tasks.customer_homepage_screenshot_url IS
|
||||
'客户游戏主页截图稳定展示地址;客服核对绑定使用';
|
||||
COMMENT ON COLUMN semi_auto_tasks.customer_homepage_screenshot_thumbnail_url IS
|
||||
'客户游戏主页截图缩略图稳定展示地址';
|
||||
COMMENT ON COLUMN semi_auto_tasks.customer_homepage_screenshot_filename IS
|
||||
'客户游戏主页截图原始文件名';
|
||||
COMMENT ON COLUMN semi_auto_tasks.customer_homepage_screenshot_uploaded_at IS
|
||||
'客户游戏主页截图随资料提交保存的时间';
|
||||
@@ -18,10 +18,12 @@ import {
|
||||
startPublicLogin,
|
||||
startPublicWeiboQrLogin,
|
||||
submitPublicRebind,
|
||||
uploadPublicTaskHomepageScreenshot,
|
||||
verifyPublicHuyaSmsChallenge,
|
||||
} from '../services/semi-auto/semi-auto-task-service.js'
|
||||
import { createSemiAutoTaskTraceHandler } from '../middleware/semi-auto-trace.js'
|
||||
import { createRateLimitMiddleware, getParamRateLimitKey } from '../middleware/rate-limit.js'
|
||||
import { uploadSingleFile } from './file-upload.js'
|
||||
import { createRouteHandler } from '../utils/http.js'
|
||||
|
||||
const router = Router()
|
||||
@@ -99,6 +101,21 @@ router.post(
|
||||
),
|
||||
)
|
||||
|
||||
// 客户游戏主页截图:与角色资料分开上传,保存资料时再按 objectKey 校验归属。
|
||||
router.post(
|
||||
'/:orderNo/tasks/:taskId/homepage-screenshot',
|
||||
writeLimit,
|
||||
uploadSingleFile,
|
||||
createRouteHandler(
|
||||
(req) => uploadPublicTaskHomepageScreenshot(req.params.orderNo, req.params.taskId, req.file),
|
||||
{
|
||||
successMessage: '主页截图已上传',
|
||||
errorMessage: '上传主页截图失败',
|
||||
scope: '[customer-fulfillment/:orderNo/tasks/:taskId/homepage-screenshot]',
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
router.post(
|
||||
'/:orderNo/tasks/:taskId/binding/reset',
|
||||
writeLimit,
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
GAME_ROLE_NAME_MIXED_WARNING,
|
||||
getGameRoleNameIssue,
|
||||
isValidGameRoleId,
|
||||
} from './game-role-name.js'
|
||||
|
||||
test('游戏角色 UID 只接受 1..20 位纯数字', () => {
|
||||
assert.equal(isValidGameRoleId('1192083858'), true)
|
||||
assert.equal(isValidGameRoleId(' 4212063544 '), true)
|
||||
assert.equal(isValidGameRoleId('0'), true)
|
||||
assert.equal(isValidGameRoleId('12345678901234567890'), true)
|
||||
assert.equal(isValidGameRoleId('123456789012345678901'), false)
|
||||
assert.equal(isValidGameRoleId('uid-not-number'), false)
|
||||
assert.equal(isValidGameRoleId('UID-not-number'), false)
|
||||
assert.equal(isValidGameRoleId('1192083858a'), false)
|
||||
assert.equal(isValidGameRoleId('-1192083858'), false)
|
||||
assert.equal(isValidGameRoleId('1192083858'), false)
|
||||
assert.equal(isValidGameRoleId(''), false)
|
||||
assert.equal(isValidGameRoleId(' '), false)
|
||||
})
|
||||
|
||||
test('纯角色名通过角色名校验', () => {
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精'), null)
|
||||
assert.equal(getGameRoleNameIssue('狙神123'), null)
|
||||
assert.equal(getGameRoleNameIssue('QQ战神'), null)
|
||||
assert.equal(getGameRoleNameIssue(''), null)
|
||||
assert.equal(getGameRoleNameIssue(' '), null)
|
||||
})
|
||||
|
||||
test('角色名混入 UID、区服或登录方式时拒绝', () => {
|
||||
assert.equal(
|
||||
getGameRoleNameIssue('花乔妖精 3379480446 安卓区 微信'),
|
||||
GAME_ROLE_NAME_MIXED_WARNING,
|
||||
)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 3379480446'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精3379480446'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 安卓区'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 微信'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 qq'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('安卓区'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('ios'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
})
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 游戏角色名与角色 UID 的公共校验口径。
|
||||
*
|
||||
* 与前端 `apps/frontend/src/utils/game-role-name.ts` 保持同一套规则:
|
||||
* 角色名只允许填写角色名称,UID、区服、登录方式属于其它字段,混入即视为填写错误。
|
||||
* 后端必须独立校验,不能只依赖前端提示。
|
||||
*/
|
||||
export const GAME_ROLE_NAME_MIXED_WARNING =
|
||||
'这里只能填写游戏角色名。检测到 UID、区服或登录方式,请只保留角色名称,例如“花乔妖精”。'
|
||||
|
||||
const ROLE_NAME_SEPARATOR = /[\s,,、|/\\·::;;_-]+/u
|
||||
const STANDALONE_UID = /^\d{6,}$/u
|
||||
const LONG_NUMBER = /\d{8,}/u
|
||||
const STANDALONE_LOGIN_OR_SYSTEM = /^(?:安卓区?|苹果区?|ios|android|微信|qq|q区|v区|手q)$/iu
|
||||
|
||||
/** 角色名允许的最大长度(与客户页输入框上限一致)。 */
|
||||
export const GAME_ROLE_NAME_MAX_LENGTH = 100
|
||||
/** 游戏角色 UID 允许的最大长度(与客户页输入框上限一致)。 */
|
||||
export const GAME_ROLE_ID_MAX_LENGTH = 20
|
||||
|
||||
const GAME_ROLE_ID_PATTERN = /^\d+$/u
|
||||
|
||||
/** 返回角色名混入 UID / 区服 / 登录方式时的提示;没有混入返回 null。 */
|
||||
export function getGameRoleNameIssue(value: string): string | null {
|
||||
const roleName = String(value ?? '').trim()
|
||||
if (!roleName) return null
|
||||
|
||||
const tokens = roleName.split(ROLE_NAME_SEPARATOR).filter(Boolean)
|
||||
const hasStandaloneUid = tokens.some((token) => STANDALONE_UID.test(token))
|
||||
const hasLongNumber = LONG_NUMBER.test(roleName)
|
||||
const hasStandaloneLoginOrSystem = tokens.some((token) => STANDALONE_LOGIN_OR_SYSTEM.test(token))
|
||||
|
||||
return hasStandaloneUid || hasLongNumber || hasStandaloneLoginOrSystem
|
||||
? GAME_ROLE_NAME_MIXED_WARNING
|
||||
: null
|
||||
}
|
||||
|
||||
/** 游戏角色 UID 必须是 1..20 位纯数字。 */
|
||||
export function isValidGameRoleId(value: string) {
|
||||
const roleId = String(value ?? '').trim()
|
||||
return (
|
||||
roleId.length > 0 &&
|
||||
roleId.length <= GAME_ROLE_ID_MAX_LENGTH &&
|
||||
GAME_ROLE_ID_PATTERN.test(roleId)
|
||||
)
|
||||
}
|
||||
@@ -154,7 +154,7 @@ describe('虎牙角色比对', () => {
|
||||
})
|
||||
|
||||
describe('客户角色资料校验', () => {
|
||||
it('游戏角色 UID 必填但不校验格式', () => {
|
||||
it('游戏角色 UID 必填且只接受纯数字', () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCustomerProfile({
|
||||
@@ -164,20 +164,38 @@ describe('客户角色资料校验', () => {
|
||||
}),
|
||||
/请完整填写区服、游戏角色 UID 和角色名/,
|
||||
)
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCustomerProfile({
|
||||
roleName: '落地盒子怪cc',
|
||||
roleId: 'uid-not-number',
|
||||
serverZone: '安卓Q区',
|
||||
}),
|
||||
/游戏角色 UID 只能填写纯数字/,
|
||||
)
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCustomerProfile({
|
||||
roleName: '落地盒子怪cc',
|
||||
roleId: '123456789012345678901',
|
||||
serverZone: '安卓Q区',
|
||||
}),
|
||||
/游戏角色 UID 只能填写纯数字/,
|
||||
)
|
||||
|
||||
const profile = normalizeCustomerProfile({
|
||||
roleName: '落地盒子怪cc',
|
||||
roleId: 'uid-not-number',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
})
|
||||
assert.deepEqual(profile, {
|
||||
roleName: '落地盒子怪cc',
|
||||
roleId: 'uid-not-number',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
})
|
||||
assert.equal(
|
||||
hasCustomerProfile({
|
||||
customer_game_id: 'uid-not-number',
|
||||
customer_game_id: '4212063544',
|
||||
customer_game_role: '落地盒子怪cc',
|
||||
customer_server_zone: '安卓Q区',
|
||||
}),
|
||||
@@ -193,6 +211,36 @@ describe('客户角色资料校验', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('角色名混入 UID、区服或登录方式时拒绝保存', () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCustomerProfile({
|
||||
roleName: '落地盒子怪cc 4212063544',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
}),
|
||||
/这里只能填写游戏角色名/,
|
||||
)
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCustomerProfile({
|
||||
roleName: '落地盒子怪cc 安卓区',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
}),
|
||||
/这里只能填写游戏角色名/,
|
||||
)
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCustomerProfile({
|
||||
roleName: '落地盒子怪cc QQ',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
}),
|
||||
/这里只能填写游戏角色名/,
|
||||
)
|
||||
})
|
||||
|
||||
it('清理空白并保留纯数字游戏角色 UID', () => {
|
||||
const profile = normalizeCustomerProfile({
|
||||
roleName: ' 落地盒子怪cc ',
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
import { runtimeConfig } from '../../config/runtime.js'
|
||||
import { query, withTransaction } from '../../db/client.js'
|
||||
import { getFileAssetByObjectKey } from '../../repositories/file-asset-repo.js'
|
||||
import { createHttpError } from '../../utils/http.js'
|
||||
import { logWarn } from '../../utils/logger.js'
|
||||
import {
|
||||
ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES,
|
||||
buildFileUrl,
|
||||
uploadFileAsset,
|
||||
} from '../file-storage/file-storage-service.js'
|
||||
import {
|
||||
GAME_ROLE_NAME_MAX_LENGTH,
|
||||
getGameRoleNameIssue,
|
||||
isValidGameRoleId,
|
||||
} from '../account-binding/game-role-name.js'
|
||||
import {
|
||||
confirmHuyaBinding,
|
||||
exportHuyaSessionCredential,
|
||||
@@ -103,15 +115,24 @@ export type CustomerProfileInput = {
|
||||
serverZone?: unknown
|
||||
}
|
||||
|
||||
/** 客户上传游戏主页截图的文件场景与归属,用于校验 file_assets 台账。 */
|
||||
export const SEMI_AUTO_HOMEPAGE_SCREENSHOT_SCENE = 'semi-auto-homepage-screenshot'
|
||||
export const SEMI_AUTO_HOMEPAGE_UPLOADER_TYPE = 'semi-auto-customer'
|
||||
|
||||
/** 截图资产必须由本次任务自己的客户上传,不能复用其它任务或其它场景的文件。 */
|
||||
export function semiAutoHomepageScreenshotUploaderId(taskId: number) {
|
||||
return `semi-auto-task-${taskId}`
|
||||
}
|
||||
|
||||
const CUSTOMER_SERVER_ZONES = new Set(['苹果Q区', '苹果V区', '安卓Q区', '安卓V区'])
|
||||
|
||||
export function normalizeCustomerProfile(input: CustomerProfileInput = {}) {
|
||||
const roleName = String(input.roleName ?? '')
|
||||
.trim()
|
||||
.slice(0, 100)
|
||||
.slice(0, GAME_ROLE_NAME_MAX_LENGTH)
|
||||
const roleId = String(input.roleId ?? '')
|
||||
.trim()
|
||||
.replace(/\s+/g, '')
|
||||
.slice(0, 64)
|
||||
const serverZone = String(input.serverZone ?? '')
|
||||
.trim()
|
||||
.slice(0, 100)
|
||||
@@ -127,18 +148,45 @@ export function normalizeCustomerProfile(input: CustomerProfileInput = {}) {
|
||||
errorCode: 'semi_auto_profile_required',
|
||||
})
|
||||
}
|
||||
if (!isValidGameRoleId(roleId)) {
|
||||
throw createHttpError('游戏角色 UID 只能填写纯数字', {
|
||||
statusCode: 400,
|
||||
errorCode: 'semi_auto_profile_role_id_invalid',
|
||||
})
|
||||
}
|
||||
const roleNameIssue = getGameRoleNameIssue(roleName)
|
||||
if (roleNameIssue) {
|
||||
throw createHttpError(roleNameIssue, {
|
||||
statusCode: 400,
|
||||
errorCode: 'semi_auto_profile_role_name_invalid',
|
||||
})
|
||||
}
|
||||
return { roleName, roleId, serverZone }
|
||||
}
|
||||
|
||||
function absoluteOrderSiteFileUrl(pathname: string) {
|
||||
const normalizedPath = String(pathname || '').trim()
|
||||
if (!normalizedPath) return ''
|
||||
try {
|
||||
return new URL(normalizedPath, new URL(runtimeConfig.orders.claimBaseUrl).origin).toString()
|
||||
} catch {
|
||||
return normalizedPath
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 半自动订单没有 work_orders,客户资料在授权页 /c/<订单号>(虎牙)或 /d/<订单号>(微博)收集。
|
||||
* 虎牙先保存目标角色名、区服和 UID,再登录账号;UID 只做资料收集,不校验格式,
|
||||
* 也不参与绑定核验。
|
||||
* 虎牙先保存目标角色名、区服、游戏角色 UID 和游戏主页截图,再登录账号;
|
||||
* 游戏角色 UID 只做资料收集与纯数字格式校验,不参与绑定核验。
|
||||
*/
|
||||
export type CustomerProfileSaveInput = CustomerProfileInput & {
|
||||
homepageScreenshotObjectKey?: unknown
|
||||
}
|
||||
|
||||
export async function savePublicTaskProfile(
|
||||
orderNoInput: unknown,
|
||||
taskIdInput: unknown,
|
||||
payload: CustomerProfileInput = {},
|
||||
payload: CustomerProfileSaveInput = {},
|
||||
) {
|
||||
const orderNo = normalizeOrderNo(orderNoInput)
|
||||
const taskId = normalizeId(taskIdInput)
|
||||
@@ -163,6 +211,15 @@ export async function savePublicTaskProfile(
|
||||
})
|
||||
}
|
||||
const profile = normalizeCustomerProfile(payload)
|
||||
const homepageScreenshotObjectKey = String(payload.homepageScreenshotObjectKey ?? '')
|
||||
.trim()
|
||||
.slice(0, 512)
|
||||
if (!homepageScreenshotObjectKey) {
|
||||
throw createHttpError('请上传游戏主页截图', {
|
||||
statusCode: 400,
|
||||
errorCode: 'semi_auto_homepage_screenshot_required',
|
||||
})
|
||||
}
|
||||
await withTransaction(async (client) => {
|
||||
const current = await loadTaskForUpdateWithClient(client, task.id)
|
||||
if (current.execution_status === 'completed' || current.execution_status === 'cancelled') {
|
||||
@@ -177,6 +234,23 @@ export async function savePublicTaskProfile(
|
||||
errorCode: 'semi_auto_profile_locked',
|
||||
})
|
||||
}
|
||||
const asset = await getFileAssetByObjectKey(homepageScreenshotObjectKey, client)
|
||||
if (
|
||||
!asset ||
|
||||
asset.uploader_type !== SEMI_AUTO_HOMEPAGE_UPLOADER_TYPE ||
|
||||
asset.uploader_id !== semiAutoHomepageScreenshotUploaderId(current.id) ||
|
||||
asset.scene !== SEMI_AUTO_HOMEPAGE_SCREENSHOT_SCENE ||
|
||||
!ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES.has(String(asset.content_type || '').trim())
|
||||
) {
|
||||
throw createHttpError('主页截图无效,请重新上传', {
|
||||
statusCode: 400,
|
||||
errorCode: 'semi_auto_homepage_screenshot_invalid',
|
||||
})
|
||||
}
|
||||
const screenshotUrl = absoluteOrderSiteFileUrl(buildFileUrl(asset.object_key))
|
||||
const thumbnailUrl = absoluteOrderSiteFileUrl(
|
||||
buildFileUrl(asset.thumbnail_object_key || asset.object_key),
|
||||
)
|
||||
await convergeSemiAutoTaskState(client, current.id, {
|
||||
reason: 'customer_profile_saved',
|
||||
actor: 'customer',
|
||||
@@ -184,8 +258,16 @@ export async function savePublicTaskProfile(
|
||||
customerGameRoleName: profile.roleName,
|
||||
customerGameRoleId: profile.roleId,
|
||||
customerGameServerZone: profile.serverZone,
|
||||
customerHomepageScreenshotObjectKey: asset.object_key,
|
||||
customerHomepageScreenshotUrl: screenshotUrl,
|
||||
customerHomepageScreenshotThumbnailUrl: thumbnailUrl,
|
||||
customerHomepageScreenshotFilename: asset.original_filename,
|
||||
customerHomepageScreenshotUploadedAt: SEMI_AUTO_NOW,
|
||||
},
|
||||
event: {
|
||||
eventType: 'customer_profile_saved',
|
||||
detail: { ...profile, homepageScreenshotObjectKey: asset.object_key },
|
||||
},
|
||||
event: { eventType: 'customer_profile_saved', detail: profile },
|
||||
})
|
||||
})
|
||||
publishSemiAutoTaskRealtimeChange(task.id, task.order_id)
|
||||
@@ -200,6 +282,40 @@ export async function savePublicTaskProfile(
|
||||
return { task: mapTask(updated) }
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户上传游戏主页截图:文件先独立落库,保存资料时再用 objectKey 校验归属并写入任务。
|
||||
* 与服务端其它上传一致,必须走 file_assets 台账,不信任前端传入的 URL。
|
||||
*/
|
||||
export async function uploadPublicTaskHomepageScreenshot(
|
||||
orderNoInput: unknown,
|
||||
taskIdInput: unknown,
|
||||
file: Express.Multer.File | null | undefined,
|
||||
) {
|
||||
const orderNo = normalizeOrderNo(orderNoInput)
|
||||
const taskId = normalizeId(taskIdInput)
|
||||
const task = await loadTaskForOrder(orderNo, taskId)
|
||||
const bindingPolicy = getAccountBindingPolicy(task.platform)
|
||||
if (!bindingPolicy.requiresCustomerProfile) {
|
||||
throw createHttpError('当前平台不需要填写游戏角色', {
|
||||
statusCode: 409,
|
||||
errorCode: 'semi_auto_profile_not_supported',
|
||||
})
|
||||
}
|
||||
if (task.execution_status === 'completed' || task.execution_status === 'cancelled') {
|
||||
throw createHttpError('当前订单已结束,不能上传资料', {
|
||||
statusCode: 409,
|
||||
errorCode: 'semi_auto_task_closed',
|
||||
})
|
||||
}
|
||||
return uploadFileAsset({
|
||||
file,
|
||||
scene: SEMI_AUTO_HOMEPAGE_SCREENSHOT_SCENE,
|
||||
uploaderType: SEMI_AUTO_HOMEPAGE_UPLOADER_TYPE,
|
||||
uploaderId: semiAutoHomepageScreenshotUploaderId(task.id),
|
||||
allowedContentTypes: ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES,
|
||||
})
|
||||
}
|
||||
|
||||
function mapLoginUpdate(session: ConnectorLoginSession) {
|
||||
const statusMap: Record<ConnectorLoginSession['status'], LoginStatus> = {
|
||||
verification_pending: 'waiting_login',
|
||||
|
||||
@@ -153,6 +153,11 @@ export type TaskRow = {
|
||||
customer_game_role_name: string
|
||||
customer_game_role_id: string
|
||||
customer_game_server_zone: string
|
||||
customer_homepage_screenshot_object_key: string
|
||||
customer_homepage_screenshot_url: string
|
||||
customer_homepage_screenshot_thumbnail_url: string
|
||||
customer_homepage_screenshot_filename: string
|
||||
customer_homepage_screenshot_uploaded_at: string | null
|
||||
customer_game_id: string
|
||||
customer_game_role: string
|
||||
customer_server_zone: string
|
||||
@@ -559,6 +564,11 @@ export function mapTask(task: TaskRow) {
|
||||
customerGameRoleId: task.customer_game_id || '',
|
||||
customerGameRoleName: task.customer_game_role || '',
|
||||
customerServerZone: task.customer_server_zone || '',
|
||||
homepageScreenshotObjectKey: task.customer_homepage_screenshot_object_key || '',
|
||||
homepageScreenshotUrl: task.customer_homepage_screenshot_url || '',
|
||||
homepageScreenshotThumbnailUrl: task.customer_homepage_screenshot_thumbnail_url || '',
|
||||
homepageScreenshotFilename: task.customer_homepage_screenshot_filename || '',
|
||||
homepageScreenshotUploadedAt: task.customer_homepage_screenshot_uploaded_at || null,
|
||||
targetQuantity: Number(task.target_quantity || 1),
|
||||
completedQuantity: Number(task.completed_quantity || 0),
|
||||
assignedAdminUserId: task.assigned_admin_user_id ? Number(task.assigned_admin_user_id) : null,
|
||||
|
||||
@@ -118,6 +118,12 @@ export type SemiAutoTaskStatePatch = {
|
||||
customerGameRoleName?: string
|
||||
customerGameRoleId?: string
|
||||
customerGameServerZone?: string
|
||||
// 客户上传的游戏主页截图(客服核对绑定使用)
|
||||
customerHomepageScreenshotObjectKey?: string
|
||||
customerHomepageScreenshotUrl?: string
|
||||
customerHomepageScreenshotThumbnailUrl?: string
|
||||
customerHomepageScreenshotFilename?: string
|
||||
customerHomepageScreenshotUploadedAt?: SemiAutoTaskTimeValue
|
||||
// 登录时间
|
||||
authStartedAt?: SemiAutoTaskTimeValue
|
||||
authenticatedAt?: SemiAutoTaskTimeValue
|
||||
@@ -192,6 +198,23 @@ const PATCH_COLUMN_MAP: Record<string, PatchColumnMeta> = {
|
||||
customerGameRoleName: { column: 'customer_game_role_name', kind: 'value' },
|
||||
customerGameRoleId: { column: 'customer_game_role_id', kind: 'value' },
|
||||
customerGameServerZone: { column: 'customer_game_server_zone', kind: 'value' },
|
||||
customerHomepageScreenshotObjectKey: {
|
||||
column: 'customer_homepage_screenshot_object_key',
|
||||
kind: 'value',
|
||||
},
|
||||
customerHomepageScreenshotUrl: { column: 'customer_homepage_screenshot_url', kind: 'value' },
|
||||
customerHomepageScreenshotThumbnailUrl: {
|
||||
column: 'customer_homepage_screenshot_thumbnail_url',
|
||||
kind: 'value',
|
||||
},
|
||||
customerHomepageScreenshotFilename: {
|
||||
column: 'customer_homepage_screenshot_filename',
|
||||
kind: 'value',
|
||||
},
|
||||
customerHomepageScreenshotUploadedAt: {
|
||||
column: 'customer_homepage_screenshot_uploaded_at',
|
||||
kind: 'time',
|
||||
},
|
||||
authStartedAt: { column: 'auth_started_at', kind: 'time' },
|
||||
authenticatedAt: { column: 'authenticated_at', kind: 'time' },
|
||||
assignedAdminUserId: { column: 'assigned_admin_user_id', kind: 'value' },
|
||||
|
||||
@@ -18,6 +18,68 @@ async function expectErrorCode(fn: () => Promise<unknown>, errorCode: string) {
|
||||
})
|
||||
}
|
||||
|
||||
/** 1x1 PNG:集成测试只需要合法图片内容,不需要真实截图。 */
|
||||
const TEST_SCREENSHOT_PNG = Buffer.from(
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==',
|
||||
'base64',
|
||||
)
|
||||
|
||||
/**
|
||||
* 造一张合法的客户游戏主页截图资产。
|
||||
*
|
||||
* 优先走生产同一条 `uploadFileAsset`;集成测试环境没有对象存储时,退化为直接写同一张
|
||||
* `file_assets` 台账行——被测路径是资料保存时的台账归属校验,不是对象存储可用性。
|
||||
*/
|
||||
async function createHomepageScreenshotAsset(
|
||||
taskId: number,
|
||||
options: { uploaderId?: string } = {},
|
||||
) {
|
||||
const { createFileAsset } = await import('../../repositories/file-asset-repo.js')
|
||||
const { ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES, buildFileUrl, uploadFileAsset } =
|
||||
await import('../file-storage/file-storage-service.js')
|
||||
const uploaderId = options.uploaderId || `semi-auto-task-${taskId}`
|
||||
const file = {
|
||||
buffer: TEST_SCREENSHOT_PNG,
|
||||
mimetype: 'image/png',
|
||||
originalname: 'game-home.png',
|
||||
size: TEST_SCREENSHOT_PNG.length,
|
||||
} as Express.Multer.File
|
||||
try {
|
||||
const uploaded = await uploadFileAsset({
|
||||
file,
|
||||
scene: 'semi-auto-homepage-screenshot',
|
||||
uploaderType: 'semi-auto-customer',
|
||||
uploaderId,
|
||||
allowedContentTypes: ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES,
|
||||
})
|
||||
return uploaded.file.objectKey
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'[semi-auto integration] 对象存储不可用,改为直接写 file_assets 台账行',
|
||||
error instanceof Error ? error.message : error,
|
||||
)
|
||||
const objectKey = `semi-auto-homepage-screenshot/${randomUUID()}.png`
|
||||
const now = new Date().toISOString()
|
||||
await createFileAsset({
|
||||
objectKey,
|
||||
scene: 'semi-auto-homepage-screenshot',
|
||||
originalFilename: 'game-home.png',
|
||||
contentType: 'image/png',
|
||||
sizeBytes: TEST_SCREENSHOT_PNG.length,
|
||||
thumbnailObjectKey: '',
|
||||
mediumObjectKey: '',
|
||||
url: buildFileUrl(objectKey),
|
||||
thumbnailUrl: buildFileUrl(objectKey),
|
||||
mediumUrl: buildFileUrl(objectKey),
|
||||
uploaderType: 'semi-auto-customer',
|
||||
uploaderId,
|
||||
metadataJson: JSON.stringify({ source: 'integration-test' }),
|
||||
now,
|
||||
})
|
||||
return objectKey
|
||||
}
|
||||
}
|
||||
|
||||
test(
|
||||
'人工渠道半自动任务可由客户入口和后台列表幂等回填',
|
||||
{ skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false },
|
||||
@@ -125,12 +187,17 @@ test(
|
||||
|
||||
const taskId = Number(tasks[0]?.id || 0)
|
||||
// 客户页流程固定为「填写资料 → 登录 → 绑定角色」:资料可先保存,绑定仍要求登录。
|
||||
const homepageScreenshotObjectKey = await createHomepageScreenshotAsset(taskId)
|
||||
const savedProfile = await savePublicTaskProfile(orderNo, taskId, {
|
||||
roleName: '集成测试角色',
|
||||
roleId: '1192083858',
|
||||
serverZone: '安卓V区',
|
||||
homepageScreenshotObjectKey,
|
||||
})
|
||||
assert.equal(savedProfile.task.customerGameRoleName, '集成测试角色')
|
||||
assert.equal(savedProfile.task.homepageScreenshotFilename, 'game-home.png')
|
||||
assert.ok(savedProfile.task.homepageScreenshotUrl)
|
||||
assert.ok(savedProfile.task.homepageScreenshotUploadedAt)
|
||||
assert.equal(savedProfile.task.customerGameRoleId, '1192083858')
|
||||
assert.equal(savedProfile.task.customerServerZone, '安卓V区')
|
||||
await expectErrorCode(() => startPublicBinding(orderNo, taskId), 'semi_auto_login_required')
|
||||
@@ -1427,10 +1494,11 @@ test(
|
||||
)
|
||||
const saved = await savePublicTaskProfile(orderNo, result.taskId, {
|
||||
roleName: 'Mock虎牙角色',
|
||||
roleId: 'UID-not-number',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓V区',
|
||||
homepageScreenshotObjectKey: await createHomepageScreenshotAsset(result.taskId),
|
||||
})
|
||||
assert.equal(saved.task.customerGameRoleId, 'UID-not-number')
|
||||
assert.equal(saved.task.customerGameRoleId, '4212063544')
|
||||
assert.equal(saved.task.loginStatus, 'waiting_login')
|
||||
assert.equal(saved.task.displayStatus.label, '等待客户授权')
|
||||
|
||||
@@ -1459,7 +1527,7 @@ test(
|
||||
assert.equal(tasks[0]?.executionStatus, 'waiting_customer')
|
||||
assert.equal(tasks[0]?.displayStatus.label, '等待客户绑定角色')
|
||||
assert.equal(tasks[0]?.customerGameRoleName, 'Mock虎牙角色')
|
||||
assert.equal(tasks[0]?.customerGameRoleId, 'UID-not-number')
|
||||
assert.equal(tasks[0]?.customerGameRoleId, '4212063544')
|
||||
assert.equal(tasks[0]?.credentialSource, 'sms')
|
||||
assert.ok(tasks[0]?.huyaUid)
|
||||
assert.equal(tasks[0]?.platformNickname, 'Mock虎牙用户')
|
||||
@@ -1670,3 +1738,144 @@ test(
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
'虎牙客户资料必须带归属本人的游戏主页截图',
|
||||
{ skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false },
|
||||
async () => {
|
||||
process.env.DATABASE_URL = TEST_DATABASE_URL
|
||||
process.env.ENABLE_DEV_MOCK = '1'
|
||||
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 { savePublicTaskProfile } = await import('./semi-auto-task-service.js')
|
||||
const suffix = `${Date.now()}_${Math.floor(Math.random() * 1_000_000)}`
|
||||
const orderNo = `IT-HUYA-SCREENSHOT-${suffix}`
|
||||
let orderId = 0
|
||||
let configId = 0
|
||||
let taskId = 0
|
||||
try {
|
||||
const result = await createSemiAutoMock({
|
||||
orderNo,
|
||||
skuName: `虎牙主页截图-${suffix}`,
|
||||
quantity: 1,
|
||||
connectorMode: 'mock',
|
||||
})
|
||||
orderId = result.orderId
|
||||
configId = result.configId
|
||||
taskId = result.taskId
|
||||
|
||||
// 1. 合法截图资产 → 保存资料成功并落库。
|
||||
const objectKey = await createHomepageScreenshotAsset(taskId)
|
||||
const saved = await savePublicTaskProfile(orderNo, taskId, {
|
||||
roleName: '截图测试角色',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
homepageScreenshotObjectKey: objectKey,
|
||||
})
|
||||
assert.equal(saved.task.customerGameRoleName, '截图测试角色')
|
||||
assert.equal(saved.task.customerGameRoleId, '4212063544')
|
||||
assert.equal(saved.task.customerServerZone, '安卓Q区')
|
||||
assert.ok(saved.task.homepageScreenshotUrl)
|
||||
assert.ok(saved.task.homepageScreenshotThumbnailUrl)
|
||||
assert.equal(saved.task.homepageScreenshotFilename, 'game-home.png')
|
||||
assert.ok(saved.task.homepageScreenshotUploadedAt)
|
||||
|
||||
const stored = await query<{
|
||||
object_key: string
|
||||
url: string
|
||||
thumbnail_url: string
|
||||
filename: string
|
||||
uploaded_at: string | null
|
||||
}>(
|
||||
`SELECT customer_homepage_screenshot_object_key AS object_key,
|
||||
customer_homepage_screenshot_url AS url,
|
||||
customer_homepage_screenshot_thumbnail_url AS thumbnail_url,
|
||||
customer_homepage_screenshot_filename AS filename,
|
||||
customer_homepage_screenshot_uploaded_at AS uploaded_at
|
||||
FROM semi_auto_tasks
|
||||
WHERE id = $1`,
|
||||
[taskId],
|
||||
)
|
||||
assert.equal(stored.rows[0]?.object_key, objectKey)
|
||||
assert.ok(stored.rows[0]?.url)
|
||||
assert.ok(stored.rows[0]?.thumbnail_url)
|
||||
assert.equal(stored.rows[0]?.filename, 'game-home.png')
|
||||
assert.ok(stored.rows[0]?.uploaded_at)
|
||||
|
||||
const event = await query<{ detail_json: { homepageScreenshotObjectKey?: string } }>(
|
||||
`SELECT detail_json
|
||||
FROM semi_auto_task_events
|
||||
WHERE task_id = $1 AND event_type = 'customer_profile_saved'
|
||||
ORDER BY id DESC
|
||||
LIMIT 1`,
|
||||
[taskId],
|
||||
)
|
||||
assert.equal(event.rows[0]?.detail_json?.homepageScreenshotObjectKey, objectKey)
|
||||
|
||||
// 2. 缺少截图 → 明确要求先上传。
|
||||
await expectErrorCode(
|
||||
() =>
|
||||
savePublicTaskProfile(orderNo, taskId, {
|
||||
roleName: '截图测试角色',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
}),
|
||||
'semi_auto_homepage_screenshot_required',
|
||||
)
|
||||
|
||||
// 3. 截图属于其它任务 → 归属校验失败。
|
||||
const foreignObjectKey = await createHomepageScreenshotAsset(taskId, {
|
||||
uploaderId: `semi-auto-task-${taskId + 999_999}`,
|
||||
})
|
||||
await expectErrorCode(
|
||||
() =>
|
||||
savePublicTaskProfile(orderNo, taskId, {
|
||||
roleName: '截图测试角色',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
homepageScreenshotObjectKey: foreignObjectKey,
|
||||
}),
|
||||
'semi_auto_homepage_screenshot_invalid',
|
||||
)
|
||||
|
||||
// 4. 游戏角色 UID 非纯数字 → 资料校验失败。
|
||||
await expectErrorCode(
|
||||
() =>
|
||||
savePublicTaskProfile(orderNo, taskId, {
|
||||
roleName: '截图测试角色',
|
||||
roleId: 'UID-not-number',
|
||||
serverZone: '安卓Q区',
|
||||
homepageScreenshotObjectKey: objectKey,
|
||||
}),
|
||||
'semi_auto_profile_role_id_invalid',
|
||||
)
|
||||
|
||||
// 5. 角色名混入 UID / 区服 → 资料校验失败。
|
||||
await expectErrorCode(
|
||||
() =>
|
||||
savePublicTaskProfile(orderNo, taskId, {
|
||||
roleName: '截图测试角色 4212063544',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
homepageScreenshotObjectKey: objectKey,
|
||||
}),
|
||||
'semi_auto_profile_role_name_invalid',
|
||||
)
|
||||
} finally {
|
||||
if (taskId > 0) {
|
||||
await query('DELETE FROM file_assets WHERE uploader_id = $1', [`semi-auto-task-${taskId}`])
|
||||
await query('DELETE FROM file_assets WHERE uploader_id = $1', [
|
||||
`semi-auto-task-${taskId + 999_999}`,
|
||||
])
|
||||
}
|
||||
if (orderId > 0) await query('DELETE FROM orders WHERE id = $1', [orderId])
|
||||
if (configId > 0) {
|
||||
await query('DELETE FROM manual_fulfillment_configs WHERE id = $1', [configId])
|
||||
}
|
||||
resetMockSessions()
|
||||
delete process.env.ENABLE_DEV_MOCK
|
||||
await closeDb()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -11,6 +11,7 @@ import QRCode from 'qrcode'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
||||
import { useLocation, useNavigate, useParams } from 'react-router'
|
||||
|
||||
import ImageUpload from '@/components/files/ImageUpload'
|
||||
import {
|
||||
confirmCustomerBinding,
|
||||
fetchCustomerFulfillment,
|
||||
@@ -28,6 +29,7 @@ import {
|
||||
startCustomerLogin,
|
||||
startCustomerWeiboQrLogin,
|
||||
submitCustomerRebind,
|
||||
uploadCustomerTaskHomepageScreenshot,
|
||||
verifyCustomerHuyaSmsChallenge,
|
||||
type CustomerHuyaChallengeSolution,
|
||||
type CustomerHuyaSmsChallenge,
|
||||
@@ -37,12 +39,20 @@ import type {
|
||||
CustomerLoginInfo,
|
||||
CustomerSemiAutoTask,
|
||||
} from '@/types/customer-fulfillment'
|
||||
import type { UploadedFile } from '@/types/worker-platform'
|
||||
import { formatAdminDateTime } from '@/utils/admin-time'
|
||||
import {
|
||||
CUSTOMER_SERVER_ZONE_OPTIONS,
|
||||
GAME_ROLE_ID_PLACEHOLDER,
|
||||
getGameRoleIdIssue,
|
||||
validateCustomerProfileSubmit,
|
||||
} from '@/utils/customer-fulfillment-profile'
|
||||
import {
|
||||
buildCustomerFulfillmentPath,
|
||||
resolveCustomerPlatformRedirect,
|
||||
type CustomerFulfillmentPlatform,
|
||||
} from '@/utils/customer-fulfillment-link'
|
||||
import { GAME_ROLE_NAME_FORMAT_HINT, getGameRoleNameIssue } from '@/utils/game-role-name'
|
||||
import { formatHuyaBindingDecisionMessage } from '@/utils/semi-auto-binding-decision'
|
||||
import { runWeiboYidunChallenge } from '@/utils/weibo-yidun'
|
||||
import HuyaChallengeModal from './HuyaChallengeModal'
|
||||
@@ -51,7 +61,7 @@ const POLL_INTERVAL_MS = 2000
|
||||
// 刷新绑定二维码的冷却时间:避免连续点击频繁请求虎牙。
|
||||
const BINDING_REFRESH_COOLDOWN_MS = 3_000
|
||||
|
||||
const SERVER_ZONE_OPTIONS = ['苹果Q区', '苹果V区', '安卓Q区', '安卓V区']
|
||||
const SERVER_ZONE_OPTIONS = CUSTOMER_SERVER_ZONE_OPTIONS
|
||||
|
||||
/** antd v6 语义化 classNames:让区服下拉弹层用页面深色样式 */
|
||||
const SERVER_ZONE_SELECT_CLASS_NAMES = { popup: { root: 'customer-collect-dropdown' } }
|
||||
@@ -88,6 +98,7 @@ export default function CustomerFulfillmentPage({
|
||||
const [profileRoleName, setProfileRoleName] = useState('')
|
||||
const [profileRoleId, setProfileRoleId] = useState('')
|
||||
const [profileServerZone, setProfileServerZone] = useState('')
|
||||
const [profileHomepageScreenshot, setProfileHomepageScreenshot] = useState<UploadedFile[]>([])
|
||||
const [profileSaving, setProfileSaving] = useState(false)
|
||||
const [profileEditing, setProfileEditing] = useState(false)
|
||||
const startingBindingRef = useRef(false)
|
||||
@@ -115,13 +126,19 @@ export default function CustomerFulfillmentPage({
|
||||
),
|
||||
)
|
||||
const isWeibo = selectedTask?.platform === 'weibo'
|
||||
// 虎牙流程:填写资料(区服/UID/角色名)→ 登录 → 绑定角色。
|
||||
// 资料齐全前不生成绑定二维码,避免客户在资料缺失时先绑错角色。
|
||||
// 虎牙流程:填写资料 → 登录 → 绑定角色。
|
||||
// 这里只判断**已保存**的三要素:截图是保存时的必填项(后端强校验),
|
||||
// 但不能拿它当「资料已完成」的门禁,否则本次改造前已填好资料的老任务会被卡回第一步。
|
||||
const profileComplete = Boolean(
|
||||
String(selectedTask?.customerServerZone || '').trim() &&
|
||||
String(selectedTask?.customerGameRoleId || '').trim() &&
|
||||
String(selectedTask?.customerGameRoleName || '').trim(),
|
||||
)
|
||||
const profileRoleIdIssue = useMemo(() => getGameRoleIdIssue(profileRoleId), [profileRoleId])
|
||||
const profileRoleNameIssue = useMemo(
|
||||
() => getGameRoleNameIssue(profileRoleName),
|
||||
[profileRoleName],
|
||||
)
|
||||
|
||||
const load = useCallback(
|
||||
async (silent = false) => {
|
||||
@@ -242,12 +259,31 @@ export default function CustomerFulfillmentPage({
|
||||
setProfileRoleName(selectedTask.customerGameRoleName || '')
|
||||
setProfileRoleId(selectedTask.customerGameRoleId || '')
|
||||
setProfileServerZone(selectedTask.customerServerZone || '')
|
||||
setProfileHomepageScreenshot(
|
||||
String(selectedTask.homepageScreenshotUrl || '').trim()
|
||||
? [
|
||||
{
|
||||
objectKey: selectedTask.homepageScreenshotObjectKey || '',
|
||||
url: selectedTask.homepageScreenshotUrl,
|
||||
thumbnailUrl:
|
||||
selectedTask.homepageScreenshotThumbnailUrl || selectedTask.homepageScreenshotUrl,
|
||||
mediumUrl: selectedTask.homepageScreenshotUrl,
|
||||
filename: selectedTask.homepageScreenshotFilename || '',
|
||||
contentType: '',
|
||||
size: 0,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
)
|
||||
setProfileEditing(false)
|
||||
}, [
|
||||
selectedTask?.id,
|
||||
selectedTask?.customerGameRoleName,
|
||||
selectedTask?.customerGameRoleId,
|
||||
selectedTask?.customerServerZone,
|
||||
selectedTask?.homepageScreenshotUrl,
|
||||
selectedTask?.homepageScreenshotThumbnailUrl,
|
||||
selectedTask?.homepageScreenshotFilename,
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
@@ -896,12 +932,15 @@ export default function CustomerFulfillmentPage({
|
||||
|
||||
async function handleSaveProfile() {
|
||||
if (!selectedTask) return
|
||||
if (!profileServerZone.trim() || !profileRoleId.trim() || !profileRoleName.trim()) {
|
||||
message.warning('请完整填写区服、游戏角色 UID 和角色名')
|
||||
return
|
||||
}
|
||||
if (!SERVER_ZONE_OPTIONS.includes(profileServerZone.trim())) {
|
||||
message.warning('请选择区服')
|
||||
const homepageScreenshotObjectKey = String(profileHomepageScreenshot[0]?.objectKey || '').trim()
|
||||
const issue = validateCustomerProfileSubmit({
|
||||
serverZone: profileServerZone,
|
||||
roleId: profileRoleId,
|
||||
roleName: profileRoleName,
|
||||
homepageScreenshotObjectKey,
|
||||
})
|
||||
if (issue) {
|
||||
message.warning(issue.message)
|
||||
return
|
||||
}
|
||||
setProfileSaving(true)
|
||||
@@ -910,6 +949,7 @@ export default function CustomerFulfillmentPage({
|
||||
roleName: profileRoleName.trim(),
|
||||
roleId: profileRoleId.trim(),
|
||||
serverZone: profileServerZone.trim(),
|
||||
homepageScreenshotObjectKey,
|
||||
})
|
||||
setTasks((current) =>
|
||||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||||
@@ -1174,7 +1214,7 @@ export default function CustomerFulfillmentPage({
|
||||
<p>
|
||||
{profileComplete
|
||||
? '修改资料后会重新核对平台角色;角色名、区服和平台信息一致后才能确认绑定。'
|
||||
: '第一步:请填写区服、游戏角色 UID 和角色名。UID 只做资料留档,不参与绑定核验。'}
|
||||
: '第一步:请填写区服、游戏角色 UID、角色名和游戏主页截图。UID 只做资料留档,不参与绑定核验。'}
|
||||
</p>
|
||||
<div className="customer-profile-form">
|
||||
<label className="customer-collect-label">
|
||||
@@ -1192,23 +1232,79 @@ export default function CustomerFulfillmentPage({
|
||||
游戏角色 UID <span>*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="customer-collect-input"
|
||||
className={`customer-collect-input${profileRoleIdIssue ? ' is-warning' : ''}`}
|
||||
value={profileRoleId}
|
||||
onChange={(event) => setProfileRoleId(event.target.value)}
|
||||
placeholder="请输入游戏角色 UID,仅作资料留档"
|
||||
maxLength={64}
|
||||
onChange={(event) => setProfileRoleId(event.target.value.replace(/\D/g, ''))}
|
||||
placeholder={GAME_ROLE_ID_PLACEHOLDER}
|
||||
maxLength={20}
|
||||
inputMode="numeric"
|
||||
aria-invalid={Boolean(profileRoleIdIssue)}
|
||||
aria-describedby="customer-profile-role-id-help"
|
||||
/>
|
||||
<p
|
||||
id="customer-profile-role-id-help"
|
||||
className={`customer-field-help${profileRoleIdIssue ? ' is-error' : ''}`}
|
||||
aria-live="polite"
|
||||
>
|
||||
{profileRoleIdIssue ? <ExclamationCircleOutlined aria-hidden="true" /> : null}
|
||||
<span>{profileRoleIdIssue || '只能填写数字,例如 4212063544'}</span>
|
||||
</p>
|
||||
<label className="customer-collect-label">
|
||||
角色名 <span>*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="customer-collect-input"
|
||||
className={`customer-collect-input${profileRoleNameIssue ? ' is-warning' : ''}`}
|
||||
value={profileRoleName}
|
||||
onChange={(event) => setProfileRoleName(event.target.value)}
|
||||
placeholder="请输入角色名"
|
||||
maxLength={100}
|
||||
aria-invalid={Boolean(profileRoleNameIssue)}
|
||||
aria-describedby="customer-profile-role-name-help"
|
||||
/>
|
||||
<p
|
||||
id="customer-profile-role-name-help"
|
||||
className={`customer-field-help${profileRoleNameIssue ? ' is-warning' : ''}`}
|
||||
aria-live="polite"
|
||||
>
|
||||
{profileRoleNameIssue ? <ExclamationCircleOutlined aria-hidden="true" /> : null}
|
||||
<span>{profileRoleNameIssue || GAME_ROLE_NAME_FORMAT_HINT}</span>
|
||||
</p>
|
||||
<label className="customer-collect-label">
|
||||
游戏主页截图 <span>*</span>
|
||||
</label>
|
||||
<div className="customer-douyu-screenshot-row">
|
||||
<div className="customer-douyu-screenshot-upload">
|
||||
<ImageUpload
|
||||
scene="semi-auto-homepage-screenshot"
|
||||
scope="collect"
|
||||
maxCount={1}
|
||||
showPasteHint
|
||||
value={profileHomepageScreenshot}
|
||||
onChange={setProfileHomepageScreenshot}
|
||||
uploader={async (file) => {
|
||||
const response = await uploadCustomerTaskHomepageScreenshot(
|
||||
orderNo,
|
||||
selectedTask?.id || 0,
|
||||
file,
|
||||
)
|
||||
return response.data.file
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="customer-douyu-screenshot-example">
|
||||
<Image
|
||||
src="/images/game-home-example.webp"
|
||||
alt="游戏主页截图示例"
|
||||
width={150}
|
||||
height={140}
|
||||
style={{ objectFit: 'cover', borderRadius: 8, border: '1px solid #334155' }}
|
||||
/>
|
||||
<span>示例:需能看到游戏名字和游戏 UID</span>
|
||||
</div>
|
||||
</div>
|
||||
<p className="customer-field-help">
|
||||
请上传游戏主页截图,需能看到游戏名字/昵称和游戏 UID(编号);用于客服核对绑定是否正确。
|
||||
</p>
|
||||
<Button
|
||||
block
|
||||
size="large"
|
||||
|
||||
@@ -26,7 +26,7 @@ import type {
|
||||
DouyuCustomerSystem,
|
||||
} from '@/types/douyu-fulfillment'
|
||||
import { formatAdminDateTime } from '@/utils/admin-time'
|
||||
import { DOUYU_ROLE_NAME_FORMAT_HINT, getDouyuRoleNameIssue } from '@/utils/douyu-role-name'
|
||||
import { GAME_ROLE_NAME_FORMAT_HINT, getGameRoleNameIssue } from '@/utils/game-role-name'
|
||||
import { useRealtimeEvents } from '@/hooks/useRealtimeEvents'
|
||||
|
||||
const BINDING_FAILURE_ISSUES = new Set([
|
||||
@@ -85,7 +85,7 @@ export default function DouyuFulfillmentPage() {
|
||||
const [bindingQrExpanded, setBindingQrExpanded] = useState(false)
|
||||
const [nowMs, setNowMs] = useState(() => Date.now())
|
||||
const customerRoleRef = useRef('')
|
||||
const roleNameIssue = useMemo(() => getDouyuRoleNameIssue(roleName), [roleName])
|
||||
const roleNameIssue = useMemo(() => getGameRoleNameIssue(roleName), [roleName])
|
||||
|
||||
const applyData = useCallback((next: DouyuCustomerFulfillment) => {
|
||||
const previousRole = customerRoleRef.current
|
||||
@@ -426,7 +426,7 @@ export default function DouyuFulfillmentPage() {
|
||||
aria-live="polite"
|
||||
>
|
||||
{roleNameIssue ? <ExclamationCircleOutlined aria-hidden="true" /> : null}
|
||||
<span>{roleNameIssue || DOUYU_ROLE_NAME_FORMAT_HINT}</span>
|
||||
<span>{roleNameIssue || GAME_ROLE_NAME_FORMAT_HINT}</span>
|
||||
</p>
|
||||
<label className="customer-collect-label">游戏主页截图(必填)</label>
|
||||
<div className="customer-douyu-screenshot-row">
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { apiGet, apiPost } from '@/lib/http'
|
||||
import { apiGet, apiPost, apiPostForm } from '@/lib/http'
|
||||
import { optimizeImageForUpload } from '@/utils/image-upload'
|
||||
import type { UploadedFile } from '@/types/worker-platform'
|
||||
import type {
|
||||
CustomerBindingInfo,
|
||||
CustomerLoginInfo,
|
||||
@@ -21,7 +23,12 @@ export function markCustomerFulfillmentOpened(orderNo: string, taskId: number) {
|
||||
export function saveCustomerTaskProfile(
|
||||
orderNo: string,
|
||||
taskId: number,
|
||||
input: { roleName: string; roleId: string; serverZone: string },
|
||||
input: {
|
||||
roleName: string
|
||||
roleId: string
|
||||
serverZone: string
|
||||
homepageScreenshotObjectKey: string
|
||||
},
|
||||
) {
|
||||
return apiPost<{ task: CustomerSemiAutoTask }>(
|
||||
`/api/v1/customer-fulfillment/${encodeURIComponent(orderNo)}/tasks/${taskId}/profile`,
|
||||
@@ -29,6 +36,21 @@ export function saveCustomerTaskProfile(
|
||||
)
|
||||
}
|
||||
|
||||
/** 客户游戏主页截图:与斗鱼一致,先压缩再上传,服务端按任务归属校验。 */
|
||||
export async function uploadCustomerTaskHomepageScreenshot(
|
||||
orderNo: string,
|
||||
taskId: number,
|
||||
file: File,
|
||||
) {
|
||||
const optimized = await optimizeImageForUpload(file, 'semi-auto-homepage-screenshot')
|
||||
const form = new FormData()
|
||||
form.append('file', optimized)
|
||||
return apiPostForm<{ file: UploadedFile }>(
|
||||
`/api/v1/customer-fulfillment/${encodeURIComponent(orderNo)}/tasks/${taskId}/homepage-screenshot`,
|
||||
form,
|
||||
)
|
||||
}
|
||||
|
||||
export function startCustomerLogin(orderNo: string, taskId: number) {
|
||||
return apiPost<{ task: CustomerSemiAutoTask; login: CustomerLoginInfo }>(
|
||||
`/api/v1/customer-fulfillment/${encodeURIComponent(orderNo)}/tasks/${taskId}/login/start`,
|
||||
|
||||
@@ -232,3 +232,28 @@
|
||||
border-color: #1d4ed8 !important;
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
/* 客户资料字段提示:虎牙资料表单与斗鱼共用同一套提示位置和配色。 */
|
||||
.customer-field-help {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
margin: -4px 2px 0;
|
||||
color: #94a3b8;
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.customer-field-help .anticon {
|
||||
flex: 0 0 auto;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
/* 格式不合法(例如 UID 非纯数字)用红字,混入资料用警示色。 */
|
||||
.customer-field-help.is-error {
|
||||
color: #f87171;
|
||||
}
|
||||
|
||||
.customer-field-help.is-warning {
|
||||
color: #fbbf24;
|
||||
}
|
||||
|
||||
@@ -58,6 +58,13 @@ export type CustomerSemiAutoTask = {
|
||||
customerGameRoleId: string
|
||||
customerGameRoleName: string
|
||||
customerServerZone: string
|
||||
/** 客户上传的游戏主页截图(客服核对绑定使用);未上传时为空串。 */
|
||||
/** 已上传截图的存储 key;改资料时原样回传,后端不再解析 URL。 */
|
||||
homepageScreenshotObjectKey: string
|
||||
homepageScreenshotUrl: string
|
||||
homepageScreenshotThumbnailUrl: string
|
||||
homepageScreenshotFilename: string
|
||||
homepageScreenshotUploadedAt: string | null
|
||||
completedAt: string | null
|
||||
completionNote: string
|
||||
semiAutoConfig: {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { getGameRoleNameIssue, isValidGameRoleId } from './game-role-name.ts'
|
||||
|
||||
/** 虎牙客户资料区服枚举,与后端 `normalizeCustomerProfile` 的集合一致。 */
|
||||
export const CUSTOMER_SERVER_ZONE_OPTIONS = ['苹果Q区', '苹果V区', '安卓Q区', '安卓V区'] as const
|
||||
|
||||
/** 游戏角色 UID 输入框提示,与后端 `semi_auto_profile_role_id_invalid` 口径一致。 */
|
||||
export const GAME_ROLE_ID_PLACEHOLDER = '请输入游戏角色 UID,纯数字uid'
|
||||
export const GAME_ROLE_ID_INVALID_HINT = '游戏角色 UID 只能填写纯数字(1-20 位)'
|
||||
|
||||
/** 输入过程中的实时提示:为空不提示(提交时再统一拦截)。 */
|
||||
export function getGameRoleIdIssue(value: string): string | null {
|
||||
const roleId = String(value ?? '').trim()
|
||||
if (!roleId) return null
|
||||
return isValidGameRoleId(roleId) ? null : GAME_ROLE_ID_INVALID_HINT
|
||||
}
|
||||
|
||||
export type CustomerProfileSubmitField = 'serverZone' | 'roleId' | 'roleName' | 'homepageScreenshot'
|
||||
|
||||
export type CustomerProfileSubmitIssue = {
|
||||
field: CustomerProfileSubmitField
|
||||
message: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户提交虎牙资料前的纯函数校验,顺序与后端 `normalizeCustomerProfile` / `savePublicTaskProfile` 一致:
|
||||
* 必填 → 区服枚举 → UID 纯数字 → 角色名不混入 UID/区服/登录方式 → 主页截图必填。
|
||||
*/
|
||||
export function validateCustomerProfileSubmit(input: {
|
||||
serverZone: string
|
||||
roleId: string
|
||||
roleName: string
|
||||
homepageScreenshotObjectKey: string
|
||||
}): CustomerProfileSubmitIssue | null {
|
||||
const serverZone = String(input.serverZone ?? '').trim()
|
||||
const roleId = String(input.roleId ?? '').trim()
|
||||
const roleName = String(input.roleName ?? '').trim()
|
||||
const homepageScreenshotObjectKey = String(input.homepageScreenshotObjectKey ?? '').trim()
|
||||
|
||||
if (!serverZone || !roleId || !roleName) {
|
||||
return {
|
||||
field: !serverZone ? 'serverZone' : !roleId ? 'roleId' : 'roleName',
|
||||
message: '请完整填写区服、游戏角色 UID 和角色名',
|
||||
}
|
||||
}
|
||||
if (!(CUSTOMER_SERVER_ZONE_OPTIONS as readonly string[]).includes(serverZone)) {
|
||||
return { field: 'serverZone', message: '请选择区服' }
|
||||
}
|
||||
if (!isValidGameRoleId(roleId)) {
|
||||
return { field: 'roleId', message: GAME_ROLE_ID_INVALID_HINT }
|
||||
}
|
||||
const roleNameIssue = getGameRoleNameIssue(roleName)
|
||||
if (roleNameIssue) {
|
||||
return { field: 'roleName', message: roleNameIssue }
|
||||
}
|
||||
if (!homepageScreenshotObjectKey) {
|
||||
return { field: 'homepageScreenshot', message: '请上传游戏主页截图' }
|
||||
}
|
||||
return null
|
||||
}
|
||||
+22
-4
@@ -1,7 +1,7 @@
|
||||
export const DOUYU_ROLE_NAME_FORMAT_HINT =
|
||||
export const GAME_ROLE_NAME_FORMAT_HINT =
|
||||
'只填写游戏角色名,不要填写 UID、区服或微信/QQ;登录方式和设备系统请在上方选择。'
|
||||
|
||||
export const DOUYU_ROLE_NAME_MIXED_WARNING =
|
||||
export const GAME_ROLE_NAME_MIXED_WARNING =
|
||||
'这里只能填写游戏角色名。检测到 UID、区服或登录方式,请只保留角色名称,例如“花乔妖精”。'
|
||||
|
||||
const ROLE_NAME_SEPARATOR = /[\s,,、|/\\·::;;_-]+/u
|
||||
@@ -9,7 +9,11 @@ const STANDALONE_UID = /^\d{6,}$/u
|
||||
const LONG_NUMBER = /\d{8,}/u
|
||||
const STANDALONE_LOGIN_OR_SYSTEM = /^(?:安卓区?|苹果区?|ios|android|微信|qq|q区|v区|手q)$/iu
|
||||
|
||||
export function getDouyuRoleNameIssue(value: string): string | null {
|
||||
/** 游戏角色 UID 只接受 1..20 位纯数字,与后端校验保持一致。 */
|
||||
export const GAME_ROLE_ID_MAX_LENGTH = 20
|
||||
const GAME_ROLE_ID_PATTERN = /^\d+$/u
|
||||
|
||||
export function getGameRoleNameIssue(value: string): string | null {
|
||||
const roleName = String(value ?? '').trim()
|
||||
if (!roleName) return null
|
||||
|
||||
@@ -19,6 +23,20 @@ export function getDouyuRoleNameIssue(value: string): string | null {
|
||||
const hasStandaloneLoginOrSystem = tokens.some((token) => STANDALONE_LOGIN_OR_SYSTEM.test(token))
|
||||
|
||||
return hasStandaloneUid || hasLongNumber || hasStandaloneLoginOrSystem
|
||||
? DOUYU_ROLE_NAME_MIXED_WARNING
|
||||
? GAME_ROLE_NAME_MIXED_WARNING
|
||||
: null
|
||||
}
|
||||
|
||||
export function isValidGameRoleId(value: string) {
|
||||
const roleId = String(value ?? '').trim()
|
||||
return (
|
||||
roleId.length > 0 &&
|
||||
roleId.length <= GAME_ROLE_ID_MAX_LENGTH &&
|
||||
GAME_ROLE_ID_PATTERN.test(roleId)
|
||||
)
|
||||
}
|
||||
|
||||
/** 输入框只保留数字,避免把字母/空格带进 UID。 */
|
||||
export function sanitizeGameRoleIdInput(value: string) {
|
||||
return String(value ?? '').replace(/\D/g, '')
|
||||
}
|
||||
@@ -53,18 +53,22 @@ test('虎牙客户页固定先填写资料,再登录并绑定角色', () => {
|
||||
assert.ok(source.includes('(isWeibo || profileComplete) &&'))
|
||||
})
|
||||
|
||||
test('资料完整要求区服、角色名和 UID,但 UID 不做格式校验', () => {
|
||||
test('资料完整只判断已保存的三要素,截图由提交校验强制', () => {
|
||||
const profileStart = source.indexOf('const profileComplete = Boolean(')
|
||||
const profileEnd = source.indexOf('\n\n const load =', profileStart)
|
||||
const profileSource = source.slice(profileStart, profileEnd)
|
||||
assert.ok(profileSource.includes('customerServerZone'))
|
||||
assert.ok(profileSource.includes('customerGameRoleId'))
|
||||
assert.ok(profileSource.includes('customerGameRoleName'))
|
||||
assert.ok(source.includes('请完整填写区服、游戏角色 UID 和角色名'))
|
||||
// 截图是保存时的必填项,但不能当「资料已完成」门禁,否则老任务会被卡回第一步。
|
||||
assert.ok(!profileSource.includes('homepageScreenshotUrl'))
|
||||
// 必填与格式校验统一收敛到纯函数,页面只负责展示提示。
|
||||
assert.ok(source.includes('validateCustomerProfileSubmit({'))
|
||||
assert.ok(source.includes('UID 只做资料留档,不参与绑定核验'))
|
||||
assert.ok(source.includes('游戏角色 UID <span>*</span>'))
|
||||
assert.ok(!source.includes('游戏角色 UID 只能是数字'))
|
||||
assert.ok(!source.includes('!/^\\d+$/.test(profileRoleId.trim())'))
|
||||
assert.ok(source.includes('游戏主页截图 <span>*</span>'))
|
||||
assert.ok(source.includes("event.target.value.replace(/\\D/g, '')"))
|
||||
assert.ok(source.includes('maxLength={20}'))
|
||||
})
|
||||
|
||||
test('登录和绑定专用同步阶段暂停整单轮询', () => {
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
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'
|
||||
|
||||
import {
|
||||
GAME_ROLE_ID_INVALID_HINT,
|
||||
GAME_ROLE_ID_PLACEHOLDER,
|
||||
getGameRoleIdIssue,
|
||||
validateCustomerProfileSubmit,
|
||||
} from '../src/utils/customer-fulfillment-profile.ts'
|
||||
import { GAME_ROLE_NAME_MIXED_WARNING } from '../src/utils/game-role-name.ts'
|
||||
|
||||
const root = dirname(fileURLToPath(import.meta.url))
|
||||
const page = readFileSync(
|
||||
join(root, '../src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx'),
|
||||
'utf8',
|
||||
)
|
||||
|
||||
const validProfile = {
|
||||
serverZone: '安卓Q区',
|
||||
roleId: '4212063544',
|
||||
roleName: '花乔妖精',
|
||||
homepageScreenshotObjectKey: 'semi-auto-homepage-screenshot/2026/11/a.png',
|
||||
}
|
||||
|
||||
test('资料完整时允许提交', () => {
|
||||
assert.equal(validateCustomerProfileSubmit(validProfile), null)
|
||||
})
|
||||
|
||||
test('必填项缺失时提示完整填写', () => {
|
||||
assert.equal(
|
||||
validateCustomerProfileSubmit({ ...validProfile, serverZone: '' })?.message,
|
||||
'请完整填写区服、游戏角色 UID 和角色名',
|
||||
)
|
||||
assert.equal(validateCustomerProfileSubmit({ ...validProfile, roleId: '' })?.field, 'roleId')
|
||||
assert.equal(
|
||||
validateCustomerProfileSubmit({ ...validProfile, roleName: ' ' })?.field,
|
||||
'roleName',
|
||||
)
|
||||
})
|
||||
|
||||
test('游戏角色 UID 必须是纯数字,且不超过 20 位', () => {
|
||||
assert.deepEqual(validateCustomerProfileSubmit({ ...validProfile, roleId: 'uid-not-number' }), {
|
||||
field: 'roleId',
|
||||
message: GAME_ROLE_ID_INVALID_HINT,
|
||||
})
|
||||
assert.deepEqual(
|
||||
validateCustomerProfileSubmit({
|
||||
...validProfile,
|
||||
roleId: '123456789012345678901',
|
||||
}),
|
||||
{ field: 'roleId', message: GAME_ROLE_ID_INVALID_HINT },
|
||||
)
|
||||
assert.equal(getGameRoleIdIssue('4212063544'), null)
|
||||
assert.equal(getGameRoleIdIssue('4212063544a'), GAME_ROLE_ID_INVALID_HINT)
|
||||
assert.equal(getGameRoleIdIssue(''), null)
|
||||
})
|
||||
|
||||
test('角色名混入 UID、区服或登录方式时阻止提交', () => {
|
||||
assert.deepEqual(
|
||||
validateCustomerProfileSubmit({ ...validProfile, roleName: '花乔妖精 4212063544' }),
|
||||
{ field: 'roleName', message: GAME_ROLE_NAME_MIXED_WARNING },
|
||||
)
|
||||
assert.deepEqual(
|
||||
validateCustomerProfileSubmit({ ...validProfile, roleName: '花乔妖精 安卓区' }),
|
||||
{ field: 'roleName', message: GAME_ROLE_NAME_MIXED_WARNING },
|
||||
)
|
||||
})
|
||||
|
||||
test('未上传游戏主页截图时阻止提交', () => {
|
||||
assert.deepEqual(
|
||||
validateCustomerProfileSubmit({ ...validProfile, homepageScreenshotObjectKey: '' }),
|
||||
{ field: 'homepageScreenshot', message: '请上传游戏主页截图' },
|
||||
)
|
||||
})
|
||||
|
||||
test('虎牙资料表单按斗鱼同款接入 UID 与主页截图', () => {
|
||||
assert.equal(GAME_ROLE_ID_PLACEHOLDER, '请输入游戏角色 UID,纯数字uid')
|
||||
assert.ok(page.includes('placeholder={GAME_ROLE_ID_PLACEHOLDER}'))
|
||||
assert.ok(page.includes("event.target.value.replace(/\\D/g, '')"))
|
||||
assert.ok(page.includes('maxLength={20}'))
|
||||
assert.ok(page.includes('{profileRoleIdIssue || '))
|
||||
assert.ok(page.includes('{profileRoleNameIssue || GAME_ROLE_NAME_FORMAT_HINT}'))
|
||||
assert.ok(page.includes('scene="semi-auto-homepage-screenshot"'))
|
||||
assert.ok(page.includes('src="/images/game-home-example.webp"'))
|
||||
assert.ok(page.includes('示例:需能看到游戏名字和游戏 UID'))
|
||||
assert.ok(page.includes('用于客服核对绑定是否正确'))
|
||||
assert.ok(page.includes('uploadCustomerTaskHomepageScreenshot'))
|
||||
assert.ok(page.includes('const issue = validateCustomerProfileSubmit({'))
|
||||
})
|
||||
@@ -39,7 +39,7 @@ test('取消直接使用原角色的快捷确认路径', () => {
|
||||
test('点击上一步修改资料会回到第一步并隐藏绑定区', () => {
|
||||
// 步骤条把编辑资料视为第一步,即使资料原本已完整。
|
||||
assert.ok(source.includes('profileEditing || !profileComplete'))
|
||||
assert.ok(source.includes("'第一步:请填写区服、游戏角色 UID 和角色名"))
|
||||
assert.ok(source.includes("'第一步:请填写区服、游戏角色 UID、角色名和游戏主页截图"))
|
||||
assert.ok(source.includes('返回绑定角色'))
|
||||
// 资料步骤隐藏二维码、失败提示和比对操作,避免与第二步混在一起。
|
||||
assert.ok(source.includes('!profileEditing'))
|
||||
|
||||
@@ -5,9 +5,10 @@ import { fileURLToPath } from 'node:url'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
DOUYU_ROLE_NAME_MIXED_WARNING,
|
||||
getDouyuRoleNameIssue,
|
||||
} from '../src/utils/douyu-role-name.ts'
|
||||
GAME_ROLE_NAME_FORMAT_HINT,
|
||||
GAME_ROLE_NAME_MIXED_WARNING,
|
||||
getGameRoleNameIssue,
|
||||
} from '../src/utils/game-role-name.ts'
|
||||
|
||||
const root = dirname(fileURLToPath(import.meta.url))
|
||||
const page = readFileSync(
|
||||
@@ -16,28 +17,28 @@ const page = readFileSync(
|
||||
)
|
||||
|
||||
test('斗鱼客户只填写角色名时通过校验', () => {
|
||||
assert.equal(getDouyuRoleNameIssue('花乔妖精'), null)
|
||||
assert.equal(getDouyuRoleNameIssue('狙神123'), null)
|
||||
assert.equal(getDouyuRoleNameIssue('QQ战神'), null)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精'), null)
|
||||
assert.equal(getGameRoleNameIssue('狙神123'), null)
|
||||
assert.equal(getGameRoleNameIssue('QQ战神'), null)
|
||||
})
|
||||
|
||||
test('识别角色名中混入的 UID、区服和登录方式', () => {
|
||||
assert.equal(
|
||||
getDouyuRoleNameIssue('花乔妖精 3379480446 安卓区 微信'),
|
||||
DOUYU_ROLE_NAME_MIXED_WARNING,
|
||||
getGameRoleNameIssue('花乔妖精 3379480446 安卓区 微信'),
|
||||
GAME_ROLE_NAME_MIXED_WARNING,
|
||||
)
|
||||
assert.equal(getDouyuRoleNameIssue('花乔妖精 3379480446'), DOUYU_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getDouyuRoleNameIssue('花乔妖精3379480446'), DOUYU_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getDouyuRoleNameIssue('安卓区'), DOUYU_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 3379480446'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精3379480446'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('安卓区'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
})
|
||||
|
||||
test('客户填写时实时提示,并在提交前阻止混合资料', () => {
|
||||
assert.ok(page.includes('const roleNameIssue = useMemo(() => getDouyuRoleNameIssue(roleName)'))
|
||||
assert.ok(page.includes('const roleNameIssue = useMemo(() => getGameRoleNameIssue(roleName)'))
|
||||
assert.ok(
|
||||
page.includes("className={`customer-collect-input${roleNameIssue ? ' is-warning' : ''}`}"),
|
||||
)
|
||||
assert.ok(page.includes('aria-invalid={Boolean(roleNameIssue)}'))
|
||||
assert.ok(!page.includes("status={roleNameIssue ? 'warning' : undefined}"))
|
||||
assert.ok(page.includes('{roleNameIssue || DOUYU_ROLE_NAME_FORMAT_HINT}'))
|
||||
assert.ok(page.includes('{roleNameIssue || GAME_ROLE_NAME_FORMAT_HINT}'))
|
||||
assert.ok(page.includes('if (roleNameIssue) {'))
|
||||
})
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
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'
|
||||
|
||||
import {
|
||||
GAME_ROLE_NAME_FORMAT_HINT,
|
||||
GAME_ROLE_NAME_MIXED_WARNING,
|
||||
getGameRoleNameIssue,
|
||||
isValidGameRoleId,
|
||||
sanitizeGameRoleIdInput,
|
||||
} from '../src/utils/game-role-name.ts'
|
||||
|
||||
const root = dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
test('斗鱼客户页与虎牙共用同一份角色名规则', () => {
|
||||
const douyuPage = readFileSync(
|
||||
join(root, '../src/pages/douyu-fulfillment/DouyuFulfillmentPage.tsx'),
|
||||
'utf8',
|
||||
)
|
||||
assert.ok(douyuPage.includes("from '@/utils/game-role-name'"))
|
||||
assert.ok(douyuPage.includes('getGameRoleNameIssue'))
|
||||
assert.ok(douyuPage.includes('GAME_ROLE_NAME_FORMAT_HINT'))
|
||||
})
|
||||
|
||||
test('虎牙角色名只填写名称时通过', () => {
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精'), null)
|
||||
assert.equal(getGameRoleNameIssue('狙神123'), null)
|
||||
assert.equal(getGameRoleNameIssue('QQ战神'), null)
|
||||
assert.equal(getGameRoleNameIssue(''), null)
|
||||
})
|
||||
|
||||
test('虎牙角色名混入 UID、区服或登录方式时提示', () => {
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 4212063544'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精4212063544'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 安卓区'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 微信'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 QQ'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
})
|
||||
|
||||
test('游戏角色 UID 只接受 1..20 位纯数字', () => {
|
||||
assert.equal(isValidGameRoleId('4212063544'), true)
|
||||
assert.equal(isValidGameRoleId(' 4212063544 '), true)
|
||||
assert.equal(isValidGameRoleId('12345678901234567890'), true)
|
||||
assert.equal(isValidGameRoleId('123456789012345678901'), false)
|
||||
assert.equal(isValidGameRoleId('UID-not-number'), false)
|
||||
assert.equal(isValidGameRoleId('4212063544a'), false)
|
||||
assert.equal(isValidGameRoleId(''), false)
|
||||
})
|
||||
|
||||
test('UID 输入框只保留数字', () => {
|
||||
assert.equal(sanitizeGameRoleIdInput(' 421 206 3544 '), '4212063544')
|
||||
assert.equal(sanitizeGameRoleIdInput('uid-4212063544'), '4212063544')
|
||||
assert.equal(sanitizeGameRoleIdInput(''), '')
|
||||
})
|
||||
@@ -16,6 +16,9 @@
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
// 前端单测用 `node --experimental-strip-types` 直接跑源码,Node ESM 要求相对导入带显式后缀。
|
||||
// 目前只有 src/utils/customer-fulfillment-profile.ts 一处运行时导入,Vite 构建不受影响。
|
||||
"allowImportingTsExtensions": true,
|
||||
"jsx": "react-jsx",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
|
||||
+17
-6
@@ -318,8 +318,12 @@ manual fulfillment
|
||||
- 半自动任务必须在 manual 渠道判定、人工配置保存/重匹配或 Carrier 补配成功后按订单项主动物化,
|
||||
不能依赖客户先打开 `/c/<订单号>` 或客服先打开半自动任务列表。后台和客户页的幂等回填仅作为兜底。
|
||||
- 虎牙客户页流程固定为「填写资料 → 登录虎牙账号 → 绑定角色 → 客服处理」:
|
||||
① 客户资料必填区服、游戏角色 UID 和角色名,三项齐全后才能展示虎牙登录或生成绑定二维码,
|
||||
页面状态显示「待客户填写资料」。游戏角色 UID 只校验非空,不校验数字格式或真实值;
|
||||
① 客户资料必填区服、游戏角色 UID(纯数字)、角色名和游戏主页截图(必填);四项齐全并保存后才能
|
||||
展示虎牙登录或生成绑定二维码,页面状态显示「待客户填写资料」。本次改造前已保存过资料的历史任务
|
||||
按已保存资料继续,不强制补传截图(重新保存资料时才要求)。游戏角色 UID 只接受 1..20 位纯数字,
|
||||
非纯数字直接拒绝保存,但仍不校验真实值;角色名只允许填写角色名称,检测到混入 UID、区服或
|
||||
登录方式时拒绝保存;游戏主页截图由客户在客户页上传,必须能看到游戏名字/昵称和游戏 UID(编号),
|
||||
文件场景为 `semi-auto-homepage-screenshot`、归属为 `semi-auto-task-{taskId}`,客服据此核对绑定是否正确;
|
||||
② 虎牙账号 UID(`huya_uid`)只用于 WUP/RPC 请求身份,与客户填写的游戏角色 UID 没有任何对应关系,
|
||||
禁止互相回退或比较;
|
||||
③ 虎牙 `gameRole.roleId` 是 40 位加密 opaque token,只可在 Connector 内部用于判断前后两次查询
|
||||
@@ -415,7 +419,8 @@ manual fulfillment
|
||||
- 半自动履约状态采用与斗鱼领取一致的同步原则:客户操作、Connector 回调和后台操作都是状态快照输入,
|
||||
统一由一个状态收敛服务在任务行锁内写入正式字段并追加事件;多个入口不得各自拼接或覆盖状态。
|
||||
- 账号绑定能力由平台声明,不由页面或业务服务按平台散落判断。虎牙、斗鱼、微博均为 `game_role`:
|
||||
虎牙客户资料收集必须有 `roleName / roleId / serverZone`,其中 `roleId` 只校验非空;
|
||||
虎牙客户资料收集必须有 `roleName / roleId / serverZone`,其中 `roleId` 只接受 1..20 位纯数字,
|
||||
`roleName` 不得混入 UID、区服或登录方式;
|
||||
绑定比对仍固定只使用 `roleName / serverZone`。客户游戏角色 UID 和平台可能返回的独立数值游戏角色 UID
|
||||
都不启用额外核验,`gameRole.roleId` 加密 token 本身也不参与客户资料比对;
|
||||
斗鱼必需字段 `roleName / serverZone`,由 live-hub 查询和提交换绑;
|
||||
@@ -806,8 +811,9 @@ Tab 内分类筛选:全部 / 直接兑换 / 预售 / 未分类
|
||||
```
|
||||
|
||||
- 虎牙三步进度固定为「填写游戏资料 → 登录虎牙账号 → 绑定游戏角色」,当前步骤高亮,已完成为勾选。
|
||||
- 客户必填区服、游戏角色 UID 和角色名,未填全时不展示虎牙登录和绑定二维码;UID 只做非空校验和资料留档,
|
||||
不校验格式或真实值。
|
||||
- 客户必填区服、游戏角色 UID、角色名和游戏主页截图,未填全时不展示虎牙登录和绑定二维码;
|
||||
UID 只接受 1..20 位纯数字(纯数字校验,不校验真实值),角色名不得混入 UID/区服/登录方式,
|
||||
主页截图用于客服核对绑定是否正确。
|
||||
- 绑定信息区只展示登录虎牙账号名称、当前平台角色名,以及存在时的待确认角色名;客户页面不得展示
|
||||
虎牙账号 UID、客户填写 UID、平台角色 UID 或待确认角色 UID。自动判定固定只比较角色名与平台区服,
|
||||
角色名、区服和平台信息一致时,页面只显示「确认绑定这个角色到虎牙」一个主操作,不再使用确认弹窗;
|
||||
@@ -1351,6 +1357,10 @@ pending 角色快照、`role_identity_source` 与 `verification_basis`。
|
||||
分类只用于兑换流程与后台 Tab 内筛选。同批代码把 26 处 `UPDATE semi_auto_tasks` 收敛为
|
||||
唯一写入口 `convergeSemiAutoTaskState`(行锁 + 状态转换规则 + 单条 UPDATE + 事件),
|
||||
并删除一次性注入票据与票据 TTL,浏览器登录态改为后台鉴权后直接下发账号级 CK。
|
||||
迁移 `191` 给 `semi_auto_tasks` 增加客户游戏主页截图字段
|
||||
(`customer_homepage_screenshot_object_key / _url / _thumbnail_url / _filename / _uploaded_at`),
|
||||
虎牙客户资料保存前必须校验 `file_assets` 的场景 `semi-auto-homepage-screenshot`、
|
||||
归属 `semi-auto-task-{taskId}` 和图片类型,用于客服核对绑定是否正确。
|
||||
迁移 `172` 将 order_site → live-hub 订单事件升级为订单项快照契约,增加配置停用/订单关闭收敛、
|
||||
稳定去重指纹和 `live_state_version`;live-hub 同步增加 `next_allocate_at`、即时选号唤醒与
|
||||
`state_version`,删除正常链路上的 500 条回查窗口。
|
||||
@@ -1372,7 +1382,8 @@ pending 角色快照、`role_identity_source` 与 `verification_basis`。
|
||||
6. 半自动平台负责客户登录、账号 CK 获取和游戏角色绑定;微博支持手机号登录、易盾二次验证、
|
||||
完整域名 Cookie 保存、会话恢复、游戏角色查询和微信/QQ 扫码绑定;虎牙支持客户手动触发的
|
||||
短信验证码登录和扫码登录。
|
||||
虎牙客户必须先填写区服 / 游戏角色 UID / 角色名,再登录账号并进入绑定;客户 UID 必填但不校验格式,
|
||||
虎牙客户必须先填写区服 / 游戏角色 UID(纯数字)/ 角色名 / 游戏主页截图,再登录账号并进入绑定;
|
||||
客户 UID 必填且只接受纯数字,角色名不得混入 UID/区服/登录方式,主页截图用于客服核对绑定;
|
||||
虎牙账号 UID 只用于登录请求。角色名与平台区服一致后,客户确认本次 pending 角色才可提交平台绑定;
|
||||
客户填写的 UID 与平台可能返回的数值角色 UID 不参与自动判定。不一致时只能重新扫码换绑或返回
|
||||
上一步修改资料,不提供直接使用原角色的快捷确认。
|
||||
|
||||
Reference in New Issue
Block a user