优化(斗鱼预售台账): 统一命名并同步客户主页图

同步履约客户游戏主页截图,兼容 order_site 绝对 URL 与 objectKey;统一预售台账用户可见文案和保护标签;移除 CK 检测与重登前端页面入口。
This commit is contained in:
yml
2026-11-26 19:11:30 +08:00
parent 7a20c63464
commit 82e1944a33
44 changed files with 204 additions and 428 deletions
+43 -7
View File
@@ -1,4 +1,4 @@
"""直播账号履约任务向斗鱼外部单协作的幂等投影。"""
"""直播账号履约任务向斗鱼预售台账的幂等投影。"""
from __future__ import annotations
@@ -24,6 +24,7 @@ from .douyu_binding import (
resolve_fulfillment_binding,
)
from .douyu_collab_common import (
MAX_IMAGES,
POINTS_THRESHOLD_DEFAULT,
SOURCE_TYPE_PLATFORM_FULFILLMENT,
STATUS_DONE,
@@ -79,18 +80,50 @@ def _platform_fulfillment_gift(
def _platform_fulfillment_order_no(task: PlatformFulfillmentTask) -> str:
"""外部协作单直接使用 order_site 的真实平台订单号。"""
"""预售单直接使用 order_site 的真实平台订单号。"""
order_no = _text(task.platform_order_id)
if not order_no:
raise CollabError("履约任务缺少平台订单号", code="platform_order_no_required")
if len(order_no) > 64:
raise CollabError(
"平台订单号超过协作单号长度限制",
"平台订单号超过预售单号长度限制",
code="platform_order_no_too_long",
)
return order_no
def _platform_fulfillment_home_images(
task: PlatformFulfillmentTask,
) -> list[str]:
"""把 order_site 的客户主页截图投影成预售台账可展示的图片引用。
order_site 快照同时带 ``url`` 和 ``objectKey``。两者可能属于 order_site
自己的文件桶,因此优先保存绝对 URL,live-hub 回读时直接使用;只有没有
URL 的旧数据才退回 object key。
"""
images: list[str] = []
for item in task.customer_home_images or []:
if isinstance(item, str):
reference = item
elif isinstance(item, dict):
reference = (
item.get("url")
or item.get("thumbnailUrl")
or item.get("thumbnail_url")
or item.get("objectKey")
or item.get("object_key")
or ""
)
else:
continue
image = _text(reference, max_length=512)
if image and image not in images:
images.append(image)
if len(images) >= MAX_IMAGES:
break
return images
def _apply_platform_fulfillment_binding(
db: Session,
order: DouyuExternalOrder,
@@ -98,7 +131,7 @@ def _apply_platform_fulfillment_binding(
*,
overwrite: bool,
) -> None:
"""把履约任务已确认的本地绑定结果投影到协作单,不额外联网。"""
"""把履约任务已确认的本地绑定结果投影到预售单,不额外联网。"""
bind_task = (
db.query(DouyuTask).filter(DouyuTask.id == task.bind_task_id).first()
if task.bind_task_id
@@ -161,7 +194,7 @@ def sync_platform_fulfillment_order(
*,
commit: bool = True,
) -> tuple[DouyuExternalOrder, str]:
"""把一条直播履约任务幂等同步为斗鱼外部协作单。"""
"""把一条直播履约任务幂等同步为斗鱼预售台账订单。"""
if task.source_system != "order_site":
raise CollabError("仅支持同步 order_site 履约任务", code="source_unsupported")
@@ -198,6 +231,7 @@ def sync_platform_fulfillment_order(
else None
)
gift_name, commodity_id, required_points = _platform_fulfillment_gift(db, task)
home_images = _platform_fulfillment_home_images(task)
if order is None:
order = DouyuExternalOrder(
@@ -229,6 +263,8 @@ def sync_platform_fulfillment_order(
order.gift_name = gift_name
order.commodity_id = commodity_id
order.required_points = required_points
if home_images:
order.home_images = home_images
if account is not None and (
created or (order.account_id is None and not order.account_username)
):
@@ -270,7 +306,7 @@ def sync_platform_fulfillment_order(
account=linked_account,
action="douyu:collab:sync_from_platform_fulfillment",
event_type=EVENT_COLLAB_SYNCED,
title=f"同步外部单协作:{order.order_no}",
title=f"同步斗鱼预售台账:{order.order_no}",
target=f"douyu_external_order:{order.id}",
detail=audit_detail,
)
@@ -358,7 +394,7 @@ def sync_platform_fulfillment_orders(
}
)
except Exception: # noqa: BLE001 - 批量边界需隔离单条未知故障
logger.exception("同步直播履约任务 {} 到斗鱼外部协作失败", task_id)
logger.exception("同步直播履约任务 {} 到斗鱼预售台账失败", task_id)
result["failed"] += 1
result["items"].append(
{