feat(fulfillment): 接收并展示 order_site 客户主页截图
- 履约任务新增客户角色/平台/系统/主页截图/更新时间字段 - 迁移 0131 - order_site contractVersion=3 快照自动落客户资料 - 增加客户资料 integration 写入接口 - 工作台详情展示客户资料、平台角色比对和截图 - 补充客户资料保存/快照解析测试与对接文档
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user