Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b495a2d999 | ||
|
|
5c448bf954 | ||
|
|
1a02733cda | ||
|
|
aafac6e536 | ||
|
|
7dec3c4c48 | ||
|
|
9feb6f4bf4 | ||
|
|
628081986f | ||
|
|
ad74fdb743 | ||
|
|
56e9568fed | ||
|
|
8822f0ab42 | ||
|
|
292f61b56a | ||
|
|
70afd34b71 | ||
|
|
eb93e7aca2 | ||
|
|
6ec8248068 |
@@ -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`
|
||||
- 工作台详情显示:
|
||||
- 客户角色、登录方式、系统;
|
||||
- 平台当前角色/渠道;
|
||||
- 一致/不一致标签;
|
||||
- 游戏主页截图缩略图预览。
|
||||
|
||||
## 约束
|
||||
|
||||
- order_site 当前必填 1 张;live-hub 接收接口兼容最多 5 张;
|
||||
- 截图只用于核对绑定,不进入斗鱼账号 CK;
|
||||
- 客户资料更新通过 outbox 快照同步,不靠客服手动转发图片。
|
||||
@@ -654,3 +654,28 @@ manual_override_at
|
||||
- 平台任务变更后自动投影到台账;
|
||||
- 旧人工台账与平台来源台账的视觉分组;
|
||||
- 台账只读后,特殊异常单的「转人工台账」入口。
|
||||
|
||||
## 15. Clean Cutover:旧数据冻结(2026-11-24 确认)
|
||||
|
||||
旧任务不再逐条清洗,统一隔离为历史任务;新订单进入 clean 流程。
|
||||
|
||||
### 15.1 数据边界
|
||||
|
||||
- `platform_fulfillment_tasks.flow_version = 1`:历史存量;
|
||||
- `flow_version = 2`:Cutover 之后的新任务;
|
||||
- 迁移执行时刻写入 `platform_fulfillment_settings.clean_flow_started_at`;
|
||||
- 旧订单在 Cutover 后补建的任务,按订单支付/创建时间仍归为 legacy。
|
||||
|
||||
### 15.2 行为边界
|
||||
|
||||
- 自动选号只处理 `flow_version=2`;
|
||||
- 历史任务只允许人工操作,不参与自动重试、自动收口和预售台账自动同步;
|
||||
- 工作台新增“历史任务”入口,主工作台默认只看 clean;
|
||||
- 历史列表不受订单起算时间限制,确保旧单可查;
|
||||
- 旧 active 租约不做强制批量释放,后续单独出候选清单。
|
||||
|
||||
### 15.3 目标
|
||||
|
||||
- 不再为 2,462 条 lease_expired 等旧噪音逐条修数据;
|
||||
- 新单人工队列只保留当前真实异常;
|
||||
- 旧数据保留可查、可审计、可人工处理。
|
||||
|
||||
@@ -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_0132"
|
||||
|
||||
# 迁移新增、但不声明在模型里的复合查询索引。
|
||||
EXTRA_INDEXES = (
|
||||
@@ -85,6 +85,12 @@ _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",
|
||||
"flow_version": "INTEGER NOT NULL DEFAULT 1",
|
||||
},
|
||||
"douyu_external_orders": {
|
||||
"succeeded_at": "DATETIME NULL",
|
||||
@@ -407,6 +413,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 +506,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 +625,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 +978,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 +1441,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 +1583,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 +1724,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"
|
||||
@@ -181,6 +182,48 @@ class TestWorkbenchReadPath(_Base):
|
||||
self.session.commit()
|
||||
return task
|
||||
|
||||
def test_all_queue_includes_mapped_and_unmapped_tasks(self):
|
||||
views.invalidate_task_list_count_cache()
|
||||
self.task()
|
||||
unmapped = PlatformFulfillmentTask(
|
||||
source_system="order_site",
|
||||
source_order_id="all-unmapped",
|
||||
source_order_item_id="all-unmapped",
|
||||
platform_order_id="ALL-UNMAPPED",
|
||||
internal_sku_key="all-unmapped",
|
||||
execution_status="pending_mapping",
|
||||
binding_status="not_started",
|
||||
exchange_status="not_started",
|
||||
paid_at=NOW,
|
||||
created_at=NOW,
|
||||
updated_at=NOW,
|
||||
)
|
||||
self.session.add(unmapped)
|
||||
self.session.commit()
|
||||
|
||||
default_result = service.list_tasks(self.session, page_size=100)
|
||||
all_result = service.list_tasks(
|
||||
self.session,
|
||||
queue_bucket="all",
|
||||
page_size=100,
|
||||
)
|
||||
|
||||
assert default_result["pagination"]["total"] == 1
|
||||
assert all_result["pagination"]["total"] == 2
|
||||
|
||||
def test_pending_mapping_queue_shows_unmapped_tasks(self):
|
||||
views.invalidate_task_list_count_cache()
|
||||
task = self.task(mapped=False)
|
||||
|
||||
result = service.list_tasks(
|
||||
self.session,
|
||||
queue_bucket="pending_mapping",
|
||||
page_size=100,
|
||||
)
|
||||
|
||||
assert [item["id"] for item in result["items"]] == [task.id]
|
||||
assert result["items"][0]["executionStatus"] == "pending_mapping"
|
||||
|
||||
def test_task_list_count_uses_short_ttl_cache_until_invalidated(self):
|
||||
views.invalidate_task_list_count_cache()
|
||||
mapping = self.mapping()
|
||||
@@ -1068,6 +1111,60 @@ class TestSnapshotSync(_Base):
|
||||
outbox = self.session.query(IntegrationOutbox).one()
|
||||
assert outbox.payload_json["items"][0]["stateVersion"] == 1
|
||||
|
||||
def test_snapshot_before_clean_cutover_creates_legacy_task(self):
|
||||
self.mapping()
|
||||
setting = self.session.get(PlatformFulfillmentSetting, 1)
|
||||
setting.clean_flow_started_at = NOW
|
||||
self.session.commit()
|
||||
|
||||
service.sync_order_snapshot(
|
||||
self.session,
|
||||
{"data": self.snapshot(paidAt=(NOW - timedelta(hours=1)).isoformat())},
|
||||
)
|
||||
|
||||
task = self.session.query(PlatformFulfillmentTask).one()
|
||||
assert task.flow_version == 1
|
||||
assert service.list_tasks(self.session, flow_version=2)["pagination"]["total"] == 0
|
||||
assert service.list_tasks(self.session, flow_version=1)["pagination"]["total"] == 1
|
||||
|
||||
def test_legacy_task_is_frozen_against_snapshot_transitions(self):
|
||||
task = self.task()
|
||||
task.flow_version = 1
|
||||
self.session.commit()
|
||||
|
||||
service.sync_order_snapshot(
|
||||
self.session,
|
||||
{"data": self.snapshot(orderStatus="refunded", douyuFulfillmentEnabled=False)},
|
||||
)
|
||||
|
||||
self.session.refresh(task)
|
||||
assert task.flow_version == 1
|
||||
assert task.execution_status == "ready"
|
||||
assert task.issue_code == ""
|
||||
assert task.source_snapshot_json["orderStatus"] == "refunded"
|
||||
|
||||
def test_snapshot_after_clean_cutover_creates_clean_task(self):
|
||||
self.mapping()
|
||||
setting = self.session.get(PlatformFulfillmentSetting, 1)
|
||||
setting.clean_flow_started_at = NOW - timedelta(hours=1)
|
||||
self.session.commit()
|
||||
|
||||
service.sync_order_snapshot(self.session, {"data": self.snapshot()})
|
||||
|
||||
task = self.session.query(PlatformFulfillmentTask).one()
|
||||
assert task.flow_version == 2
|
||||
|
||||
def test_legacy_list_ignores_order_match_cutoff(self):
|
||||
task = self.task()
|
||||
task.flow_version = 1
|
||||
task.paid_at = NOW - timedelta(days=10)
|
||||
self.session.commit()
|
||||
|
||||
listed = service.list_tasks(self.session, flow_version=1)
|
||||
|
||||
assert listed["pagination"]["total"] == 1
|
||||
assert listed["items"][0]["flowVersion"] == 1
|
||||
|
||||
def test_duplicate_snapshot_keeps_allocated_task_state(self):
|
||||
self.mapping()
|
||||
account = self.account("snapshot-allocated")
|
||||
@@ -1140,6 +1237,30 @@ class TestSnapshotSync(_Base):
|
||||
assert task.state_version == 2
|
||||
assert task.next_allocate_at is None
|
||||
|
||||
def test_valid_snapshot_restores_source_cancelled_task(self):
|
||||
self.mapping()
|
||||
service.sync_order_snapshot(self.session, {"data": self.snapshot()})
|
||||
service.sync_order_snapshot(
|
||||
self.session,
|
||||
{"data": self.snapshot(douyuFulfillmentEnabled=False)},
|
||||
)
|
||||
task = self.session.query(PlatformFulfillmentTask).one()
|
||||
assert task.execution_status == "cancelled"
|
||||
assert task.issue_code == "source_cancelled"
|
||||
|
||||
service.sync_order_snapshot(self.session, {"data": self.snapshot()})
|
||||
|
||||
self.session.refresh(task)
|
||||
assert task.execution_status == "ready"
|
||||
assert task.issue_code == ""
|
||||
assert task.last_error == ""
|
||||
assert (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="source_order_restored")
|
||||
.count()
|
||||
== 1
|
||||
)
|
||||
|
||||
def test_unpaid_snapshot_does_not_enter_live_fulfillment(self):
|
||||
self.mapping()
|
||||
|
||||
@@ -3148,6 +3269,98 @@ 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_matches_online_qq_channel_label(self):
|
||||
task = self._allocated()
|
||||
account = self.session.get(Account, task.account_id)
|
||||
account.game_name = "手Q角色"
|
||||
account.game_channel = "手Q · 苹果(iOS)"
|
||||
self.session.commit()
|
||||
|
||||
detail = service.save_customer_profile(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
customer_role_name="手Q角色",
|
||||
platform="qq",
|
||||
system="ios",
|
||||
home_images=[{"url": "https://example.com/qq-home.png"}],
|
||||
)
|
||||
|
||||
assert detail["customerProfile"]["channelMatched"] is True
|
||||
|
||||
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)
|
||||
|
||||
@@ -357,3 +357,44 @@ def test_schedule_retry_preserves_longer_capability_retry(db):
|
||||
|
||||
db.refresh(task)
|
||||
assert task.next_allocate_at == retry_at
|
||||
|
||||
|
||||
def test_auto_allocator_ignores_legacy_tasks(db):
|
||||
actor = User(
|
||||
username="auto-legacy-actor", password_hash="h", role="super_admin"
|
||||
)
|
||||
db.add_all(
|
||||
[
|
||||
actor,
|
||||
PlatformFulfillmentSetting(
|
||||
id=1,
|
||||
lease_duration_minutes=None,
|
||||
order_match_started_at=datetime.now(UTC) - timedelta(days=1),
|
||||
),
|
||||
PlatformFulfillmentTask(
|
||||
source_system="order_site",
|
||||
source_order_id="legacy-1",
|
||||
source_order_item_id="legacy-1",
|
||||
platform_order_id="AUTO-LEGACY",
|
||||
internal_sku_key="skin",
|
||||
commodity_id="commodity-1",
|
||||
flow_version=1,
|
||||
execution_status="ready",
|
||||
binding_status="not_started",
|
||||
exchange_status="not_started",
|
||||
paid_at=datetime.now(UTC),
|
||||
next_allocate_at=datetime.now(UTC),
|
||||
updated_at=datetime.now(UTC),
|
||||
),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
|
||||
with patch.object(
|
||||
auto_allocator.service,
|
||||
"allocate_task",
|
||||
side_effect=AssertionError("legacy tasks must not be auto allocated"),
|
||||
):
|
||||
result = auto_allocator.run_auto_allocation_once(db, limit=10)
|
||||
|
||||
assert result == {"checked": 0, "allocated": 0, "failed": 0}
|
||||
|
||||
@@ -521,6 +521,14 @@
|
||||
"20261124_0130_douyu_api_max_amount.py": {
|
||||
"revision": "20261124_0130",
|
||||
"sha256": "fcaa64dfa069084fd6636b459b53f670376c79adf765f41646f05b6829ee9885"
|
||||
},
|
||||
"20261124_0131_fulfillment_customer_profile.py": {
|
||||
"revision": "20261124_0131",
|
||||
"sha256": "23f8780eb16a689a5f929f3f1e1865e84c0896dbde70be6bbffb0ef77d06d587"
|
||||
},
|
||||
"20261124_0132_fulfillment_flow_version.py": {
|
||||
"revision": "20261124_0132",
|
||||
"sha256": "c32ae403de640251e4ae8d86bd0948c189c3580141f1454490b4798bb286e3a3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -0,0 +1,91 @@
|
||||
"""直播履约 clean/legacy 流程分界。
|
||||
|
||||
- 存量任务统一标记为 legacy(flow_version=1);
|
||||
- 迁移执行时设置 clean_flow_started_at,之后的订单进入 clean 流程;
|
||||
- 已经是 clean 的任务不会再被自动调度逻辑回退。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20261124_0132"
|
||||
down_revision: str | None = "20261124_0131"
|
||||
branch_labels: str | None = None
|
||||
depends_on: str | None = None
|
||||
|
||||
TASK_TABLE = "platform_fulfillment_tasks"
|
||||
SETTINGS_TABLE = "platform_fulfillment_settings"
|
||||
|
||||
|
||||
def _column_exists(table: str, 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 _index_exists(table: str, name: str) -> bool:
|
||||
conn = op.get_bind()
|
||||
count = conn.execute(
|
||||
sa.text(
|
||||
"SELECT COUNT(*) FROM information_schema.statistics "
|
||||
"WHERE table_schema = DATABASE() AND table_name = :table "
|
||||
"AND index_name = :name"
|
||||
),
|
||||
{"table": table, "name": name},
|
||||
).scalar()
|
||||
return bool(count)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if not _column_exists(TASK_TABLE, "flow_version"):
|
||||
op.add_column(
|
||||
TASK_TABLE,
|
||||
sa.Column(
|
||||
"flow_version",
|
||||
sa.Integer(),
|
||||
nullable=False,
|
||||
server_default="1",
|
||||
),
|
||||
)
|
||||
if not _index_exists(TASK_TABLE, "ix_platform_fulfillment_tasks_flow_version"):
|
||||
op.create_index(
|
||||
"ix_platform_fulfillment_tasks_flow_version",
|
||||
TASK_TABLE,
|
||||
["flow_version"],
|
||||
)
|
||||
if not _column_exists(SETTINGS_TABLE, "clean_flow_started_at"):
|
||||
op.add_column(
|
||||
SETTINGS_TABLE,
|
||||
sa.Column("clean_flow_started_at", sa.DateTime(), nullable=True),
|
||||
)
|
||||
# 迁移执行时刻就是 Cutover;存量任务已在 flow_version 默认值 1。
|
||||
op.execute(
|
||||
sa.text(
|
||||
"""
|
||||
UPDATE platform_fulfillment_settings
|
||||
SET clean_flow_started_at = UTC_TIMESTAMP()
|
||||
WHERE id = 1 AND clean_flow_started_at IS NULL
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _column_exists(SETTINGS_TABLE, "clean_flow_started_at"):
|
||||
op.drop_column(SETTINGS_TABLE, "clean_flow_started_at")
|
||||
if _index_exists(TASK_TABLE, "ix_platform_fulfillment_tasks_flow_version"):
|
||||
op.drop_index(
|
||||
"ix_platform_fulfillment_tasks_flow_version",
|
||||
table_name=TASK_TABLE,
|
||||
)
|
||||
if _column_exists(TASK_TABLE, "flow_version"):
|
||||
op.drop_column(TASK_TABLE, "flow_version")
|
||||
@@ -2313,6 +2313,11 @@ class PlatformFulfillmentSetting(Base):
|
||||
nullable=False,
|
||||
default=_utcnow,
|
||||
)
|
||||
# Clean Cutover 时间;之前是 legacy 任务,之后进入 clean 流程。
|
||||
clean_flow_started_at: Mapped[datetime | None] = mapped_column(
|
||||
UTCDateTime,
|
||||
nullable=True,
|
||||
)
|
||||
updated_by: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("users.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
@@ -2408,6 +2413,14 @@ class PlatformFulfillmentTask(Base):
|
||||
source_fulfillment_id: Mapped[str] = mapped_column(
|
||||
String(64), nullable=False, default="", server_default=""
|
||||
)
|
||||
# 1 = 历史存量,只允许人工处理;2 = Clean Cutover 后的新单。
|
||||
flow_version: Mapped[int] = mapped_column(
|
||||
Integer,
|
||||
nullable=False,
|
||||
default=2,
|
||||
server_default="1",
|
||||
index=True,
|
||||
)
|
||||
platform_order_id: Mapped[str] = mapped_column(
|
||||
String(128), nullable=False, default="", server_default=""
|
||||
)
|
||||
@@ -2467,6 +2480,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
|
||||
)
|
||||
|
||||
@@ -80,6 +80,7 @@ def list_tasks(
|
||||
status: str = Query("", max_length=32),
|
||||
queue_bucket: str = Query("", max_length=32),
|
||||
sale_mode: str = Query("", max_length=16),
|
||||
flow_version: int | None = Query(None, ge=1, le=2),
|
||||
keyword: str = Query("", max_length=200),
|
||||
page: int = Query(1, ge=1),
|
||||
page_size: int = Query(20, ge=1, le=100),
|
||||
@@ -92,6 +93,7 @@ def list_tasks(
|
||||
status=status,
|
||||
queue_bucket=queue_bucket,
|
||||
sale_mode=sale_mode,
|
||||
flow_version=flow_version,
|
||||
keyword=keyword,
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
|
||||
@@ -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)],
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from sqlalchemy.orm import Session
|
||||
from ...database import WorkerSessionLocal
|
||||
from ...models import PlatformFulfillmentTask
|
||||
from . import service
|
||||
from .common import FLOW_VERSION_CLEAN
|
||||
|
||||
DEFAULT_INTERVAL_SECONDS = 20
|
||||
DEFAULT_MIN_INTERVAL_SECONDS = 5
|
||||
@@ -138,6 +139,8 @@ def run_auto_allocation_once(
|
||||
due_cutoff = moment + timedelta(seconds=1)
|
||||
query = db.query(PlatformFulfillmentTask).filter(
|
||||
PlatformFulfillmentTask.execution_status == "ready",
|
||||
# 存量任务只允许人工处理,自动选号只服务 Clean Cutover 之后的新单。
|
||||
PlatformFulfillmentTask.flow_version == FLOW_VERSION_CLEAN,
|
||||
PlatformFulfillmentTask.account_id.is_(None),
|
||||
PlatformFulfillmentTask.commodity_id != "",
|
||||
or_(
|
||||
|
||||
@@ -21,6 +21,8 @@ from ..douyu_account_state import DouyuLiveAccountState
|
||||
|
||||
TARGET_PLATFORM = "douyu"
|
||||
SCOPE_ELITE = "elite"
|
||||
FLOW_VERSION_LEGACY = 1
|
||||
FLOW_VERSION_CLEAN = 2
|
||||
BINDING_COOLDOWN_ISSUES = frozenset({"account_role_cooldown", "customer_role_cooldown"})
|
||||
ACTIVE_STATUSES = {
|
||||
"ready",
|
||||
@@ -148,6 +150,33 @@ def _order_match_started_at(db: Session) -> datetime | None:
|
||||
return row.order_match_started_at if row is not None else None
|
||||
|
||||
|
||||
def _clean_flow_started_at(db: Session) -> datetime | None:
|
||||
row = (
|
||||
db.query(PlatformFulfillmentSetting)
|
||||
.filter(PlatformFulfillmentSetting.id == 1)
|
||||
.first()
|
||||
)
|
||||
return row.clean_flow_started_at if row is not None else None
|
||||
|
||||
|
||||
def _flow_version_for_order(
|
||||
db: Session,
|
||||
*,
|
||||
paid_at: datetime | None,
|
||||
created_at: datetime | None,
|
||||
) -> int:
|
||||
"""按订单支付/创建时间划分 legacy/clean,避免旧订单补建任务混入新流程。"""
|
||||
cutoff = _clean_flow_started_at(db)
|
||||
basis = paid_at or created_at
|
||||
if cutoff is None or basis is None:
|
||||
return FLOW_VERSION_CLEAN
|
||||
if cutoff.tzinfo is None:
|
||||
cutoff = cutoff.replace(tzinfo=UTC)
|
||||
if basis.tzinfo is None:
|
||||
basis = basis.replace(tzinfo=UTC)
|
||||
return FLOW_VERSION_LEGACY if basis < cutoff else FLOW_VERSION_CLEAN
|
||||
|
||||
|
||||
def _apply_order_match_cutoff(
|
||||
query,
|
||||
match_started_at: datetime | None,
|
||||
|
||||
@@ -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,
|
||||
*,
|
||||
|
||||
@@ -21,8 +21,10 @@ from ..external_order_source import (
|
||||
)
|
||||
from .common import (
|
||||
AUTO_SYNC_INTERVAL_SECONDS,
|
||||
FLOW_VERSION_LEGACY,
|
||||
SCOPE_ELITE,
|
||||
TARGET_PLATFORM,
|
||||
_flow_version_for_order,
|
||||
_jsonable,
|
||||
_now,
|
||||
_order_match_started_at,
|
||||
@@ -42,6 +44,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],
|
||||
@@ -91,6 +159,10 @@ def _upsert_order_snapshot(
|
||||
.first()
|
||||
)
|
||||
created = task is None
|
||||
if task is not None and task.flow_version == FLOW_VERSION_LEGACY:
|
||||
# 历史任务冻结:只保留来源快照,不参与任何自动状态迁移。
|
||||
task.source_snapshot_json = _jsonable(snapshot)
|
||||
return task, created, False
|
||||
if task is None:
|
||||
task = PlatformFulfillmentTask(
|
||||
source_system="order_site",
|
||||
@@ -115,6 +187,11 @@ def _upsert_order_snapshot(
|
||||
),
|
||||
target_platform=TARGET_PLATFORM,
|
||||
scope=SCOPE_ELITE,
|
||||
flow_version=_flow_version_for_order(
|
||||
db,
|
||||
paid_at=paid_at,
|
||||
created_at=order_created_at,
|
||||
),
|
||||
created_at=_now(),
|
||||
updated_at=_now(),
|
||||
)
|
||||
@@ -150,11 +227,7 @@ def _upsert_order_snapshot(
|
||||
task.required_points,
|
||||
task.issue_code,
|
||||
)
|
||||
if task.execution_status in {"completed", "cancelled"}:
|
||||
task.source_snapshot_json = _jsonable(snapshot)
|
||||
return task, created, False
|
||||
|
||||
previous_execution_status = task.execution_status
|
||||
_apply_customer_profile(task, snapshot)
|
||||
terminal = (
|
||||
terminal_order
|
||||
or _snapshot_value(
|
||||
@@ -179,6 +252,30 @@ def _upsert_order_snapshot(
|
||||
)
|
||||
is False
|
||||
)
|
||||
if task.execution_status in {"completed", "cancelled"}:
|
||||
# 历史“停用配置”的旧快照可能先到,随后开启配置的新快照又到;
|
||||
# 系统原因取消的任务允许被后续有效快照恢复。用户取消/完成的仍保持终态。
|
||||
if (
|
||||
task.execution_status == "cancelled"
|
||||
and task.issue_code == "source_cancelled"
|
||||
and not terminal
|
||||
):
|
||||
task.execution_status = "pending_mapping"
|
||||
task.issue_code = ""
|
||||
task.last_error = ""
|
||||
task.next_allocate_at = None
|
||||
task.completed_at = None
|
||||
_append_event(
|
||||
db,
|
||||
task.id,
|
||||
"source_order_restored",
|
||||
detail={"reason": "valid_snapshot_after_source_cancel"},
|
||||
)
|
||||
else:
|
||||
task.source_snapshot_json = _jsonable(snapshot)
|
||||
return task, created, False
|
||||
|
||||
previous_execution_status = task.execution_status
|
||||
|
||||
task.platform_order_id = str(
|
||||
_snapshot_value(snapshot, "platformOrderId", "platform_order_id", default="")
|
||||
@@ -448,6 +545,11 @@ def _sync_pending_tasks(
|
||||
source_order_id=str(row.get("source_order_id") or ""),
|
||||
source_order_item_id=item_id,
|
||||
source_fulfillment_id=str(row.get("source_fulfillment_id") or ""),
|
||||
flow_version=_flow_version_for_order(
|
||||
db,
|
||||
paid_at=_parse_snapshot_datetime(row.get("paid_at")),
|
||||
created_at=_now(),
|
||||
),
|
||||
created_at=_now(),
|
||||
updated_at=_now(),
|
||||
)
|
||||
@@ -481,6 +583,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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -79,6 +79,7 @@ def _count_cache_key(
|
||||
status: str,
|
||||
queue_bucket: str,
|
||||
sale_mode: str,
|
||||
flow_version: int | None,
|
||||
keyword: str,
|
||||
) -> tuple[Any, ...]:
|
||||
return (
|
||||
@@ -86,6 +87,7 @@ def _count_cache_key(
|
||||
status,
|
||||
queue_bucket,
|
||||
sale_mode,
|
||||
flow_version,
|
||||
keyword.strip(),
|
||||
)
|
||||
|
||||
@@ -209,25 +211,32 @@ def list_tasks(
|
||||
status: str = "",
|
||||
queue_bucket: str = "",
|
||||
sale_mode: str = "",
|
||||
flow_version: int | None = None,
|
||||
keyword: str = "",
|
||||
page: int = 1,
|
||||
page_size: int = 20,
|
||||
) -> dict[str, Any]:
|
||||
cutoff = _order_match_started_at(db)
|
||||
query = db.query(PlatformFulfillmentTask)
|
||||
query = _apply_order_match_cutoff(query, cutoff)
|
||||
query = query.filter(
|
||||
or_(
|
||||
PlatformFulfillmentTask.commodity_mapping_id.isnot(None),
|
||||
PlatformFulfillmentTask.commodity_id != "",
|
||||
if flow_version is not None:
|
||||
query = query.filter(PlatformFulfillmentTask.flow_version == flow_version)
|
||||
# 历史任务不受订单起算时间限制,否则很多旧单在工作台里永远看不到。
|
||||
if flow_version != 1:
|
||||
query = _apply_order_match_cutoff(query, cutoff)
|
||||
# “全部”和“待映射”都要展示未映射任务,不能再套映射存在条件。
|
||||
if queue_bucket not in {"all", "pending_mapping"}:
|
||||
query = query.filter(
|
||||
or_(
|
||||
PlatformFulfillmentTask.commodity_mapping_id.isnot(None),
|
||||
PlatformFulfillmentTask.commodity_id != "",
|
||||
)
|
||||
)
|
||||
)
|
||||
mode_filter = classification.normalize_sale_mode(sale_mode)
|
||||
if sale_mode and mode_filter != "unknown":
|
||||
query = query.filter(PlatformFulfillmentTask.sale_mode == mode_filter)
|
||||
elif sale_mode == "unknown":
|
||||
query = query.filter(PlatformFulfillmentTask.sale_mode == "unknown")
|
||||
if queue_bucket:
|
||||
if queue_bucket and queue_bucket != "all":
|
||||
now = datetime.now(UTC)
|
||||
if queue_bucket == classification.QUEUE_CANCELLED:
|
||||
query = query.filter(
|
||||
@@ -308,6 +317,7 @@ def list_tasks(
|
||||
status=status,
|
||||
queue_bucket=queue_bucket,
|
||||
sale_mode=sale_mode,
|
||||
flow_version=flow_version,
|
||||
keyword=keyword,
|
||||
),
|
||||
)
|
||||
@@ -424,6 +434,7 @@ def _task_out(
|
||||
"goodsName": goods_name,
|
||||
"requiredPoints": task.required_points,
|
||||
"saleMode": sale_mode,
|
||||
"flowVersion": int(task.flow_version or 1),
|
||||
"campaignKey": task.campaign_key,
|
||||
"campaignName": task.campaign_name,
|
||||
"offerAvailableFrom": task.offer_available_from,
|
||||
@@ -506,6 +517,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 +702,63 @@ 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
|
||||
# 线上账号渠道写作「微信 / 手Q」,QQ 不能直接拿 "QQ" 去比。
|
||||
customer_channel = " ".join(
|
||||
[
|
||||
"微信"
|
||||
if task.customer_platform == "wechat"
|
||||
else ("手Q" 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 +823,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),
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ export const platformFulfillmentApi = {
|
||||
status?: string;
|
||||
queue_bucket?: string;
|
||||
sale_mode?: string;
|
||||
flow_version?: number;
|
||||
keyword?: string;
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
|
||||
@@ -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;
|
||||
@@ -2554,6 +2573,7 @@ export interface PlatformFulfillmentTask {
|
||||
goodsName: string;
|
||||
requiredPoints: number | null;
|
||||
saleMode: 'presale' | 'direct' | 'manual' | 'unknown';
|
||||
flowVersion: number;
|
||||
campaignKey: string;
|
||||
campaignName: string;
|
||||
offerAvailableFrom: string | null;
|
||||
@@ -2582,6 +2602,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;
|
||||
|
||||
@@ -88,7 +88,7 @@ export default function MainLayout({ onLogout }: { onLogout?: () => void }) {
|
||||
|
||||
// 外部单协作:权限独立,客服没有 douyu:task 也要能进共享台账。
|
||||
if (can('douyu:collab:view')) {
|
||||
douyuItems.push({ key: '/douyu/collab', label: '订单台账', icon: <FileExcelOutlined /> });
|
||||
douyuItems.push({ key: '/douyu/collab', label: '斗鱼预售台账', icon: <FileExcelOutlined /> });
|
||||
}
|
||||
if (can('platform_fulfillment:view')) {
|
||||
douyuItems.push({ key: '/platform-fulfillment', label: '直播账号履约', icon: <ThunderboltOutlined /> });
|
||||
|
||||
@@ -1743,8 +1743,8 @@ export default function DouyuCollabPage() {
|
||||
return (
|
||||
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
||||
<div>
|
||||
<h2 style={{ margin: 0 }}>斗鱼订单台账</h2>
|
||||
<Text type="secondary">系统正常订单由直播账号履约工作台维护;这里记录财务、异常和人工补登记</Text>
|
||||
<h2 style={{ margin: 0 }}>斗鱼预售台账</h2>
|
||||
<Text type="secondary">预售订单在直播账号履约工作台绑定完成后同步到这里;这里记录财务、异常和人工补登记</Text>
|
||||
</div>
|
||||
|
||||
<Row gutter={[8, 8]}>
|
||||
|
||||
@@ -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, Tabs, 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<string, string> = {
|
||||
wechat: '微信',
|
||||
qq: 'QQ',
|
||||
};
|
||||
|
||||
const CUSTOMER_SYSTEM_LABELS: Record<string, string> = {
|
||||
ios: '苹果',
|
||||
android: '安卓',
|
||||
};
|
||||
|
||||
function customerMatchTone(profile: NonNullable<PlatformFulfillmentTask['customerProfile']>) {
|
||||
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: '待映射' },
|
||||
@@ -104,9 +120,23 @@ const MANUAL_REASON_LABELS: Record<string, string> = {
|
||||
other_manual: '其他人工',
|
||||
};
|
||||
|
||||
const SALE_MODE_TAB_STORAGE_KEY = 'platform_fulfillment_sale_mode_tab';
|
||||
|
||||
const QUEUE_BUCKET_OPTIONS = [
|
||||
{ value: 'all', label: '全部' },
|
||||
{ value: 'current', label: '当前待办' },
|
||||
{ value: 'pending_mapping', label: '待映射' },
|
||||
{ value: 'ready_for_fulfillment', label: '可履约' },
|
||||
{ value: 'needs_action', label: '需要人工' },
|
||||
{ value: 'completed', label: '已完成' },
|
||||
{ value: 'cancelled', label: '已取消' },
|
||||
];
|
||||
|
||||
const PRESALE_QUEUE_BUCKET_OPTIONS = [
|
||||
{ value: 'all', label: '全部' },
|
||||
{ value: 'current', label: '当前待办' },
|
||||
{ value: 'presale_waiting', label: '预售待开放' },
|
||||
{ value: 'pending_mapping', label: '待映射' },
|
||||
{ value: 'ready_for_fulfillment', label: '可履约' },
|
||||
{ value: 'needs_action', label: '需要人工' },
|
||||
{ value: 'completed', label: '已完成' },
|
||||
@@ -330,7 +360,7 @@ function eventDescription(event: { eventType: string; detail: Record<string, unk
|
||||
return String(detail.reason || '已转人工处理');
|
||||
}
|
||||
if (event.eventType === 'released_to_manual') {
|
||||
return `转人工原因:${String(detail.reason || '以外部单协作人工处理为准')}`;
|
||||
return `转人工原因:${String(detail.reason || '以订单台账人工处理为准')}`;
|
||||
}
|
||||
if (event.eventType === 'task_cancelled') {
|
||||
return `取消原因:${String(detail.reason || '人工取消')}`;
|
||||
@@ -436,8 +466,16 @@ export default function PlatformFulfillmentPage() {
|
||||
const user = getUser();
|
||||
const navigate = useNavigate();
|
||||
const { can } = usePermissions(user);
|
||||
const [queueBucket, setQueueBucket] = useState('current');
|
||||
const [saleModeFilter, setSaleModeFilter] = useState('');
|
||||
const [queueBucket, setQueueBucket] = useState('all');
|
||||
const [saleModeTab, setSaleModeTab] = useState<'direct' | 'presale' | 'unknown' | 'legacy'>(() => {
|
||||
const saved = localStorage.getItem(SALE_MODE_TAB_STORAGE_KEY);
|
||||
if (saved === 'presale' || saved === 'unknown' || saved === 'legacy') return saved;
|
||||
return 'direct';
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(SALE_MODE_TAB_STORAGE_KEY, saleModeTab);
|
||||
}, [saleModeTab]);
|
||||
const [keyword, setKeyword] = useState('');
|
||||
const [page, setPage] = useState(1);
|
||||
const [pageSize, setPageSize] = useState(20);
|
||||
@@ -521,13 +559,19 @@ export default function PlatformFulfillmentPage() {
|
||||
const queueBackedStatus = queueBucket === 'current'
|
||||
? 'unfinished'
|
||||
: (['completed', 'cancelled'].includes(queueBucket) ? queueBucket : undefined);
|
||||
const backendBucket = ['presale_waiting', 'ready_for_fulfillment', 'needs_action'].includes(queueBucket)
|
||||
const backendBucket = [
|
||||
'pending_mapping',
|
||||
'presale_waiting',
|
||||
'ready_for_fulfillment',
|
||||
'needs_action',
|
||||
].includes(queueBucket)
|
||||
? queueBucket
|
||||
: undefined;
|
||||
const result = await platformFulfillmentApi.listTasks({
|
||||
status: queueBackedStatus,
|
||||
queue_bucket: backendBucket,
|
||||
sale_mode: saleModeFilter || undefined,
|
||||
queue_bucket: queueBucket === 'all' ? 'all' : backendBucket,
|
||||
sale_mode: saleModeTab === 'legacy' ? undefined : saleModeTab,
|
||||
flow_version: saleModeTab === 'legacy' ? 1 : 2,
|
||||
keyword: keyword.trim() || undefined,
|
||||
page,
|
||||
page_size: pageSize,
|
||||
@@ -539,7 +583,7 @@ export default function PlatformFulfillmentPage() {
|
||||
} finally {
|
||||
if (!silent) setLoading(false);
|
||||
}
|
||||
}, [keyword, page, pageSize, queueBucket, saleModeFilter]);
|
||||
}, [keyword, page, pageSize, queueBucket, saleModeTab]);
|
||||
|
||||
const loadDetail = useCallback(async (taskId: number, silent = false) => {
|
||||
if (!silent) setDetailLoading(true);
|
||||
@@ -687,7 +731,7 @@ export default function PlatformFulfillmentPage() {
|
||||
const result = await platformFulfillmentApi.syncCollab(taskIds);
|
||||
const syncedOrderNo =
|
||||
result.items.find((item) => item.action === 'created' || item.action === 'updated')?.orderNo || '';
|
||||
const summary = `外部协作同步完成:新增 ${result.created},更新 ${result.updated}${
|
||||
const summary = `斗鱼预售台账同步完成:新增 ${result.created},更新 ${result.updated}${
|
||||
taskIds.length === 1 && syncedOrderNo ? `,订单 ${syncedOrderNo}` : ''
|
||||
}`;
|
||||
if (result.failed || result.skipped) {
|
||||
@@ -1280,26 +1324,19 @@ export default function PlatformFulfillmentPage() {
|
||||
{
|
||||
title: '商品映射',
|
||||
key: 'mapping',
|
||||
width: 230,
|
||||
width: 270,
|
||||
render: (_, task) => (
|
||||
<Space direction="vertical" size={2}>
|
||||
<Space direction="vertical" size={3}>
|
||||
<Text ellipsis title={task.commodityId}>
|
||||
{task.goodsName || task.skuName || task.internalSkuKey || '未映射'}
|
||||
</Text>
|
||||
<Text type="secondary">{task.requiredPoints != null ? `${task.requiredPoints} 积分` : '价格未知'}</Text>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '分类',
|
||||
key: 'classification',
|
||||
width: 190,
|
||||
render: (_, task) => (
|
||||
<Space direction="vertical" size={3}>
|
||||
<Space size={4}>
|
||||
<Space size={6} wrap>
|
||||
<Tag color={task.saleMode === 'presale' ? 'gold' : task.saleMode === 'direct' ? 'green' : 'default'}>
|
||||
{SALE_MODE_LABELS[task.saleMode] || task.saleMode}
|
||||
</Tag>
|
||||
<Text type="secondary">
|
||||
{task.requiredPoints != null ? `${task.requiredPoints} 积分` : '价格未知'}
|
||||
</Text>
|
||||
</Space>
|
||||
<Text type="secondary" ellipsis title={task.campaignName || task.campaignKey || '-'}>
|
||||
{task.campaignName || task.campaignKey || '未设置活动批次'}
|
||||
@@ -1336,7 +1373,7 @@ export default function PlatformFulfillmentPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '绑定',
|
||||
title: '用户角色绑定',
|
||||
key: 'binding',
|
||||
width: 180,
|
||||
render: (_, task) => (
|
||||
@@ -1353,6 +1390,31 @@ export default function PlatformFulfillmentPage() {
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '游戏主页',
|
||||
key: 'customer_home_images',
|
||||
width: 120,
|
||||
render: (_, task) => {
|
||||
const images = task.customerProfile?.homeImages || [];
|
||||
if (images.length === 0) return <Text type="secondary">未上传</Text>;
|
||||
return (
|
||||
<Image.PreviewGroup items={images.map((item) => item.url)}>
|
||||
<Space size={4} wrap>
|
||||
{images.slice(0, 2).map((item, index) => (
|
||||
<Image
|
||||
key={`${item.objectKey || item.url}-${index}`}
|
||||
src={item.thumbnailUrl || item.url}
|
||||
width={44}
|
||||
height={44}
|
||||
style={{ objectFit: 'cover', borderRadius: 4 }}
|
||||
alt={`游戏主页截图 ${index + 1}`}
|
||||
/>
|
||||
))}
|
||||
</Space>
|
||||
</Image.PreviewGroup>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
key: 'status',
|
||||
@@ -1370,7 +1432,7 @@ export default function PlatformFulfillmentPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '外部协作',
|
||||
title: '斗鱼预售台账',
|
||||
key: 'collab',
|
||||
width: 150,
|
||||
render: (_, task) =>
|
||||
@@ -1414,20 +1476,23 @@ export default function PlatformFulfillmentPage() {
|
||||
<Button size="small" onClick={() => setSelectedId(task.id)}>
|
||||
详情
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
type={task.collabOrder ? 'default' : 'primary'}
|
||||
icon={<LinkOutlined />}
|
||||
loading={rowCollabSyncingId === task.id}
|
||||
disabled={
|
||||
!can('platform_fulfillment:use') ||
|
||||
collabSyncing ||
|
||||
(rowCollabSyncingId !== null && rowCollabSyncingId !== task.id)
|
||||
}
|
||||
onClick={() => void performCollabSync([task.id], task.id)}
|
||||
>
|
||||
同步外部单协作
|
||||
</Button>
|
||||
{saleModeTab === 'presale' ? (
|
||||
<Button
|
||||
size="small"
|
||||
type={task.collabOrder ? 'default' : 'primary'}
|
||||
icon={<LinkOutlined />}
|
||||
loading={rowCollabSyncingId === task.id}
|
||||
disabled={
|
||||
!can('platform_fulfillment:use') ||
|
||||
task.bindingStatus !== 'bound' ||
|
||||
collabSyncing ||
|
||||
(rowCollabSyncingId !== null && rowCollabSyncingId !== task.id)
|
||||
}
|
||||
onClick={() => void performCollabSync([task.id], task.id)}
|
||||
>
|
||||
同步到斗鱼预售台账
|
||||
</Button>
|
||||
) : null}
|
||||
{task.executionStatus === 'pending_mapping' ? (
|
||||
<Button size="small" type="primary" icon={<LinkOutlined />} disabled={!can('platform_fulfillment:admin')} onClick={() => void openMapping(task)}>
|
||||
配置映射
|
||||
@@ -1490,6 +1555,22 @@ export default function PlatformFulfillmentPage() {
|
||||
},
|
||||
];
|
||||
|
||||
const centeredColumns = columns
|
||||
.filter((column) => saleModeTab !== 'direct' || column.key !== 'collab')
|
||||
.map((column) => ({
|
||||
...column,
|
||||
align: 'center' as const,
|
||||
onHeaderCell: () => ({ style: { textAlign: 'center' as const } }),
|
||||
}));
|
||||
|
||||
const selectedCollabReady =
|
||||
selectedRowKeys.length > 0 &&
|
||||
rows.filter((row) => selectedRowKeys.map(String).includes(String(row.id))).length ===
|
||||
selectedRowKeys.length &&
|
||||
rows
|
||||
.filter((row) => selectedRowKeys.map(String).includes(String(row.id)))
|
||||
.every((row) => row.bindingStatus === 'bound');
|
||||
|
||||
const actionButtons = selected ? (
|
||||
<Space wrap>
|
||||
{selected.bindTask?.qrUrl ? (
|
||||
@@ -1531,7 +1612,7 @@ export default function PlatformFulfillmentPage() {
|
||||
icon={<UserSwitchOutlined />}
|
||||
onClick={() => {
|
||||
setManualReleaseTarget(selected);
|
||||
setManualReleaseReason('以外部单协作人工处理为准');
|
||||
setManualReleaseReason('以订单台账人工处理为准');
|
||||
}}
|
||||
>
|
||||
释放并转人工
|
||||
@@ -1589,18 +1670,21 @@ export default function PlatformFulfillmentPage() {
|
||||
<Button icon={<LinkOutlined />} disabled={!can('platform_fulfillment:admin')} onClick={() => void openMapping()}>
|
||||
商品映射
|
||||
</Button>
|
||||
<Button
|
||||
icon={<LinkOutlined />}
|
||||
loading={collabSyncing}
|
||||
disabled={
|
||||
!can('platform_fulfillment:use') ||
|
||||
selectedRowKeys.length === 0 ||
|
||||
rowCollabSyncingId !== null
|
||||
}
|
||||
onClick={() => void syncCollab()}
|
||||
>
|
||||
同步外部单协作{selectedRowKeys.length > 0 ? `(${selectedRowKeys.length})` : ''}
|
||||
</Button>
|
||||
{saleModeTab === 'presale' ? (
|
||||
<Button
|
||||
icon={<LinkOutlined />}
|
||||
loading={collabSyncing}
|
||||
disabled={
|
||||
!can('platform_fulfillment:use') ||
|
||||
selectedRowKeys.length === 0 ||
|
||||
!selectedCollabReady ||
|
||||
rowCollabSyncingId !== null
|
||||
}
|
||||
onClick={() => void syncCollab()}
|
||||
>
|
||||
同步到斗鱼预售台账{selectedRowKeys.length > 0 ? `(${selectedRowKeys.length})` : ''}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button type="primary" loading={syncing} icon={<SyncOutlined />} onClick={() => void sync()}>
|
||||
同步待履约订单
|
||||
</Button>
|
||||
@@ -1608,6 +1692,40 @@ export default function PlatformFulfillmentPage() {
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
<Tabs
|
||||
activeKey={saleModeTab}
|
||||
onChange={(value) => {
|
||||
const next =
|
||||
value === 'presale'
|
||||
? 'presale'
|
||||
: value === 'unknown'
|
||||
? 'unknown'
|
||||
: value === 'legacy'
|
||||
? 'legacy'
|
||||
: 'direct';
|
||||
setSaleModeTab(next);
|
||||
if (next !== 'presale' && queueBucket === 'presale_waiting') {
|
||||
setQueueBucket('current');
|
||||
}
|
||||
setSelectedRowKeys([]);
|
||||
setPage(1);
|
||||
}}
|
||||
items={[
|
||||
{ key: 'direct', label: '直接兑换' },
|
||||
{ key: 'presale', label: '预售' },
|
||||
{ key: 'unknown', label: '未分类' },
|
||||
{ key: 'legacy', label: '历史任务' },
|
||||
]}
|
||||
/>
|
||||
|
||||
{saleModeTab === 'legacy' ? (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message="历史任务仅允许人工处理,不参与自动选号、自动重试和预售台账同步。"
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<Card size="small">
|
||||
<Space wrap style={{ marginBottom: 16 }}>
|
||||
<Input.Search
|
||||
@@ -1622,24 +1740,15 @@ export default function PlatformFulfillmentPage() {
|
||||
/>
|
||||
<Segmented
|
||||
value={queueBucket}
|
||||
options={QUEUE_BUCKET_OPTIONS}
|
||||
options={
|
||||
saleModeTab === 'presale' ? PRESALE_QUEUE_BUCKET_OPTIONS : QUEUE_BUCKET_OPTIONS
|
||||
}
|
||||
onChange={(value) => {
|
||||
setQueueBucket(String(value));
|
||||
setSelectedRowKeys([]);
|
||||
setPage(1);
|
||||
}}
|
||||
/>
|
||||
<Select
|
||||
value={saleModeFilter}
|
||||
options={[
|
||||
{ value: '', label: '全部销售模式' },
|
||||
...Object.entries(SALE_MODE_LABELS).map(([value, label]) => ({ value, label })),
|
||||
]}
|
||||
onChange={(value) => {
|
||||
setSaleModeFilter(value);
|
||||
setPage(1);
|
||||
}}
|
||||
style={{ width: 150 }}
|
||||
/>
|
||||
<Button icon={<ReloadOutlined />} onClick={() => void loadTasks()}>
|
||||
刷新
|
||||
</Button>
|
||||
@@ -1647,7 +1756,7 @@ export default function PlatformFulfillmentPage() {
|
||||
<Table<PlatformFulfillmentTask>
|
||||
rowKey="id"
|
||||
loading={loading}
|
||||
columns={columns}
|
||||
columns={centeredColumns}
|
||||
dataSource={rows}
|
||||
rowSelection={{
|
||||
selectedRowKeys,
|
||||
@@ -1788,7 +1897,7 @@ export default function PlatformFulfillmentPage() {
|
||||
{bindingStatusLabel(selected.bindingStatus)}
|
||||
</Tag>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="外部协作单" span={2}>
|
||||
<Descriptions.Item label="斗鱼预售台账" span={2}>
|
||||
{selected.collabOrder
|
||||
? `${selected.collabOrder.orderNo} · ${collabStatusLabel(selected.collabOrder.status)}`
|
||||
: '未同步'}
|
||||
@@ -1798,6 +1907,65 @@ export default function PlatformFulfillmentPage() {
|
||||
</Descriptions>
|
||||
</Card>
|
||||
|
||||
<Card size="small" title="用户资料(order_site)">
|
||||
{selected.customerProfile ? (
|
||||
<Space direction="vertical" size={10} style={{ width: '100%' }}>
|
||||
<Descriptions bordered size="small" column={2}>
|
||||
<Descriptions.Item label="客户角色" span={2}>
|
||||
{selected.customerProfile.roleName || '未填写'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="登录方式">
|
||||
{CUSTOMER_PLATFORM_LABELS[selected.customerProfile.platform] || selected.customerProfile.platform || '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="系统">
|
||||
{CUSTOMER_SYSTEM_LABELS[selected.customerProfile.system] || selected.customerProfile.system || '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="平台当前角色">
|
||||
{selected.customerProfile.platformRoleName || '未识别'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="平台渠道">
|
||||
{selected.customerProfile.platformChannel || '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="绑定比对" span={2}>
|
||||
<Space wrap size={6}>
|
||||
<Tag color={customerMatchTone(selected.customerProfile)}>
|
||||
{selected.customerProfile.message}
|
||||
</Tag>
|
||||
{selected.customerProfile.updatedAt ? (
|
||||
<Text type="secondary">更新 {formatTime(selected.customerProfile.updatedAt)}</Text>
|
||||
) : null}
|
||||
</Space>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
{selected.customerProfile.homeImages.length ? (
|
||||
<Image.PreviewGroup
|
||||
items={selected.customerProfile.homeImages.map((item) => item.url)}
|
||||
>
|
||||
<Space wrap size={8}>
|
||||
{selected.customerProfile.homeImages.map((item, index) => (
|
||||
<Image
|
||||
key={`${item.objectKey || item.url}-${index}`}
|
||||
src={item.thumbnailUrl || item.url}
|
||||
width={96}
|
||||
height={96}
|
||||
style={{ objectFit: 'cover', borderRadius: 6 }}
|
||||
alt={`游戏主页截图 ${index + 1}`}
|
||||
/>
|
||||
))}
|
||||
</Space>
|
||||
</Image.PreviewGroup>
|
||||
) : (
|
||||
<Text type="secondary">没有游戏主页截图</Text>
|
||||
)}
|
||||
</Space>
|
||||
) : (
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description="客户尚未同步资料和游戏主页截图"
|
||||
/>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<Card size="small" title="账号实时状态">
|
||||
{selected.account ? (
|
||||
<Descriptions bordered size="small" column={2}>
|
||||
|
||||
Reference in New Issue
Block a user