add get day claim reward endpoint
This commit is contained in:
@ -115,4 +115,30 @@ class DailyRewardService:
|
||||
"next_claim_at_utc": start_tomorrow_utc.isoformat().replace("+00:00", "Z"),
|
||||
"next_claim_at_local": (start_today_local + timedelta(days=1)).isoformat(),
|
||||
"streak": int(user.get("daily_streak", 0) or 0),
|
||||
}
|
||||
}
|
||||
|
||||
async def get_claim_days(self, username: str, limit: int = 60) -> dict:
|
||||
# Берём последние N записей daily_login и превращаем в список уникальных дней по ЕКБ
|
||||
cursor = coins_sessions_collection.find(
|
||||
{"player_name": username, "update_type": "daily_login"},
|
||||
{"timestamp": 1, "_id": 0},
|
||||
).sort("timestamp", -1).limit(limit)
|
||||
|
||||
days = []
|
||||
seen = set()
|
||||
|
||||
async for doc in cursor:
|
||||
ts = doc.get("timestamp")
|
||||
if not ts:
|
||||
continue
|
||||
|
||||
# У тебя timestamp в Mongo — naive UTC (now_utc.replace(tzinfo=None)) :contentReference[oaicite:1]{index=1}
|
||||
ts_utc = ts.replace(tzinfo=timezone.utc)
|
||||
day_local = ts_utc.astimezone(TZ).date().isoformat() # YYYY-MM-DD по ЕКБ
|
||||
|
||||
if day_local not in seen:
|
||||
seen.add(day_local)
|
||||
days.append(day_local)
|
||||
|
||||
days.reverse() # чтобы было по возрастанию (старые → новые), если надо
|
||||
return {"ok": True, "days": days, "count": len(days)}
|
||||
Reference in New Issue
Block a user