Stabilize staff concurrency and premium emoji; enable verified Drone deployment
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -34,50 +34,12 @@ class LotteryServiceImpl(ILotteryService):
|
||||
created_at=datetime.now(timezone.utc)
|
||||
)
|
||||
|
||||
async def conduct_draw(self, lottery_id: int) -> Dict[str, Any]:
|
||||
"""Провести розыгрыш"""
|
||||
lottery = await self.lottery_repo.get_by_id(lottery_id)
|
||||
if not lottery or lottery.is_completed:
|
||||
return {}
|
||||
|
||||
# Получаем участников
|
||||
participations = await self.participation_repo.get_by_lottery(lottery_id)
|
||||
if not participations:
|
||||
return {}
|
||||
|
||||
# Проводим розыгрыш
|
||||
random.shuffle(participations)
|
||||
results = {}
|
||||
|
||||
num_prizes = len(lottery.prizes) if lottery.prizes else 3
|
||||
winners = participations[:num_prizes]
|
||||
|
||||
for i, participation in enumerate(winners):
|
||||
place = i + 1
|
||||
prize = lottery.prizes[i] if lottery.prizes and i < len(lottery.prizes) else f"Приз {place}"
|
||||
|
||||
# Создаем запись о победителе
|
||||
winner = await self.winner_repo.create(
|
||||
lottery_id=lottery_id,
|
||||
user_id=participation.user_id,
|
||||
account_number=participation.account_number,
|
||||
place=place,
|
||||
prize=prize,
|
||||
is_manual=False
|
||||
)
|
||||
|
||||
results[str(place)] = {
|
||||
'winner': winner,
|
||||
'user': participation.user,
|
||||
'prize': prize
|
||||
}
|
||||
|
||||
# Помечаем розыгрыш как завершенный
|
||||
lottery.is_completed = True
|
||||
lottery.draw_results = {str(k): v['prize'] for k, v in results.items()}
|
||||
await self.lottery_repo.update(lottery)
|
||||
|
||||
return results
|
||||
async def conduct_draw(self, lottery_id):
|
||||
from src.core.services import LotteryService
|
||||
result = await LotteryService.conduct_draw(self.lottery_repo.session, lottery_id)
|
||||
winners = await self.winner_repo.get_by_lottery(lottery_id) if result else []
|
||||
return {str(place): dict(info, winner=next(w for w in winners if w.place == place))
|
||||
for place, info in result.items()}
|
||||
|
||||
async def get_active_lotteries(self) -> List[Lottery]:
|
||||
"""Получить активные розыгрыши"""
|
||||
@@ -92,26 +54,13 @@ class UserServiceImpl(IUserService):
|
||||
|
||||
async def get_or_create_user(self, telegram_id: int, **kwargs) -> User:
|
||||
"""Получить или создать пользователя"""
|
||||
user = await self.user_repo.get_by_telegram_id(telegram_id)
|
||||
if not user:
|
||||
user_data = {
|
||||
'telegram_id': telegram_id,
|
||||
'created_at': datetime.now(timezone.utc),
|
||||
**kwargs
|
||||
}
|
||||
user = await self.user_repo.create(**user_data)
|
||||
return user
|
||||
from src.core.services import UserService
|
||||
return await UserService.get_or_create_user(self.user_repo.session, telegram_id, **kwargs)
|
||||
|
||||
async def register_user(self, telegram_id: int, phone: str, club_card_number: str) -> bool:
|
||||
"""Зарегистрировать пользователя"""
|
||||
user = await self.user_repo.get_by_telegram_id(telegram_id)
|
||||
if not user:
|
||||
from src.core.registration_services import RegistrationService
|
||||
try:
|
||||
await RegistrationService.register_user(self.user_repo.session, telegram_id, club_card_number, phone)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
user.phone = phone
|
||||
user.club_card_number = club_card_number
|
||||
user.is_registered = True
|
||||
user.generate_verification_code()
|
||||
|
||||
await self.user_repo.update(user)
|
||||
return True
|
||||
Reference in New Issue
Block a user