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
+57 -4
View File
@@ -336,6 +336,62 @@ def _lock_payment_accounts(
)
def find_reusable_active_payment_task(
db: Session,
account_id: int,
*,
task_type: str,
handbook_scope: str,
recharge_channel: str = "",
recharge_amount: int | None = None,
) -> DouyuTask | None:
"""查找同账号当前未过期的同类型支付任务,用于关闭二维码弹窗后重新打开。"""
if task_type not in DOUYU_ACTIVE_PAYMENT_TASK_TYPES:
return None
if task_type == "create_gold_qr" and recharge_channel == "supplier_api":
return None
locked = (
db.query(Account.id)
.filter(Account.id == int(account_id), cookie_holding_filter())
.with_for_update()
.first()
)
if locked is None:
return None
conflict = (
db.query(DouyuTask)
.filter(
DouyuTask.account_id == int(account_id),
DouyuTask.status.in_(DOUYU_ACTIVE_TASK_STATUSES),
DouyuTask.task_type.in_(DOUYU_ACTIVE_PAYMENT_TASK_TYPES),
)
.order_by(DouyuTask.id.desc())
.with_for_update()
.first()
)
if conflict is None:
return None
if (
str(conflict.task_type or "") != task_type
or str(conflict.handbook_scope or "") != handbook_scope
):
return None
if task_type == "create_gold_qr" and (
str(conflict.recharge_channel or "") != str(recharge_channel or "")
or conflict.recharge_amount != recharge_amount
):
return None
if conflict.run_deadline_at is not None:
deadline = (
conflict.run_deadline_at
if conflict.run_deadline_at.tzinfo is not None
else conflict.run_deadline_at.replace(tzinfo=UTC)
)
if deadline <= datetime.now(UTC):
return None
return conflict
def update_account_profile_from_cookie(account: Account, cookie: str) -> None:
"""从 Cookie 回填 uid/nickname。"""
from .douyu_account_probe import update_identity_from_cookie
@@ -405,10 +461,7 @@ def create_douyu_planned_tasks(
"force_expected_role": inspection["account_role"],
"force_platform_task_id": inspection["platform_task_id"],
}
if (
task_type in {"refresh_esports_goods", "refresh_xpd_goods"}
and accounts
):
if task_type in {"refresh_esports_goods", "refresh_xpd_goods"} and accounts:
# 商品快照是全局数据,一个可用 CK 足够;没有 CK 时前端无法选账号创建任务。
accounts = accounts[:1]