Check
This commit is contained in:
@@ -74,14 +74,16 @@ class DatabaseManager:
|
||||
result = await session.execute(select(User).where(User.telegram_id == telegram_id))
|
||||
user = result.scalars().first()
|
||||
if user:
|
||||
user.balance = amount
|
||||
user.balance += int(amount)
|
||||
await self.add_transaction(user.id, amount)
|
||||
await session.commit()
|
||||
else:
|
||||
self.logger.warning(f"Пользователь с Telegram ID {telegram_id} не найден.")
|
||||
return "ERROR"
|
||||
except SQLAlchemyError as e:
|
||||
self.logger.error(f"Ошибка при обновлении баланса: {e}")
|
||||
await session.rollback()
|
||||
return "ERROR"
|
||||
|
||||
async def last_subscription(self, user_id: int):
|
||||
"""
|
||||
@@ -131,14 +133,16 @@ class DatabaseManager:
|
||||
return "ERROR"
|
||||
|
||||
# Проверка достаточности средств для покупки подписки
|
||||
cost = plan["cost"]
|
||||
cost = int(plan["price"])
|
||||
if result.balance >= cost:
|
||||
result.balance -= cost
|
||||
await session.commit()
|
||||
|
||||
# Создание подписки для пользователя
|
||||
expiry_date = datetime.now(datetime.timezone.utc) + relativedelta(months=plan["duration_months"])
|
||||
new_subscription = Subscription(user_id=result.id, vpn_server_id=None, plan=plan_id, expiry_date=expiry_date)
|
||||
expiry_date = datetime.utcnow() + relativedelta(months=plan["duration_months"])
|
||||
server = await self.mongo_repo.get_server_with_least_clients()
|
||||
self.logger.info(f"{server}")
|
||||
new_subscription = Subscription(user_id=result.id, vpn_server_id=str(server['server']["name"]), plan=plan_id, expiry_date=expiry_date)
|
||||
session.add(new_subscription)
|
||||
await session.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user