fix(fulfillment): 支持重开未过期支付二维码并展示具体待人工原因
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -1893,6 +1893,7 @@ class DouyuTaskBatchRequest(BaseModel):
|
||||
platform_task_id: int | None = Field(None, gt=0)
|
||||
recharge_confirmation_token: str | None = Field(None, max_length=64)
|
||||
force_occupied: bool = False
|
||||
reuse_active_payment: bool = False
|
||||
|
||||
|
||||
class DouyuWorkbenchAccountsUpdate(BaseModel):
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -73,16 +73,10 @@ def manual_reason(issue_code: str, exchange_status: str) -> str:
|
||||
return "elite_not_opened"
|
||||
if issue == "commodity_limit_reached" or exchange == "limited":
|
||||
return "limit_reached"
|
||||
if issue in {
|
||||
"binding_failed",
|
||||
"account_role_cooldown",
|
||||
"customer_role_cooldown",
|
||||
"customer_role_bound_elsewhere",
|
||||
"account_role_bound_elsewhere",
|
||||
}:
|
||||
return "binding_failed"
|
||||
if issue in {"lease_expired", "manual_required"}:
|
||||
return "account_cooldown"
|
||||
if issue and issue != "manual_required":
|
||||
return issue
|
||||
if issue == "manual_required":
|
||||
return "manual_required"
|
||||
return "other_manual"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user