重构虎牙精英宝典协议与支付状态链路
This commit is contained in:
@@ -58,6 +58,12 @@ class GoodsMixin:
|
||||
return
|
||||
result = response.to_dict()
|
||||
result["act_id"] = act_id
|
||||
act_info = client.get_act_info(act_id=act_id)
|
||||
user_tasks = client.get_act_user_task_detail(uid=uid, cookie=cookie, act_id=act_id)
|
||||
if act_info is not None:
|
||||
result["act_info"] = act_info.to_dict()
|
||||
if user_tasks is not None:
|
||||
result["user_task_detail"] = user_tasks.to_dict()
|
||||
if response.status != 200:
|
||||
self._mark_task(
|
||||
worker_db,
|
||||
@@ -324,6 +330,44 @@ class GoodsMixin:
|
||||
client: Any = HuyaHttpClient(
|
||||
logger=lambda msg: self._push_log("info", f"[{uid}] {msg}")
|
||||
)
|
||||
detail = client.get_act_prize_detail(
|
||||
uid=uid, cookie=cookie, sid=sid_int, pid=product_id
|
||||
)
|
||||
if detail is None:
|
||||
self._mark_task(worker_db, task, "error", "虎牙兑换详情接口无响应")
|
||||
return
|
||||
detail_result = detail.to_dict()
|
||||
prize = detail.prize
|
||||
if detail.status != 200 or prize is None:
|
||||
self._mark_task(
|
||||
worker_db,
|
||||
task,
|
||||
"failed",
|
||||
detail.msg or f"虎牙兑换详情获取失败: {detail.status}",
|
||||
detail_result,
|
||||
)
|
||||
return
|
||||
now_ts = int(time.time())
|
||||
if prize.isCanExchange == 0:
|
||||
self._mark_task(worker_db, task, "failed", "该商品当前不可兑换", detail_result)
|
||||
return
|
||||
if prize.isShowNum and prize.leftNum <= 0:
|
||||
self._mark_task(worker_db, task, "failed", "该商品库存不足", detail_result)
|
||||
return
|
||||
if prize.exchangeStartTime and now_ts < prize.exchangeStartTime:
|
||||
self._mark_task(worker_db, task, "failed", "该商品尚未开始兑换", detail_result)
|
||||
return
|
||||
if prize.exchangeEndTime and now_ts > prize.exchangeEndTime:
|
||||
self._mark_task(worker_db, task, "failed", "该商品兑换已结束", detail_result)
|
||||
return
|
||||
score = client.query_user_score(uid=uid, cookie=cookie, sid=sid_int)
|
||||
if score is None:
|
||||
self._mark_task(worker_db, task, "error", "兑换前积分查询无响应", detail_result)
|
||||
return
|
||||
if score.status != 200 or score.available_score < prize.newScore:
|
||||
detail_result["score"] = score.to_dict()
|
||||
self._mark_task(worker_db, task, "failed", "可用积分不足", detail_result)
|
||||
return
|
||||
response = client.score_exchange_prize(
|
||||
uid=uid, cookie=cookie, sid=sid_int, pid=product_id
|
||||
)
|
||||
@@ -340,6 +384,7 @@ class GoodsMixin:
|
||||
"scheduled_at": scheduled_at.isoformat() if scheduled_at else "",
|
||||
"executed_at": datetime.now(UTC).isoformat(),
|
||||
"goods": snapshot.raw if snapshot else None,
|
||||
"prize_detail": detail_result,
|
||||
}
|
||||
)
|
||||
if response.status != 200:
|
||||
@@ -352,6 +397,13 @@ class GoodsMixin:
|
||||
)
|
||||
return
|
||||
|
||||
post_score = client.query_user_score(uid=uid, cookie=cookie, sid=sid_int)
|
||||
post_records = client.get_user_prize_records(uid=uid, cookie=cookie, sid=sid_int)
|
||||
if post_score is not None:
|
||||
result["post_exchange_score"] = post_score.to_dict()
|
||||
account.points = post_score.available_score
|
||||
if post_records is not None:
|
||||
result["post_exchange_records"] = post_records.to_dict()
|
||||
account.status = "goods_exchanged"
|
||||
account.updated_at = datetime.now(UTC)
|
||||
message = response.msg or f"兑换成功: {product_name}"
|
||||
|
||||
Reference in New Issue
Block a user