修复(履约确认): 扫码角色消失不再误报客户冷却

- confirm 找不到已识别角色时归为 role_changed
- 客户页/工作台允许刷新二维码重新扫码
- 保留账号,避免角色变化被当成换绑冷却
- 补充角色消失分类测试
This commit is contained in:
yml
2026-11-25 14:22:58 +08:00
parent 2d7f605270
commit 3d8a3ff0fc
5 changed files with 63 additions and 3 deletions
@@ -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 会继续启动绑定。
@@ -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)
@@ -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
@@ -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),
);
}