From d22f9aaf629e60cdf71394d80546a764b078c5ad Mon Sep 17 00:00:00 2001 From: Pedzeo Date: Fri, 26 Sep 2025 17:14:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=20=D0=BF=D0=BE=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BA=D0=B5=D1=82=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/reporting_service.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/services/reporting_service.py b/app/services/reporting_service.py index 3f9161a1..b0cc9505 100644 --- a/app/services/reporting_service.py +++ b/app/services/reporting_service.py @@ -17,6 +17,8 @@ from app.database.database import AsyncSessionLocal from app.database.models import ( Subscription, SubscriptionConversion, + Ticket, + TicketStatus, Transaction, TransactionType, ) @@ -203,6 +205,10 @@ class ReportingService: f"• Активных сейчас: {totals['active_paid']}", f"• Новых за период: {period_stats['new_paid_subscriptions']}", "", + "🎟️ Тикеты поддержки", + f"• Активных сейчас: {totals['open_tickets']}", + f"• Новых за период: {period_stats['new_tickets']}", + "", "💰 Платежи", f"• Оплат подписок: {period_stats['subscription_payments_count']} на сумму " f"{self._format_amount(period_stats['subscription_payments_amount'])}", @@ -243,9 +249,22 @@ class ReportingService: async def _collect_current_totals(self, session) -> dict: stats = await get_subscriptions_statistics(session) + open_tickets_result = await session.execute( + select(func.count(Ticket.id)).where( + Ticket.status.in_( + [ + TicketStatus.OPEN.value, + TicketStatus.ANSWERED.value, + TicketStatus.PENDING.value, + ] + ) + ) + ) + open_tickets = int(open_tickets_result.scalar() or 0) return { "active_trials": stats.get("trial_subscriptions", 0) or 0, "active_paid": stats.get("paid_subscriptions", 0) or 0, + "open_tickets": open_tickets, } async def _collect_period_stats( @@ -315,6 +334,13 @@ class ReportingService: total_payments_count = subscription_payments_count + deposits_count total_payments_amount = subscription_payments_amount + deposits_amount + new_tickets_result = await session.execute( + select(func.count(Ticket.id)).where( + Ticket.created_at >= start_utc, + Ticket.created_at < end_utc, + ) + ) + new_tickets = int(new_tickets_result.scalar() or 0) return { "new_trials": new_trials, @@ -325,6 +351,7 @@ class ReportingService: "deposits_amount": deposits_amount, "total_payments_count": total_payments_count, "total_payments_amount": total_payments_amount, + "new_tickets": new_tickets, } def _format_period_label(self, start: datetime, end: datetime) -> str: