feat(douyu): 完成账号平台阶段一到四并接入最新协议

This commit is contained in:
yml
2026-11-21 23:51:41 +08:00
parent d67b7dd6a3
commit 0ac6c7e82e
19 changed files with 2163 additions and 396 deletions
+8 -52
View File
@@ -12,13 +12,8 @@ from sqlalchemy.orm import Session
from core.douyu import DouyuActivityClient, DouyuActivityError
from ..models import Account, DouyuEsportsGoodsSnapshot, DouyuGoodsSnapshot, DouyuTask
from .account_sync_service import (
DOMAIN_EXCHANGE_RECORDS,
finish_sync_failure,
finish_sync_success,
start_sync_run,
sync_storehome_snapshot,
)
from .account_exchange_sync_service import sync_exchange_records
from .account_sync_service import sync_storehome_snapshot
from .business_events import record_exchange
from .douyu_activity_query import (
query_activity_goods,
@@ -26,12 +21,10 @@ from .douyu_activity_query import (
query_csrf,
query_elite_user_info,
query_esports_goods_result,
query_exchange_records_result,
query_limited_goods_result,
)
from .douyu_goods_service import upsert_goods_snapshot
from .douyu_read_gateway import storehome_snapshot_from_result
from .douyu_runner_overview import record_official_exchange_records
from .high_value_service import (
DEFAULT_HIGH_VALUE_GOODS,
HIGH_VALUE_STATUS_OWNED,
@@ -793,58 +786,21 @@ class GoodsMixin:
self, db: Session, task: DouyuTask, account: Account, cookie: str, config: dict
):
client = self._client(cookie)
result = query_exchange_records_result(
client,
manual_id=str(config["manual_id"]),
limit=100,
offset=0,
)
records = result.get("records") or []
observed_at = datetime.now(UTC)
sync_run = start_sync_run(
result = sync_exchange_records(
db,
account_id=int(account.id),
domain=DOMAIN_EXCHANGE_RECORDS,
account,
client,
config,
source="douyu_task.query_exchange_records",
task_id=task.id,
)
try:
added = record_official_exchange_records(
db,
account,
[("elite", record) for record in records if isinstance(record, dict)],
)
finish_sync_success(
db,
sync_run,
item_count=len(records),
changed_count=added,
observed_at=observed_at,
raw_payload=(
result.get("raw")
if isinstance(result.get("raw"), dict)
else None
),
)
except Exception as exc:
finish_sync_failure(
db,
sync_run,
error=exc,
raw_payload=(
result.get("raw")
if isinstance(result.get("raw"), dict)
else None
),
)
raise
result["exchange_events_added"] = added
account.updated_at = datetime.now(UTC)
item_count = int(result.get("item_count") or 0)
self._mark_task(
db,
task,
"success",
f"兑换记录 {len(records)} 条" if records else "暂无兑换记录",
f"兑换记录 {item_count} 条" if item_count else "暂无兑换记录",
result,
)