实现虎牙查询兑换记录
This commit is contained in:
@@ -211,6 +211,65 @@ class HuyaBatchRunner:
|
||||
account.updated_at = datetime.now(timezone.utc)
|
||||
self._mark_task(worker_db, task, "success", f"积分: {points}", result)
|
||||
|
||||
def _execute_query_exchange_records(
|
||||
self,
|
||||
worker_db: Session,
|
||||
task: HuyaTask,
|
||||
account: HuyaAccount,
|
||||
account_info: dict,
|
||||
config_info: dict,
|
||||
):
|
||||
sid = str(self.payload.get("sid") or config_info.get("sid") or "").strip()
|
||||
if not sid:
|
||||
self._mark_task(worker_db, task, "failed", "请先配置虎牙活动 SID")
|
||||
return
|
||||
|
||||
sid_int = self._to_int(sid)
|
||||
if not sid_int:
|
||||
self._mark_task(worker_db, task, "failed", f"虎牙活动 SID 无效: {sid}")
|
||||
return
|
||||
|
||||
uid = self._resolve_uid(account_info)
|
||||
if not uid:
|
||||
self._mark_task(worker_db, task, "failed", "无法从账号或 Cookie 解析 yyuid")
|
||||
return
|
||||
|
||||
cookie = account_info.get("cookie") or ""
|
||||
if not cookie:
|
||||
self._mark_task(worker_db, task, "failed", "账号 Cookie 为空")
|
||||
return
|
||||
|
||||
client = HuyaHttpClient(logger=lambda msg: self._push_log("info", f"[{uid}] {msg}"))
|
||||
response = client.get_user_prize_records(uid=uid, cookie=cookie, sid=sid_int)
|
||||
if response is None:
|
||||
self._mark_task(worker_db, task, "error", "虎牙兑换记录接口无响应")
|
||||
return
|
||||
|
||||
result = response.to_dict()
|
||||
result["sid"] = sid_int
|
||||
if response.status != 200:
|
||||
self._mark_task(
|
||||
worker_db,
|
||||
task,
|
||||
"failed",
|
||||
response.msg or f"虎牙兑换记录查询失败: {response.status}",
|
||||
result,
|
||||
)
|
||||
return
|
||||
|
||||
records = result.get("records", [])
|
||||
for index, item in enumerate(records, start=1):
|
||||
item["index"] = index
|
||||
item["exchange_time_text"] = self._format_local_time(int(item.get("exchange_time") or 0))
|
||||
if item.get("score") is not None:
|
||||
item["score_text"] = f"{int(item.get('score') or 0)}积分"
|
||||
|
||||
account.status = "exchange_records_queried"
|
||||
account.updated_at = datetime.now(timezone.utc)
|
||||
count = len(records)
|
||||
message = f"兑换记录 {count} 条" if count else "暂无兑换记录"
|
||||
self._mark_task(worker_db, task, "success", message, result)
|
||||
|
||||
def _execute_refresh_goods(
|
||||
self,
|
||||
worker_db: Session,
|
||||
@@ -955,6 +1014,7 @@ class HuyaBatchRunner:
|
||||
"get_bind_qr",
|
||||
"confirm_bind",
|
||||
"query_game_name",
|
||||
"query_exchange_records",
|
||||
"refresh_goods",
|
||||
"refresh_recharge_goods",
|
||||
"create_recharge_order",
|
||||
@@ -978,6 +1038,8 @@ class HuyaBatchRunner:
|
||||
self._execute_confirm_bind(worker_db, task, account, account_info, config_info)
|
||||
elif self.task_type == "query_game_name":
|
||||
self._execute_query_game_name(worker_db, task, account, account_info, config_info)
|
||||
elif self.task_type == "query_exchange_records":
|
||||
self._execute_query_exchange_records(worker_db, task, account, account_info, config_info)
|
||||
worker_db.refresh(task)
|
||||
if task.status == "success":
|
||||
self._push_log("success", f"[{current}] {name} {task.message}")
|
||||
|
||||
Reference in New Issue
Block a user