diff --git a/web/backend/services/huya_runner_bind.py b/web/backend/services/huya_runner_bind.py index da110c6..20a7fec 100644 --- a/web/backend/services/huya_runner_bind.py +++ b/web/backend/services/huya_runner_bind.py @@ -3,6 +3,7 @@ from __future__ import annotations import time from datetime import datetime, timezone +from typing import Any from sqlalchemy.orm import Session @@ -18,10 +19,27 @@ HUYA_BIND_ROLE_POLL_SECONDS = 180 HUYA_BIND_ROLE_POLL_INTERVAL = 3 HUYA_BIND_ZT_UUID = "b02faae1" HUYA_BIND_ROOM_ID = "30596253" -from .huya_runner_core import HUYA_RECHARGE_SOURCE_ID +from .huya_runner_core import HUYA_RECHARGE_SOURCE_ID, HuyaBatchRunnerCore + class BindMixin: """游戏角色绑定域:绑定状态机、扫码/确认绑定。""" + + if TYPE_CHECKING: + _stop: Any + payload: dict + + @staticmethod + def _format_local_time(timestamp: int) -> str: ... + + @staticmethod + def _to_int(value: Any) -> int: ... + + def _resolve_uid(self, account_info: dict) -> int: ... + def _push_log(self, level: str, message: str) -> None: ... + def _mark_task(self, *args: Any, **kwargs: Any) -> None: ... + def _update_task_progress(self, *args: Any, **kwargs: Any) -> None: ... + @staticmethod def _role_name(bind_status) -> str: account_data = bind_status.accountData @@ -29,7 +47,7 @@ class BindMixin: @staticmethod def _has_bind_role(bind_status) -> bool: - return bool(bind_status and HuyaBatchRunner._role_name(bind_status)) + return bool(bind_status and BindMixin._role_name(bind_status)) @staticmethod def _bind_role_result(bind_status) -> dict: @@ -38,7 +56,7 @@ class BindMixin: game_role = account_data.gameRole return { "game_title": bind_status.gameName, - "role_name": HuyaBatchRunner._role_name(bind_status), + "role_name": BindMixin._role_name(bind_status), "change_bind_day": bind_status.changeBindDay, "is_bind_account": account_data.isBindAcount, "is_bind_role": account_data.isBindRole, @@ -54,8 +72,8 @@ class BindMixin: parts = [game_role.platName, game_role.areaName] return " / ".join(part for part in parts if part) - @classmethod - def _bind_change_state(cls, bind_status) -> dict: + @staticmethod + def _bind_change_state(bind_status) -> dict: account_data = bind_status.accountData is_bound = bool(account_data.isBindAcount and account_data.isBindRole) change_time = int(account_data.changBindTime or 0) @@ -65,16 +83,16 @@ class BindMixin: "is_bound": is_bound, "can_change_bind": can_change, "change_bind_time": change_time, - "change_available_at": cls._format_local_time(change_time), + "change_available_at": HuyaBatchRunnerCore._format_local_time(change_time), "change_bind_day": int(bind_status.changeBindDay or 0), } - @classmethod - def _bind_ready_result(cls, bind_status) -> dict: - role_info = cls._bind_role_result(bind_status) + @staticmethod + def _bind_ready_result(bind_status) -> dict: + role_info = BindMixin._bind_role_result(bind_status) return { **role_info, - **cls._bind_change_state(bind_status), + **BindMixin._bind_change_state(bind_status), "bind_status": bind_status.to_dict(), "bind_ready_for_confirm": bool(role_info["role_name"]), "bind_phase": "role_ready" if role_info["role_name"] else "waiting_role", @@ -82,7 +100,7 @@ class BindMixin: def _resolve_bind_status( self, - client: HuyaHttpClient, + client: Any, uid: int, cookie: str, b_act_id_int: int, @@ -106,9 +124,10 @@ class BindMixin: chosen_status = outer_status account_data = outer_status.accountData - should_check_inner = ( - not self._has_bind_role(outer_status) - and bool(account_data.isNeedActCheck or not account_data.isBindAcount or not account_data.isBindRole) + should_check_inner = not self._has_bind_role(outer_status) and bool( + account_data.isNeedActCheck + or not account_data.isBindAcount + or not account_data.isBindRole ) if should_check_inner: inner_status = client.check_user_bind_game_account( @@ -162,22 +181,28 @@ class BindMixin: qrcode_token = str(result.get("qrcode_token") or "") qrcode_finished = not qrcode_token result["bind_polling"] = True - self._update_task_progress(worker_db, task, "running", "已生成绑定小程序码,等待扫码绑定", result) + self._update_task_progress( + worker_db, task, "running", "已生成绑定小程序码,等待扫码绑定", result + ) while not self._stop.is_set() and time.monotonic() < deadline: if self._stop.wait(HUYA_BIND_ROLE_POLL_INTERVAL): break if qrcode_token and not qrcode_finished: - qrcode_status = client.get_livelink_qrcode_status(qrcode_token, timeout=10.0) + qrcode_status = client.get_livelink_qrcode_status( + qrcode_token, timeout=10.0 + ) if qrcode_status is not None: result["qrcode_status"] = qrcode_status if qrcode_status["is_expired"] or qrcode_status["is_failure"]: - result.update({ - "bind_phase": "qrcode_expired", - "bind_ready_for_confirm": False, - "bind_polling": False, - }) + result.update( + { + "bind_phase": "qrcode_expired", + "bind_ready_for_confirm": False, + "bind_polling": False, + } + ) self._update_task_progress( worker_db, task, @@ -205,10 +230,12 @@ class BindMixin: result.update(bind_query_result) if bind_status.status != 200: - result.update({ - "bind_phase": "role_check_failed", - "bind_status": bind_status.to_dict(), - }) + result.update( + { + "bind_phase": "role_check_failed", + "bind_status": bind_status.to_dict(), + } + ) self._update_task_progress( worker_db, task, @@ -250,11 +277,13 @@ class BindMixin: message = "已生成绑定小程序码,等待扫码绑定" self._update_task_progress(worker_db, task, "running", message, result) - result.update({ - "bind_phase": "role_timeout" if not self._stop.is_set() else "stopped", - "bind_ready_for_confirm": False, - "bind_polling": False, - }) + result.update( + { + "bind_phase": "role_timeout" if not self._stop.is_set() else "stopped", + "bind_ready_for_confirm": False, + "bind_polling": False, + } + ) return "", result def _execute_get_bind_qr( @@ -265,14 +294,18 @@ class BindMixin: account_info: dict, config_info: dict, ): - b_act_id = str(self.payload.get("bind_act_id") or config_info.get("bind_act_id") or "").strip() + b_act_id = str( + self.payload.get("bind_act_id") or config_info.get("bind_act_id") or "" + ).strip() if not b_act_id: self._mark_task(worker_db, task, "failed", "请先配置虎牙绑定 bActId") return b_act_id_int = self._to_int(b_act_id) if not b_act_id_int: - self._mark_task(worker_db, task, "failed", f"虎牙绑定 bActId 无效: {b_act_id}") + self._mark_task( + worker_db, task, "failed", f"虎牙绑定 bActId 无效: {b_act_id}" + ) return uid = self._resolve_uid(account_info) @@ -285,7 +318,9 @@ class BindMixin: self._mark_task(worker_db, task, "failed", "账号 Cookie 为空") return - client = HuyaHttpClient(logger=lambda msg: self._push_log("info", f"[{uid}] {msg}")) + client: Any = HuyaHttpClient( + logger=lambda msg: self._push_log("info", f"[{uid}] {msg}") + ) bind_status, bind_query_result = self._resolve_bind_status( client=client, uid=uid, @@ -308,7 +343,9 @@ class BindMixin: role_info = self._bind_role_result(bind_status) change_state = self._bind_change_state(bind_status) if role_info["role_name"]: - self._apply_role_to_account(account, bind_status, account.status or "imported") + self._apply_role_to_account( + account, bind_status, account.status or "imported" + ) if not change_state["can_change_bind"]: role_name = role_info["role_name"] or "当前角色" available_at = change_state["change_available_at"] @@ -346,9 +383,13 @@ class BindMixin: ) return - profile_nick = account_info.get("nickname") or account_info.get("username") or "" + profile_nick = ( + account_info.get("nickname") or account_info.get("username") or "" + ) profile_avatar = "" - profile_resp = client.get_user_profile_batch(uid=uid, cookie=cookie, target_uids=[uid]) + profile_resp = client.get_user_profile_batch( + uid=uid, cookie=cookie, target_uids=[uid] + ) if profile_resp is not None and profile_resp.profiles: profile = profile_resp.profiles[0] profile_nick = profile.nick or profile.passport or profile_nick @@ -380,7 +421,9 @@ class BindMixin: "mini_qrcode_image": mini_qrcode["mini_qrcode_image"], "qrcode_token": mini_qrcode.get("qrcode_token") or "", **bind_query_result, - "bind_phase": "waiting_scan" if mini_qrcode.get("qrcode_token") else "waiting_role", + "bind_phase": "waiting_scan" + if mini_qrcode.get("qrcode_token") + else "waiting_role", "bind_ready_for_confirm": False, "bind_polling": True, "bind_redirect_url": bind_redirect_url, @@ -410,16 +453,26 @@ class BindMixin: result=result, ) if role_name: - self._mark_task(worker_db, task, "success", f"已识别角色: {role_name},待确认绑定", result) + self._mark_task( + worker_db, + task, + "success", + f"已识别角色: {role_name},待确认绑定", + result, + ) return if result.get("bind_phase") == "stopped": self._mark_task(worker_db, task, "stopped", "任务已停止", result) return if result.get("bind_phase") == "qrcode_expired": - self._mark_task(worker_db, task, "failed", "绑定小程序码已失效,请重新获取", result) + self._mark_task( + worker_db, task, "failed", "绑定小程序码已失效,请重新获取", result + ) return - self._mark_task(worker_db, task, "success", "已生成绑定小程序码,未检测到绑定角色", result) + self._mark_task( + worker_db, task, "success", "已生成绑定小程序码,未检测到绑定角色", result + ) def _execute_query_game_name( self, @@ -429,14 +482,18 @@ class BindMixin: account_info: dict, config_info: dict, ): - b_act_id = str(self.payload.get("bind_act_id") or config_info.get("bind_act_id") or "").strip() + b_act_id = str( + self.payload.get("bind_act_id") or config_info.get("bind_act_id") or "" + ).strip() if not b_act_id: self._mark_task(worker_db, task, "failed", "请先配置虎牙绑定 bActId") return b_act_id_int = self._to_int(b_act_id) if not b_act_id_int: - self._mark_task(worker_db, task, "failed", f"虎牙绑定 bActId 无效: {b_act_id}") + self._mark_task( + worker_db, task, "failed", f"虎牙绑定 bActId 无效: {b_act_id}" + ) return uid = self._resolve_uid(account_info) @@ -449,7 +506,9 @@ class BindMixin: self._mark_task(worker_db, task, "failed", "账号 Cookie 为空") return - client = HuyaHttpClient(logger=lambda msg: self._push_log("info", f"[{uid}] {msg}")) + client: Any = HuyaHttpClient( + logger=lambda msg: self._push_log("info", f"[{uid}] {msg}") + ) bind_status, bind_query_result = self._resolve_bind_status( client=client, uid=uid, @@ -497,14 +556,18 @@ class BindMixin: account_info: dict, config_info: dict, ): - b_act_id = str(self.payload.get("bind_act_id") or config_info.get("bind_act_id") or "").strip() + b_act_id = str( + self.payload.get("bind_act_id") or config_info.get("bind_act_id") or "" + ).strip() if not b_act_id: self._mark_task(worker_db, task, "failed", "请先配置虎牙绑定 bActId") return b_act_id_int = self._to_int(b_act_id) if not b_act_id_int: - self._mark_task(worker_db, task, "failed", f"虎牙绑定 bActId 无效: {b_act_id}") + self._mark_task( + worker_db, task, "failed", f"虎牙绑定 bActId 无效: {b_act_id}" + ) return uid = self._resolve_uid(account_info) @@ -517,7 +580,9 @@ class BindMixin: self._mark_task(worker_db, task, "failed", "账号 Cookie 为空") return - client = HuyaHttpClient(logger=lambda msg: self._push_log("info", f"[{uid}] {msg}")) + client: Any = HuyaHttpClient( + logger=lambda msg: self._push_log("info", f"[{uid}] {msg}") + ) role_status, role_query_result = self._resolve_bind_status( client=client, uid=uid, @@ -545,7 +610,13 @@ class BindMixin: "bind_confirmed": False, **role_query_result, } - self._mark_task(worker_db, task, "failed", "尚未识别到待确认角色,请先扫码完成绑定", result) + self._mark_task( + worker_db, + task, + "failed", + "尚未识别到待确认角色,请先扫码完成绑定", + result, + ) return confirm_resp = client.confirm_bind_act_account( @@ -589,7 +660,9 @@ class BindMixin: **role_query_result, } self._apply_role_to_account(account, role_status, "bind_confirmed") - self._mark_task(worker_db, task, "success", f"确认绑定: {role_name}", result) + self._mark_task( + worker_db, task, "success", f"确认绑定: {role_name}", result + ) return if refreshed_status.status != 200: result = { @@ -602,7 +675,9 @@ class BindMixin: "refresh_error": refreshed_query_result, } self._apply_role_to_account(account, role_status, "bind_confirmed") - self._mark_task(worker_db, task, "success", f"确认绑定: {role_name}", result) + self._mark_task( + worker_db, task, "success", f"确认绑定: {role_name}", result + ) return refreshed_confirmed = bool( @@ -610,8 +685,12 @@ class BindMixin: and refreshed_status.accountData.isBindRole ) refreshed_role_info = self._bind_role_result(refreshed_status) - final_status = refreshed_status if refreshed_role_info["role_name"] else role_status - final_role_info = refreshed_role_info if refreshed_role_info["role_name"] else role_info + final_status = ( + refreshed_status if refreshed_role_info["role_name"] else role_status + ) + final_role_info = ( + refreshed_role_info if refreshed_role_info["role_name"] else role_info + ) result = { "bind_act_id": b_act_id_int, "bind_confirmed": True, @@ -625,4 +704,3 @@ class BindMixin: self._apply_role_to_account(account, final_status, "bind_confirmed") role_name = final_role_info["role_name"] or role_name or "已绑定" self._mark_task(worker_db, task, "success", f"确认绑定: {role_name}", result) - diff --git a/web/backend/services/huya_runner_recharge.py b/web/backend/services/huya_runner_recharge.py index 9c3c12a..d4a67cb 100644 --- a/web/backend/services/huya_runner_recharge.py +++ b/web/backend/services/huya_runner_recharge.py @@ -3,6 +3,7 @@ from __future__ import annotations import time from datetime import datetime, timezone +from typing import Any, TYPE_CHECKING from sqlalchemy.orm import Session @@ -24,8 +25,28 @@ HUYA_RECHARGE_EXTRA_PRODUCTS = [ ] from .huya_runner_core import HUYA_RECHARGE_SOURCE_ID +if TYPE_CHECKING: + from .huya_runner import HuyaBatchRunner + + class RechargeMixin: """充值域:充值商品、下单与到账轮询。""" + + if TYPE_CHECKING: + _stop: Any + payload: dict + + @staticmethod + def _to_int(value: Any) -> int: ... + + def _resolve_uid(self, account_info: dict) -> int: ... + def _push_log(self, level: str, message: str) -> None: ... + def _mark_task(self, *args: Any, **kwargs: Any) -> None: ... + def _update_task_progress(self, *args: Any, **kwargs: Any) -> None: ... + + @staticmethod + def _format_local_time(timestamp: int) -> str: ... + @staticmethod def _huya_order_status_label(status: int) -> str: from core.huya.shop_structs import OrderStatus @@ -43,8 +64,8 @@ class RechargeMixin: } return labels.get(int(status or 0), str(status or "未知")) - @classmethod - def _is_huya_order_paid(cls, order) -> bool: + @staticmethod + def _is_huya_order_paid(order) -> bool: from core.huya.shop_structs import OrderStatus paid_statuses = { @@ -54,11 +75,14 @@ class RechargeMixin: OrderStatus.FINISHED, OrderStatus.FINISHED_CLOSED, } - return int(getattr(order, "payTime", 0) or 0) > 0 or int(getattr(order, "orderStatus", 0) or 0) in paid_statuses + return ( + int(getattr(order, "payTime", 0) or 0) > 0 + or int(getattr(order, "orderStatus", 0) or 0) in paid_statuses + ) def _wait_recharge_payment( self, - client: HuyaHttpClient, + client: Any, uid: int, guid: str, cookie: str, @@ -86,19 +110,25 @@ class RechargeMixin: continue last_order = order.to_dict() status = int(getattr(order, "orderStatus", 0) or 0) - result.update({ - "payment_checked_at": checked_at, - "payment_order": last_order, - "payment_order_status": status, - "payment_order_status_label": self._huya_order_status_label(status), - }) + result.update( + { + "payment_checked_at": checked_at, + "payment_order": last_order, + "payment_order_status": status, + "payment_order_status_label": self._huya_order_status_label( + status + ), + } + ) if self._is_huya_order_paid(order): - result.update({ - "payment_status": "paid", - "payment_status_label": "已支付", - "payment_paid": True, - "payment_paid_at": checked_at, - }) + result.update( + { + "payment_status": "paid", + "payment_status_label": "已支付", + "payment_paid": True, + "payment_paid_at": checked_at, + } + ) return "paid", last_order break else: @@ -106,12 +136,16 @@ class RechargeMixin: if self._stop.wait(HUYA_PAYMENT_POLL_INTERVAL): break - result.update({ - "payment_status": "timeout" if not self._stop.is_set() else "stopped", - "payment_status_label": "等待支付超时" if not self._stop.is_set() else "已停止监听", - "payment_paid": False, - "payment_timeout_seconds": HUYA_PAYMENT_POLL_SECONDS, - }) + result.update( + { + "payment_status": "timeout" if not self._stop.is_set() else "stopped", + "payment_status_label": "等待支付超时" + if not self._stop.is_set() + else "已停止监听", + "payment_paid": False, + "payment_timeout_seconds": HUYA_PAYMENT_POLL_SECONDS, + } + ) if last_order: result["payment_order"] = last_order return result["payment_status"], last_order @@ -157,8 +191,12 @@ class RechargeMixin: self._mark_task(worker_db, task, "failed", "账号 Cookie 为空") return - client = HuyaHttpClient(logger=lambda msg: self._push_log("info", f"[{uid}] {msg}")) - task_resp = client.get_act_task_detail(uid=uid, cookie=cookie, act_id=HUYA_RECHARGE_ACT_ID) + client: Any = HuyaHttpClient( + logger=lambda msg: self._push_log("info", f"[{uid}] {msg}") + ) + task_resp = client.get_act_task_detail( + uid=uid, cookie=cookie, act_id=HUYA_RECHARGE_ACT_ID + ) if task_resp is None: self._mark_task(worker_db, task, "error", "虎牙充值任务详情接口无响应") return @@ -190,20 +228,24 @@ class RechargeMixin: for index, item in enumerate(task_result.get("tasks", []), start=1): if int(item.get("task_type") or 0) != 67: continue - add_candidate({ - "spu_id": item.get("spu_id") or "", - "name": item.get("name") or "", - "task_id": str(item.get("task_id") or ""), - "task_name": item.get("name") or "", - "description": item.get("description") or "", - "icon": item.get("icon") or "", - "task_url": item.get("task_url") or "", - "prizes": item.get("prizes") or [], - "sort": index, - }) + add_candidate( + { + "spu_id": item.get("spu_id") or "", + "name": item.get("name") or "", + "task_id": str(item.get("task_id") or ""), + "task_name": item.get("name") or "", + "description": item.get("description") or "", + "icon": item.get("icon") or "", + "task_url": item.get("task_url") or "", + "prizes": item.get("prizes") or [], + "sort": index, + } + ) if not candidates: - self._mark_task(worker_db, task, "failed", "未从活动任务中发现充值商品", task_result) + self._mark_task( + worker_db, task, "failed", "未从活动任务中发现充值商品", task_result + ) return now = datetime.now(timezone.utc) @@ -228,11 +270,14 @@ class RechargeMixin: continue detail = detail_resp.to_dict() if detail_resp.code != 200 or not detail.get("sku_id"): - failed.append({ - "spu_id": spu_id, - "message": detail_resp.message or f"商品详情获取失败: {detail_resp.code}", - "detail": detail, - }) + failed.append( + { + "spu_id": spu_id, + "message": detail_resp.message + or f"商品详情获取失败: {detail_resp.code}", + "detail": detail, + } + ) continue item = { @@ -241,7 +286,9 @@ class RechargeMixin: "spu_id": detail.get("spu_id") or spu_id, "sku_id": str(detail.get("sku_id") or ""), "name": detail.get("name") or candidate.get("name") or spu_id, - "description": detail.get("description") or candidate.get("description") or "", + "description": detail.get("description") + or candidate.get("description") + or "", "icon": detail.get("icon") or candidate.get("icon") or "", "task_id": candidate.get("task_id") or "", "task_name": candidate.get("task_name") or candidate.get("name") or "", @@ -251,20 +298,22 @@ class RechargeMixin: worker_db.query(HuyaRechargeGoodsSnapshot).delete(synchronize_session=False) for item in goods: - worker_db.add(HuyaRechargeGoodsSnapshot( - spu_id=item["spu_id"], - sku_id=item["sku_id"], - name=item["name"], - price=item.get("price") or None, - stock=item.get("stock") or None, - buy_limit=item.get("buy_limit") or None, - icon=item.get("icon") or "", - description=item.get("description") or "", - task_id=item.get("task_id") or "", - task_name=item.get("task_name") or "", - raw=item, - updated_at=now, - )) + worker_db.add( + HuyaRechargeGoodsSnapshot( + spu_id=item["spu_id"], + sku_id=item["sku_id"], + name=item["name"], + price=item.get("price") or None, + stock=item.get("stock") or None, + buy_limit=item.get("buy_limit") or None, + icon=item.get("icon") or "", + description=item.get("description") or "", + task_id=item.get("task_id") or "", + task_name=item.get("task_name") or "", + raw=item, + updated_at=now, + ) + ) account.status = "recharge_goods_refreshed" account.updated_at = now @@ -279,7 +328,9 @@ class RechargeMixin: "failed": failed, "task_detail": task_result, } - self._mark_task(worker_db, task, "success" if goods else "failed", message, result) + self._mark_task( + worker_db, task, "success" if goods else "failed", message, result + ) def _execute_create_recharge_order( self, @@ -301,7 +352,9 @@ class RechargeMixin: count = self._to_int(self.payload.get("count")) or 1 count = max(1, min(count, 999)) - pay_channel = self._normalize_pay_channel(self.payload.get("pay_channel") or config_info.get("pay_channel")) + pay_channel = self._normalize_pay_channel( + self.payload.get("pay_channel") or config_info.get("pay_channel") + ) uid = self._resolve_uid(account_info) if not uid: @@ -313,15 +366,23 @@ class RechargeMixin: self._mark_task(worker_db, task, "failed", "账号 Cookie 为空") return - snapshot = worker_db.query(HuyaRechargeGoodsSnapshot).filter( - HuyaRechargeGoodsSnapshot.spu_id == spu_id - ).first() + snapshot = ( + worker_db.query(HuyaRechargeGoodsSnapshot) + .filter(HuyaRechargeGoodsSnapshot.spu_id == spu_id) + .first() + ) payload_sku_id = self._to_int(self.payload.get("sku_id")) sku_id = payload_sku_id or self._to_int(snapshot.sku_id if snapshot else "") - product_name = str(self.payload.get("product_name") or (snapshot.name if snapshot else "") or spu_id) + product_name = str( + self.payload.get("product_name") + or (snapshot.name if snapshot else "") + or spu_id + ) unit_price = int(snapshot.price or 0) if snapshot else 0 - client = HuyaHttpClient(logger=lambda msg: self._push_log("info", f"[{uid}] {msg}")) + client: Any = HuyaHttpClient( + logger=lambda msg: self._push_log("info", f"[{uid}] {msg}") + ) detail_resp = client.get_goods_info( uid=uid, guid="", @@ -351,7 +412,13 @@ class RechargeMixin: product_name = detail.get("name") or product_name unit_price = int(detail.get("price") or unit_price or 0) if not sku_id: - self._mark_task(worker_db, task, "failed", "充值商品缺少 SKU,请先刷新充值商品列表", detail) + self._mark_task( + worker_db, + task, + "failed", + "充值商品缺少 SKU,请先刷新充值商品列表", + detail, + ) return order_resp = client.create_order( @@ -393,7 +460,13 @@ class RechargeMixin: item_count=count, ) if pay_resp is None: - self._mark_task(worker_db, task, "error", "虎牙支付接口无响应", {"goods": detail, "order": order_result}) + self._mark_task( + worker_db, + task, + "error", + "虎牙支付接口无响应", + {"goods": detail, "order": order_result}, + ) return pay_result = pay_resp.to_dict() if pay_resp.code != 200 or not pay_resp.payUrl: @@ -430,8 +503,12 @@ class RechargeMixin: account.status = "recharge_order_created" account.updated_at = datetime.now(timezone.utc) message = f"{product_name} x{count} {self._pay_channel_label(pay_channel)} {result['amount_text']}" - self._update_task_progress(worker_db, task, "running", f"{message},等待扫码支付", result) - self._push_log("info", f"[{uid}] 已生成虎牙支付二维码,开始监听订单 {order_resp.orderId}") + self._update_task_progress( + worker_db, task, "running", f"{message},等待扫码支付", result + ) + self._push_log( + "info", f"[{uid}] 已生成虎牙支付二维码,开始监听订单 {order_resp.orderId}" + ) payment_status, payment_order = self._wait_recharge_payment( client=client, @@ -451,10 +528,11 @@ class RechargeMixin: return if payment_status == "stopped": account.status = "recharge_order_created" - self._mark_task(worker_db, task, "stopped", f"{message},已停止监听支付", result) + self._mark_task( + worker_db, task, "stopped", f"{message},已停止监听支付", result + ) return account.status = "recharge_order_created" timeout_message = f"{message},{result['payment_status_label']}" self._mark_task(worker_db, task, "success", timeout_message, result) -