feature/chat-system #2

Merged
trevor merged 28 commits from feature/chat-system into master 2025-11-17 06:05:49 +00:00
14 changed files with 1037 additions and 270 deletions
Showing only changes of commit 1d715d4f63 - Show all commits

View File

@@ -1 +1 @@
851623
859161

View File

@@ -583,19 +583,47 @@ class ParticipationService:
results["errors"].append(f"Пользователь с счётом {formatted_account}{card_info} не найден")
continue
# Пробуем добавить в розыгрыш
if await ParticipationService.add_participant(session, lottery_id, user.id):
results["added"] += 1
detail = f"{user.first_name} ({formatted_account})"
if card_number:
detail = f"{user.first_name} (карта: {card_number}, счёт: {formatted_account})"
results["details"].append(detail)
else:
# Получаем запись Account для этого счета
account_record = await session.execute(
select(Account).where(Account.account_number == formatted_account)
)
account_record = account_record.scalar_one_or_none()
if not account_record:
card_info = f" (карта: {card_number})" if card_number else ""
results["errors"].append(f"Запись счета {formatted_account}{card_info} не найдена в базе")
continue
# Проверяем, не участвует ли уже этот счет
existing = await session.execute(
select(Participation).where(
Participation.lottery_id == lottery_id,
Participation.account_number == formatted_account
)
)
if existing.scalar_one_or_none():
results["skipped"] += 1
detail = f"{user.first_name} ({formatted_account})"
if card_number:
detail = f"{user.first_name} (карта: {card_number}, счёт: {formatted_account})"
results["details"].append(f"Уже участвует: {detail}")
continue
# Добавляем участие по счету
participation = Participation(
lottery_id=lottery_id,
user_id=user.id,
account_id=account_record.id,
account_number=formatted_account
)
session.add(participation)
await session.commit()
results["added"] += 1
detail = f"{user.first_name} ({formatted_account})"
if card_number:
detail = f"{user.first_name} (карта: {card_number}, счёт: {formatted_account})"
results["details"].append(detail)
except Exception as e:
results["errors"].append(f"Ошибка с {account_input}: {str(e)}")
@@ -650,8 +678,19 @@ class ParticipationService:
results["details"].append(f"Не найден: {formatted_account}{card_info}")
continue
# Пробуем удалить из розыгрыша
if await ParticipationService.remove_participant(session, lottery_id, user.id):
# Ищем участие по номеру счета (не по user_id!)
participation = await session.execute(
select(Participation).where(
Participation.lottery_id == lottery_id,
Participation.account_number == formatted_account
)
)
participation = participation.scalar_one_or_none()
if participation:
await session.delete(participation)
await session.commit()
results["removed"] += 1
detail = f"{user.first_name} ({formatted_account})"
if card_number: