Enhance login display with raffle participation history
- Show active vs closed raffles for each login - Display win/loss status (🏆 for winners, ✗ for non-winners) - Limit display to 5 active + 3 closed raffles - Update help documentation with detailed status explanation - Add status icons (✅/⏸️) for active/inactive logins
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
from aiogram import Router, F
|
||||
from aiogram.types import Message, CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from aiogram.filters import Command, StateFilter
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from src.filters.case_insensitive import CaseInsensitiveCommand
|
||||
from aiogram.fsm.context import FSMContext
|
||||
@@ -11,6 +13,7 @@ import logging
|
||||
from src.core.database import async_session_maker
|
||||
from src.core.registration_services import RegistrationService, AccountService
|
||||
from src.core.services import UserService
|
||||
from src.core.models import Participation, Winner, Lottery
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = Router()
|
||||
@@ -222,7 +225,7 @@ async def show_verification_code(message: Message):
|
||||
|
||||
@router.message(Command("my_accounts"))
|
||||
async def show_user_accounts(message: Message):
|
||||
"""Показать счета пользователя"""
|
||||
"""Показать логины пользователя с информацией о розыгрышах"""
|
||||
async with async_session_maker() as session:
|
||||
user = await UserService.get_user_by_telegram_id(session, message.from_user.id)
|
||||
|
||||
@@ -234,15 +237,69 @@ async def show_user_accounts(message: Message):
|
||||
|
||||
if not accounts:
|
||||
await message.answer(
|
||||
"У вас пока нет привязанных счетов.\n\n"
|
||||
"Счета добавляются администратором."
|
||||
"У вас пока нет привязанных логинов.\n\n"
|
||||
"Логины добавляются администратором."
|
||||
)
|
||||
return
|
||||
|
||||
text = f"💳 Ваши счета (Клубная карта: {user.club_card_number}):\n\n"
|
||||
text = f"📱 <b>Ваши логины</b> (Клубная карта: {user.club_card_number})\n\n"
|
||||
|
||||
for i, account in enumerate(accounts, 1):
|
||||
status = "✅" if account.is_active else "❌"
|
||||
text += f"{i}. {status} {account.account_number}\n"
|
||||
# Получаем participations для этого account с загруженными данными о lottery
|
||||
participations = await session.execute(
|
||||
select(Participation)
|
||||
.where(Participation.account_id == account.id)
|
||||
.options(selectinload(Participation.lottery))
|
||||
)
|
||||
participations = participations.scalars().all()
|
||||
|
||||
# Определяем статус логина
|
||||
active_participations = [p for p in participations if not p.lottery.is_completed]
|
||||
closed_participations = [p for p in participations if p.lottery.is_completed]
|
||||
|
||||
# Основная информация о логине
|
||||
status_icon = "✅" if account.is_active and active_participations else "⏸️"
|
||||
text += f"{i}. {status_icon} <b>{account.account_number}</b>\n"
|
||||
|
||||
if active_participations:
|
||||
text += " 🎲 <b>Активные розыгрыши:</b>\n"
|
||||
for p in active_participations[:5]: # Показываем не более 5
|
||||
status = "🟢"
|
||||
text += f" {status} {p.lottery.title}\n"
|
||||
if len(active_participations) > 5:
|
||||
text += f" ... и еще {len(active_participations) - 5}\n"
|
||||
|
||||
if closed_participations:
|
||||
text += " 🏁 <b>Завершенные розыгрыши:</b>\n"
|
||||
for p in closed_participations[:3]: # Показываем не более 3
|
||||
# Проверяем, выиграл ли в этом розыгрыше
|
||||
winner_result = await session.execute(
|
||||
select(Winner)
|
||||
.where(
|
||||
(Winner.lottery_id == p.lottery_id) &
|
||||
(Winner.account_number == account.account_number)
|
||||
)
|
||||
)
|
||||
winner = winner_result.scalar_one_or_none()
|
||||
|
||||
if winner:
|
||||
text += f" 🏆 {p.lottery.title} - <b>ВЫИГРАЛ!</b> ({winner.place} место)\n"
|
||||
else:
|
||||
text += f" ✗ {p.lottery.title}\n"
|
||||
|
||||
if len(closed_participations) > 3:
|
||||
text += f" ... и еще {len(closed_participations) - 3} закрытых\n"
|
||||
|
||||
if not participations:
|
||||
text += " ℹ️ В розыгрышах не участвовал\n"
|
||||
|
||||
text += "\n"
|
||||
|
||||
await message.answer(text)
|
||||
# Добавляем примечание о неактивных логинах
|
||||
if any(not acc.is_active for acc in accounts):
|
||||
text += "⏸️ - Логин не участвует в новых розыгрышах\n"
|
||||
text += "✅ - Логин активен и может участвовать\n\n"
|
||||
|
||||
text += "💡 <b>Заметка:</b> Логины, участвовавшие в закрытых розыгрышах, не добавляются в новые розыгрыши."
|
||||
|
||||
await message.answer(text, parse_mode="HTML")
|
||||
|
||||
Reference in New Issue
Block a user