Spaces:
Running
feat: Партнёрская панель и улучшенная реферальная система
Browse filesFRONTEND (/partner):
- Создана партнёрская панель с полной статистикой
- Метрики: баланс, всего заработано, клиентов, активных
- Реферальная ссылка с кнопкой копирования
- Таблица привлечённых клиентов с детальной информацией
- Показывает: план, статус, оплачено, заработано, дата
- Визуальные бейджи для планов и статусов
- Градиентный дизайн в стиле платформы
BACKEND API:
- GET /billing/partner/clients - список привлечённых клиентов
- Расчёт total_paid для каждого клиента (сумма SUBSCRIPTION транзакций)
- Расчёт commission_earned для каждого клиента (сумма COMMISSION)
- GET /billing/referral-link теперь возвращает счётчики клиентов
- Подсчёт referred_tenants_count и active_tenants_count
ЛОГИКА РЕФЕРАЛЬНОЙ СИСТЕМЫ:
✅ Регистрация с ?ref=CODE → автоматическая привязка к партнёру
✅ При оплате подписки → 50% комиссия партнёру
✅ Партнёр видит всех своих клиентов в панели
✅ Партнёр видит сколько заработал с каждого клиента
✅ Статусы клиентов обновляются в реальном времени
ДОСТУП:
- Только для партнёров со статусом ACTIVE
- Требуется покупка франшизы ()
- Защита на уровне API и UI
ФУНКЦИИ:
- Копирование реферальной ссылки одной кнопкой
- Просмотр истории всех привлечённых клиентов
- Отслеживание активных vs. неактивных клиентов
- Расчёт total earned и balance в реальном времени
- backend/app/api/billing.py +99 -1
- frontend/app/partner/page.tsx +305 -0
|
@@ -213,6 +213,14 @@ async def get_referral_link(
|
|
| 213 |
# Генерируем реферальную ссылку
|
| 214 |
referral_link = f"{settings.FRONTEND_URL}/register?ref={partner.referral_code}"
|
| 215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
logger.info(
|
| 217 |
"Реферальная ссылка сгенерирована",
|
| 218 |
partner_id=str(partner.id),
|
|
@@ -226,7 +234,97 @@ async def get_referral_link(
|
|
| 226 |
"partner_status": partner.status,
|
| 227 |
"commission_rate": partner.commission_rate,
|
| 228 |
"total_earned": partner.total_earned,
|
| 229 |
-
"company_name": partner.company_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
}
|
| 231 |
|
| 232 |
|
|
|
|
| 213 |
# Генерируем реферальную ссылку
|
| 214 |
referral_link = f"{settings.FRONTEND_URL}/register?ref={partner.referral_code}"
|
| 215 |
|
| 216 |
+
# ✅ Подсчёт количества клиентов
|
| 217 |
+
stmt_count = select(Tenant).where(Tenant.partner_ref_id == partner.id)
|
| 218 |
+
result_count = await session.execute(stmt_count)
|
| 219 |
+
all_tenants = result_count.scalars().all()
|
| 220 |
+
|
| 221 |
+
referred_count = len(all_tenants)
|
| 222 |
+
active_count = len([t for t in all_tenants if t.subscription_status == "active"])
|
| 223 |
+
|
| 224 |
logger.info(
|
| 225 |
"Реферальная ссылка сгенерирована",
|
| 226 |
partner_id=str(partner.id),
|
|
|
|
| 234 |
"partner_status": partner.status,
|
| 235 |
"commission_rate": partner.commission_rate,
|
| 236 |
"total_earned": partner.total_earned,
|
| 237 |
+
"company_name": partner.company_name,
|
| 238 |
+
"partner_id": str(partner.id),
|
| 239 |
+
"balance_usd": partner.balance_usd,
|
| 240 |
+
"referred_tenants_count": referred_count,
|
| 241 |
+
"active_tenants_count": active_count
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
@router.get("/partner/clients")
|
| 246 |
+
async def get_partner_clients(
|
| 247 |
+
current_user: User = Depends(get_current_user),
|
| 248 |
+
session: AsyncSession = Depends(get_async_session)
|
| 249 |
+
):
|
| 250 |
+
"""
|
| 251 |
+
Получить список клиентов, привлечённых партнёром.
|
| 252 |
+
|
| 253 |
+
Только для ACTIVE партнёров.
|
| 254 |
+
"""
|
| 255 |
+
|
| 256 |
+
# Get partner record
|
| 257 |
+
stmt = select(Partner).where(Partner.user_id == current_user.id)
|
| 258 |
+
result = await session.execute(stmt)
|
| 259 |
+
partner = result.scalar_one_or_none()
|
| 260 |
+
|
| 261 |
+
if not partner:
|
| 262 |
+
raise HTTPException(
|
| 263 |
+
status_code=status.HTTP_404_NOT_FOUND,
|
| 264 |
+
detail="Партнерская запись не найдена"
|
| 265 |
+
)
|
| 266 |
+
|
| 267 |
+
if partner.status != PartnerStatus.ACTIVE:
|
| 268 |
+
raise HTTPException(
|
| 269 |
+
status_code=status.HTTP_403_FORBIDDEN,
|
| 270 |
+
detail="Доступ только для активных партнёров"
|
| 271 |
+
)
|
| 272 |
+
|
| 273 |
+
# Get all tenants referred by this partner
|
| 274 |
+
stmt = select(Tenant, User).join(
|
| 275 |
+
User, Tenant.id == User.tenant_id
|
| 276 |
+
).where(
|
| 277 |
+
Tenant.partner_ref_id == partner.id,
|
| 278 |
+
User.role == "OWNER" # Get owner email
|
| 279 |
+
).order_by(Tenant.created_at.desc())
|
| 280 |
+
|
| 281 |
+
result = await session.execute(stmt)
|
| 282 |
+
rows = result.all()
|
| 283 |
+
|
| 284 |
+
# Calculate commissions for each tenant
|
| 285 |
+
clients_data = []
|
| 286 |
+
|
| 287 |
+
for tenant, owner in rows:
|
| 288 |
+
# Get total paid by this tenant (sum of all SUBSCRIPTION transactions)
|
| 289 |
+
stmt_earnings = select(PartnerEarning).where(
|
| 290 |
+
PartnerEarning.tenant_id == tenant.id,
|
| 291 |
+
PartnerEarning.transaction_type.in_(["SUBSCRIPTION", "TRIAL_CONVERSION"])
|
| 292 |
+
)
|
| 293 |
+
result_earnings = await session.execute(stmt_earnings)
|
| 294 |
+
transactions = result_earnings.scalars().all()
|
| 295 |
+
|
| 296 |
+
total_paid = sum(t.amount_usd for t in transactions)
|
| 297 |
+
|
| 298 |
+
# Get commission earned from this tenant
|
| 299 |
+
stmt_commission = select(PartnerEarning).where(
|
| 300 |
+
PartnerEarning.partner_id == partner.id,
|
| 301 |
+
PartnerEarning.tenant_id == tenant.id,
|
| 302 |
+
PartnerEarning.transaction_type == "COMMISSION"
|
| 303 |
+
)
|
| 304 |
+
result_commission = await session.execute(stmt_commission)
|
| 305 |
+
commission_transactions = result_commission.scalars().all()
|
| 306 |
+
|
| 307 |
+
commission_earned = sum(t.amount_usd for t in commission_transactions)
|
| 308 |
+
|
| 309 |
+
clients_data.append({
|
| 310 |
+
"id": str(tenant.id),
|
| 311 |
+
"name": tenant.name,
|
| 312 |
+
"business_name": tenant.business_name,
|
| 313 |
+
"email": owner.email,
|
| 314 |
+
"subscription_plan": tenant.subscription_plan,
|
| 315 |
+
"subscription_status": tenant.subscription_status,
|
| 316 |
+
"created_at": tenant.created_at.isoformat(),
|
| 317 |
+
"total_paid": round(total_paid, 2),
|
| 318 |
+
"commission_earned": round(commission_earned, 2)
|
| 319 |
+
})
|
| 320 |
+
|
| 321 |
+
# Count active tenants
|
| 322 |
+
active_count = len([c for c in clients_data if c["subscription_status"] == "active"])
|
| 323 |
+
|
| 324 |
+
return {
|
| 325 |
+
"clients": clients_data,
|
| 326 |
+
"total_clients": len(clients_data),
|
| 327 |
+
"active_clients": active_count
|
| 328 |
}
|
| 329 |
|
| 330 |
|
|
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use client'
|
| 2 |
+
|
| 3 |
+
import { useState, useEffect } from 'react'
|
| 4 |
+
import { useAuth } from '@/contexts/AuthContext'
|
| 5 |
+
import { useToast } from '@/contexts/ToastContext'
|
| 6 |
+
import {
|
| 7 |
+
Users,
|
| 8 |
+
DollarSign,
|
| 9 |
+
TrendingUp,
|
| 10 |
+
Copy,
|
| 11 |
+
CheckCircle,
|
| 12 |
+
Link2,
|
| 13 |
+
UserPlus,
|
| 14 |
+
Crown,
|
| 15 |
+
Calendar,
|
| 16 |
+
Eye,
|
| 17 |
+
AlertCircle,
|
| 18 |
+
Sparkles,
|
| 19 |
+
Target
|
| 20 |
+
} from 'lucide-react'
|
| 21 |
+
|
| 22 |
+
interface PartnerInfo {
|
| 23 |
+
partner_id: string
|
| 24 |
+
company_name: string
|
| 25 |
+
referral_code: string
|
| 26 |
+
referral_link: string
|
| 27 |
+
status: string
|
| 28 |
+
commission_rate: number
|
| 29 |
+
balance_usd: number
|
| 30 |
+
total_earned: number
|
| 31 |
+
referred_tenants_count: number
|
| 32 |
+
active_tenants_count: number
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
interface ReferredClient {
|
| 36 |
+
id: string
|
| 37 |
+
name: string
|
| 38 |
+
business_name: string
|
| 39 |
+
email: string
|
| 40 |
+
subscription_plan: string
|
| 41 |
+
subscription_status: string
|
| 42 |
+
created_at: string
|
| 43 |
+
total_paid: number
|
| 44 |
+
commission_earned: number
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
export default function PartnerDashboardPage() {
|
| 48 |
+
const { user } = useAuth()
|
| 49 |
+
const toast = useToast()
|
| 50 |
+
const [partnerInfo, setPartnerInfo] = useState<PartnerInfo | null>(null)
|
| 51 |
+
const [clients, setClients] = useState<ReferredClient[]>([])
|
| 52 |
+
const [loading, setLoading] = useState(true)
|
| 53 |
+
const [copied, setCopied] = useState(false)
|
| 54 |
+
|
| 55 |
+
useEffect(() => {
|
| 56 |
+
loadPartnerData()
|
| 57 |
+
}, [])
|
| 58 |
+
|
| 59 |
+
const loadPartnerData = async () => {
|
| 60 |
+
try {
|
| 61 |
+
const [infoRes, clientsRes] = await Promise.all([
|
| 62 |
+
fetch('/api/v1/billing/referral-link', {
|
| 63 |
+
headers: { 'Authorization': `Bearer ${localStorage.getItem('access_token')}` }
|
| 64 |
+
}),
|
| 65 |
+
fetch('/api/v1/partner/clients', {
|
| 66 |
+
headers: { 'Authorization': `Bearer ${localStorage.getItem('access_token')}` }
|
| 67 |
+
})
|
| 68 |
+
])
|
| 69 |
+
|
| 70 |
+
if (infoRes.ok) {
|
| 71 |
+
const data = await infoRes.json()
|
| 72 |
+
setPartnerInfo(data)
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
if (clientsRes.ok) {
|
| 76 |
+
const data = await clientsRes.json()
|
| 77 |
+
setClients(data.clients || [])
|
| 78 |
+
}
|
| 79 |
+
} catch (error) {
|
| 80 |
+
console.error('Error loading partner data:', error)
|
| 81 |
+
toast.error('Ошибка', 'Не удалось загрузить данные')
|
| 82 |
+
} finally {
|
| 83 |
+
setLoading(false)
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
const copyReferralLink = () => {
|
| 88 |
+
if (partnerInfo?.referral_link) {
|
| 89 |
+
navigator.clipboard.writeText(partnerInfo.referral_link)
|
| 90 |
+
setCopied(true)
|
| 91 |
+
toast.success('Скопировано!', 'Реферальная ссылка скопирована в буфер обмена')
|
| 92 |
+
setTimeout(() => setCopied(false), 2000)
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
const getStatusBadge = (status: string) => {
|
| 97 |
+
const badges: Record<string, { color: string; label: string }> = {
|
| 98 |
+
trial: { color: 'bg-amber-100 text-amber-800', label: 'ПРОБНЫЙ' },
|
| 99 |
+
active: { color: 'bg-emerald-100 text-emerald-800', label: 'АКТИВЕН' },
|
| 100 |
+
expired: { color: 'bg-red-100 text-red-800', label: 'ИСТЁК' },
|
| 101 |
+
cancelled: { color: 'bg-slate-100 text-slate-800', label: 'ОТМЕНЁН' }
|
| 102 |
+
}
|
| 103 |
+
const badge = badges[status] || badges.trial
|
| 104 |
+
return (
|
| 105 |
+
<span className={`px-2 py-1 rounded-lg text-xs font-bold ${badge.color}`}>
|
| 106 |
+
{badge.label}
|
| 107 |
+
</span>
|
| 108 |
+
)
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
const getPlanBadge = (plan: string) => {
|
| 112 |
+
const badges: Record<string, { color: string; label: string }> = {
|
| 113 |
+
trial: { color: 'bg-slate-100 text-slate-700', label: 'Trial' },
|
| 114 |
+
start: { color: 'bg-blue-100 text-blue-700', label: 'Start $99' },
|
| 115 |
+
growth: { color: 'bg-indigo-100 text-indigo-700', label: 'Growth $199' },
|
| 116 |
+
unlimited: { color: 'bg-purple-100 text-purple-700', label: 'Unlimited $500' }
|
| 117 |
+
}
|
| 118 |
+
const badge = badges[plan] || badges.trial
|
| 119 |
+
return (
|
| 120 |
+
<span className={`px-3 py-1 rounded-full text-xs font-bold ${badge.color}`}>
|
| 121 |
+
{badge.label}
|
| 122 |
+
</span>
|
| 123 |
+
)
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
if (loading) {
|
| 127 |
+
return (
|
| 128 |
+
<div className="min-h-screen bg-gradient-to-br from-slate-50 to-slate-100 flex items-center justify-center">
|
| 129 |
+
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-indigo-600"></div>
|
| 130 |
+
</div>
|
| 131 |
+
)
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
if (!partnerInfo) {
|
| 135 |
+
return (
|
| 136 |
+
<div className="min-h-screen bg-gradient-to-br from-slate-50 to-slate-100 flex items-center justify-center p-8">
|
| 137 |
+
<div className="bg-white rounded-2xl shadow-lg border-2 border-amber-200 p-8 text-center max-w-md">
|
| 138 |
+
<div className="w-16 h-16 bg-amber-100 rounded-full flex items-center justify-center mx-auto mb-4">
|
| 139 |
+
<AlertCircle className="w-8 h-8 text-amber-600" />
|
| 140 |
+
</div>
|
| 141 |
+
<h1 className="text-2xl font-bold text-slate-900 mb-2">Партнёрская программа недоступна</h1>
|
| 142 |
+
<p className="text-slate-600 mb-4">
|
| 143 |
+
Вы не являетесь активным партнёром. Купите франшизу за $500, чтобы получить доступ к партнёрской панели.
|
| 144 |
+
</p>
|
| 145 |
+
</div>
|
| 146 |
+
</div>
|
| 147 |
+
)
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
return (
|
| 151 |
+
<div className="min-h-screen bg-gradient-to-br from-slate-50 via-indigo-50/20 to-purple-50/20">
|
| 152 |
+
{/* Header */}
|
| 153 |
+
<div className="bg-white border-b-2 border-indigo-100 shadow-sm">
|
| 154 |
+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
|
| 155 |
+
<div className="flex items-center gap-4">
|
| 156 |
+
<div className="p-3 bg-gradient-to-br from-indigo-500 to-purple-600 rounded-xl shadow-lg">
|
| 157 |
+
<Crown className="w-8 h-8 text-white" />
|
| 158 |
+
</div>
|
| 159 |
+
<div>
|
| 160 |
+
<h1 className="text-3xl font-bold bg-gradient-to-r from-indigo-600 to-purple-600 bg-clip-text text-transparent">
|
| 161 |
+
Партнёрская панель
|
| 162 |
+
</h1>
|
| 163 |
+
<p className="text-sm text-slate-600 mt-1">{partnerInfo.company_name}</p>
|
| 164 |
+
</div>
|
| 165 |
+
</div>
|
| 166 |
+
</div>
|
| 167 |
+
</div>
|
| 168 |
+
|
| 169 |
+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
| 170 |
+
{/* Stats Cards */}
|
| 171 |
+
<div className="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8">
|
| 172 |
+
<div className="bg-white rounded-2xl shadow-lg border-2 border-emerald-100 p-6">
|
| 173 |
+
<div className="flex items-center gap-3 mb-2">
|
| 174 |
+
<DollarSign className="w-6 h-6 text-emerald-600" />
|
| 175 |
+
<span className="text-sm font-semibold text-slate-600">Баланс</span>
|
| 176 |
+
</div>
|
| 177 |
+
<p className="text-3xl font-bold text-emerald-600">${partnerInfo.balance_usd.toFixed(2)}</p>
|
| 178 |
+
</div>
|
| 179 |
+
|
| 180 |
+
<div className="bg-white rounded-2xl shadow-lg border-2 border-indigo-100 p-6">
|
| 181 |
+
<div className="flex items-center gap-3 mb-2">
|
| 182 |
+
<TrendingUp className="w-6 h-6 text-indigo-600" />
|
| 183 |
+
<span className="text-sm font-semibold text-slate-600">Всего заработано</span>
|
| 184 |
+
</div>
|
| 185 |
+
<p className="text-3xl font-bold text-indigo-600">${partnerInfo.total_earned.toFixed(2)}</p>
|
| 186 |
+
</div>
|
| 187 |
+
|
| 188 |
+
<div className="bg-white rounded-2xl shadow-lg border-2 border-purple-100 p-6">
|
| 189 |
+
<div className="flex items-center gap-3 mb-2">
|
| 190 |
+
<Users className="w-6 h-6 text-purple-600" />
|
| 191 |
+
<span className="text-sm font-semibold text-slate-600">Всего клиентов</span>
|
| 192 |
+
</div>
|
| 193 |
+
<p className="text-3xl font-bold text-purple-600">{partnerInfo.referred_tenants_count}</p>
|
| 194 |
+
</div>
|
| 195 |
+
|
| 196 |
+
<div className="bg-white rounded-2xl shadow-lg border-2 border-blue-100 p-6">
|
| 197 |
+
<div className="flex items-center gap-3 mb-2">
|
| 198 |
+
<CheckCircle className="w-6 h-6 text-blue-600" />
|
| 199 |
+
<span className="text-sm font-semibold text-slate-600">Активных</span>
|
| 200 |
+
</div>
|
| 201 |
+
<p className="text-3xl font-bold text-blue-600">{partnerInfo.active_tenants_count}</p>
|
| 202 |
+
</div>
|
| 203 |
+
</div>
|
| 204 |
+
|
| 205 |
+
{/* Referral Link Card */}
|
| 206 |
+
<div className="bg-gradient-to-br from-indigo-500 to-purple-600 rounded-2xl shadow-2xl p-8 mb-8 text-white">
|
| 207 |
+
<div className="flex items-center gap-3 mb-4">
|
| 208 |
+
<Link2 className="w-6 h-6" />
|
| 209 |
+
<h2 className="text-2xl font-bold">Ваша реферальная ссылка</h2>
|
| 210 |
+
</div>
|
| 211 |
+
<p className="text-indigo-100 mb-4">
|
| 212 |
+
Делитесь этой ссылкой с потенциальными клиентами. Вы получите {(partnerInfo.commission_rate * 100).toFixed(0)}% комиссии от их платежей!
|
| 213 |
+
</p>
|
| 214 |
+
|
| 215 |
+
<div className="flex items-center gap-3">
|
| 216 |
+
<div className="flex-1 bg-white/10 backdrop-blur rounded-xl px-4 py-3 border-2 border-white/20">
|
| 217 |
+
<p className="text-white font-mono text-sm break-all">{partnerInfo.referral_link}</p>
|
| 218 |
+
</div>
|
| 219 |
+
<button
|
| 220 |
+
onClick={copyReferralLink}
|
| 221 |
+
className="flex items-center gap-2 px-6 py-3 bg-white text-indigo-600 font-bold rounded-xl hover:bg-indigo-50 transition-colors"
|
| 222 |
+
>
|
| 223 |
+
{copied ? (
|
| 224 |
+
<>
|
| 225 |
+
<CheckCircle className="w-5 h-5" />
|
| 226 |
+
Скопировано!
|
| 227 |
+
</>
|
| 228 |
+
) : (
|
| 229 |
+
<>
|
| 230 |
+
<Copy className="w-5 h-5" />
|
| 231 |
+
Копировать
|
| 232 |
+
</>
|
| 233 |
+
)}
|
| 234 |
+
</button>
|
| 235 |
+
</div>
|
| 236 |
+
|
| 237 |
+
<div className="mt-4 flex items-center gap-2 text-sm text-indigo-100">
|
| 238 |
+
<Sparkles className="w-4 h-4" />
|
| 239 |
+
<span>Код: <span className="font-bold text-white">{partnerInfo.referral_code}</span></span>
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
+
|
| 243 |
+
{/* Clients Table */}
|
| 244 |
+
<div className="bg-white rounded-2xl shadow-lg border-2 border-indigo-100 overflow-hidden">
|
| 245 |
+
<div className="px-6 py-4 border-b-2 border-slate-100">
|
| 246 |
+
<h2 className="text-xl font-bold text-slate-900 flex items-center gap-2">
|
| 247 |
+
<UserPlus className="w-6 h-6 text-indigo-600" />
|
| 248 |
+
Привлечённые клиенты
|
| 249 |
+
</h2>
|
| 250 |
+
</div>
|
| 251 |
+
|
| 252 |
+
{clients.length === 0 ? (
|
| 253 |
+
<div className="p-12 text-center">
|
| 254 |
+
<div className="w-16 h-16 bg-slate-100 rounded-2xl flex items-center justify-center mx-auto mb-4">
|
| 255 |
+
<Users className="w-8 h-8 text-slate-400" />
|
| 256 |
+
</div>
|
| 257 |
+
<h3 className="font-bold text-slate-900 mb-2">Пока нет клиентов</h3>
|
| 258 |
+
<p className="text-sm text-slate-500">Поделитесь реферальной ссылкой, чтобы начать зарабатывать</p>
|
| 259 |
+
</div>
|
| 260 |
+
) : (
|
| 261 |
+
<div className="overflow-x-auto">
|
| 262 |
+
<table className="w-full">
|
| 263 |
+
<thead className="bg-gradient-to-r from-indigo-50 to-purple-50">
|
| 264 |
+
<tr>
|
| 265 |
+
<th className="px-6 py-4 text-left text-xs font-bold text-slate-700 uppercase">Клиент</th>
|
| 266 |
+
<th className="px-6 py-4 text-left text-xs font-bold text-slate-700 uppercase">Email</th>
|
| 267 |
+
<th className="px-6 py-4 text-left text-xs font-bold text-slate-700 uppercase">План</th>
|
| 268 |
+
<th className="px-6 py-4 text-left text-xs font-bold text-slate-700 uppercase">Статус</th>
|
| 269 |
+
<th className="px-6 py-4 text-left text-xs font-bold text-slate-700 uppercase">Оплачено</th>
|
| 270 |
+
<th className="px-6 py-4 text-left text-xs font-bold text-slate-700 uppercase">Заработано</th>
|
| 271 |
+
<th className="px-6 py-4 text-left text-xs font-bold text-slate-700 uppercase">Дата</th>
|
| 272 |
+
</tr>
|
| 273 |
+
</thead>
|
| 274 |
+
<tbody className="divide-y divide-slate-100">
|
| 275 |
+
{clients.map((client) => (
|
| 276 |
+
<tr key={client.id} className="hover:bg-slate-50 transition-colors">
|
| 277 |
+
<td className="px-6 py-4">
|
| 278 |
+
<div>
|
| 279 |
+
<p className="font-semibold text-slate-900">{client.business_name}</p>
|
| 280 |
+
<p className="text-xs text-slate-500">{client.name}</p>
|
| 281 |
+
</div>
|
| 282 |
+
</td>
|
| 283 |
+
<td className="px-6 py-4 text-sm text-slate-600">{client.email}</td>
|
| 284 |
+
<td className="px-6 py-4">{getPlanBadge(client.subscription_plan)}</td>
|
| 285 |
+
<td className="px-6 py-4">{getStatusBadge(client.subscription_status)}</td>
|
| 286 |
+
<td className="px-6 py-4">
|
| 287 |
+
<span className="font-semibold text-slate-900">${client.total_paid.toFixed(2)}</span>
|
| 288 |
+
</td>
|
| 289 |
+
<td className="px-6 py-4">
|
| 290 |
+
<span className="font-bold text-emerald-600">${client.commission_earned.toFixed(2)}</span>
|
| 291 |
+
</td>
|
| 292 |
+
<td className="px-6 py-4 text-sm text-slate-600">
|
| 293 |
+
{new Date(client.created_at).toLocaleDateString('ru-RU')}
|
| 294 |
+
</td>
|
| 295 |
+
</tr>
|
| 296 |
+
))}
|
| 297 |
+
</tbody>
|
| 298 |
+
</table>
|
| 299 |
+
</div>
|
| 300 |
+
)}
|
| 301 |
+
</div>
|
| 302 |
+
</div>
|
| 303 |
+
</div>
|
| 304 |
+
)
|
| 305 |
+
}
|