From d17c14b84faf3c23502b405dba2eadfd4f70dfdf Mon Sep 17 00:00:00 2001 From: yml Date: Thu, 26 Nov 2026 22:25:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D(=E5=B1=A5=E7=BA=A6=E7=BB=91?= =?UTF-8?q?=E5=AE=9A):=20=E6=81=A2=E5=A4=8D=E5=B7=B2=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E6=89=AB=E7=A0=81=E5=90=8E=E7=9A=84=E6=88=90=E5=8A=9F=E7=A1=AE?= =?UTF-8?q?=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- pyproject.toml | 2 +- tests/test_platform_fulfillment.py | 68 +++++++++++++++++++ uv.lock | 2 +- .../services/platform_fulfillment/binding.py | 10 ++- 5 files changed, 79 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fbfaab9..35b976b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 直播账号运营后台 -斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.2)。 +斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.3)。 ## 能做什么 diff --git a/pyproject.toml b/pyproject.toml index 9e83046..0dfdb03 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "live-hub-py" -version = "0.4.2" +version = "0.4.3" description = "直播账号运营 Web 后台" readme = "README.md" requires-python = ">=3.12,<3.13" diff --git a/tests/test_platform_fulfillment.py b/tests/test_platform_fulfillment.py index bfe8b7d..32e2ca6 100644 --- a/tests/test_platform_fulfillment.py +++ b/tests/test_platform_fulfillment.py @@ -5740,6 +5740,74 @@ class TestBindingAndCompletion(_Base): assert task.last_error == "" assert updated["task"]["bindingStatus"] == "bound" + def test_refresh_recovers_old_qr_timeout_with_newer_owned_confirm(self): + """旧二维码已超时失败时,更晚且归属本单的成功确认仍应恢复待确认。""" + task = self._allocated() + task.customer_role_name = "狞王ゞ" + task.customer_platform = "wechat" + task.customer_system = "android" + qr_task = DouyuTask( + batch_id="timed-out-qr-before-confirm", + account_id=task.account_id, + account_assigned_to=self.admin_id, + task_type="get_bind_qr", + handbook_scope="elite", + status="failed", + platform_task_id=task.id, + result={"bind_phase": "role_timeout"}, + message="等待扫码绑定超时", + created_by=self.admin_id, + ) + self.session.add(qr_task) + self.session.flush() + task.bind_task_id = qr_task.id + task.binding_status = "failed" + task.execution_status = "manual_required" + task.issue_code = "binding_failed" + task.last_error = "等待扫码绑定超时" + account = self.session.get(Account, task.account_id) + account.role_bind_status = "bound" + account.game_name = "゚狙王゜" + account.game_channel = "微信 · 安卓(android)" + confirm_task = DouyuTask( + batch_id="late-confirm-after-qr-timeout", + account_id=task.account_id, + account_assigned_to=self.admin_id, + task_type="confirm_bind", + handbook_scope="elite", + status="success", + platform_task_id=task.id, + result={ + "role_name": "゚狙王゜", + "area_name": "微信", + "plat_name": "安卓(android)", + "bind_confirmed": True, + "bind_phase": "confirmed", + }, + created_by=self.admin_id, + ) + self.session.add(confirm_task) + self.session.commit() + + detail = service.refresh_binding(self.session, task_id=task.id) + + self.session.refresh(task) + assert task.bind_task_id == confirm_task.id + assert detail["task"]["bindingStatus"] == "role_ready" + assert detail["task"]["executionStatus"] == "role_ready" + assert task.issue_code == "" + assert "゚狙王゜" in (task.last_error or "") + assert ( + self.session.query(PlatformFulfillmentEvent) + .filter_by(task_id=task.id, event_type="binding_sync_rejected") + .filter( + PlatformFulfillmentEvent.detail_json["sourceTaskId"].as_integer() + == int(confirm_task.id) + ) + .count() + == 1 + ) + def test_save_customer_profile_immediately_reconciles_existing_qr_candidates(self): """先出码扫码、后提交客户资料时,保存资料应立即把订单收敛到 role_ready。""" task = self._allocated() diff --git a/uv.lock b/uv.lock index 0522182..1915c53 100644 --- a/uv.lock +++ b/uv.lock @@ -381,7 +381,7 @@ wheels = [ [[package]] name = "live-hub-py" -version = "0.4.2" +version = "0.4.3" source = { editable = "." } dependencies = [ { name = "alembic" }, diff --git a/web/backend/services/platform_fulfillment/binding.py b/web/backend/services/platform_fulfillment/binding.py index fd7e4bd..d488584 100644 --- a/web/backend/services/platform_fulfillment/binding.py +++ b/web/backend/services/platform_fulfillment/binding.py @@ -104,6 +104,12 @@ ACTIVE_BINDING_STATUSES = frozenset( "role_ready", } ) +#: 已归属本单的成功确认任务可以让这些状态重新收敛。failed 包含旧二维码已超时, +#: 但精英宝典工作台随后已经确认成功的情况。 +CONFIRM_EVIDENCE_BINDING_STATUSES = ACTIVE_BINDING_STATUSES | { + "confirming", + "failed", +} #: 订单的权威绑定任务类型。查询任务只能展示,不能结算。 BINDING_EVIDENCE_TASK_TYPES = frozenset({"get_bind_qr", "confirm_bind"}) assert BINDING_EVIDENCE_TASK_TYPES <= BINDING_TASK_TYPES @@ -1212,7 +1218,7 @@ def _apply_binding_task( accepted = False elif source.task_type == "confirm_bind": accepted = ( - phase in ACTIVE_BINDING_STATUSES | {"confirming"} + phase in CONFIRM_EVIDENCE_BINDING_STATUSES and bool(expected_role) and role_names_match(confirmed_role, expected_role) ) @@ -1230,7 +1236,7 @@ def _apply_binding_task( if ( source.task_type == "confirm_bind" and (owned or is_current) - and phase in ACTIVE_BINDING_STATUSES | {"confirming"} + and phase in CONFIRM_EVIDENCE_BINDING_STATUSES ): message = _binding_target_mismatch_message( confirmed_role,