fix: apply club card format parsing to winner setting mechanism

- Updated parse_accounts_from_message() to support 'CARD ACCOUNT' format
- Updated set_account_as_winner() to split by space before formatting
- Added card number display in success/error messages
- Now winner setting works with format '2521 45-59-19-91-23-80-37'
This commit is contained in:
2025-11-17 08:22:13 +09:00
parent ce696b1e76
commit 2d03c3e14c
3 changed files with 60 additions and 19 deletions

View File

@@ -199,30 +199,52 @@ class AccountParticipationService:
session: AsyncSession,
lottery_id: int,
account_number: str,
place: int,
prize: Optional[str] = None
) -> Dict[str, Any]:
place: int = 1,
prize: str = ""
):
"""
Установить счет как победителя на указанное место
Устанавливает счет как победителя в розыгрыше.
Поддерживает формат: "КАРТА СЧЕТ" или просто "СЧЕТ"
"""
formatted_account = format_account_number(account_number)
# Разделяем номер карты и счета, если они указаны вместе
card_number = None
parts = account_number.split()
if len(parts) == 2:
# Формат: "КАРТА СЧЕТ"
card_number = parts[0]
account_to_format = parts[1]
elif len(parts) == 1:
# Формат: только "СЧЕТ"
account_to_format = parts[0]
else:
return {
"success": False,
"message": f"❌ Неверный формат: {account_number}"
}
# Форматируем номер счета
formatted_account = format_account_number(account_to_format)
if not formatted_account:
return {
"success": False,
"message": f"Неверный формат счета: {account_number}"
"message": f"Неверный формат счета: {account_number}"
}
# Проверяем, участвует ли счет в розыгрыше
# Проверяем, что счет участвует в розыгрыше
participation = await session.execute(
select(Participation).where(
Participation.lottery_id == lottery_id,
Participation.account_number == formatted_account
)
)
if not participation.scalar_one_or_none():
participation = participation.scalar_one_or_none()
if not participation:
card_info = f" (карта: {card_number})" if card_number else ""
return {
"success": False,
"message": f"Счет {formatted_account} не участвует в розыгрыше"
"message": f"Счет {formatted_account}{card_info} не участвует в розыгрыше"
}
# Проверяем, не занято ли уже это место
@@ -255,9 +277,10 @@ class AccountParticipationService:
await session.commit()
card_info = f" (карта: {card_number})" if card_number else ""
return {
"success": True,
"message": f"Счет {formatted_account} установлен победителем на место {place}",
"message": f"Счет {formatted_account}{card_info} установлен победителем на место {place}",
"account_number": formatted_account,
"place": place
}