fix(fulfillment): 保持外部协作人工数据并支持转人工

This commit is contained in:
yml
2026-11-18 22:14:16 +08:00
parent e90e93d515
commit 86b586b96d
6 changed files with 302 additions and 14 deletions
+23 -7
View File
@@ -731,6 +731,8 @@ def _apply_platform_fulfillment_binding(
db: Session,
order: DouyuExternalOrder,
task: PlatformFulfillmentTask,
*,
overwrite: bool,
) -> None:
"""把履约任务已确认的本地绑定结果投影到协作单,不额外联网。"""
bind_task = (
@@ -742,11 +744,13 @@ def _apply_platform_fulfillment_binding(
role = binding_role_from_result(result)
if not role:
return
order.bind_game_role = _text(role, max_length=128)
if overwrite or not order.bind_game_role:
order.bind_game_role = _text(role, max_length=128)
channel = binding_channel(result)
if channel:
if channel and (overwrite or not order.bind_game_channel):
order.bind_game_channel = _text(channel, max_length=128)
order.bind_snapshot_at = order.bind_snapshot_at or _now()
if overwrite or not order.bind_snapshot_at:
order.bind_snapshot_at = _now()
def _apply_platform_fulfillment_status(
@@ -855,12 +859,19 @@ def sync_platform_fulfillment_order(
order.gift_name = gift_name
order.commodity_id = commodity_id
order.required_points = required_points
if account is not None:
if account is not None and (
created or (order.account_id is None and not order.account_username)
):
order.account_id = int(account.id)
order.account_username = _text(account.username, max_length=128)
order.account_uid = _text(account.uid, max_length=32)
order.account_nickname = _text(account.nickname, max_length=128)
_apply_platform_fulfillment_binding(db, order, task)
_apply_platform_fulfillment_binding(
db,
order,
task,
overwrite=created,
)
_apply_platform_fulfillment_status(order, task, created=created)
order.version = int(order.version or 0) + 1
db.flush()
@@ -871,11 +882,16 @@ def sync_platform_fulfillment_order(
"created": created,
"status": order.status,
}
if account is not None:
linked_account = (
db.query(Account).filter(Account.id == order.account_id).first()
if order.account_id
else None
)
if linked_account is not None:
record_account_action(
db,
current,
account=account,
account=linked_account,
action="douyu:collab:sync_from_platform_fulfillment",
event_type=EVENT_COLLAB_SYNCED,
title=f"同步外部单协作:{order.order_no}",