fix(platform): 持久化并完善斗鱼兑换结果图片
This commit is contained in:
@@ -56,6 +56,7 @@ from ..external_order_source import (
|
||||
list_pending_manual_fulfillments,
|
||||
lookup_pending_manual_fulfillment,
|
||||
)
|
||||
from ..file_service import build_file_url
|
||||
from .account_selector import (
|
||||
AccountCandidate,
|
||||
capability_candidate_accounts,
|
||||
@@ -662,6 +663,8 @@ def record_douyu_operation_started(
|
||||
payload: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
"""记录履约上下文发起的斗鱼操作,账号任务结果由执行器补写。"""
|
||||
if task_type == "exchange_goods" and len(douyu_task_ids) == 1:
|
||||
task.exchange_task_id = int(douyu_task_ids[0])
|
||||
_append_event(
|
||||
db,
|
||||
task.id,
|
||||
@@ -1056,6 +1059,7 @@ def _task_out(
|
||||
task: PlatformFulfillmentTask,
|
||||
*,
|
||||
include_qr: bool = False,
|
||||
include_exchange_task: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
account = (
|
||||
db.query(Account).filter(Account.id == task.account_id).first()
|
||||
@@ -1078,6 +1082,18 @@ def _task_out(
|
||||
.first()
|
||||
)
|
||||
bind_result = (bind_task.result or {}) if bind_task else {}
|
||||
exchange_task_id = task.exchange_task_id
|
||||
if exchange_task_id is None and include_exchange_task:
|
||||
exchange_task_id = (
|
||||
db.query(DouyuTask.id)
|
||||
.filter(
|
||||
DouyuTask.platform_task_id == task.id,
|
||||
DouyuTask.task_type == "exchange_goods",
|
||||
)
|
||||
.order_by(DouyuTask.id.desc())
|
||||
.limit(1)
|
||||
.scalar()
|
||||
)
|
||||
# 外层只消费共享绑定规则,不再自己比较角色名或 bindAct。
|
||||
pending_role = pending_binding_role_from_result(bind_result)
|
||||
return {
|
||||
@@ -1163,6 +1179,16 @@ def _task_out(
|
||||
if bind_task
|
||||
else None
|
||||
),
|
||||
"exchangeTaskId": exchange_task_id,
|
||||
"exchangeResultImage": (
|
||||
{
|
||||
"objectKey": task.exchange_result_image_key,
|
||||
"url": build_file_url(task.exchange_result_image_key),
|
||||
"savedAt": task.exchange_result_image_saved_at,
|
||||
}
|
||||
if task.exchange_result_image_key
|
||||
else None
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@@ -1189,7 +1215,7 @@ def get_task_detail(db: Session, task_id: int) -> dict[str, Any]:
|
||||
else {}
|
||||
)
|
||||
return {
|
||||
"task": _task_out(db, task, include_qr=True),
|
||||
"task": _task_out(db, task, include_qr=True, include_exchange_task=True),
|
||||
"events": [
|
||||
{
|
||||
"id": event.id,
|
||||
|
||||
Reference in New Issue
Block a user