diff --git a/tests/test_douyu_binding_state.py b/tests/test_douyu_binding_state.py index e700cf0..1ae0dc2 100644 --- a/tests/test_douyu_binding_state.py +++ b/tests/test_douyu_binding_state.py @@ -730,6 +730,49 @@ def test_result_rejects_legacy_role_when_action_alias_still_has_role(): assert pending_binding_role_from_result(result) == "" +def test_result_accepts_legacy_role_matching_customer_target(): + candidates = [ + _role_candidate(LEGACY_ALIAS, "情绪稳妥"), + _role_candidate(ACT_ALIAS, "呆혹", bound_act=True), + ] + result = { + "role_name": "情绪稳妥", + "act_alias": LEGACY_ALIAS, + "action_act_aliases": [ACT_ALIAS], + "baseline_role_name": "呆혹", + "baseline_is_bound_act": True, + "expected_role_name": "情绪稳妥", + "bind_ready_for_confirm": True, + "bind_confirmed": False, + "bind_candidates": [ + { + "act_alias": LEGACY_ALIAS, + "role_name": "情绪稳妥", + "is_bound_act": False, + }, + { + "act_alias": ACT_ALIAS, + "role_name": "呆혹", + "is_bound_act": True, + }, + ], + } + + assert pending_binding_role_from_result(result) == "情绪稳妥" + decisions = _RolePicker()._binding_candidate_decisions( + candidates, + baseline_role_name="呆혹", + baseline_is_bound_act=True, + actionable_aliases=[ACT_ALIAS], + expected_role_name="情绪稳妥", + ) + legacy_decision = next( + item for item in decisions if item["alias"] == LEGACY_ALIAS + ) + assert legacy_decision["confirmable"] is True + assert legacy_decision["reason"] == "role_changed" + + def test_expected_role_never_falls_back_to_old_activity_role(): old_role = "狗鼻子弗尼亚bd" new_role = "我是火星人2222" diff --git a/web/backend/services/account_binding.py b/web/backend/services/account_binding.py index d7ad727..87e1c64 100644 --- a/web/backend/services/account_binding.py +++ b/web/backend/services/account_binding.py @@ -559,16 +559,22 @@ def pending_binding_role_from_result(result: dict[str, Any] | None) -> str: in action_alias_set and str(item.get("role_name") or "").strip() ] + expected_role_name = str(result.get("expected_role_name") or "").strip() + expected_matches = bool( + expected_role_name + and role_name.casefold() == expected_role_name.casefold() + ) if ( action_alias_set and selected_alias and selected_alias not in action_alias_set and action_evidence + and not expected_matches ): # legacy(cjm) 可能返回同一斗鱼账号历史绑过的另一个游戏角色。 - # 动作 alias 仍有明确角色时,legacy 的 role_name 不能成为本单 pending。 + # 动作 alias 仍有明确角色时,只有与客户目标一致的 legacy 角色可以进入 + # pending;不匹配的历史角色不能覆盖本单。 return "" - expected_role_name = str(result.get("expected_role_name") or "").strip() if is_pending_binding_role( result, baseline_role_name=baseline, diff --git a/web/backend/services/douyu_runner_bind.py b/web/backend/services/douyu_runner_bind.py index 403e5d7..88d12d6 100644 --- a/web/backend/services/douyu_runner_bind.py +++ b/web/backend/services/douyu_runner_bind.py @@ -382,7 +382,16 @@ class BindMixin: for info, decision in zip(candidates, decisions, strict=True): alias = str(info.get("act_alias") or "").strip() role_name = str(info.get("role_name") or "").strip() - if alias not in alias_set and role_name not in action_roles: + expected_matches = bool( + expected_role_name + and role_name.casefold() + == expected_role_name.strip().casefold() + ) + if ( + alias not in alias_set + and role_name not in action_roles + and not expected_matches + ): decision.update( { "confirmable": False, @@ -714,7 +723,14 @@ class BindMixin: if not role_name or role_name.casefold() == baseline: continue alias = str(info.get("act_alias") or "").strip() - if action_alias_has_role and alias not in alias_set: + expected_matches = bool( + expected and role_name.casefold() == expected + ) + if ( + action_alias_has_role + and alias not in alias_set + and not expected_matches + ): continue if expected and role_name.casefold() != expected: continue @@ -730,7 +746,14 @@ class BindMixin: for info in ordered: role_name = str(info.get("role_name") or "").strip() alias = str(info.get("act_alias") or "").strip() - if action_alias_has_role and alias not in alias_set: + expected_matches = bool( + expected and role_name.casefold() == expected + ) + if ( + action_alias_has_role + and alias not in alias_set + and not expected_matches + ): continue if expected and role_name.casefold() != expected: continue diff --git a/web/frontend/src/pages/PlatformFulfillmentPage.tsx b/web/frontend/src/pages/PlatformFulfillmentPage.tsx index d18db6b..0c55bd9 100644 --- a/web/frontend/src/pages/PlatformFulfillmentPage.tsx +++ b/web/frontend/src/pages/PlatformFulfillmentPage.tsx @@ -1398,22 +1398,28 @@ export default function PlatformFulfillmentPage() { title: '用户角色绑定', key: 'binding', width: 180, - render: (_, task) => ( - - - {bindingStatusLabel(task.bindingStatus)} - - {task.account && task.bindingStatus === 'failed' ? ( - 账号保留中 - ) : null} - {task.bindTask?.roleName || (task.bindTask?.bindPhase === 'role_ready' ? '角色待确认' : '-')} - {task.bindingStatus === 'bound' ? ( - - 换绑时间:{formatTime(task.account?.roleChangeAvailableAt) || '无冷却'} - - ) : null} - - ), + render: (_, task) => { + const roleName = + task.bindTask?.roleName?.trim() || + task.customerProfile?.roleName?.trim() || + '-'; + return ( + + + {bindingStatusLabel(task.bindingStatus)} + + {task.account && task.bindingStatus === 'failed' ? ( + 账号保留中 + ) : null} + {roleName} + {task.bindingStatus === 'bound' ? ( + + 换绑时间:{formatTime(task.account?.roleChangeAvailableAt) || '无冷却'} + + ) : null} + + ); + }, }, { title: '游戏主页',