From c6e6e66f2d066529fba9147550e221e76da39e09 Mon Sep 17 00:00:00 2001 From: yml Date: Tue, 24 Nov 2026 16:57:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(fulfillment):=20=E5=8C=BA=E5=88=86?= =?UTF-8?q?=E6=99=AE=E9=80=9A=E4=BB=A3=E7=A1=AE=E8=AE=A4=E4=B8=8E=E4=BA=BA?= =?UTF-8?q?=E5=B7=A5=E5=BC=BA=E5=88=B6=E7=A1=AE=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 普通代确认走 refresh_binding + actBind,不填角色/备注 - 强制确认保留角色+依据,并校验账号当前角色一致 - 前端拆成“代客户确认”和红色“强制确认” - 补充普通代确认/角色不匹配回归测试与文档 --- docs/斗鱼/履约绑定状态机与踩坑复盘.md | 37 ++++++++++++ tests/test_platform_fulfillment.py | 59 +++++++++++++++++++ web/backend/routers/platform_fulfillment.py | 23 ++++++++ .../services/platform_fulfillment/binding.py | 29 +++++++++ .../services/platform_fulfillment/service.py | 2 + web/frontend/src/api/platformFulfillment.ts | 4 ++ .../src/pages/PlatformFulfillmentPage.tsx | 43 +++++++++++--- 7 files changed, 188 insertions(+), 9 deletions(-) diff --git a/docs/斗鱼/履约绑定状态机与踩坑复盘.md b/docs/斗鱼/履约绑定状态机与踩坑复盘.md index bfe9dbf..c413612 100644 --- a/docs/斗鱼/履约绑定状态机与踩坑复盘.md +++ b/docs/斗鱼/履约绑定状态机与踩坑复盘.md @@ -649,3 +649,40 @@ confirm_bind.error: 人工确认只能作为“账号已经绑定到该角色、只是缺本次扫码证据”的兜底, 不能作为“换绑失败后强行标记成功”的按钮。 + +### 9.12 普通代确认 vs 人工强制确认 + +两种人工动作必须分开,不能都要求填角色/备注: + +| 动作 | 使用场景 | 是否填信息 | 行为 | +| --- | --- | --- | --- | +| 代客户确认 | 客户已登记资料、已扫码,只是没点确认 | 否 | 刷新绑定证据后走正常 `actBind`;成功才 bound | +| 人工强制确认 | 账号已确认绑定该角色,但没有本次扫码证据 | 是(角色+依据) | 直接标 bound;必须记录操作人/角色/备注 | + +普通代确认: + +- `POST /tasks/{id}/bind/operator-confirm`; +- 内部 `refresh_binding` → 要求平台任务 `role_ready` → 创建正常 `confirm_bind`; +- 不直接改 bound,不写 `binding_manually_confirmed`; +- 同账号同角色可复用的情况会直接 bound(已有复用逻辑); +- 角色锁/actBind 冷却仍然生效。 + +人工强制确认: + +- `POST /tasks/{id}/bind/manual-confirm`; +- 必须账号 `role_bind_status=bound` 且 `game_name == 确认角色`; +- 必须填写角色 + 至少 2 字依据; +- 不一致 409; +- 前端红色按钮,不一致时禁用。 + +订单 2632801853205627(任务 7936)这类: + +```text +本次扫码角色 = 账号当前角色 +本次可确认 = 不可确认(same_role_stale) +本次扫码与账号当前角色相同,可复用 +``` + +属于**普通代确认**,运营一键“代客户确认”即可;不需要填写角色/备注,也不应该走强制确认。 + +订单 2632801603123492(任务 7882)这类账号当前角色与客户角色不一致的,普通代确认会被 actBind/角色锁挡住;强制确认也必须拒绝,只能换号或等冷却。 diff --git a/tests/test_platform_fulfillment.py b/tests/test_platform_fulfillment.py index 0dbf6f4..e395f76 100644 --- a/tests/test_platform_fulfillment.py +++ b/tests/test_platform_fulfillment.py @@ -3089,6 +3089,65 @@ class TestBindingAndCompletion(_Base): == 1 ) + def test_operator_confirm_uses_scanned_role_without_form(self): + task = self._allocated() + account = self.session.get(Account, task.account_id) + account.game_name = "旧角色" + account.role_bind_status = "bound" + qr_task = DouyuTask( + batch_id="operator-confirm-qr", + account_id=task.account_id, + account_assigned_to=self.admin_id, + task_type="get_bind_qr", + handbook_scope="elite", + status="success", + platform_task_id=task.id, + result={ + "act_alias": "cjm", + "role_name": "新角色", + "current_role_name": "旧角色", + "baseline_role_name": "旧角色", + "action_act_aliases": ["20260120QYOOB"], + "bind_ready_for_confirm": True, + "bind_confirmed": False, + "bind_phase": "role_ready", + "bind_decision": { + "alias": "cjm", + "role_name": "新角色", + "reason": "role_changed", + "confirmable": True, + "actionable_alias": False, + }, + }, + created_by=self.admin_id, + ) + self.session.add(qr_task) + self.session.flush() + task.bind_task_id = qr_task.id + task.binding_status = "qr_pending" + task.execution_status = "waiting_bind" + self.session.commit() + + detail = service.operator_confirm_binding_sync( + self.session, + task_id=task.id, + current=self.admin, + ) + + confirm_task = ( + self.session.query(DouyuTask) + .filter_by(task_type="confirm_bind", platform_task_id=task.id) + .one() + ) + assert confirm_task.result["expected_role_name"] == "新角色" + assert detail["task"]["bindingStatus"] in {"role_ready", "confirming"} + assert ( + self.session.query(PlatformFulfillmentEvent) + .filter_by(task_id=task.id, event_type="binding_manually_confirmed") + .count() + == 0 + ) + def test_manual_confirm_rejects_role_not_currently_bound(self): task = self._allocated() account = self.session.get(Account, task.account_id) diff --git a/web/backend/routers/platform_fulfillment.py b/web/backend/routers/platform_fulfillment.py index c2ace09..416a718 100644 --- a/web/backend/routers/platform_fulfillment.py +++ b/web/backend/routers/platform_fulfillment.py @@ -465,6 +465,29 @@ async def confirm_binding( return result +@router.post("/tasks/{task_id}/bind/operator-confirm") +def operator_confirm_binding( + task_id: int, + db: Session = Depends(get_db), + current: User = Depends(require_permission("platform_fulfillment:use")), +) -> dict[str, Any]: + """普通人工代确认:客户已扫码但没点确认,运营代为提交正常 actBind。""" + result = service.operator_confirm_binding_sync( + db, + task_id=task_id, + current=current, + ) + record_audit( + db, + current, + action="platform_fulfillment:binding:operator_confirm", + target=f"platform_fulfillment_task:{task_id}", + detail={"bindingStatus": result.get("task", {}).get("bindingStatus")}, + ) + db.commit() + return result + + @router.post("/tasks/{task_id}/bind/manual-confirm") def manual_confirm_binding( task_id: int, diff --git a/web/backend/services/platform_fulfillment/binding.py b/web/backend/services/platform_fulfillment/binding.py index fe4d71c..54e5613 100644 --- a/web/backend/services/platform_fulfillment/binding.py +++ b/web/backend/services/platform_fulfillment/binding.py @@ -598,6 +598,35 @@ def _mark_reused_pair( return True +def operator_confirm_binding_sync( + db: Session, + *, + task_id: int, + current: User, +) -> dict[str, Any]: + """普通人工代确认:客户已扫码但没点确认,运营代为提交正常 actBind。 + + 不填写角色/备注,不直接标 bound;复用客户确认的同一套确认任务。 + 当前没有可确认的扫码角色时,要求客户扫码或走“强制确认”。 + """ + task = _load_task_for_update(db, task_id) + if _frozen(task): + return get_task_detail(db, task.id) + refresh_binding(db, task_id=task.id) + task = _load_task(db, task.id) + if task.binding_status == "bound": + return get_task_detail(db, task.id) + if task.binding_status != "role_ready": + raise HTTPException( + status_code=409, + detail=( + "当前没有可代确认的扫码角色。请让客户先扫码;" + "只有账号已绑定到该角色、但缺少本次扫码证据时,才使用强制确认。" + ), + ) + return confirm_binding_sync(db, task_id=task.id, current=current) + + def manual_confirm_binding_sync( db: Session, *, diff --git a/web/backend/services/platform_fulfillment/service.py b/web/backend/services/platform_fulfillment/service.py index 987e380..9d05db1 100644 --- a/web/backend/services/platform_fulfillment/service.py +++ b/web/backend/services/platform_fulfillment/service.py @@ -30,6 +30,7 @@ from .binding import ( # noqa: F401 confirm_binding, confirm_binding_sync, manual_confirm_binding_sync, + operator_confirm_binding_sync, reconcile_binding_observations, reconcile_binding_state_outbox, refresh_binding, @@ -156,6 +157,7 @@ __all__ = [ "manual_confirm_binding_sync", "mapping_impact", "mark_manual_required", + "operator_confirm_binding_sync", "prepare_manual_allocation", "prepare_platform_task_for_collab_takeover", "reconcile_binding_observations", diff --git a/web/frontend/src/api/platformFulfillment.ts b/web/frontend/src/api/platformFulfillment.ts index b1ffc9c..39be3b1 100644 --- a/web/frontend/src/api/platformFulfillment.ts +++ b/web/frontend/src/api/platformFulfillment.ts @@ -137,6 +137,10 @@ export const platformFulfillmentApi = { api.post( `/platform-fulfillment/tasks/${taskId}/bind/confirm`, ), + operatorConfirmBinding: (taskId: number) => + api.post( + `/platform-fulfillment/tasks/${taskId}/bind/operator-confirm`, + ), manualConfirmBinding: (taskId: number, roleName: string, note: string) => api.post( `/platform-fulfillment/tasks/${taskId}/bind/manual-confirm`, diff --git a/web/frontend/src/pages/PlatformFulfillmentPage.tsx b/web/frontend/src/pages/PlatformFulfillmentPage.tsx index 4d3340f..e835850 100644 --- a/web/frontend/src/pages/PlatformFulfillmentPage.tsx +++ b/web/frontend/src/pages/PlatformFulfillmentPage.tsx @@ -896,6 +896,18 @@ export default function PlatformFulfillmentPage() { } }; + const submitOperatorConfirm = async (task: PlatformFulfillmentTask) => { + try { + const result = await platformFulfillmentApi.operatorConfirmBinding(task.id); + setDetail(result); + setSelectedId(result.task.id); + await loadTasks(); + message.success('已代客户提交确认,等待绑定结果'); + } catch (error) { + message.error(getErrorMessage(error)); + } + }; + const runDouyuAccountAction = async (taskType: string) => { if (!selected?.account) { message.warning('当前履约任务还没有分配斗鱼账号'); @@ -1432,12 +1444,17 @@ export default function PlatformFulfillmentPage() { ) : null} {task.executionStatus === 'role_ready' ? ( + ) : null} + {canManualConfirmBinding(task) && task.executionStatus !== 'role_ready' && task.bindTask?.roleName ? ( + ) : null} {can('platform_fulfillment:use') && canManualConfirmBinding(task) ? ( - ) : null} {canResetBinding(task) ? ( @@ -1485,9 +1502,17 @@ export default function PlatformFulfillmentPage() { 刷新二维码 ) : null} + {selected && + selected.executionStatus !== 'role_ready' && + selected.executionStatus !== 'bound' && + (selected.bindingEvidence?.scannedRole || selected.bindTask?.roleName) ? ( + + ) : null} {selected && can('platform_fulfillment:use') && canManualConfirmBinding(selected) ? ( - ) : null} {selected.account && @@ -2251,9 +2276,9 @@ export default function PlatformFulfillmentPage() { {manualBindMismatch ? (