From d1c8580cf30fe8510493187900cfc18ac768c35f Mon Sep 17 00:00:00 2001 From: yml Date: Wed, 25 Nov 2026 14:35:20 +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=E5=90=8E=E5=8F=B0=E4=BA=BA=E5=B7=A5=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E4=B9=9F=E5=BF=85=E9=A1=BB=E5=85=88=E6=9C=89=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E6=B8=B8=E6=88=8F=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 工作台 start/confirm/代确认/强制确认入口统一校验角色和主页截图 - 仅 clean 任务强制,历史任务保持兼容 - 补充后台绑定资料校验测试 --- tests/test_platform_fulfillment.py | 15 ++++++++++++++- web/backend/routers/platform_fulfillment.py | 4 ++++ .../services/platform_fulfillment/binding.py | 8 +++++++- .../services/platform_fulfillment/service.py | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/test_platform_fulfillment.py b/tests/test_platform_fulfillment.py index f20ca64..b477614 100644 --- a/tests/test_platform_fulfillment.py +++ b/tests/test_platform_fulfillment.py @@ -3856,6 +3856,15 @@ class TestBindingAndCompletion(_Base): assert captured["job_type"] == "douyu_binding" assert captured["batch_id"].startswith(f"pfbind-{task.id}-") + def test_admin_binding_requires_game_home_profile(self): + task = self._allocated() + with pytest.raises(HTTPException) as exc_info: + service.ensure_customer_profile_for_binding(self.session, task_id=task.id) + assert exc_info.value.status_code == 409 + + self.complete_customer_profile(task) + service.ensure_customer_profile_for_binding(self.session, task_id=task.id) + def test_customer_start_requires_game_home_profile(self): task = self._allocated() @@ -3876,6 +3885,9 @@ class TestBindingAndCompletion(_Base): ) barrier = threading.Barrier(2) errors: list[BaseException] = [] + first_session = make_test_session(self.engine) + first_admin = first_session.get(User, self.admin_id) + assert first_admin is not None other_session = make_test_session(self.engine) other_admin = other_session.get(User, self.admin_id) assert other_admin is not None @@ -3893,12 +3905,13 @@ class TestBindingAndCompletion(_Base): except BaseException as exc: # noqa: BLE001 - surfaced below errors.append(exc) - first = threading.Thread(target=start, args=(self.session, self.admin)) + first = threading.Thread(target=start, args=(first_session, first_admin)) second = threading.Thread(target=start, args=(other_session, other_admin)) first.start() second.start() first.join(timeout=10) second.join(timeout=10) + first_session.close() other_session.close() assert not first.is_alive() diff --git a/web/backend/routers/platform_fulfillment.py b/web/backend/routers/platform_fulfillment.py index 5239217..0d2643b 100644 --- a/web/backend/routers/platform_fulfillment.py +++ b/web/backend/routers/platform_fulfillment.py @@ -403,6 +403,7 @@ async def start_binding( db: Session = Depends(get_db), current: User = Depends(require_permission("platform_fulfillment:use")), ) -> dict[str, Any]: + service.ensure_customer_profile_for_binding(db, task_id=task_id) result = await service.start_binding(db, task_id=task_id, current=current) record_audit( db, @@ -455,6 +456,7 @@ async def confirm_binding( db: Session = Depends(get_db), current: User = Depends(require_permission("platform_fulfillment:use")), ) -> dict[str, Any]: + service.ensure_customer_profile_for_binding(db, task_id=task_id) result = await service.confirm_binding(db, task_id=task_id, current=current) record_audit( db, @@ -474,6 +476,7 @@ def operator_confirm_binding( current: User = Depends(require_permission("platform_fulfillment:use")), ) -> dict[str, Any]: """普通人工代确认:客户已扫码但没点确认,运营代为提交正常 actBind。""" + service.ensure_customer_profile_for_binding(db, task_id=task_id) result = service.operator_confirm_binding_sync( db, task_id=task_id, @@ -498,6 +501,7 @@ def manual_confirm_binding( current: User = Depends(require_permission("platform_fulfillment:use")), ) -> dict[str, Any]: """运营人工确认绑定:用于客户已在别处绑定、或账号当前角色已确认的场景。""" + service.ensure_customer_profile_for_binding(db, task_id=task_id) result = service.manual_confirm_binding_sync( db, task_id=task_id, diff --git a/web/backend/services/platform_fulfillment/binding.py b/web/backend/services/platform_fulfillment/binding.py index 54e5613..d2cafed 100644 --- a/web/backend/services/platform_fulfillment/binding.py +++ b/web/backend/services/platform_fulfillment/binding.py @@ -44,7 +44,7 @@ from .binding_status import ( _binding_failure_raw_message, _customer_task_message, ) -from .common import _now +from .common import FLOW_VERSION_CLEAN, _has_game_home_profile, _now from .outbox import _emit_order_site_binding_state from .repository import ( _binding_qr_expired, @@ -1494,6 +1494,12 @@ def reconcile_binding_state_outbox( } +def ensure_customer_profile_for_binding(db: Session, *, task_id: int) -> None: + task = _load_task(db, task_id) + if task.flow_version == FLOW_VERSION_CLEAN and not _has_game_home_profile(task): + raise HTTPException(status_code=409, detail="请先提交游戏角色和游戏主页截图") + + def confirm_binding_sync(db: Session, *, task_id: int, current: User) -> dict[str, Any]: task = _load_task_for_update(db, task_id) task = _load_task(db, refresh_binding(db, task_id=task.id)["task"]["id"]) diff --git a/web/backend/services/platform_fulfillment/service.py b/web/backend/services/platform_fulfillment/service.py index 32489b5..70a5bb7 100644 --- a/web/backend/services/platform_fulfillment/service.py +++ b/web/backend/services/platform_fulfillment/service.py @@ -29,6 +29,7 @@ from .allocation import ( # noqa: F401 from .binding import ( # noqa: F401 confirm_binding, confirm_binding_sync, + ensure_customer_profile_for_binding, manual_confirm_binding_sync, operator_confirm_binding_sync, reconcile_binding_observations,