From 40d2aa8e929f8ce957d735cfe5f0e033f1933508 Mon Sep 17 00:00:00 2001 From: Capybara-z Date: Tue, 18 Nov 2025 10:50:07 +0300 Subject: [PATCH] Fix referral bonus calculation --- database/referrals.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/database/referrals.py b/database/referrals.py index e29a1ee9..37018c47 100644 --- a/database/referrals.py +++ b/database/referrals.py @@ -81,7 +81,8 @@ async def get_total_referral_bonus(session: AsyncSession, referrer_tg_id: int, m earliest_payments AS ( SELECT DISTINCT ON (tg_id) tg_id, amount, created_at FROM payments - WHERE status = 'success' + WHERE status = 'success' + AND payment_system NOT IN ('coupon', 'admin', 'referral') ORDER BY tg_id, created_at ) """ @@ -148,7 +149,9 @@ async def get_total_referral_bonus(session: AsyncSession, referrer_tg_id: int, m ), 0) AS total_bonus FROM referral_levels rl JOIN payments p ON rl.referred_tg_id = p.tg_id - WHERE p.status = 'success' AND rl.level <= :max_levels + WHERE p.status = 'success' + AND p.payment_system NOT IN ('coupon', 'admin', 'referral') + AND rl.level <= :max_levels """ )