feat(douyu): 落地账号平台同步与登录配额
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
@@ -18,6 +18,10 @@ from core.douyu import DouyuActivityClient
|
||||
|
||||
from ..models import Account
|
||||
from .account_binding import is_role_change_cooling
|
||||
from .account_capability_service import (
|
||||
AVAILABILITY_AVAILABLE,
|
||||
classify_goods_items,
|
||||
)
|
||||
from .cookie_check_service import check_douyu_cookie
|
||||
from .douyu_account_probe import config_mapping, persist_probe_result, probe_account
|
||||
|
||||
@@ -35,6 +39,8 @@ class DouyuLiveAccountState:
|
||||
role_change_available_at: datetime | None
|
||||
error: str = ""
|
||||
role_change_blocked: bool = False
|
||||
commodity_availability: dict[str, str] = field(default_factory=dict)
|
||||
commodity_blocking_reasons: dict[str, str] = field(default_factory=dict)
|
||||
|
||||
def blocking_reasons(
|
||||
self,
|
||||
@@ -48,6 +54,15 @@ class DouyuLiveAccountState:
|
||||
reasons.append(self.error)
|
||||
if commodity_id in self.limited_ids:
|
||||
reasons.append("该商品已达限兑上限")
|
||||
elif self.commodity_availability:
|
||||
availability = self.commodity_availability.get(commodity_id)
|
||||
if availability is None:
|
||||
reasons.append("官方商品列表本次未返回该商品,可能已下架")
|
||||
elif availability != AVAILABILITY_AVAILABLE:
|
||||
reasons.append(
|
||||
self.commodity_blocking_reasons.get(commodity_id)
|
||||
or f"商品当前不可兑换({availability})"
|
||||
)
|
||||
if self.role_change_blocked:
|
||||
available_text = (
|
||||
self.role_change_available_at.isoformat()
|
||||
@@ -150,6 +165,23 @@ def refresh_douyu_account_state(
|
||||
limited_ids = frozenset(
|
||||
str(item) for item in eligibility.get("limited_ids") or [] if str(item)
|
||||
)
|
||||
assessments = classify_goods_items(
|
||||
[
|
||||
item
|
||||
for item in eligibility.get("storehome_goods") or []
|
||||
if isinstance(item, dict)
|
||||
],
|
||||
now=now,
|
||||
)
|
||||
commodity_availability = {
|
||||
commodity_id: assessment.availability
|
||||
for commodity_id, assessment in assessments.items()
|
||||
}
|
||||
commodity_blocking_reasons = {
|
||||
commodity_id: assessment.blocking_reason
|
||||
for commodity_id, assessment in assessments.items()
|
||||
if assessment.blocking_reason
|
||||
}
|
||||
return DouyuLiveAccountState(
|
||||
account_id=int(account.id),
|
||||
account_name=account.nickname
|
||||
@@ -167,6 +199,8 @@ def refresh_douyu_account_state(
|
||||
role_change_available_at=account.role_change_available_at,
|
||||
error=";".join(errors),
|
||||
role_change_blocked=is_role_change_cooling(bind_info),
|
||||
commodity_availability=commodity_availability,
|
||||
commodity_blocking_reasons=commodity_blocking_reasons,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user