From eab1d1937ae3fb7ab1bd2a920acf1e811eaa2781 Mon Sep 17 00:00:00 2001 From: yml Date: Wed, 25 Nov 2026 14:04:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D(=E5=B1=A5=E7=BA=A6=E9=87=8D?= =?UTF-8?q?=E8=AF=95):=20=E7=BB=91=E5=AE=9A=E5=A4=B1=E8=B4=A5=E6=97=A0?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E4=BB=BB=E5=8A=A1=E5=85=81=E8=AE=B8=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E9=80=89=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - prepare_manual_allocation 支持 binding_failed/lease_expired 的人工重新选号 - 客户刷新时把任务重置为 ready 并唤醒选号 - 保留客户资料,分配成功后继续启动绑定 - 补充重试测试 --- tests/test_platform_fulfillment.py | 27 ++++++++++++++++++ .../platform_fulfillment/allocation.py | 28 +++++++++++++++++++ .../services/platform_fulfillment/customer.py | 12 ++++++++ 3 files changed, 67 insertions(+) diff --git a/tests/test_platform_fulfillment.py b/tests/test_platform_fulfillment.py index 340bfa9..12c8811 100644 --- a/tests/test_platform_fulfillment.py +++ b/tests/test_platform_fulfillment.py @@ -1332,6 +1332,33 @@ class TestAccountSelection(_Base): assert task.next_allocate_at is not None assert old_retry_at is None or task.next_allocate_at >= old_retry_at + def test_manual_allocation_allows_rebind_after_released_binding_failure(self): + task = self.task() + task.execution_status = "manual_required" + task.binding_status = "failed" + task.issue_code = "binding_failed" + task.last_error = "绑定二维码已过期" + self.session.commit() + + detail = service.prepare_manual_allocation( + self.session, + task_id=task.id, + current=self.admin, + ) + + self.session.refresh(task) + assert detail["task"]["executionStatus"] == "ready" + assert task.execution_status == "ready" + assert task.binding_status == "not_started" + assert task.issue_code == "" + assert task.next_allocate_at is not None + assert ( + self.session.query(PlatformFulfillmentEvent) + .filter_by(task_id=task.id, event_type="binding_retry_requested") + .count() + == 1 + ) + def test_capability_match_uses_local_index_without_live_probe(self): account = self.account("capability-fast", capability=False) task = self.task() diff --git a/web/backend/services/platform_fulfillment/allocation.py b/web/backend/services/platform_fulfillment/allocation.py index 3f4147b..634da67 100644 --- a/web/backend/services/platform_fulfillment/allocation.py +++ b/web/backend/services/platform_fulfillment/allocation.py @@ -616,6 +616,34 @@ def prepare_manual_allocation( lease = db.query(AccountLease).filter(AccountLease.id == task.lease_id).first() if lease and lease.status == "active": return get_task_detail(db, task.id) + if ( + task.execution_status == "manual_required" + and not task.account_id + and not task.lease_id + and task.issue_code in {"binding_failed", "lease_expired"} + ): + # 绑定失败账号已释放后,人工触发一次重新选号; + # 客户资料保留,分配成功后 auto allocator 会继续启动绑定。 + task.execution_status = "ready" + task.binding_status = "not_started" + task.bind_task_id = None + task.issue_code = "" + task.last_error = "" + task.next_allocate_at = _now() + task.operator_id = current.id + task.updated_at = _now() + task.state_version = int(task.state_version or 0) + 1 + _append_event( + db, + task.id, + "binding_retry_requested", + actor_type="user", + actor_id=current.id, + detail={"reason": "manual_reallocate_after_binding_failure"}, + ) + _emit_order_site_binding_state(db, task.id) + db.flush() + return get_task_detail(db, task.id) if task.execution_status != "ready": raise HTTPException(status_code=409, detail="只有待分配任务可以重新选号") task.next_allocate_at = _now() diff --git a/web/backend/services/platform_fulfillment/customer.py b/web/backend/services/platform_fulfillment/customer.py index 14467ed..94fc0a4 100644 --- a/web/backend/services/platform_fulfillment/customer.py +++ b/web/backend/services/platform_fulfillment/customer.py @@ -131,6 +131,18 @@ async def customer_start_binding( raise HTTPException(status_code=409, detail="请先提交游戏角色和游戏主页截图") 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"} + ): + from .allocation import prepare_manual_allocation + + prepare_manual_allocation( + db, + task_id=task.id, + current=_integration_actor(db), + ) + db.commit() from .auto_allocator import wake_auto_allocator wake_auto_allocator([int(task.id)])