fix: show payment statuses in balance operations
This commit is contained in:
@@ -32,6 +32,17 @@ def format_admin_operation(amount: float, created_at: datetime) -> str:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def format_user_payment(amount: float, created_at: datetime, payment_system: str, status: str) -> str:
|
||||||
|
date_str = created_at.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
abs_amount = abs(amount)
|
||||||
|
system_name = payment_system or "Неизвестно"
|
||||||
|
return (
|
||||||
|
f"\n<blockquote>💸 Сумма: {abs_amount} | {system_name}"
|
||||||
|
f"\n📌 Статус: {status}"
|
||||||
|
f"\n⏳ Дата: {date_str}</blockquote>"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.callback_query(
|
@router.callback_query(
|
||||||
AdminUserEditorCallback.filter(F.action == "users_balance_edit"),
|
AdminUserEditorCallback.filter(F.action == "users_balance_edit"),
|
||||||
IsAdminFilter(),
|
IsAdminFilter(),
|
||||||
@@ -46,28 +57,47 @@ async def handle_balance_change(
|
|||||||
balance = await get_balance(session, tg_id)
|
balance = await get_balance(session, tg_id)
|
||||||
balance = int(balance or 0)
|
balance = int(balance or 0)
|
||||||
|
|
||||||
stmt = (
|
stmt_admin = (
|
||||||
select(Payment.amount, Payment.created_at)
|
select(Payment.amount, Payment.created_at)
|
||||||
.where(Payment.tg_id == tg_id, Payment.payment_system == "admin")
|
.where(Payment.tg_id == tg_id, Payment.payment_system == "admin")
|
||||||
.order_by(Payment.created_at.desc())
|
.order_by(Payment.created_at.desc())
|
||||||
.limit(5)
|
.limit(5)
|
||||||
)
|
)
|
||||||
result = await session.execute(stmt)
|
result_admin = await session.execute(stmt_admin)
|
||||||
records = result.all()
|
admin_records = result_admin.all()
|
||||||
|
|
||||||
|
stmt_user = (
|
||||||
|
select(Payment.amount, Payment.created_at, Payment.payment_system, Payment.status)
|
||||||
|
.where(
|
||||||
|
Payment.tg_id == tg_id,
|
||||||
|
Payment.payment_system != "admin"
|
||||||
|
)
|
||||||
|
.order_by(Payment.created_at.desc())
|
||||||
|
.limit(5)
|
||||||
|
)
|
||||||
|
result_user = await session.execute(stmt_user)
|
||||||
|
user_records = result_user.all()
|
||||||
|
|
||||||
text = (
|
text = (
|
||||||
f"<b>💵 Изменение баланса</b>"
|
f"<b>💵 Изменение баланса</b>"
|
||||||
f"\n\n🆔 ID: <b>{tg_id}</b>"
|
f"\n\n🆔 ID: <b>{tg_id}</b>"
|
||||||
f"\n💰 Баланс: <b>{balance}Р</b>"
|
f"\n💰 Баланс: <b>{balance}Р</b>"
|
||||||
f"\n📊 Операции админа (5):"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if records:
|
text += "\n\n<b>📊 Операции админа (5):</b>"
|
||||||
for amount, created_at in records:
|
if admin_records:
|
||||||
|
for amount, created_at in admin_records:
|
||||||
text += format_admin_operation(amount, created_at)
|
text += format_admin_operation(amount, created_at)
|
||||||
else:
|
else:
|
||||||
text += "\n<i>🚫 Операции отсутствуют</i>"
|
text += "\n<i>🚫 Операции отсутствуют</i>"
|
||||||
|
|
||||||
|
text += "\n\n<b>📊 Последние операции (5):</b>"
|
||||||
|
if user_records:
|
||||||
|
for amount, created_at, payment_system, status in user_records:
|
||||||
|
text += format_user_payment(amount, created_at, payment_system, status)
|
||||||
|
else:
|
||||||
|
text += "\n<i>🚫 Операции отсутствуют</i>"
|
||||||
|
|
||||||
await callback_query.message.edit_text(
|
await callback_query.message.edit_text(
|
||||||
text=text,
|
text=text,
|
||||||
reply_markup=await build_users_balance_kb(session, tg_id),
|
reply_markup=await build_users_balance_kb(session, tg_id),
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||||||
from database.models import ManualBan
|
from database.models import ManualBan
|
||||||
from filters.admin import IsAdminFilter
|
from filters.admin import IsAdminFilter
|
||||||
|
|
||||||
from .keyboard import AdminUserEditorCallback, build_editor_btn, build_editor_kb
|
from .keyboard import AdminUserEditorCallback, build_editor_btn, build_editor_kb, build_user_ban_type_kb
|
||||||
from .users_states import BanUserStates
|
from .users_states import BanUserStates
|
||||||
|
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ async def handle_user_ban(callback: CallbackQuery, callback_data: AdminUserEdito
|
|||||||
|
|
||||||
await callback.message.edit_text(
|
await callback.message.edit_text(
|
||||||
text="🚫 Выберите тип блокировки пользователя:",
|
text="🚫 Выберите тип блокировки пользователя:",
|
||||||
reply_markup=build_editor_btn("🚫 Блокировки", tg_id=callback_data.tg_id, edit=True),
|
reply_markup=build_user_ban_type_kb(callback_data.tg_id),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user