调整(半自动履约): 去掉后台「领取」,任一客服均可操作
- 删除 POST /admin/semi-auto/tasks/:taskId/claim 与 claimAdminSemiAutoTask; 前端列表行与详情抽屉的「领取」按钮、claim 服务封装一并移除。 - 去掉三处「该任务已被其他客服领取」409 门禁(重新授权、开浏览器会话、完成履约), 任一有半自动权限的客服都能直接操作。 - assigned_admin_user_id 保留为「最近操作客服」:开浏览器会话与完成履约时写当前操作人, 列表/详情的列名改为「最近操作」,未操作过显示「—」。 - 权威文档改为「不设任务领取人门禁」,CK 导出与注入说明同步去掉领取人口径。 - 集成测试补断言:客服 A 开过会话后客服 B 仍可注入,且任务记录的是最近操作人。
This commit is contained in:
@@ -2,7 +2,6 @@ import { Router } from 'express'
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
cancelAdminSemiAutoTask,
|
cancelAdminSemiAutoTask,
|
||||||
claimAdminSemiAutoTask,
|
|
||||||
completeAdminSemiAutoTask,
|
completeAdminSemiAutoTask,
|
||||||
createAdminBrowserSession,
|
createAdminBrowserSession,
|
||||||
exportAdminSemiAutoCredential,
|
exportAdminSemiAutoCredential,
|
||||||
@@ -90,21 +89,6 @@ router.post(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
router.post(
|
|
||||||
'/semi-auto/tasks/:taskId/claim',
|
|
||||||
createJsonHandler((req) => claimAdminSemiAutoTask(req.params.taskId, sessionOf(req)), {
|
|
||||||
successMessage: '任务已领取',
|
|
||||||
errorMessage: '领取半自动履约任务失败',
|
|
||||||
scope: '[admin/semi-auto/tasks/:taskId/claim]',
|
|
||||||
audit: (req) => ({
|
|
||||||
action: 'semi_auto_task_claimed',
|
|
||||||
targetType: 'semi_auto_task',
|
|
||||||
targetId: String(req.params.taskId || ''),
|
|
||||||
data: {},
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
'/semi-auto/tasks/:taskId/sync',
|
'/semi-auto/tasks/:taskId/sync',
|
||||||
createJsonHandler((req) => syncAdminSemiAutoTask(req.params.taskId), {
|
createJsonHandler((req) => syncAdminSemiAutoTask(req.params.taskId), {
|
||||||
|
|||||||
@@ -270,40 +270,6 @@ export async function exportAdminSemiAutoCredential(taskIdInput: unknown) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function claimAdminSemiAutoTask(taskIdInput: unknown, session: AdminSession) {
|
|
||||||
const taskId = normalizeId(taskIdInput)
|
|
||||||
const adminUserId = Number(session.userId || 0)
|
|
||||||
let orderId = 0
|
|
||||||
await withTransaction(async (client) => {
|
|
||||||
const task = await loadTaskForUpdateWithClient(client, taskId)
|
|
||||||
if (task.execution_status === 'completed' || task.execution_status === 'cancelled') {
|
|
||||||
throw createHttpError('当前任务已结束,不能领取', {
|
|
||||||
statusCode: 409,
|
|
||||||
errorCode:
|
|
||||||
task.execution_status === 'completed'
|
|
||||||
? 'semi_auto_task_completed'
|
|
||||||
: 'semi_auto_task_cancelled',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if (task.assigned_admin_user_id && Number(task.assigned_admin_user_id) !== adminUserId) {
|
|
||||||
throw createHttpError('该任务已被其他客服领取', {
|
|
||||||
statusCode: 409,
|
|
||||||
errorCode: 'semi_auto_task_claimed',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
orderId = Number(task.order_id)
|
|
||||||
await convergeSemiAutoTaskState(client, taskId, {
|
|
||||||
reason: 'task_claimed',
|
|
||||||
actor: 'admin',
|
|
||||||
actorId: String(adminUserId),
|
|
||||||
patch: { assignedAdminUserId: adminUserId },
|
|
||||||
event: { eventType: 'task_claimed' },
|
|
||||||
})
|
|
||||||
})
|
|
||||||
publishSemiAutoTaskRealtimeChange(taskId, orderId)
|
|
||||||
return getAdminSemiAutoTask(taskId)
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function syncAdminSemiAutoTask(taskIdInput: unknown) {
|
export async function syncAdminSemiAutoTask(taskIdInput: unknown) {
|
||||||
const taskId = normalizeId(taskIdInput)
|
const taskId = normalizeId(taskIdInput)
|
||||||
let task = await ensureConnectorSessionForTask(await loadTask(taskId))
|
let task = await ensureConnectorSessionForTask(await loadTask(taskId))
|
||||||
@@ -777,12 +743,6 @@ export async function requestAdminSemiAutoCustomerReauth(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
const adminUserId = Number(session.userId || 0)
|
const adminUserId = Number(session.userId || 0)
|
||||||
if (task.assigned_admin_user_id && Number(task.assigned_admin_user_id) !== adminUserId) {
|
|
||||||
throw createHttpError('该任务已被其他客服领取', {
|
|
||||||
statusCode: 409,
|
|
||||||
errorCode: 'semi_auto_task_claimed',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if (task.connector_session_id) {
|
if (task.connector_session_id) {
|
||||||
await revokeSessionForTask(task, task.connector_session_id).catch(() => undefined)
|
await revokeSessionForTask(task, task.connector_session_id).catch(() => undefined)
|
||||||
}
|
}
|
||||||
@@ -803,12 +763,6 @@ export async function createAdminBrowserSession(
|
|||||||
const taskId = normalizeId(taskIdInput)
|
const taskId = normalizeId(taskIdInput)
|
||||||
const task = await ensureConnectorSessionForTask(await loadTask(taskId))
|
const task = await ensureConnectorSessionForTask(await loadTask(taskId))
|
||||||
const adminUserId = Number(session.userId || 0)
|
const adminUserId = Number(session.userId || 0)
|
||||||
if (task.assigned_admin_user_id && Number(task.assigned_admin_user_id) !== adminUserId) {
|
|
||||||
throw createHttpError('该任务已被其他客服领取', {
|
|
||||||
statusCode: 409,
|
|
||||||
errorCode: 'semi_auto_task_claimed',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if (!task.connector_session_id || task.login_status !== 'authenticated') {
|
if (!task.connector_session_id || task.login_status !== 'authenticated') {
|
||||||
throw createHttpError('客户尚未完成登录,或登录会话已失效', {
|
throw createHttpError('客户尚未完成登录,或登录会话已失效', {
|
||||||
statusCode: 409,
|
statusCode: 409,
|
||||||
@@ -873,10 +827,8 @@ export async function createAdminBrowserSession(
|
|||||||
actor: 'admin',
|
actor: 'admin',
|
||||||
actorId: String(adminUserId),
|
actorId: String(adminUserId),
|
||||||
patch: {
|
patch: {
|
||||||
// 已领取任务保持原领取人(原 COALESCE 语义)。
|
// 不设领取人:任何客服都能操作,这里只记录最近一次操作人。
|
||||||
assignedAdminUserId: current.assigned_admin_user_id
|
assignedAdminUserId: adminUserId,
|
||||||
? Number(current.assigned_admin_user_id)
|
|
||||||
: adminUserId,
|
|
||||||
executionStatus:
|
executionStatus:
|
||||||
current.execution_status === 'waiting_operator' ? 'processing' : current.execution_status,
|
current.execution_status === 'waiting_operator' ? 'processing' : current.execution_status,
|
||||||
},
|
},
|
||||||
@@ -993,12 +945,6 @@ export async function completeAdminSemiAutoTask(
|
|||||||
errorCode: 'weibo_binding_not_confirmed',
|
errorCode: 'weibo_binding_not_confirmed',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (task.assigned_admin_user_id && Number(task.assigned_admin_user_id) !== adminUserId) {
|
|
||||||
throw createHttpError('该任务已被其他客服领取', {
|
|
||||||
statusCode: 409,
|
|
||||||
errorCode: 'semi_auto_task_claimed',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
await confirmManualFulfillment(
|
await confirmManualFulfillment(
|
||||||
{
|
{
|
||||||
@@ -1016,10 +962,8 @@ export async function completeAdminSemiAutoTask(
|
|||||||
actor: 'admin',
|
actor: 'admin',
|
||||||
actorId: String(adminUserId),
|
actorId: String(adminUserId),
|
||||||
patch: {
|
patch: {
|
||||||
// 已领取任务保持原领取人(原 COALESCE 语义)。
|
// 不设领取人:任何客服都能完成,这里只记录最近一次操作人。
|
||||||
assignedAdminUserId: task.assigned_admin_user_id
|
assignedAdminUserId: adminUserId,
|
||||||
? Number(task.assigned_admin_user_id)
|
|
||||||
: adminUserId,
|
|
||||||
executionStatus: 'completed',
|
executionStatus: 'completed',
|
||||||
completedQuantity: Number(task.target_quantity || 0),
|
completedQuantity: Number(task.target_quantity || 0),
|
||||||
completedAt: SEMI_AUTO_NOW,
|
completedAt: SEMI_AUTO_NOW,
|
||||||
|
|||||||
@@ -1181,6 +1181,26 @@ test(
|
|||||||
role: 'support',
|
role: 'support',
|
||||||
displayName: '集成测试客服',
|
displayName: '集成测试客服',
|
||||||
} as never)
|
} as never)
|
||||||
|
|
||||||
|
// 后台没有「领取」动作:另一个客服也能直接操作同一任务,不会被领取人挡住。
|
||||||
|
const secondAdmin = await query<{ id: number }>(
|
||||||
|
`INSERT INTO admin_users (username, password_hash, role, status, created_at, updated_at)
|
||||||
|
VALUES ($1, 'x', 'support', 'active', NOW(), NOW()) RETURNING id`,
|
||||||
|
[`it_huya_restore_admin2_${suffix}`],
|
||||||
|
)
|
||||||
|
const secondAdminId = Number(secondAdmin.rows[0]?.id || 0)
|
||||||
|
const secondInjection = await createAdminBrowserSession(
|
||||||
|
result.taskId,
|
||||||
|
'https://www.huya.com/',
|
||||||
|
{ userId: secondAdminId, role: 'support', displayName: '另一个客服' } as never,
|
||||||
|
)
|
||||||
|
assert.equal(secondInjection.cookies.length > 0, true)
|
||||||
|
const operator = await query<{ assigned_admin_user_id: number | null }>(
|
||||||
|
'SELECT assigned_admin_user_id FROM semi_auto_tasks WHERE id = $1',
|
||||||
|
[result.taskId],
|
||||||
|
)
|
||||||
|
// 只记录最近操作人,不构成门禁。
|
||||||
|
assert.equal(Number(operator.rows[0]?.assigned_admin_user_id), secondAdminId)
|
||||||
const restored = await query<{
|
const restored = await query<{
|
||||||
connector_session_id: string
|
connector_session_id: string
|
||||||
credential_session_restored: number
|
credential_session_restored: number
|
||||||
@@ -1202,7 +1222,8 @@ test(
|
|||||||
|
|
||||||
// 直接下发账号级 CK:没有票据、没有 TTL,权限靠后台登录态 + 领取人 + 审计。
|
// 直接下发账号级 CK:没有票据、没有 TTL,权限靠后台登录态 + 领取人 + 审计。
|
||||||
assert.equal(injection.platform, 'huya')
|
assert.equal(injection.platform, 'huya')
|
||||||
assert.equal(injection.targetUrl, 'https://www.huya.com/')
|
// 传平台首页等于「没指定落地页」,必须回落到策略默认的兑换入口页。
|
||||||
|
assert.match(injection.targetUrl, /^https:\/\/m-shop\.huya\.com\/points\.html\?/)
|
||||||
assert.equal(
|
assert.equal(
|
||||||
injection.cookies.find((cookie) => cookie.name === 'udb_cred')?.value,
|
injection.cookies.find((cookie) => cookie.name === 'udb_cred')?.value,
|
||||||
`restored-${suffix}`,
|
`restored-${suffix}`,
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
KeyOutlined,
|
KeyOutlined,
|
||||||
ReloadOutlined,
|
ReloadOutlined,
|
||||||
SendOutlined,
|
SendOutlined,
|
||||||
UserSwitchOutlined,
|
|
||||||
} from '@ant-design/icons'
|
} from '@ant-design/icons'
|
||||||
import {
|
import {
|
||||||
Alert,
|
Alert,
|
||||||
@@ -37,7 +36,6 @@ import SemiAutoTaskHistoryDrawer from '@/components/admin/SemiAutoTaskHistoryDra
|
|||||||
import PercentTable from '@/components/common/PercentTable'
|
import PercentTable from '@/components/common/PercentTable'
|
||||||
import {
|
import {
|
||||||
cancelAdminSemiAutoTask,
|
cancelAdminSemiAutoTask,
|
||||||
claimAdminSemiAutoTask,
|
|
||||||
completeAdminSemiAutoTask,
|
completeAdminSemiAutoTask,
|
||||||
createSemiAutoBrowserSession,
|
createSemiAutoBrowserSession,
|
||||||
exportAdminSemiAutoCredential,
|
exportAdminSemiAutoCredential,
|
||||||
@@ -245,15 +243,6 @@ export default function AdminSemiAutoTasksPage() {
|
|||||||
onError: (error) => message.error(error instanceof Error ? error.message : '刷新失败'),
|
onError: (error) => message.error(error instanceof Error ? error.message : '刷新失败'),
|
||||||
})
|
})
|
||||||
|
|
||||||
const claimMutation = useMutation({
|
|
||||||
mutationFn: (taskId: number) => claimAdminSemiAutoTask(taskId),
|
|
||||||
onSuccess: () => {
|
|
||||||
message.success('任务已领取')
|
|
||||||
void refreshAll()
|
|
||||||
},
|
|
||||||
onError: (error) => message.error(error instanceof Error ? error.message : '领取失败'),
|
|
||||||
})
|
|
||||||
|
|
||||||
function cancelPendingInjection() {
|
function cancelPendingInjection() {
|
||||||
const pending = pendingInjectionRef.current
|
const pending = pendingInjectionRef.current
|
||||||
if (!pending) return
|
if (!pending) return
|
||||||
@@ -566,10 +555,10 @@ export default function AdminSemiAutoTasksPage() {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '客服',
|
title: '最近操作',
|
||||||
dataIndex: 'assignedAdminName',
|
dataIndex: 'assignedAdminName',
|
||||||
width: 110,
|
width: 110,
|
||||||
render: (value: string) => value || '未领取',
|
render: (value: string) => value || '—',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '更新时间',
|
title: '更新时间',
|
||||||
@@ -640,16 +629,6 @@ export default function AdminSemiAutoTasksPage() {
|
|||||||
>
|
>
|
||||||
刷新
|
刷新
|
||||||
</Button>
|
</Button>
|
||||||
{!task.assignedAdminUserId ? (
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
icon={<UserSwitchOutlined />}
|
|
||||||
loading={claimMutation.isPending}
|
|
||||||
onClick={() => claimMutation.mutate(task.id)}
|
|
||||||
>
|
|
||||||
领取
|
|
||||||
</Button>
|
|
||||||
) : null}
|
|
||||||
{task.executionStatus !== 'completed' &&
|
{task.executionStatus !== 'completed' &&
|
||||||
task.executionStatus !== 'cancelled' &&
|
task.executionStatus !== 'cancelled' &&
|
||||||
!taskNeedsCustomerReauth(task) ? (
|
!taskNeedsCustomerReauth(task) ? (
|
||||||
@@ -928,8 +907,8 @@ export default function AdminSemiAutoTasksPage() {
|
|||||||
) : null}
|
) : null}
|
||||||
</Space>
|
</Space>
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="客服">
|
<Descriptions.Item label="最近操作">
|
||||||
{detail.task.assignedAdminName || '未领取'}
|
{detail.task.assignedAdminName || '—'}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="更新时间">
|
<Descriptions.Item label="更新时间">
|
||||||
{formatAdminDateTime(detail.task.updatedAt)}
|
{formatAdminDateTime(detail.task.updatedAt)}
|
||||||
|
|||||||
@@ -29,10 +29,6 @@ export function exportAdminSemiAutoCredential(taskId: number) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function claimAdminSemiAutoTask(taskId: number) {
|
|
||||||
return apiPost<SemiAutoTaskDetail>(`/api/v1/admin/semi-auto/tasks/${taskId}/claim`, {})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function syncAdminSemiAutoTask(taskId: number) {
|
export function syncAdminSemiAutoTask(taskId: number) {
|
||||||
return apiPost<SemiAutoTaskDetail>(`/api/v1/admin/semi-auto/tasks/${taskId}/sync`, {})
|
return apiPost<SemiAutoTaskDetail>(`/api/v1/admin/semi-auto/tasks/${taskId}/sync`, {})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -357,7 +357,8 @@ manual fulfillment
|
|||||||
恢复失败时更新凭证健康状态并要求重新登录。
|
恢复失败时更新凭证健康状态并要求重新登录。
|
||||||
- 后台「注入浏览器」必须先把当前任务的有效 Connector 会话准备或恢复出来,再按目标 URL 过滤后
|
- 后台「注入浏览器」必须先把当前任务的有效 Connector 会话准备或恢复出来,再按目标 URL 过滤后
|
||||||
**直接下发账号级 Cookie**;不签发一次性票据、不设票据 TTL。权限边界与「导出 CK」同一级:
|
**直接下发账号级 Cookie**;不签发一次性票据、不设票据 TTL。权限边界与「导出 CK」同一级:
|
||||||
后台登录态 + 任务领取人校验 + 审计日志。不得只读取 `credential_status` 就直接要求内存会话存在;
|
后台登录态 + 审计日志,不设任务领取人门禁:任一有半自动权限的客服都可操作。
|
||||||
|
不得只读取 `credential_status` 就直接要求内存会话存在;
|
||||||
凭证健康状态只是上一次检查结论,不是永久黑名单:恢复失败才置 `invalid`,恢复成功必须回写 `valid`。
|
凭证健康状态只是上一次检查结论,不是永久黑名单:恢复失败才置 `invalid`,恢复成功必须回写 `valid`。
|
||||||
虎牙内置 Connector 必须从账号级 CK 恢复账号 UID、登录 Cookie 和设备身份后才能下发。
|
虎牙内置 Connector 必须从账号级 CK 恢复账号 UID、登录 Cookie 和设备身份后才能下发。
|
||||||
- 平台明确返回 CK 失效或账号不一致时,当前任务必须退出“已授权”状态,清空当前 Connector 会话并回到
|
- 平台明确返回 CK 失效或账号不一致时,当前任务必须退出“已授权”状态,清空当前 Connector 会话并回到
|
||||||
@@ -365,7 +366,7 @@ manual fulfillment
|
|||||||
执行“重新发送授权”,重置当前任务并复制客户 `/c/<平台订单号>` 链接,客户重新登录后更新 CK。
|
执行“重新发送授权”,重置当前任务并复制客户 `/c/<平台订单号>` 链接,客户重新登录后更新 CK。
|
||||||
- CK 不得进入普通任务 DTO、客户页面、任务事件、错误日志或审计明细。人工后台默认只展示平台 UID、
|
- CK 不得进入普通任务 DTO、客户页面、任务事件、错误日志或审计明细。人工后台默认只展示平台 UID、
|
||||||
凭证来源、健康状态和更新时间;已登录后台的管理员、运营或客服均可导出任务账号 CK,
|
凭证来源、健康状态和更新时间;已登录后台的管理员、运营或客服均可导出任务账号 CK,
|
||||||
不受 Connector 模式、任务领取人或额外权限限制。导出响应必须禁止缓存,审计只记录任务、
|
不受 Connector 模式、操作人或额外权限限制。导出响应必须禁止缓存,审计只记录任务、
|
||||||
凭证 ID 和平台,不记录 Cookie 内容。
|
凭证 ID 和平台,不记录 Cookie 内容。
|
||||||
- 微博登录必须保留完整域名/路径 Cookie Jar,不能在跨域跳转后把所有同名 Cookie 合并成单个字符串。
|
- 微博登录必须保留完整域名/路径 Cookie Jar,不能在跨域跳转后把所有同名 Cookie 合并成单个字符串。
|
||||||
浏览器注入只下发与目标 URL 匹配的 Cookie;账号级凭证保存完整集合,以便导出、会话恢复和跨域重放。
|
浏览器注入只下发与目标 URL 匹配的 Cookie;账号级凭证保存完整集合,以便导出、会话恢复和跨域重放。
|
||||||
@@ -818,7 +819,8 @@ Tab 内分类筛选:全部 / 直接兑换 / 预售 / 未分类
|
|||||||
未绑定时展示扫码二维码,扫码后重新读取平台角色,角色名发生变化才视为换绑成功。
|
未绑定时展示扫码二维码,扫码后重新读取平台角色,角色名发生变化才视为换绑成功。
|
||||||
- 页面只能展示客户完成操作所需的最小信息,不得展示 CK、内部成本或其他订单。后台默认只展示平台 UID、
|
- 页面只能展示客户完成操作所需的最小信息,不得展示 CK、内部成本或其他订单。后台默认只展示平台 UID、
|
||||||
凭证来源、健康状态、更新时间、CK 导出和浏览器登录态下发入口。CK 导出与浏览器登录态下发都不依赖
|
凭证来源、健康状态、更新时间、CK 导出和浏览器登录态下发入口。CK 导出与浏览器登录态下发都不依赖
|
||||||
绑定状态、任务领取人或额外权限;两者都必须留审计且不得复用普通详情接口。
|
绑定状态、操作人或额外权限;后台不设「领取」动作,任一有半自动权限的客服都能执行,两者都必须留审计
|
||||||
|
且不得复用普通详情接口。
|
||||||
|
|
||||||
### 7.2 接单平台订单关闭
|
### 7.2 接单平台订单关闭
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user