refactor(douyu): 统一活动查询与直播商品映射
- 收口斗鱼活动、商品、绑定信息和兑换资格查询 - 工作台改为复用统一客户端、快照与实时商品目录 - 补充活动查询与商品映射测试
This commit is contained in:
@@ -12,6 +12,7 @@ from core.douyu import DouyuActivityClient, DouyuActivityError
|
||||
|
||||
from ..models import Account, DouyuTask
|
||||
from .account_events_service import EVENT_ELITE_OPENED, EVENT_ESPORTS_OPENED, emit
|
||||
from .douyu_activity_query import query_csrf, query_elite_user_info, query_points
|
||||
from .douyu_runner_core import DOUYU_PAYMENT_POLL_INTERVAL, DOUYU_PAYMENT_POLL_SECONDS
|
||||
from .douyu_service import account_uid, update_account_profile_from_cookie
|
||||
|
||||
@@ -49,8 +50,8 @@ class ManualMixin:
|
||||
uid = account_uid(account, cookie)
|
||||
if not uid:
|
||||
raise DouyuActivityError("Cookie 中没有 acf_uid,无法查询积分")
|
||||
ctn_value = ctn or client.acf_ccn(refresh_subscribe=False)
|
||||
result = client.query_points(uid=uid, ctn=ctn_value)
|
||||
ctn_value = ctn or query_csrf(client)
|
||||
result = query_points(client, uid=uid, ctn=ctn_value)
|
||||
points = self._to_int(result.get("points"))
|
||||
account.uid = uid
|
||||
account.points = points
|
||||
@@ -79,7 +80,7 @@ class ManualMixin:
|
||||
积分区分不了「开通后积分花完」和「从未开通」,manualType 才是权威口径:
|
||||
0=未开通,>=1=已开通。
|
||||
"""
|
||||
result = client.elite_user_info(manual_id=manual_id, rid=rid)
|
||||
result = query_elite_user_info(client, manual_id=manual_id, rid=rid)
|
||||
manual_type = self._to_int(result.get("manual_type")) or 0
|
||||
manual_score = self._to_int(result.get("manual_score"))
|
||||
expire_time = self._to_int(result.get("expire_time")) or 0
|
||||
@@ -211,9 +212,7 @@ class ManualMixin:
|
||||
account.esports_opened = manual_type is not None and manual_type >= 1
|
||||
# 到期时间也落库 —— 否则界面只能显示"已开通",看不到什么时候到期
|
||||
expire_raw = result.get("expire_time")
|
||||
expire_int = (
|
||||
int(expire_raw) if str(expire_raw or "").strip().isdigit() else None
|
||||
)
|
||||
expire_int = self._to_int(expire_raw)
|
||||
# ⚠️ 斗鱼用 0 表示「没有到期时间」。直接存 0 的话界面会显示 1970/1/1
|
||||
# (这个坑在积分到期上踩过一次,这里别再踩)。
|
||||
account.esports_expire_time = (
|
||||
@@ -306,7 +305,7 @@ class ManualMixin:
|
||||
client = self._client(cookie)
|
||||
ctn = str(self._task_payload(task).get("ctn") or "")
|
||||
if not ctn:
|
||||
ctn = client.acf_ccn(refresh_subscribe=True)
|
||||
ctn = query_csrf(client, refresh_subscribe=True)
|
||||
act_alias = self._confirm_act_alias(config) or self._bind_qr_act_alias(config)
|
||||
if not act_alias:
|
||||
self._mark_task(db, task, "failed", "请先配置开通宝典活动 actAlias")
|
||||
@@ -435,7 +434,7 @@ class ManualMixin:
|
||||
client = self._client(cookie)
|
||||
ctn = str(self._task_payload(task).get("ctn") or "")
|
||||
if not ctn:
|
||||
ctn = client.acf_ccn(refresh_subscribe=True)
|
||||
ctn = query_csrf(client, refresh_subscribe=True)
|
||||
act_alias = str(config.get("esports_act_alias") or "").strip()
|
||||
manual_id = str(config.get("esports_manual_id") or "").strip()
|
||||
if not act_alias or not manual_id:
|
||||
@@ -561,7 +560,7 @@ class ManualMixin:
|
||||
self, db: Session, task: DouyuTask, account: Account, cookie: str, config: dict
|
||||
):
|
||||
client = self._client(cookie)
|
||||
ctn = client.acf_ccn(refresh_subscribe=False)
|
||||
ctn = query_csrf(client)
|
||||
result = self._refresh_account_points(client, account, cookie, ctn=ctn)
|
||||
account.updated_at = datetime.now(UTC)
|
||||
points = result["points"]
|
||||
|
||||
Reference in New Issue
Block a user