112 lines
4.7 KiB
Python
112 lines
4.7 KiB
Python
from django.contrib.auth.models import AbstractUser
|
||
from django.db import models
|
||
from django.utils.translation import gettext_lazy as _
|
||
from django.utils import timezone
|
||
from django.db.models.signals import post_save
|
||
from django.dispatch import receiver
|
||
|
||
|
||
# Users model
|
||
class User(AbstractUser):
|
||
photo = models.ImageField('Аватарка пользователя', upload_to='static/media/user_photo/')
|
||
tg_id = models.CharField('Telegram ID', max_length=250, blank=True)
|
||
tg_username = models.CharField('Имя пользователя', max_length=250, blank=True)
|
||
name = models.CharField('Имя', max_length=300, blank=True)
|
||
referral_code = models.CharField('Код рефферала', max_length=250, unique=True, blank=True, null=True)
|
||
referred_by = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, related_name='referrals')
|
||
coins_for_referral = models.BigIntegerField("Монеты полученные от рефералов", default=0, blank=True)
|
||
|
||
|
||
def __str__(self):
|
||
return self.tg_username
|
||
|
||
|
||
# Уровни пользователя
|
||
class Levels(models.Model):
|
||
|
||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||
name = models.CharField('Имя',max_length=300, blank=True)
|
||
level = models.IntegerField("Уровень")
|
||
photo = models.ImageField('Фото уровня', upload_to='static/media/levels/')
|
||
need_coins = models.IntegerField("Количество нужных монет")
|
||
|
||
|
||
def __str__(self):
|
||
return f"Пользователь {self.user.username} - {self.name} {self.level}"
|
||
class Meta:
|
||
verbose_name = 'Уровень'
|
||
verbose_name_plural = 'Уровни'
|
||
|
||
|
||
#Баланс пользователя
|
||
class Balance(models.Model):
|
||
class ColorEnum(models.TextChoices):
|
||
YELLOW = 'Yl', _('Yellow')
|
||
BLACK = 'BK', _('Black')
|
||
GREY = 'GR', _('Grey')
|
||
BLUE = 'BL', _('Blue')
|
||
|
||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||
name = models.CharField("Имя баланса")
|
||
wallet = models.CharField('Кошелек', max_length=350, blank=True, null=True)
|
||
currency = models.CharField('Валюта', max_length=250, blank=True)
|
||
balance = models.BigIntegerField("Количество монет/Сумма", default=0)
|
||
color = models.CharField('Цвет', choices=ColorEnum.choices, default=ColorEnum.YELLOW, max_length=250)
|
||
|
||
|
||
def __str__(self):
|
||
return f"Сумма {self.balance} {self.currency} - {self.user.username}"
|
||
|
||
class Meta:
|
||
verbose_name = 'Баланс пользователя'
|
||
verbose_name_plural = 'Балансы пользователей'
|
||
|
||
|
||
|
||
# Ежедневная награда
|
||
class DailyReward(models.Model):
|
||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||
day = models.IntegerField("День")
|
||
reward_amount = models.IntegerField("Сумма награды")
|
||
claimed = models.BooleanField('Была ли награда получена',default=False)
|
||
claim_date = models.DateTimeField('Время получения награды',null=True, blank=True)
|
||
|
||
def __str__(self):
|
||
return f"День {self.day} - {self.user.username}"
|
||
|
||
class Meta:
|
||
verbose_name = 'Ежедневная награда'
|
||
verbose_name_plural = 'Ежедневные награды'
|
||
|
||
|
||
# Список ежедневных наград
|
||
class DailyRewardsList(models.Model):
|
||
class MonthEnum(models.TextChoices):
|
||
TO28 = 'До 28', _('До 28')
|
||
TO29 = 'До 29', _('До 29')
|
||
TO30 = 'До 30', _('До 30')
|
||
TO31 = 'До 31', _('До 31')
|
||
|
||
active_day = models.IntegerField('Активный день', blank=True)
|
||
month_max_day = models.CharField('Длительность месяца', choices=MonthEnum.choices, max_length=250)
|
||
|
||
def __str__(self):
|
||
return f"Месяц с {self.month_max_day} днями - Активный день: {self.active_day}"
|
||
|
||
class Meta:
|
||
verbose_name = 'Список наград'
|
||
verbose_name_plural = 'Список наград'
|
||
|
||
from django.db import models
|
||
|
||
class Transaction(models.Model):
|
||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||
amount = models.DecimalField("Сумма", max_digits=10, decimal_places=2)
|
||
currency = models.CharField("Валюта", max_length=10)
|
||
status = models.CharField("Статус", max_length=50, default="Pending")
|
||
transaction_id = models.CharField("ID транзакции", max_length=100, unique=True)
|
||
created_at = models.DateTimeField("Дата создания", auto_now_add=True)
|
||
|
||
def __str__(self):
|
||
return f"Транзакция {self.transaction_id} пользователя {self.user.username}"
|