From 6ec8248068ff263f085679c6dcc1d47128d83fa9 Mon Sep 17 00:00:00 2001 From: yml Date: Tue, 24 Nov 2026 21:25:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(fulfillment):=20=E6=8E=A5=E6=94=B6?= =?UTF-8?q?=E5=B9=B6=E5=B1=95=E7=A4=BA=20order=5Fsite=20=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E4=B8=BB=E9=A1=B5=E6=88=AA=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 履约任务新增客户角色/平台/系统/主页截图/更新时间字段 - 迁移 0131 - order_site contractVersion=3 快照自动落客户资料 - 增加客户资料 integration 写入接口 - 工作台详情展示客户资料、平台角色比对和截图 - 补充客户资料保存/快照解析测试与对接文档 --- docs/斗鱼/order_site客户主页截图对接.md | 50 ++++++++++++ tests/test_migrations.py | 14 +++- tests/test_platform_fulfillment.py | 75 ++++++++++++++++++ .../migrations/migration_manifest.json | 4 + ...61124_0131_fulfillment_customer_profile.py | 64 +++++++++++++++ web/backend/models.py | 15 ++++ .../platform_fulfillment_integration.py | 21 +++++ web/backend/schemas.py | 15 ++++ .../services/platform_fulfillment/customer.py | 54 +++++++++++++ .../platform_fulfillment/order_sync.py | 68 ++++++++++++++++ .../services/platform_fulfillment/service.py | 2 + .../services/platform_fulfillment/views.py | 54 +++++++++++++ web/frontend/src/api/types.ts | 20 +++++ .../src/pages/PlatformFulfillmentPage.tsx | 77 ++++++++++++++++++- 14 files changed, 531 insertions(+), 2 deletions(-) create mode 100644 docs/斗鱼/order_site客户主页截图对接.md create mode 100644 web/backend/migrations/versions/20261124_0131_fulfillment_customer_profile.py diff --git a/docs/斗鱼/order_site客户主页截图对接.md b/docs/斗鱼/order_site客户主页截图对接.md new file mode 100644 index 0000000..943e8f7 --- /dev/null +++ b/docs/斗鱼/order_site客户主页截图对接.md @@ -0,0 +1,50 @@ +# order_site 客户主页截图对接 + +## 流程 + +```text +order_site 斗鱼领取页 + → 客户填写游戏角色 + 上传个人主页截图(必填) + → order_site 文件服务上传,保存 objectKey + → douyu_fulfillment_tasks 保存截图字段 + → live_hub outbox:platform_fulfillment.order_snapshot + contractVersion=3 + customerRoleName / customerPlatform / customerSystem + homeImages[{url,thumbnailUrl,objectKey,filename}] + customerProfileUpdatedAt + → live-hub sync_order_snapshot 落平台履约任务 + → 直播账号履约工作台「用户资料(order_site)」展示并比对 +``` + +## order_site + +- 迁移:`180_douyu_customer_homepage_screenshot.sql` +- 上传接口:`POST /api/v1/douyu-fulfillment/:orderNo/homepage-screenshot` +- 保存资料:`POST /api/v1/douyu-fulfillment/:orderNo/profile` + - `homepageScreenshotObjectKey` 必填; + - 后端校验 `file_assets` 的 scene/uploader/type; + - 截图 URL 使用 `orders.claimBaseUrl` 的 origin 生成绝对地址。 + +## live-hub + +- 迁移:`20261124_0131_fulfillment_customer_profile` +- 字段: + - `customer_role_name` + - `customer_platform` + - `customer_system` + - `customer_home_images`(URL/缩略图/objectKey) + - `customer_profile_updated_at` +- 快照同步自动落这些字段; +- 备用 integration 接口: + `POST /api/integration/platform-fulfillment/customer-sessions/{task_id}/profile` +- 工作台详情显示: + - 客户角色、登录方式、系统; + - 平台当前角色/渠道; + - 一致/不一致标签; + - 主页截图缩略图预览。 + +## 约束 + +- 截图至少 1 张,最多 5 张; +- 截图只用于核对绑定,不进入斗鱼账号 CK; +- 客户资料更新通过 outbox 快照同步,不靠客服手动转发图片。 diff --git a/tests/test_migrations.py b/tests/test_migrations.py index e46bc6a..21dbf43 100644 --- a/tests/test_migrations.py +++ b/tests/test_migrations.py @@ -45,7 +45,7 @@ TESTS_DIR = Path(__file__).resolve().parent PROJECT_ROOT = TESTS_DIR.parent VERSIONS_DIR = PROJECT_ROOT / "web" / "backend" / "migrations" / "versions" -HEAD_REVISION = "20261124_0130" +HEAD_REVISION = "20261124_0131" # 迁移新增、但不声明在模型里的复合查询索引。 EXTRA_INDEXES = ( @@ -85,6 +85,11 @@ _LATER_ORM_COLUMNS = { "classification_source": "VARCHAR(24) NOT NULL DEFAULT 'unknown'", "exchange_result_image_key": "VARCHAR(512) NOT NULL DEFAULT ''", "exchange_result_image_saved_at": "DATETIME NULL", + "customer_role_name": "VARCHAR(128) NOT NULL DEFAULT ''", + "customer_platform": "VARCHAR(16) NOT NULL DEFAULT ''", + "customer_system": "VARCHAR(16) NOT NULL DEFAULT ''", + "customer_home_images": "JSON NULL", + "customer_profile_updated_at": "DATETIME NULL", }, "douyu_external_orders": { "succeeded_at": "DATETIME NULL", @@ -407,6 +412,7 @@ class TestMigrationSmoke: cfg.set_main_option("sqlalchemy.url", mig_url) command.upgrade(cfg, "20261123_0123") _add_account_platform_columns(mig_engine) + _add_later_orm_columns(mig_engine, ("platform_fulfillment_tasks",)) with Session(mig_engine) as session: user = User( username="binding-sync-user", @@ -499,6 +505,7 @@ class TestMigrationSmoke: cfg.set_main_option("sqlalchemy.url", mig_url) command.upgrade(cfg, "20261123_0125") _add_account_platform_columns(mig_engine) + _add_later_orm_columns(mig_engine, ("platform_fulfillment_tasks",)) with Session(mig_engine) as session: user = User( username="false-binding-user", @@ -617,6 +624,7 @@ class TestMigrationSmoke: cfg.set_main_option("sqlalchemy.url", mig_url) command.upgrade(cfg, "20261123_0126") _add_account_platform_columns(mig_engine) + _add_later_orm_columns(mig_engine, ("platform_fulfillment_tasks",)) with Session(mig_engine) as session: user = User( username="pending-link-user", @@ -969,6 +977,7 @@ class TestMigrationSmoke: cfg.set_main_option("sqlalchemy.url", mig_url) command.upgrade(cfg, "20261121_0106") _add_account_platform_columns(mig_engine) + _add_later_orm_columns(mig_engine, ("platform_fulfillment_tasks",)) with Session(mig_engine) as session: user = User( username="repair-0107-user", @@ -1431,6 +1440,7 @@ class TestMigrationSmoke: cfg.set_main_option("sqlalchemy.url", mig_url) command.upgrade(cfg, "20261118_0089") _add_account_platform_columns(mig_engine) + _add_later_orm_columns(mig_engine, ("platform_fulfillment_tasks",)) with Session(mig_engine) as session: user = User( @@ -1572,6 +1582,7 @@ class TestMigrationSmoke: cfg.set_main_option("sqlalchemy.url", mig_url) command.upgrade(cfg, "20261118_0091") _add_account_platform_columns(mig_engine) + _add_later_orm_columns(mig_engine, ("platform_fulfillment_tasks",)) with Session(mig_engine) as session: account = Account( @@ -1712,6 +1723,7 @@ class TestMigrationSmoke: cfg.set_main_option("sqlalchemy.url", mig_url) command.upgrade(cfg, "20261119_0097") _add_account_platform_columns(mig_engine) + _add_later_orm_columns(mig_engine, ("platform_fulfillment_tasks",)) _add_later_orm_columns(mig_engine, ("douyu_external_orders",)) with Session(mig_engine) as session: diff --git a/tests/test_platform_fulfillment.py b/tests/test_platform_fulfillment.py index 7e5f35a..169b739 100644 --- a/tests/test_platform_fulfillment.py +++ b/tests/test_platform_fulfillment.py @@ -38,6 +38,7 @@ from web.backend.services.automation.jobs import ( platform_fulfillment_lease_reaper as reaper, ) from web.backend.services.platform_fulfillment import account_selector, service, views +from web.backend.services.platform_fulfillment.order_sync import _apply_customer_profile NOW = datetime.now(UTC).replace(microsecond=0) COMMODITY = "20260120QYOOB_bag10" @@ -3148,6 +3149,80 @@ class TestBindingAndCompletion(_Base): == 0 ) + def test_customer_profile_snapshot_is_applied_to_task(self): + task = self._allocated() + _apply_customer_profile( + task, + { + "customerRoleName": "小淋笨", + "customerPlatform": "wechat", + "customerSystem": "android", + "homeImages": [ + { + "url": "https://order.example.com/a.png", + "thumbnailUrl": "https://order.example.com/a-thumb.png", + "objectKey": "douyu-homepage-screenshot/a.png", + } + ], + "customerProfileUpdatedAt": "2026-11-24T12:00:00.000Z", + }, + ) + assert task.customer_role_name == "小淋笨" + assert task.customer_platform == "wechat" + assert task.customer_system == "android" + assert task.customer_home_images[0]["objectKey"].endswith("a.png") + assert task.customer_profile_updated_at is not None + + def test_customer_profile_with_home_image_is_saved_and_compared(self): + task = self._allocated() + account = self.session.get(Account, task.account_id) + account.game_name = "小淋笨" + account.game_channel = "微信 · 安卓(android)" + self.session.commit() + + detail = service.save_customer_profile( + self.session, + task_id=task.id, + customer_role_name="小淋笨", + platform="wechat", + system="android", + home_images=[ + { + "url": "https://example.com/customer-home.png", + "thumbnail_url": "https://example.com/customer-home-thumb.png", + "object_key": "collect-material/customer-home.png", + } + ], + ) + + self.session.refresh(task) + profile = detail["customerProfile"] + assert task.customer_role_name == "小淋笨" + assert task.customer_home_images[0]["url"].endswith("customer-home.png") + assert profile["roleMatched"] is True + assert profile["channelMatched"] is True + assert profile["homeImages"][0]["thumbnailUrl"].endswith("thumb.png") + assert ( + self.session.query(PlatformFulfillmentEvent) + .filter_by(task_id=task.id, event_type="customer_profile_saved") + .count() + == 1 + ) + + def test_customer_profile_requires_home_image(self): + task = self._allocated() + with pytest.raises(HTTPException) as exc_info: + service.save_customer_profile( + self.session, + task_id=task.id, + customer_role_name="小淋笨", + platform="wechat", + system="android", + home_images=[], + ) + assert exc_info.value.status_code == 409 + assert "主页截图" in str(exc_info.value.detail) + def test_manual_confirm_rejects_role_not_currently_bound(self): task = self._allocated() account = self.session.get(Account, task.account_id) diff --git a/web/backend/migrations/migration_manifest.json b/web/backend/migrations/migration_manifest.json index 1a323ba..02c6a4a 100644 --- a/web/backend/migrations/migration_manifest.json +++ b/web/backend/migrations/migration_manifest.json @@ -521,6 +521,10 @@ "20261124_0130_douyu_api_max_amount.py": { "revision": "20261124_0130", "sha256": "fcaa64dfa069084fd6636b459b53f670376c79adf765f41646f05b6829ee9885" + }, + "20261124_0131_fulfillment_customer_profile.py": { + "revision": "20261124_0131", + "sha256": "23f8780eb16a689a5f929f3f1e1865e84c0896dbde70be6bbffb0ef77d06d587" } } } diff --git a/web/backend/migrations/versions/20261124_0131_fulfillment_customer_profile.py b/web/backend/migrations/versions/20261124_0131_fulfillment_customer_profile.py new file mode 100644 index 0000000..ac0d0bc --- /dev/null +++ b/web/backend/migrations/versions/20261124_0131_fulfillment_customer_profile.py @@ -0,0 +1,64 @@ +"""直播账号履约保存 order_site 客户资料与主页截图。 + +客户领取页改为必填主页截图;order_site 通过 integration API 推送到 live-hub, +履约工作台直接展示并和绑定角色比对,不再由客服手动索要。 +""" + +from __future__ import annotations + +import sqlalchemy as sa +from alembic import op + +revision: str = "20261124_0131" +down_revision: str | None = "20261124_0130" +branch_labels: str | None = None +depends_on: str | None = None + +TABLE = "platform_fulfillment_tasks" + +COLUMNS = { + "customer_role_name": sa.String(length=128), + "customer_platform": sa.String(length=16), + "customer_system": sa.String(length=16), + "customer_home_images": sa.JSON(), + "customer_profile_updated_at": sa.DateTime(), +} + + +def _column_exists(name: str) -> bool: + conn = op.get_bind() + count = conn.execute( + sa.text( + "SELECT COUNT(*) FROM information_schema.columns " + "WHERE table_schema = DATABASE() AND table_name = :table " + "AND column_name = :name" + ), + {"table": TABLE, "name": name}, + ).scalar() + return bool(count) + + +def upgrade() -> None: + text_columns = { + "customer_role_name", + "customer_platform", + "customer_system", + } + for name, column_type in COLUMNS.items(): + if _column_exists(name): + continue + op.add_column( + TABLE, + sa.Column( + name, + column_type, + nullable=name not in text_columns, + server_default="" if name in text_columns else None, + ), + ) + + +def downgrade() -> None: + for name in reversed(tuple(COLUMNS)): + if _column_exists(name): + op.drop_column(TABLE, name) diff --git a/web/backend/models.py b/web/backend/models.py index 0bcbb5e..688cbef 100644 --- a/web/backend/models.py +++ b/web/backend/models.py @@ -2467,6 +2467,21 @@ class PlatformFulfillmentTask(Base): classification_source: Mapped[str] = mapped_column( String(24), nullable=False, default="unknown", server_default="unknown" ) + # 客户在 order_site 领取页填写的资料。图片存 order_site 文件 URL, + # live-hub 只做展示和绑定比对,不再让客服手动索要主页截图。 + customer_role_name: Mapped[str] = mapped_column( + String(128), nullable=False, default="", server_default="" + ) + customer_platform: Mapped[str] = mapped_column( + String(16), nullable=False, default="", server_default="" + ) + customer_system: Mapped[str] = mapped_column( + String(16), nullable=False, default="", server_default="" + ) + customer_home_images: Mapped[list | None] = mapped_column(JSON, nullable=True) + customer_profile_updated_at: Mapped[datetime | None] = mapped_column( + UTCDateTime, nullable=True + ) account_id: Mapped[int | None] = mapped_column( ForeignKey("accounts.id", ondelete="SET NULL"), nullable=True, index=True ) diff --git a/web/backend/routers/platform_fulfillment_integration.py b/web/backend/routers/platform_fulfillment_integration.py index 513d47a..2bb3c7b 100644 --- a/web/backend/routers/platform_fulfillment_integration.py +++ b/web/backend/routers/platform_fulfillment_integration.py @@ -17,6 +17,7 @@ from ..database import get_db from ..models import IntegrationInbox from ..schemas import ( PlatformFulfillmentCustomerBindingAction, + PlatformFulfillmentCustomerProfileRequest, PlatformFulfillmentCustomerSessionBatchRequest, PlatformFulfillmentCustomerSessionRequest, ) @@ -132,6 +133,26 @@ def ensure_customer_session( ) +@router.post( + "/customer-sessions/{task_id}/profile", + dependencies=[Depends(require_integration_key)], +) +def save_customer_profile( + task_id: int, + req: PlatformFulfillmentCustomerProfileRequest, + db: Session = Depends(get_db), +) -> dict[str, Any]: + """接 order_site 客户领取页资料与主页截图;order_site 端保证必填。""" + return service.save_customer_profile( + db, + task_id=task_id, + customer_role_name=req.customer_role_name, + platform=req.platform, + system=req.system, + home_images=[item.model_dump() for item in req.home_images], + ) + + @router.post( "/customer-sessions/{task_id}/binding/start", dependencies=[Depends(require_integration_key)], diff --git a/web/backend/schemas.py b/web/backend/schemas.py index 0867c35..e3f8a49 100644 --- a/web/backend/schemas.py +++ b/web/backend/schemas.py @@ -1762,6 +1762,21 @@ class PlatformFulfillmentCustomerSessionRequest(BaseModel): platform_order_id: str = Field(default="", max_length=255) +class PlatformFulfillmentCustomerImage(BaseModel): + url: str = Field(..., min_length=1, max_length=2048) + thumbnail_url: str = Field("", max_length=2048) + object_key: str = Field("", max_length=512) + + +class PlatformFulfillmentCustomerProfileRequest(BaseModel): + customer_role_name: str = Field(..., min_length=1, max_length=128) + platform: str = Field(..., pattern="^(wechat|qq)$") + system: str = Field(..., pattern="^(ios|android)$") + home_images: list[PlatformFulfillmentCustomerImage] = Field( + ..., min_length=1, max_length=5 + ) + + class PlatformFulfillmentCustomerBindingAction(BaseModel): force_refresh: bool = False diff --git a/web/backend/services/platform_fulfillment/customer.py b/web/backend/services/platform_fulfillment/customer.py index 352cda5..97af17c 100644 --- a/web/backend/services/platform_fulfillment/customer.py +++ b/web/backend/services/platform_fulfillment/customer.py @@ -2,6 +2,7 @@ from __future__ import annotations +from datetime import UTC, datetime from typing import Any from fastapi import HTTPException @@ -21,7 +22,9 @@ from .repository import ( _find_customer_task, _integration_actor, _load_task, + _load_task_for_update, ) +from .runtime import _append_event from .views import customer_binding_out @@ -61,6 +64,57 @@ def ensure_customer_session( return customer_binding_out(db, task.id) +def save_customer_profile( + db: Session, + *, + task_id: int, + customer_role_name: str, + platform: str, + system: str, + home_images: list[dict[str, str]], + commit: bool = True, +) -> dict[str, Any]: + """保存 order_site 客户资料;至少一张主页截图由 order_site 端强制。""" + task = _load_task_for_update(db, task_id) + if task.execution_status in {"completed", "cancelled"}: + raise HTTPException(status_code=409, detail="订单已结束,不能修改客户资料") + images = [] + for item in home_images[:5]: + url = str(item.get("url") or "").strip() + if not url: + continue + images.append( + { + "url": url[:2048], + "thumbnailUrl": str(item.get("thumbnail_url") or item.get("thumbnailUrl") or url)[:2048], + "objectKey": str(item.get("object_key") or item.get("objectKey") or "")[:512], + } + ) + if not images: + raise HTTPException(status_code=409, detail="客户主页截图至少需要 1 张") + task.customer_role_name = str(customer_role_name or "").strip()[:128] + task.customer_platform = str(platform or "").strip()[:16] + task.customer_system = str(system or "").strip()[:16] + task.customer_home_images = images + task.customer_profile_updated_at = datetime.now(UTC) + task.updated_at = datetime.now(UTC) + _append_event( + db, + task.id, + "customer_profile_saved", + actor_type="integration", + detail={ + "customerRoleName": task.customer_role_name, + "platform": task.customer_platform, + "system": task.customer_system, + "homeImageCount": len(images), + }, + ) + if commit: + db.commit() + return customer_binding_out(db, task.id) + + async def customer_start_binding( db: Session, *, diff --git a/web/backend/services/platform_fulfillment/order_sync.py b/web/backend/services/platform_fulfillment/order_sync.py index 0ad7cf3..a5eaea8 100644 --- a/web/backend/services/platform_fulfillment/order_sync.py +++ b/web/backend/services/platform_fulfillment/order_sync.py @@ -42,6 +42,72 @@ _AUTO_SYNC_LOCK = threading.Lock() _AUTO_SYNC_LAST_ATTEMPT = float("-inf") +def _apply_customer_profile( + task: PlatformFulfillmentTask, + snapshot: dict[str, Any], +) -> None: + """order_site contractVersion=3 快照里的客户资料和主页截图。""" + keys = { + "customerRoleName", + "customer_role_name", + "homeImages", + "home_images", + } + if not keys.intersection(snapshot): + return + task.customer_role_name = str( + _snapshot_value(snapshot, "customerRoleName", "customer_role_name") + or "" + )[:128] + task.customer_platform = str( + _snapshot_value(snapshot, "customerPlatform", "customer_platform") + or "" + )[:16] + task.customer_system = str( + _snapshot_value(snapshot, "customerSystem", "customer_system") + or "" + )[:16] + raw_images = _snapshot_value( + snapshot, + "homeImages", + "home_images", + default=[], + ) + images: list[dict[str, str]] = [] + if isinstance(raw_images, list): + for item in raw_images[:5]: + if isinstance(item, str): + url = item.strip() + if url: + images.append({"url": url[:2048], "thumbnailUrl": url[:2048], "objectKey": ""}) + continue + if not isinstance(item, dict): + continue + url = str(item.get("url") or "").strip() + if not url: + continue + images.append( + { + "url": url[:2048], + "thumbnailUrl": str( + item.get("thumbnailUrl") or item.get("thumbnail_url") or url + )[:2048], + "objectKey": str( + item.get("objectKey") or item.get("object_key") or "" + )[:512], + } + ) + task.customer_home_images = images or None + task.customer_profile_updated_at = _parse_snapshot_datetime( + _snapshot_value( + snapshot, + "customerProfileUpdatedAt", + "customer_profile_updated_at", + default=None, + ) + ) + + def _upsert_order_snapshot( db: Session, snapshot: dict[str, Any], @@ -150,6 +216,7 @@ def _upsert_order_snapshot( task.required_points, task.issue_code, ) + _apply_customer_profile(task, snapshot) if task.execution_status in {"completed", "cancelled"}: task.source_snapshot_json = _jsonable(snapshot) return task, created, False @@ -481,6 +548,7 @@ def _sync_pending_tasks( task.target_platform = TARGET_PLATFORM task.scope = SCOPE_ELITE task.source_snapshot_json = _jsonable(row) + _apply_customer_profile(task, row) task.updated_at = _now() if task.account_id is None and task.execution_status in { "pending_mapping", diff --git a/web/backend/services/platform_fulfillment/service.py b/web/backend/services/platform_fulfillment/service.py index 9d05db1..32489b5 100644 --- a/web/backend/services/platform_fulfillment/service.py +++ b/web/backend/services/platform_fulfillment/service.py @@ -67,6 +67,7 @@ from .customer import ( customer_refresh_bindings, customer_start_binding, ensure_customer_session, + save_customer_profile, ) from .lifecycle import ( cancel_task, @@ -173,6 +174,7 @@ __all__ = [ "reset_task_binding", "restore_cancelled_task", "restore_mapping", + "save_customer_profile", "set_mapping_enabled", "start_binding", "sync_active_task_from_account_binding", diff --git a/web/backend/services/platform_fulfillment/views.py b/web/backend/services/platform_fulfillment/views.py index d851335..bc17207 100644 --- a/web/backend/services/platform_fulfillment/views.py +++ b/web/backend/services/platform_fulfillment/views.py @@ -506,6 +506,7 @@ def _task_out( if include_qr and bind_task is not None else None ), + "customerProfile": _customer_profile_out(task, account, binding), "exchangeTaskId": exchange_task_id, "exchangeResultImage": ( { @@ -690,6 +691,58 @@ def _customer_binding_queue_state( return "preparing", 1000 +def _customer_profile_out( + task: PlatformFulfillmentTask, + account: Account | None, + binding, +) -> dict[str, Any] | None: + """客户资料 + 与平台当前/确认角色的绑定比对。""" + role = str(task.customer_role_name or "").strip() + images = list(task.customer_home_images or []) + if not role and not images: + return None + platform_role = str(binding.effective_role_name or "").strip() + if not platform_role and account is not None: + platform_role = str(account.game_name or "").strip() + role_matched: bool | None = None + if role and platform_role: + role_matched = role == platform_role + channel_matched: bool | None = None + customer_channel = " ".join( + [ + "微信" if task.customer_platform == "wechat" else ("QQ" if task.customer_platform == "qq" else ""), + "苹果" if task.customer_system == "ios" else ("安卓" if task.customer_system == "android" else ""), + ] + ).strip() + account_channel = str( + binding.effective_channel + or (account.game_channel if account is not None else "") + or "" + ) + if customer_channel and account_channel: + channel_matched = all(part in account_channel for part in customer_channel.split()) + if role and not platform_role: + message = "客户已填角色,平台还未识别绑定角色" + elif role_matched is True and channel_matched is not False: + message = "客户资料与平台角色一致" + elif role_matched is False or channel_matched is False: + message = "客户资料与平台角色不一致,请核对绑定" + else: + message = "客户资料已收到,等待平台识别角色" + return { + "roleName": role, + "platform": str(task.customer_platform or ""), + "system": str(task.customer_system or ""), + "homeImages": images, + "updatedAt": _jsonable(task.customer_profile_updated_at), + "platformRoleName": platform_role, + "platformChannel": account_channel, + "roleMatched": role_matched, + "channelMatched": channel_matched, + "message": message, + } + + def customer_binding_out(db: Session, task_id: int) -> dict[str, Any]: """面向前端客户页的安全绑定快照,不包含账号、CK、积分和租约。""" task = _load_task(db, task_id) @@ -754,6 +807,7 @@ def customer_binding_out(db: Session, task_id: int) -> dict[str, Any]: "queueLane": bind_task.queue_lane if bind_task else "", "accepted": False, "stateVersion": int(task.state_version or 0), + "customerProfile": _customer_profile_out(task, account, binding), "completedAt": _jsonable(task.completed_at), "updatedAt": _jsonable(task.updated_at), } diff --git a/web/frontend/src/api/types.ts b/web/frontend/src/api/types.ts index 0f0a531..ad5fee6 100644 --- a/web/frontend/src/api/types.ts +++ b/web/frontend/src/api/types.ts @@ -2532,6 +2532,25 @@ export interface PlatformFulfillmentBindingEvidence { accountLock: PlatformFulfillmentBindingLock | null; } +export interface PlatformFulfillmentCustomerImage { + url: string; + thumbnailUrl: string; + objectKey: string; +} + +export interface PlatformFulfillmentCustomerProfile { + roleName: string; + platform: string; + system: string; + homeImages: PlatformFulfillmentCustomerImage[]; + updatedAt: string | null; + platformRoleName: string; + platformChannel: string; + roleMatched: boolean | null; + channelMatched: boolean | null; + message: string; +} + export interface PlatformFulfillmentTask { id: number; sourceSystem: string; @@ -2582,6 +2601,7 @@ export interface PlatformFulfillmentTask { lease: { id: number; status: string; expiresAt: string | null } | null; bindTask: PlatformFulfillmentBindTask | null; bindingEvidence: PlatformFulfillmentBindingEvidence | null; + customerProfile: PlatformFulfillmentCustomerProfile | null; exchangeTaskId: number | null; exchangeResultImage: { objectKey: string; diff --git a/web/frontend/src/pages/PlatformFulfillmentPage.tsx b/web/frontend/src/pages/PlatformFulfillmentPage.tsx index 8ff09ea..e0ed2e2 100644 --- a/web/frontend/src/pages/PlatformFulfillmentPage.tsx +++ b/web/frontend/src/pages/PlatformFulfillmentPage.tsx @@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import dayjs from 'dayjs'; import type { Dayjs } from 'dayjs'; -import { Alert, Button, Card, Col, DatePicker, Descriptions, Drawer, Empty, Input, InputNumber, Modal, QRCode, Row, Segmented, Select, Space, Switch, Table, Tag, Timeline, Typography } from 'antd'; +import { Alert, Button, Card, Col, DatePicker, Descriptions, Drawer, Empty, Image, Input, InputNumber, Modal, QRCode, Row, Segmented, Select, Space, Switch, Table, Tag, Timeline, Typography } from 'antd'; import { CheckCircleOutlined, CopyOutlined, CreditCardOutlined, DownloadOutlined, GiftOutlined, LinkOutlined, QrcodeOutlined, ReloadOutlined, SettingOutlined, ShoppingOutlined, SyncOutlined, UndoOutlined, UserSwitchOutlined } from '@ant-design/icons'; import type { ColumnsType } from 'antd/es/table'; import { douyuApi, platformFulfillmentApi } from '../api/modules'; @@ -18,6 +18,22 @@ import { usePermissions } from '../hooks/usePermissions'; const { Text, Title } = Typography; +const CUSTOMER_PLATFORM_LABELS: Record = { + wechat: '微信', + qq: 'QQ', +}; + +const CUSTOMER_SYSTEM_LABELS: Record = { + ios: '苹果', + android: '安卓', +}; + +function customerMatchTone(profile: NonNullable) { + if (profile.roleMatched === false || profile.channelMatched === false) return 'red'; + if (profile.roleMatched === true && profile.channelMatched === true) return 'green'; + return 'gold'; +} + const STATUS_OPTIONS = [ { value: '', label: '全部' }, { value: 'pending_mapping', label: '待映射' }, @@ -1798,6 +1814,65 @@ export default function PlatformFulfillmentPage() { + + {selected.customerProfile ? ( + + + + {selected.customerProfile.roleName || '未填写'} + + + {CUSTOMER_PLATFORM_LABELS[selected.customerProfile.platform] || selected.customerProfile.platform || '-'} + + + {CUSTOMER_SYSTEM_LABELS[selected.customerProfile.system] || selected.customerProfile.system || '-'} + + + {selected.customerProfile.platformRoleName || '未识别'} + + + {selected.customerProfile.platformChannel || '-'} + + + + + {selected.customerProfile.message} + + {selected.customerProfile.updatedAt ? ( + 更新 {formatTime(selected.customerProfile.updatedAt)} + ) : null} + + + + {selected.customerProfile.homeImages.length ? ( + item.url)} + > + + {selected.customerProfile.homeImages.map((item, index) => ( + {`客户主页截图 + ))} + + + ) : ( + 没有主页截图 + )} + + ) : ( + + )} + + {selected.account ? (