uchill/backend/apps/subscriptions/management/commands/create_sample_subscriptions.py

263 lines
13 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Команда для создания примерных тарифных планов.
"""
from django.core.management.base import BaseCommand
from django.utils import timezone
from apps.subscriptions.models import SubscriptionPlan, BulkDiscount
from decimal import Decimal
class Command(BaseCommand):
help = 'Создает примерные тарифные планы для тестирования'
def handle(self, *args, **options):
self.stdout.write('Создание примерных тарифных планов...')
# 1. Подписка "За ученика" (базовая)
plan_per_student, created = SubscriptionPlan.objects.get_or_create(
slug='per-student-basic',
defaults={
'name': 'За ученика (Базовый)',
'description': 'Оплата за каждого ученика. Гибкая система оплаты в зависимости от количества учеников.',
'price': Decimal('0'), # Не используется для этого типа
'price_per_student': Decimal('100'),
'currency': 'RUB',
'billing_period': 'monthly',
'subscription_type': 'per_student',
'trial_days': 7,
'max_clients': None, # Без ограничений
'max_lessons_per_month': None,
'max_storage_mb': 5120, # 5 GB
'max_video_minutes_per_month': None,
'allow_video_calls': True,
'allow_screen_sharing': True,
'allow_whiteboard': True,
'allow_homework': True,
'allow_materials': True,
'allow_analytics': True,
'allow_telegram_bot': True,
'allow_api_access': False,
'is_active': True,
'is_featured': True,
'sort_order': 1,
}
)
if created:
self.stdout.write(self.style.SUCCESS(f'✓ Создан план: {plan_per_student.name}'))
# Создаем прогрессирующие скидки для "За ученика"
# 1-4 ученика: 100 руб за каждого (базовая цена)
BulkDiscount.objects.get_or_create(
plan=plan_per_student,
min_students=1,
max_students=4,
defaults={
'total_price': Decimal('100'), # За 1 ученика (100 руб)
}
)
# 5-9 учеников: 84 руб за каждого (скидка 16%)
# total_price = 84 * 5 = 420 руб за 5 учеников
BulkDiscount.objects.get_or_create(
plan=plan_per_student,
min_students=5,
max_students=9,
defaults={
'total_price': Decimal('420'), # За 5 учеников (84 руб за каждого)
}
)
# 10+ учеников: 85 руб за каждого (скидка 15%)
# total_price = 85 * 10 = 850 руб за 10 учеников
BulkDiscount.objects.get_or_create(
plan=plan_per_student,
min_students=10,
max_students=None, # Без ограничений
defaults={
'total_price': Decimal('850'), # За 10 учеников (85 руб за каждого)
}
)
self.stdout.write(self.style.SUCCESS(' ✓ Созданы прогрессирующие скидки'))
else:
self.stdout.write(self.style.WARNING(f'⚠ План уже существует: {plan_per_student.name}'))
# 2. Подписка "За ученика" (премиум)
plan_per_student_premium, created = SubscriptionPlan.objects.get_or_create(
slug='per-student-premium',
defaults={
'name': 'За ученика (Премиум)',
'description': 'Премиум подписка за ученика с расширенными возможностями и приоритетной поддержкой.',
'price': Decimal('0'),
'price_per_student': Decimal('150'),
'currency': 'RUB',
'billing_period': 'monthly',
'subscription_type': 'per_student',
'trial_days': 14,
'max_clients': None,
'max_lessons_per_month': None,
'max_storage_mb': 10240, # 10 GB
'max_video_minutes_per_month': None,
'allow_video_calls': True,
'allow_screen_sharing': True,
'allow_whiteboard': True,
'allow_homework': True,
'allow_materials': True,
'allow_analytics': True,
'allow_telegram_bot': True,
'allow_api_access': True,
'is_active': True,
'is_featured': True,
'sort_order': 2,
}
)
if created:
self.stdout.write(self.style.SUCCESS(f'✓ Создан план: {plan_per_student_premium.name}'))
# Прогрессирующие скидки для премиум
# 1-4: 150 руб за каждого (базовая цена)
BulkDiscount.objects.get_or_create(
plan=plan_per_student_premium,
min_students=1,
max_students=4,
defaults={'total_price': Decimal('150')} # За 1 ученика
)
# 5-9: 126 руб за каждого (скидка 16%)
# total_price = 126 * 5 = 630 руб за 5 учеников
BulkDiscount.objects.get_or_create(
plan=plan_per_student_premium,
min_students=5,
max_students=9,
defaults={'total_price': Decimal('630')} # За 5 учеников
)
# 10+: 127.5 руб за каждого (скидка 15%)
# total_price = 127.5 * 10 = 1275 руб за 10 учеников
BulkDiscount.objects.get_or_create(
plan=plan_per_student_premium,
min_students=10,
max_students=None,
defaults={'total_price': Decimal('1275')} # За 10 учеников
)
self.stdout.write(self.style.SUCCESS(' ✓ Созданы прогрессирующие скидки'))
else:
self.stdout.write(self.style.WARNING(f'⚠ План уже существует: {plan_per_student_premium.name}'))
# 3. Ежемесячная подписка (Базовый)
plan_monthly_basic, created = SubscriptionPlan.objects.get_or_create(
slug='monthly-basic',
defaults={
'name': 'Ежемесячная (Базовый)',
'description': 'Ежемесячная подписка с фиксированной ценой. До 20 учеников включено.',
'price': Decimal('1000'),
'price_per_student': None,
'currency': 'RUB',
'billing_period': 'monthly',
'subscription_type': 'monthly',
'trial_days': 7,
'max_clients': 20,
'max_lessons_per_month': 100,
'max_storage_mb': 5120, # 5 GB
'max_video_minutes_per_month': 1000,
'allow_video_calls': True,
'allow_screen_sharing': True,
'allow_whiteboard': True,
'allow_homework': True,
'allow_materials': True,
'allow_analytics': True,
'allow_telegram_bot': True,
'allow_api_access': False,
'is_active': True,
'is_featured': False,
'sort_order': 3,
}
)
if created:
self.stdout.write(self.style.SUCCESS(f'✓ Создан план: {plan_monthly_basic.name}'))
else:
self.stdout.write(self.style.WARNING(f'⚠ План уже существует: {plan_monthly_basic.name}'))
# 4. Ежемесячная подписка (Профессиональный)
plan_monthly_pro, created = SubscriptionPlan.objects.get_or_create(
slug='monthly-professional',
defaults={
'name': 'Ежемесячная (Профессиональный)',
'description': 'Профессиональная ежемесячная подписка. До 50 учеников, безлимитные занятия и материалы.',
'price': Decimal('2500'),
'price_per_student': None,
'currency': 'RUB',
'billing_period': 'monthly',
'subscription_type': 'monthly',
'trial_days': 14,
'max_clients': 50,
'max_lessons_per_month': None, # Безлимит
'max_storage_mb': 20480, # 20 GB
'max_video_minutes_per_month': None, # Безлимит
'allow_video_calls': True,
'allow_screen_sharing': True,
'allow_whiteboard': True,
'allow_homework': True,
'allow_materials': True,
'allow_analytics': True,
'allow_telegram_bot': True,
'allow_api_access': True,
'is_active': True,
'is_featured': True,
'sort_order': 4,
}
)
if created:
self.stdout.write(self.style.SUCCESS(f'✓ Создан план: {plan_monthly_pro.name}'))
else:
self.stdout.write(self.style.WARNING(f'⚠ План уже существует: {plan_monthly_pro.name}'))
# 5. Ежемесячная подписка (Бизнес)
plan_monthly_business, created = SubscriptionPlan.objects.get_or_create(
slug='monthly-business',
defaults={
'name': 'Ежемесячная (Бизнес)',
'description': 'Бизнес подписка для крупных образовательных центров. Безлимит учеников и все функции.',
'price': Decimal('5000'),
'price_per_student': None,
'currency': 'RUB',
'billing_period': 'monthly',
'subscription_type': 'monthly',
'trial_days': 30,
'max_clients': None, # Безлимит
'max_lessons_per_month': None, # Безлимит
'max_storage_mb': 51200, # 50 GB
'max_video_minutes_per_month': None, # Безлимит
'allow_video_calls': True,
'allow_screen_sharing': True,
'allow_whiteboard': True,
'allow_homework': True,
'allow_materials': True,
'allow_analytics': True,
'allow_telegram_bot': True,
'allow_api_access': True,
'is_active': True,
'is_featured': True,
'sort_order': 5,
}
)
if created:
self.stdout.write(self.style.SUCCESS(f'✓ Создан план: {plan_monthly_business.name}'))
else:
self.stdout.write(self.style.WARNING(f'⚠ План уже существует: {plan_monthly_business.name}'))
self.stdout.write(self.style.SUCCESS('\nВсе тарифные планы созданы!'))
self.stdout.write('\nДоступные планы:')
self.stdout.write(' 1. За ученика (Базовый) - 100 руб/ученик (с прогрессирующими скидками)')
self.stdout.write(' 2. За ученика (Премиум) - 150 руб/ученик (с прогрессирующими скидками)')
self.stdout.write(' 3. Ежемесячная (Базовый) - 1000 руб/мес (до 20 учеников)')
self.stdout.write(' 4. Ежемесячная (Профессиональный) - 2500 руб/мес (до 50 учеников)')
self.stdout.write(' 5. Ежемесячная (Бизнес) - 5000 руб/мес (безлимит)')