diff --git a/app/cabinet/routes/partner_application.py b/app/cabinet/routes/partner_application.py index cd4fb6ee..7434bb4f 100644 --- a/app/cabinet/routes/partner_application.py +++ b/app/cabinet/routes/partner_application.py @@ -122,6 +122,31 @@ async def apply_for_partner( detail=error, ) + # Уведомляем админов о новой заявке + try: + from aiogram import Bot + + from app.services.admin_notification_service import AdminNotificationService + + if getattr(settings, 'ADMIN_NOTIFICATIONS_ENABLED', False) and settings.BOT_TOKEN: + bot = Bot(token=settings.BOT_TOKEN) + try: + notification_service = AdminNotificationService(bot) + await notification_service.send_partner_application_notification( + user=user, + application_data={ + 'company_name': request.company_name, + 'telegram_channel': request.telegram_channel, + 'website_url': request.website_url, + 'description': request.description, + 'expected_monthly_referrals': request.expected_monthly_referrals, + }, + ) + finally: + await bot.session.close() + except Exception as e: + logger.error('Failed to send admin notification for partner application', error=e) + return PartnerApplicationInfo( id=application.id, status=application.status, diff --git a/app/cabinet/routes/withdrawal.py b/app/cabinet/routes/withdrawal.py index 46c5ced2..a72f2c98 100644 --- a/app/cabinet/routes/withdrawal.py +++ b/app/cabinet/routes/withdrawal.py @@ -68,6 +68,26 @@ async def create_withdrawal( detail=error, ) + # Уведомляем админов о запросе на вывод + try: + from aiogram import Bot + + from app.services.admin_notification_service import AdminNotificationService + + if getattr(settings, 'ADMIN_NOTIFICATIONS_ENABLED', False) and settings.BOT_TOKEN: + bot = Bot(token=settings.BOT_TOKEN) + try: + notification_service = AdminNotificationService(bot) + await notification_service.send_withdrawal_request_notification( + user=user, + amount_kopeks=request.amount_kopeks, + payment_details=request.payment_details, + ) + finally: + await bot.session.close() + except Exception as e: + logger.error('Failed to send admin notification for withdrawal request', error=e) + return WithdrawalCreateResponse( id=withdrawal.id, amount_kopeks=withdrawal.amount_kopeks, diff --git a/app/services/admin_notification_service.py b/app/services/admin_notification_service.py index 7b13d5f1..6ad2f259 100644 --- a/app/services/admin_notification_service.py +++ b/app/services/admin_notification_service.py @@ -1635,6 +1635,103 @@ class AdminNotificationService: return str(value) return str(value) + async def send_partner_application_notification( + self, + user: User, + application_data: dict[str, Any], + ) -> bool: + """Уведомление о новой заявке на партнёрку.""" + if not self._is_enabled(): + return False + + try: + user_display = self._get_user_display(user) + user_id_display = self._get_user_identifier_display(user) + + message_lines = [ + '🤝 ЗАЯВКА НА ПАРТНЁРКУ', + '', + f'👤 {user_display} ({user_id_display})', + ] + + username = getattr(user, 'username', None) + if username: + message_lines.append(f'📱 @{username}') + + message_lines.append('') + + if application_data.get('company_name'): + message_lines.append(f'🏢 Компания: {application_data["company_name"]}') + if application_data.get('telegram_channel'): + message_lines.append(f'📢 Канал: {application_data["telegram_channel"]}') + if application_data.get('website_url'): + message_lines.append(f'🌐 Сайт: {application_data["website_url"]}') + if application_data.get('description'): + desc = application_data['description'] + if len(desc) > 200: + desc = desc[:197] + '...' + message_lines.append(f'📝 {desc}') + if application_data.get('expected_monthly_referrals'): + message_lines.append(f'👥 Ожидаемых рефералов: {application_data["expected_monthly_referrals"]}/мес') + + message_lines.extend([ + '', + f'⏰ {format_local_datetime(datetime.now(UTC), "%d.%m.%Y %H:%M:%S")}', + ]) + + return await self._send_message('\n'.join(message_lines)) + + except Exception as e: + logger.error('Ошибка отправки уведомления о заявке на партнёрку', error=e) + return False + + async def send_withdrawal_request_notification( + self, + user: User, + amount_kopeks: int, + payment_details: str | None = None, + ) -> bool: + """Уведомление о запросе на вывод средств.""" + if not self._is_enabled(): + return False + + try: + user_display = self._get_user_display(user) + user_id_display = self._get_user_identifier_display(user) + + message_lines = [ + '💸 ЗАПРОС НА ВЫВОД СРЕДСТВ', + '', + f'👤 {user_display} ({user_id_display})', + ] + + username = getattr(user, 'username', None) + if username: + message_lines.append(f'📱 @{username}') + + message_lines.extend([ + '', + f'💵 Сумма: {settings.format_price(amount_kopeks)}', + f'💰 Баланс: {settings.format_price(user.balance_kopeks)}', + ]) + + if payment_details: + details = payment_details + if len(details) > 200: + details = details[:197] + '...' + message_lines.extend(['', f'💳 Реквизиты: {details}']) + + message_lines.extend([ + '', + f'⏰ {format_local_datetime(datetime.now(UTC), "%d.%m.%Y %H:%M:%S")}', + ]) + + return await self._send_message('\n'.join(message_lines)) + + except Exception as e: + logger.error('Ошибка отправки уведомления о запросе на вывод', error=e) + return False + async def send_bulk_ban_notification( self, admin_user_id: int,