This commit is contained in:
Vladless
2025-05-25 23:56:02 +03:00
2 changed files with 16 additions and 0 deletions
+9
View File
@@ -5,6 +5,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from config import CHECK_REFERRAL_REWARD_ISSUED, REFERRAL_BONUS_PERCENTAGES
from database.models import Referral
from logger import logger
from database import add_payment
async def add_referral(session: AsyncSession, referred_tg_id: int, referrer_tg_id: int):
@@ -173,6 +174,14 @@ async def get_total_referral_bonus(
)
total_bonus_raw = result.scalar()
total_bonus = round(float(total_bonus_raw or 0), 2)
if total_bonus > 0:
await add_payment(
session,
tg_id=referrer_tg_id,
amount=total_bonus,
payment_system="referral"
)
logger.debug(f"Получена общая сумма бонусов от рефералов: {total_bonus}")
return total_bonus
+7
View File
@@ -22,6 +22,7 @@ from database import (
update_balance,
update_coupon_usage_count,
update_key_expiry,
add_payment,
)
from handlers.buttons import MAIN_MENU
from handlers.keys.key_utils import renew_key_in_cluster
@@ -124,6 +125,12 @@ async def activate_coupon(
await update_balance(session, user_id, coupon.amount)
await update_coupon_usage_count(session, coupon.id)
await create_coupon_usage(session, coupon.id, user_id)
await add_payment(
session,
tg_id=user_id,
amount=coupon.amount,
payment_system="coupon"
)
await message.answer(
f"✅ Купон активирован, на баланс начислено {coupon.amount} рублей."
)