fix(fulfillment): 支持重开未过期支付二维码并展示具体待人工原因

This commit is contained in:
yml
2026-11-28 14:11:21 +08:00
parent 20314a2f1d
commit 2013a9bdeb
9 changed files with 302 additions and 64 deletions
+44 -31
View File
@@ -118,6 +118,7 @@ from ..services.douyu_service import (
douyu_config_value,
douyu_task_payload,
ensure_douyu_config,
find_reusable_active_payment_task,
visible_douyu_task_accounts,
)
from ..services.execution_jobs import (
@@ -439,9 +440,7 @@ def _list_visible_tasks_for_admin(
if batch_id:
base_query = base_query.filter(DouyuTask.batch_id == batch_id)
if account_scope_query is not None:
base_query = base_query.filter(
DouyuTask.account_id.in_(account_scope_query)
)
base_query = base_query.filter(DouyuTask.account_id.in_(account_scope_query))
for query in _split_task_scope_query(base_query, handbook_scope):
rows = query.order_by(DouyuTask.id.desc()).limit(take).all()
task_ids.extend(int(row[0]) for row in rows)
@@ -695,7 +694,9 @@ def _account_out(account: Account) -> DouyuTaskAccountOut:
esports_change_role_wait_time=(
account.esports_change_role_wait_time if esports_cooldown else 0
),
esports_can_change_time=account.esports_can_change_time if esports_cooldown else None,
esports_can_change_time=account.esports_can_change_time
if esports_cooldown
else None,
xpd_game_name=account.xpd_game_name or "",
xpd_openid=account.xpd_openid or "",
xpd_role_id=account.xpd_role_id or "",
@@ -741,9 +742,7 @@ def _config_out(config: DouyuConfig) -> DouyuConfigOut:
gold_recharge_channel=text("gold_recharge_channel"),
gold_api_product_id=text("gold_api_product_id"),
gold_api_account_template_name=text("gold_api_account_template_name"),
recharge_duplicate_confirm_minutes=number(
"recharge_duplicate_confirm_minutes"
),
recharge_duplicate_confirm_minutes=number("recharge_duplicate_confirm_minutes"),
gold_api_max_amount=number("gold_api_max_amount"),
gift_id=text("gift_id"),
skin_id=text("skin_id"),
@@ -1351,8 +1350,7 @@ def _api_recharge_duplicate_guard(
confirmation = (
db.query(DouyuRechargeConfirmation)
.filter(
DouyuRechargeConfirmation.token
== req.recharge_confirmation_token,
DouyuRechargeConfirmation.token == req.recharge_confirmation_token,
)
.with_for_update()
.first()
@@ -1411,9 +1409,7 @@ def _api_recharge_duplicate_guard(
)
if not previous:
return None
duplicate_account_ids = {
int(task.account_id) for task in previous
}
duplicate_account_ids = {int(task.account_id) for task in previous}
account_rows = (
db.query(Account)
.filter(Account.id.in_(duplicate_account_ids))
@@ -1432,8 +1428,7 @@ def _api_recharge_duplicate_guard(
)
db.commit()
names = [
row.nickname or row.username or row.uid or f"#{row.id}"
for row in account_rows
row.nickname or row.username or row.uid or f"#{row.id}" for row in account_rows
]
return {
"batch_id": "",
@@ -1517,9 +1512,31 @@ def _prepare_task_batch(
else None
)
if (
req.task_type == "create_gold_qr"
and recharge_channel == "supplier_api"
req.reuse_active_payment
and len(req.account_ids) == 1
and req.task_type in {"create_elite_qr", "create_esports_qr", "create_gold_qr"}
and not (
req.task_type == "create_gold_qr" and recharge_channel == "supplier_api"
)
):
reusable = find_reusable_active_payment_task(
db,
int(req.account_ids[0]),
task_type=req.task_type,
handbook_scope=req.handbook_scope,
recharge_channel=recharge_channel,
recharge_amount=recharge_amount,
)
if reusable is not None:
return {
"batch_id": reusable.batch_id,
"count": 1,
"success": True,
"reused": True,
"message": "当前已有未过期的支付二维码,已重新打开",
}
if req.task_type == "create_gold_qr" and recharge_channel == "supplier_api":
guard = _api_recharge_duplicate_guard(
db,
req=req,
@@ -1574,8 +1591,7 @@ def _prepare_task_batch(
):
visible_accounts = visible_douyu_task_accounts(db, req.account_ids)
inspections = [
workbench_force_goods_inspection(db, acc)
for acc in visible_accounts
workbench_force_goods_inspection(db, acc) for acc in visible_accounts
]
occupied_items = [item for item in inspections if item["occupied"]]
blocked = next(
@@ -1632,7 +1648,9 @@ def _prepare_task_batch(
)
forced_pf_details: list[dict[str, Any]] = []
for douyu_task, account in forced_rows:
result_data = douyu_task.result if isinstance(douyu_task.result, dict) else {}
result_data = (
douyu_task.result if isinstance(douyu_task.result, dict) else {}
)
raw_payload = result_data.get("payload")
payload_meta = raw_payload if isinstance(raw_payload, dict) else {}
pf_task_id = payload_meta.get("force_platform_task_id")
@@ -1779,13 +1797,12 @@ def list_tasks(
account_scope_query: Select | None = None
if workbench_only:
if not handbook_scope:
raise HTTPException(status_code=400, detail="工作台任务查询必须指定手册类型")
account_scope_query = (
select(DouyuWorkbenchAccount.account_id)
.where(
DouyuWorkbenchAccount.user_id == current.id,
DouyuWorkbenchAccount.handbook_scope == handbook_scope,
raise HTTPException(
status_code=400, detail="工作台任务查询必须指定手册类型"
)
account_scope_query = select(DouyuWorkbenchAccount.account_id).where(
DouyuWorkbenchAccount.user_id == current.id,
DouyuWorkbenchAccount.handbook_scope == handbook_scope,
)
if _can_view_all(current):
@@ -2083,16 +2100,12 @@ async def ws_douyu_logs(websocket: WebSocket, batch_id: str):
return
continue
if job is None or job.status in TERMINAL_STATUSES:
await websocket.send_json(
{"level": "result", "message": "批次已结束"}
)
await websocket.send_json({"level": "result", "message": "批次已结束"})
return
await asyncio.sleep(0.5)
idle_seconds += 0.5
if idle_seconds >= 30:
await websocket.send_json(
{"level": "heartbeat", "message": ""}
)
await websocket.send_json({"level": "heartbeat", "message": ""})
idle_seconds = 0
log_queue: asyncio.Queue = batch["log_queue"]