Merge pull request #2523 from BEDOLAGA-DEV/dev

Dev
This commit is contained in:
Egor
2026-02-04 03:05:46 +03:00
committed by GitHub
4 changed files with 39 additions and 22 deletions
+11 -5
View File
@@ -683,11 +683,17 @@ async def purchase_traffic(
if traffic_discount_percent > 0:
base_price_kopeks = int(base_price_kopeks * (100 - traffic_discount_percent) / 100)
# Пропорциональный расчёт цены
final_price, months_charged = calculate_prorated_price(
base_price_kopeks,
subscription.end_date,
)
# На тарифах пакеты трафика покупаются на 1 месяц (30 дней),
# цена в тарифе уже месячная — не умножаем на оставшиеся месяцы подписки.
# Пропорциональный расчёт применяем только в классическом режиме.
if is_tariff_mode:
final_price = base_price_kopeks
months_charged = 1
else:
final_price, months_charged = calculate_prorated_price(
base_price_kopeks,
subscription.end_date,
)
# Проверяем баланс
if user.balance_kopeks < final_price:
+8 -1
View File
@@ -484,7 +484,14 @@ async def add_traffic(callback: types.CallbackQuery, db_user: User, db: AsyncSes
discount_per_month = discount_result['discount']
charged_months = 1
if subscription:
# На тарифах пакеты трафика покупаются на 1 месяц (30 дней),
# цена в тарифе уже месячная — не умножаем на оставшиеся месяцы подписки.
# Пропорциональный расчёт применяем только в классическом режиме.
is_tariff_mode = settings.is_tariffs_mode() and subscription and subscription.tariff_id
if is_tariff_mode:
price = discounted_per_month
elif subscription:
price, charged_months = calculate_prorated_price(
discounted_per_month,
subscription.end_date,
+9 -16
View File
@@ -1860,17 +1860,8 @@ def get_add_traffic_keyboard_from_tariff(
subscription_end_date: Дата окончания подписки для расчета цены
discount_percent: Процент скидки
"""
from app.utils.pricing_utils import get_remaining_months
texts = get_texts(language)
months_multiplier = 1
period_text = ''
if subscription_end_date:
months_multiplier = get_remaining_months(subscription_end_date)
if months_multiplier > 1:
period_text = f' (за {months_multiplier} мес)'
if not packages:
return InlineKeyboardMarkup(
inline_keyboard=[
@@ -1889,21 +1880,23 @@ def get_add_traffic_keyboard_from_tariff(
# Сортируем пакеты по размеру
sorted_packages = sorted(packages.items(), key=lambda x: x[0])
# Пакеты трафика на тарифах покупаются на 1 месяц (30 дней),
# цена в тарифе уже месячная — не умножаем на оставшиеся месяцы подписки
for gb, price_per_month in sorted_packages:
discounted_per_month, discount_per_month = apply_percentage_discount(
discounted_price, discount_value = apply_percentage_discount(
price_per_month,
discount_percent,
)
total_price = discounted_per_month * months_multiplier
total_discount = discount_per_month * months_multiplier
period_text = ' /мес' if language == 'ru' else ' /mo'
if language == 'ru':
text = f'📊 +{gb} ГБ трафика - {total_price // 100}{period_text}'
text = f'📊 +{gb} ГБ трафика - {discounted_price // 100}{period_text}'
else:
text = f'📊 +{gb} GB traffic - {total_price // 100}{period_text}'
text = f'📊 +{gb} GB traffic - {discounted_price // 100}{period_text}'
if discount_percent > 0 and total_discount > 0:
text += f' (скидка {discount_percent}%: -{total_discount // 100}₽)'
if discount_percent > 0 and discount_value > 0:
text += f' (скидка {discount_percent}%: -{discount_value // 100}₽)'
buttons.append([InlineKeyboardButton(text=text, callback_data=f'add_traffic_{gb}')])
+11
View File
@@ -100,6 +100,17 @@ class WataPaymentMixin:
payment_module = import_module('app.services.payment_service')
# Добавляем идентификатор плательщика (telegram_id или email) в описание
try:
user = await payment_module.get_user_by_id(db, user_id)
if user:
if user.telegram_id:
description = f'{description} | ID: {user.telegram_id}'
elif user.email:
description = f'{description} | {user.email}'
except Exception as error:
logger.debug('Не удалось получить данные пользователя для описания WATA: %s', error)
order_id = f'wata_{user_id}_{uuid.uuid4().hex[:12]}'
try: