diff --git a/handlers/admin/gifts/gifts_handler.py b/handlers/admin/gifts/gifts_handler.py
index c314a7ce..76656386 100644
--- a/handlers/admin/gifts/gifts_handler.py
+++ b/handlers/admin/gifts/gifts_handler.py
@@ -6,9 +6,11 @@ from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select, delete, func
from aiogram.utils.keyboard import InlineKeyboardBuilder
+
from ..panel.keyboard import AdminPanelCallback
from .keyboard import build_admin_gifts_kb, build_gifts_list_kb
from database.models import Tariff, Gift, GiftUsage
+from handlers.utils import format_days, format_months
router = Router()
@@ -41,9 +43,16 @@ async def admin_create_gift_step1(callback: CallbackQuery, session: AsyncSession
kb = InlineKeyboardBuilder()
for t in tariffs:
- kb.button(text=f"{t.name} – {t.duration_days // 30} мес", callback_data=f"admin_gift_select|{t.id}")
- kb.row(types.InlineKeyboardButton(text="🔙 Назад", callback_data=AdminPanelCallback(action="gifts").pack()
-))
+ if t.duration_days % 30 == 0:
+ duration_text = format_months(t.duration_days // 30)
+ else:
+ duration_text = format_days(t.duration_days)
+
+ kb.button(
+ text=f"{t.name} – {duration_text}",
+ callback_data=f"admin_gift_select|{t.id}"
+ )
+
await callback.message.edit_text(
"🎁 Выберите тариф для подарка:",
@@ -89,10 +98,12 @@ async def handle_limited_gift_input(message: types.Message, session: AsyncSessio
await state.clear()
await finalize_gift(message, session, bot, data, is_unlimited=False)
+
@router.callback_query(F.data == "admin_gifts_all")
async def show_gifts_page(callback: CallbackQuery, session: AsyncSession):
await show_gift_list(callback, session, page=1)
+
@router.callback_query(F.data.startswith("gifts_page|"))
async def paginate_gifts(callback: CallbackQuery, session: AsyncSession):
page = int(callback.data.split("|")[1])
@@ -173,15 +184,20 @@ async def view_gift(callback: CallbackQuery, session: AsyncSession):
select(func.count()).select_from(GiftUsage).where(GiftUsage.gift_id == gift_id)
)
used_count = usage_result.scalar_one()
-
usage_text = f"{used_count}/{gift.max_usages}" if gift.max_usages else "∞"
+ duration_days = (gift.expiry_time.date() - gift.created_at.date()).days
+ if duration_days % 30 == 0:
+ duration_text = format_months(duration_days // 30)
+ else:
+ duration_text = format_days(duration_days)
+
text = (
f"🎁 Подарок\n"
f"ID: {gift.gift_id}\n"
- f"Месяцев: {gift.selected_months}\n"
+ f"Срок: {duration_text}\n"
f"Активаций: {usage_text}\n"
- f"Срок действия: {gift.expiry_time.strftime('%d.%m.%Y')}\n"
+ f"Истекает: {gift.expiry_time.strftime('%d.%m.%Y')}\n"
f"Ссылка для активации:\n
{gift.gift_link}" ) diff --git a/handlers/admin/gifts/keyboard.py b/handlers/admin/gifts/keyboard.py index 2be1c4cd..c23433b9 100644 --- a/handlers/admin/gifts/keyboard.py +++ b/handlers/admin/gifts/keyboard.py @@ -2,6 +2,7 @@ from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton from aiogram.utils.keyboard import InlineKeyboardBuilder from database.models import Tariff, Gift from ..panel.keyboard import AdminPanelCallback +from handlers.utils import get_plural_form, format_months, format_days from handlers.buttons import BACK @@ -35,21 +36,38 @@ def build_gift_tariffs_kb(tariffs: list[Tariff]) -> InlineKeyboardMarkup: def build_gifts_list_kb(gifts: list[Gift], page: int, total: int) -> InlineKeyboardMarkup: builder = InlineKeyboardBuilder() + row = [] - for gift in gifts: - button_text = f"{gift.gift_id[:6]}... — {gift.selected_months} мес." - builder.button( - text=button_text, - callback_data=f"gift_view|{gift.gift_id}", + for i, gift in enumerate(gifts): + if gift.selected_months > 0: + duration_text = format_months(gift.selected_months) + else: + days = (gift.expiry_time.date() - gift.created_at.date()).days + duration_text = format_days(days) + + button_text = f"{gift.gift_id[:6]}... — {duration_text}" + + row.append( + InlineKeyboardButton( + text=button_text, + callback_data=f"gift_view|{gift.gift_id}", + ) ) + if len(row) == 2 or i == len(gifts) - 1: + builder.row(*row) + row = [] + nav = [] if page > 1: nav.append(InlineKeyboardButton(text="⬅️ Назад", callback_data=f"gifts_page|{page - 1}")) if len(gifts) == 10: nav.append(InlineKeyboardButton(text="➡️ Далее", callback_data=f"gifts_page|{page + 1}")) + if nav: + builder.row(*nav) - builder.row(*nav) - builder.button(text="🔙 Назад", callback_data=AdminPanelCallback(action="gifts").pack()) + builder.row( + InlineKeyboardButton(text="🔙 Назад", callback_data=AdminPanelCallback(action="gifts").pack()) + ) return builder.as_markup() \ No newline at end of file diff --git a/handlers/admin/tariffs/keyboard.py b/handlers/admin/tariffs/keyboard.py index 9e7438f6..3c4518ec 100644 --- a/handlers/admin/tariffs/keyboard.py +++ b/handlers/admin/tariffs/keyboard.py @@ -46,14 +46,22 @@ def build_cancel_kb() -> InlineKeyboardMarkup: def build_tariff_groups_kb(groups: list[str]) -> InlineKeyboardMarkup: builder = InlineKeyboardBuilder() - for group in groups: - builder.button( - text=group, - callback_data=AdminTariffCallback(action=f"group|{group}").pack(), + row = [] + + for i, group in enumerate(groups): + row.append( + InlineKeyboardButton( + text=group, + callback_data=AdminTariffCallback(action=f"group|{group}").pack(), + ) ) + if len(row) == 2 or i == len(groups) - 1: + builder.row(*row) + row = [] builder.row( InlineKeyboardButton( - text="⬅️ Назад", callback_data=AdminPanelCallback(action="tariffs").pack() + text="⬅️ Назад", + callback_data=AdminPanelCallback(action="tariffs").pack(), ) ) return builder.as_markup() diff --git a/handlers/payments/gift.cpython-312-x86_64-linux-gnu.so b/handlers/payments/gift.cpython-312-x86_64-linux-gnu.so index b64766a9..d94a83ec 100644 Binary files a/handlers/payments/gift.cpython-312-x86_64-linux-gnu.so and b/handlers/payments/gift.cpython-312-x86_64-linux-gnu.so differ diff --git a/handlers/utils.py b/handlers/utils.py index 3f31e10f..3610cad0 100644 --- a/handlers/utils.py +++ b/handlers/utils.py @@ -173,13 +173,6 @@ def format_days(days: int) -> str: return f"{days} {get_plural_form(days, 'день', 'дня', 'дней')}" -def format_hours(hours: int) -> str: - """Форматирует количество часов с правильным склонением""" - if hours <= 0: - return "0 часов" - return f"{hours} {get_plural_form(hours, 'час', 'часа', 'часов')}" - - def format_minutes(minutes: int) -> str: """Форматирует количество минут с правильным склонением""" if minutes <= 0: