diff --git a/tests/test_platform_fulfillment.py b/tests/test_platform_fulfillment.py index 311ba4b..2dd743e 100644 --- a/tests/test_platform_fulfillment.py +++ b/tests/test_platform_fulfillment.py @@ -2000,6 +2000,84 @@ class TestBindingAndCompletion(_Base): assert detail["task"]["bindTask"]["roleName"] == "测试角色" assert notified == [task.id] + def test_refresh_qr_reuses_unexpired_qr_and_keeps_account(self): + task = self._allocated() + account_id = int(task.account_id or 0) + bind_task = DouyuTask( + batch_id="bind-valid-qr", + account_id=account_id, + account_assigned_to=self.admin_id, + task_type="get_bind_qr", + handbook_scope="elite", + status="success", + result={ + "url": "https://example.com/current-qr", + "qr_expires_at": (NOW + timedelta(minutes=5)).isoformat(), + }, + created_by=self.admin_id, + ) + self.session.add(bind_task) + self.session.flush() + task.bind_task_id = bind_task.id + task.binding_status = "qr_pending" + task.execution_status = "waiting_bind" + self.session.commit() + + detail = asyncio.run( + service.start_binding( + self.session, + task_id=task.id, + current=self.admin, + force_refresh=True, + ) + ) + + self.session.refresh(task) + assert task.bind_task_id == bind_task.id + assert task.account_id == account_id + assert detail["task"]["bindTask"]["id"] == bind_task.id + + def test_refresh_expired_qr_reuses_same_account(self, monkeypatch): + task = self._allocated() + account_id = int(task.account_id or 0) + old_bind_task = DouyuTask( + batch_id="bind-expired-qr", + account_id=account_id, + account_assigned_to=self.admin_id, + task_type="get_bind_qr", + handbook_scope="elite", + status="success", + result={ + "url": "https://example.com/expired-qr", + "qr_expires_at": (NOW - timedelta(minutes=1)).isoformat(), + }, + created_by=self.admin_id, + ) + self.session.add(old_bind_task) + self.session.flush() + task.bind_task_id = old_bind_task.id + task.binding_status = "qr_pending" + task.execution_status = "waiting_bind" + self.session.commit() + monkeypatch.setattr(service, "start_douyu_batch", lambda **_kwargs: None) + + asyncio.run( + service.start_binding( + self.session, + task_id=task.id, + current=self.admin, + force_refresh=True, + ) + ) + + self.session.refresh(task) + assert task.account_id == account_id + assert task.bind_task_id != old_bind_task.id + refreshed_task = self.session.get(DouyuTask, task.bind_task_id) + assert refreshed_task is not None + assert refreshed_task.account_id == account_id + assert refreshed_task.task_type == "get_bind_qr" + def test_refresh_binding_ignores_legacy_same_role_pending(self): task = self._allocated() bind_task = DouyuTask( diff --git a/web/frontend/src/pages/PlatformFulfillmentPage.tsx b/web/frontend/src/pages/PlatformFulfillmentPage.tsx index a292752..582486a 100644 --- a/web/frontend/src/pages/PlatformFulfillmentPage.tsx +++ b/web/frontend/src/pages/PlatformFulfillmentPage.tsx @@ -294,6 +294,11 @@ function canResetBinding(task: PlatformFulfillmentTask) { return task.bindingStatus === 'failed'; } +function canRefreshBindingQr(task: PlatformFulfillmentTask) { + if (!task.account) return false; + return !['role_ready', 'bound', 'completed', 'cancelled'].includes(task.executionStatus); +} + export default function PlatformFulfillmentPage() { const user = getUser(); const navigate = useNavigate(); @@ -917,9 +922,9 @@ export default function PlatformFulfillmentPage() { 人工重试选号 ) : null} - {['waiting_bind', 'binding_confirming'].includes(task.executionStatus) ? ( - ) : null} {task.executionStatus === 'role_ready' ? ( @@ -964,6 +969,14 @@ export default function PlatformFulfillmentPage() { 释放并重新选号 ) : null} + {selected && canRefreshBindingQr(selected) ? ( + + ) : null} {selected.account && selected.executionStatus !== 'completed' && selected.executionStatus !== 'cancelled' &&