From 3d8a3ff0fc9f54860776e88b83b1c9e0613e32b0 Mon Sep 17 00:00:00 2001 From: yml Date: Wed, 25 Nov 2026 14:22:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D(=E5=B1=A5=E7=BA=A6=E7=A1=AE?= =?UTF-8?q?=E8=AE=A4):=20=E6=89=AB=E7=A0=81=E8=A7=92=E8=89=B2=E6=B6=88?= =?UTF-8?q?=E5=A4=B1=E4=B8=8D=E5=86=8D=E8=AF=AF=E6=8A=A5=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E5=86=B7=E5=8D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - confirm 找不到已识别角色时归为 role_changed - 客户页/工作台允许刷新二维码重新扫码 - 保留账号,避免角色变化被当成换绑冷却 - 补充角色消失分类测试 --- tests/test_platform_fulfillment.py | 23 ++++++++++++ .../platform_fulfillment/allocation.py | 2 +- .../platform_fulfillment/binding_status.py | 37 +++++++++++++++++++ .../services/platform_fulfillment/customer.py | 2 +- .../src/pages/PlatformFulfillmentPage.tsx | 2 +- 5 files changed, 63 insertions(+), 3 deletions(-) diff --git a/tests/test_platform_fulfillment.py b/tests/test_platform_fulfillment.py index 12c8811..f20ca64 100644 --- a/tests/test_platform_fulfillment.py +++ b/tests/test_platform_fulfillment.py @@ -38,6 +38,10 @@ from web.backend.services.automation.jobs import ( platform_fulfillment_lease_reaper as reaper, ) from web.backend.services.platform_fulfillment import account_selector, service, views +from web.backend.services.platform_fulfillment.binding_status import ( + _binding_failure_issue, + _binding_failure_raw_message, +) from web.backend.services.platform_fulfillment.order_sync import _apply_customer_profile NOW = datetime.now(UTC).replace(microsecond=0) @@ -3387,6 +3391,25 @@ class TestBindingAndCompletion(_Base): assert detail["customerProfile"]["channelMatched"] is True + def test_confirm_role_disappeared_is_not_customer_cooldown(self): + result = { + "bind_phase": "confirm_failed", + "expected_role_name": "再说就一坨儿", + "bind_candidates": [ + {"act_alias": "cjm", "role_name": ""}, + {"act_alias": "20260120QYOOB", "role_name": "小无恩"}, + ], + } + task = DouyuTask( + message="待确认角色已变化,未找到: 再说就一坨儿", + result=result, + ) + + assert _binding_failure_issue(task, result) == "role_changed" + assert "扫码角色已失效" in _binding_failure_raw_message( + "role_changed", result + ) + def test_customer_profile_requires_home_image(self): task = self._allocated() with pytest.raises(HTTPException) as exc_info: diff --git a/web/backend/services/platform_fulfillment/allocation.py b/web/backend/services/platform_fulfillment/allocation.py index 634da67..25d9198 100644 --- a/web/backend/services/platform_fulfillment/allocation.py +++ b/web/backend/services/platform_fulfillment/allocation.py @@ -620,7 +620,7 @@ def prepare_manual_allocation( task.execution_status == "manual_required" and not task.account_id and not task.lease_id - and task.issue_code in {"binding_failed", "lease_expired"} + and task.issue_code in {"binding_failed", "lease_expired", "role_changed"} ): # 绑定失败账号已释放后,人工触发一次重新选号; # 客户资料保留,分配成功后 auto allocator 会继续启动绑定。 diff --git a/web/backend/services/platform_fulfillment/binding_status.py b/web/backend/services/platform_fulfillment/binding_status.py index ce36245..dc8bc99 100644 --- a/web/backend/services/platform_fulfillment/binding_status.py +++ b/web/backend/services/platform_fulfillment/binding_status.py @@ -24,6 +24,7 @@ def _customer_task_message_for(issue_code: str) -> str: "points_short": "账号正在补充积分,请稍后重试", "commodity_limit_reached": "当前商品暂时无法兑换,请联系客服", "binding_failed": "暂未识别到绑定角色,请继续使用当前二维码完成扫码", + "role_changed": "扫码角色已失效,请刷新二维码后重新扫码", "account_role_cooldown": "当前斗鱼账号未到换绑时间,请截图本页面并联系客服处理", "customer_role_cooldown": "该游戏角色仍在换绑冷却期,请截图本页面并联系客服处理", "customer_role_bound_elsewhere": "该游戏角色 7 天内已绑定其他斗鱼账号,请使用原账号或等待", @@ -38,6 +39,32 @@ def _customer_task_message(task: PlatformFulfillmentTask) -> str: return _customer_task_message_for(task.issue_code) +def _is_role_changed_failure( + phase: str, + message: str, + confirm_error: str, + result: dict[str, Any], +) -> bool: + """确认时角色凭空消失,不等于客户角色处于换绑冷却。""" + if phase != "confirm_failed": + return False + text = f"{message} {confirm_error}" + if "未找到" in text or "角色已变化" in text or "待确认角色已变化" in text: + return True + expected = str(result.get("expected_role_name") or "").strip() + candidates = result.get("bind_candidates") + if expected and isinstance(candidates, list): + roles = { + str(item.get("role_name") or "").strip().casefold() + for item in candidates + if isinstance(item, dict) + } + roles.discard("") + if roles and expected.casefold() not in roles: + return True + return False + + def _binding_failure_raw_message( issue_code: str, result: dict[str, Any], @@ -51,6 +78,9 @@ def _binding_failure_raw_message( else "" ) role_name = str(result.get("role_name") or "") + if issue_code == "role_changed": + expected = str(result.get("expected_role_name") or role_name or "-") + return f"扫码角色已失效(原角色: {expected}),请刷新二维码重新扫码" if issue_code == "account_role_cooldown": role_label = before_bound_role or role_name or "当前角色" return ( @@ -70,6 +100,13 @@ def _binding_failure_issue(bind_task: DouyuTask, result: dict[str, Any]) -> str: message = str(bind_task.message or "") confirm_error = str(result.get("confirm_error") or "") confirm_code = result.get("confirm_error_code") + if _is_role_changed_failure( + phase, + message, + f"{confirm_error} {result.get('bind_phase') or ''}", + result, + ): + return "role_changed" # 原始接口文案是分类的第一事实源。历史任务可能已经写入了错误的 # derived issue_code,不能在刷新时继续让错误派生值覆盖原始响应。 cooldown_kind = classify_bind_cooldown(None, confirm_error) diff --git a/web/backend/services/platform_fulfillment/customer.py b/web/backend/services/platform_fulfillment/customer.py index 94fc0a4..68a001b 100644 --- a/web/backend/services/platform_fulfillment/customer.py +++ b/web/backend/services/platform_fulfillment/customer.py @@ -133,7 +133,7 @@ async def customer_start_binding( if not task.account_id or not task.lease_id: if ( task.execution_status == "manual_required" - and task.issue_code in {"binding_failed", "lease_expired"} + and task.issue_code in {"binding_failed", "lease_expired", "role_changed"} ): from .allocation import prepare_manual_allocation diff --git a/web/frontend/src/pages/PlatformFulfillmentPage.tsx b/web/frontend/src/pages/PlatformFulfillmentPage.tsx index 1b3226e..d18db6b 100644 --- a/web/frontend/src/pages/PlatformFulfillmentPage.tsx +++ b/web/frontend/src/pages/PlatformFulfillmentPage.tsx @@ -462,7 +462,7 @@ function canReallocateAndBind(task: PlatformFulfillmentTask) { !task.account && task.customerProfile && task.executionStatus === 'manual_required' && - ['binding_failed', 'lease_expired'].includes(task.issueCode), + ['binding_failed', 'lease_expired', 'role_changed'].includes(task.issueCode), ); }