start project
8
.dockerignore
Normal file
@ -0,0 +1,8 @@
|
||||
.venv/
|
||||
venv/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
.git/
|
||||
.idea/
|
||||
.DS_Store
|
0
.gitignore
vendored
Normal file
15
Dockerfile
Normal file
@ -0,0 +1,15 @@
|
||||
# Используйте официальный образ Python в качестве базового
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Установите рабочую директорию
|
||||
WORKDIR /app
|
||||
|
||||
# Скопируйте файл зависимостей и установите их
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Скопируйте все файлы в рабочую директорию
|
||||
COPY . .
|
||||
|
||||
# Выполните миграции при запуске контейнера
|
||||
CMD ["sh", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"]
|
45
README.md
Normal file
@ -0,0 +1,45 @@
|
||||
McDuckMist
|
||||
|
||||
Чат-бот с WebApp
|
||||
|
||||
Содержание
|
||||
[Установка](#установка)
|
||||
[Использование](#использование)
|
||||
[Требования](#требования)
|
||||
|
||||
|
||||
|
||||
[Установка](#установка)
|
||||
<a name="установка">Установка</a>
|
||||
|
||||
```bash
|
||||
git clone https://git.wizardstech.ru/Sanzhar.swydk/McDuck.git
|
||||
```
|
||||
|
||||
```bash
|
||||
docker-compose up --build
|
||||
```
|
||||
|
||||
|
||||
|
||||
[Использование](#использование)
|
||||
<a name="использование">Использование</a>
|
||||
|
||||
После запуска перейдите по пути http://127.0.0.1:8000/api/ можно посмотреть, добавить, удалить и изменить данные.
|
||||
Сможете посмотреть все ссылки/пути для API, а также вот несколько эндпоинтов которые есть в проекте.
|
||||
/api/users/get_datetime/
|
||||
/api/users/get_referrals/
|
||||
/api/balance/add_for_balance/
|
||||
/api/levels/create_new_levels/
|
||||
|
||||
<a name="требования">Требования</a>
|
||||
|
||||
```markdown
|
||||
|
||||
|
||||
- Docker
|
||||
- Postgresql
|
||||
- Django
|
||||
- Python 3.10+
|
||||
- Библотеки указаны в requirements.txt
|
||||
```
|
0
backend/__init__.py
Normal file
BIN
backend/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
backend/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
backend/__pycache__/settings.cpython-310.pyc
Normal file
BIN
backend/__pycache__/settings.cpython-311.pyc
Normal file
BIN
backend/__pycache__/urls.cpython-310.pyc
Normal file
BIN
backend/__pycache__/urls.cpython-311.pyc
Normal file
BIN
backend/__pycache__/wsgi.cpython-310.pyc
Normal file
BIN
backend/__pycache__/wsgi.cpython-311.pyc
Normal file
16
backend/asgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for backend project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
|
||||
|
||||
application = get_asgi_application()
|
163
backend/settings.py
Normal file
@ -0,0 +1,163 @@
|
||||
"""
|
||||
Django settings for backend project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 5.0.6.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.0/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/5.0/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-xbb0o#ev2jhjdsgy7ugsrp__1r8ssq_)*o(%w6$+&+w!g_%*7('
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'main',
|
||||
'users',
|
||||
'tapdata',
|
||||
'stacking',
|
||||
'rest_framework',
|
||||
'corsheaders',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
|
||||
]
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_PERMISSION_CLASSES':[
|
||||
'rest_framework.permissions.AllowAny'
|
||||
]
|
||||
}
|
||||
|
||||
CORS_ALLOWED_ORIGINS = [
|
||||
'https://pizzafresca.ru', #TODOPROJECT CHANGE IT
|
||||
|
||||
# другие источники, если необходимо
|
||||
]
|
||||
|
||||
|
||||
ROOT_URLCONF = 'backend.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'backend.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
|
||||
|
||||
""" DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': 'mcduck', # Поставлено как пример
|
||||
'USER': 'postgres',
|
||||
'PASSWORD': 'swydk', # Поставлено как пример
|
||||
'HOST': 'localhost',
|
||||
'PORT': '5432',
|
||||
}
|
||||
} """
|
||||
import os
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': 'mydatabase',
|
||||
'USER': 'myuser',
|
||||
'PASSWORD': 'mypassword',
|
||||
'HOST': 'db',
|
||||
'PORT': '5432',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/5.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'ru'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/5.0/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
AUTH_USER_MODEL = 'users.User'
|
||||
|
||||
TURCODE_API_KEY = "3feeee2c981eab39c2ff8b2ecc9fad18"
|
25
backend/urls.py
Normal file
@ -0,0 +1,25 @@
|
||||
"""
|
||||
URL configuration for backend project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/5.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('',include("main.urls")),
|
||||
]
|
||||
|
||||
|
16
backend/wsgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for backend project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
|
||||
|
||||
application = get_wsgi_application()
|
24
docker-compose.yml
Normal file
@ -0,0 +1,24 @@
|
||||
version: '3.10'
|
||||
|
||||
services:
|
||||
db:
|
||||
image: postgres:15
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
environment:
|
||||
POSTGRES_DB: mydatabase
|
||||
POSTGRES_USER: myuser
|
||||
POSTGRES_PASSWORD: mypassword
|
||||
|
||||
web:
|
||||
build: .
|
||||
command: ["sh", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"]
|
||||
volumes:
|
||||
- .:/app
|
||||
ports:
|
||||
- "8000:8000"
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
0
main/__init__.py
Normal file
BIN
main/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
main/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
main/__pycache__/admin.cpython-310.pyc
Normal file
BIN
main/__pycache__/admin.cpython-311.pyc
Normal file
BIN
main/__pycache__/apps.cpython-310.pyc
Normal file
BIN
main/__pycache__/apps.cpython-311.pyc
Normal file
BIN
main/__pycache__/models.cpython-310.pyc
Normal file
BIN
main/__pycache__/models.cpython-311.pyc
Normal file
BIN
main/__pycache__/urls.cpython-310.pyc
Normal file
BIN
main/__pycache__/urls.cpython-311.pyc
Normal file
3
main/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
main/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class MainConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'main'
|
3
main/models.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
3
main/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
31
main/urls.py
Normal file
@ -0,0 +1,31 @@
|
||||
# urls.py
|
||||
from django.urls import path, include
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from users.views import UserViewSet, DailyRewardViewSet, DailyRewardsListViewSet, BalanceViewSet, LevelsViewSet
|
||||
from tapdata.views import FarmingViewSet
|
||||
from stacking.views import UserStakeViewSet, StakeViewSet
|
||||
|
||||
|
||||
""" from tapdata.views import TapDataViewSet
|
||||
from stacking.views import UserStakeViewSet, StakeViewSet """
|
||||
|
||||
|
||||
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register(r'users', UserViewSet)
|
||||
router.register(r'dailyreward', DailyRewardViewSet)
|
||||
router.register(r'dailyrewardlist', DailyRewardsListViewSet)
|
||||
router.register(r'balance', BalanceViewSet)
|
||||
router.register(r'levels', LevelsViewSet)
|
||||
router.register(r'farming', FarmingViewSet)
|
||||
router.register(r'stacking', UserStakeViewSet)
|
||||
router.register(r'stake', StakeViewSet)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('api/', include(router.urls)),
|
||||
]
|
3
main/views.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
22
manage.py
Normal file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
15
requirements.txt
Normal file
@ -0,0 +1,15 @@
|
||||
asgiref==3.8.1
|
||||
certifi==2024.7.4
|
||||
charset-normalizer==3.3.2
|
||||
Django==5.0.6
|
||||
django-cors-headers==4.4.0
|
||||
djangorestframework==3.15.2
|
||||
gunicorn==23.0.0
|
||||
idna==3.7
|
||||
packaging==24.1
|
||||
pillow==10.4.0
|
||||
psycopg2-binary==2.9.9
|
||||
requests==2.32.3
|
||||
sqlparse==0.5.1
|
||||
typing_extensions==4.12.2
|
||||
urllib3==2.2.2
|
0
stacking/__init__.py
Normal file
BIN
stacking/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
stacking/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
stacking/__pycache__/admin.cpython-310.pyc
Normal file
BIN
stacking/__pycache__/admin.cpython-311.pyc
Normal file
BIN
stacking/__pycache__/apps.cpython-310.pyc
Normal file
BIN
stacking/__pycache__/apps.cpython-311.pyc
Normal file
BIN
stacking/__pycache__/models.cpython-310.pyc
Normal file
BIN
stacking/__pycache__/models.cpython-311.pyc
Normal file
BIN
stacking/__pycache__/serializers.cpython-310.pyc
Normal file
BIN
stacking/__pycache__/serializers.cpython-311.pyc
Normal file
BIN
stacking/__pycache__/views.cpython-310.pyc
Normal file
BIN
stacking/__pycache__/views.cpython-311.pyc
Normal file
12
stacking/admin.py
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
from django.contrib import admin
|
||||
from .models import Stake, UserStake
|
||||
|
||||
admin.site.register(Stake)
|
||||
admin.site.register(UserStake)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
6
stacking/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class StackingConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'stacking'
|
35
stacking/migrations/0001_initial.py
Normal file
@ -0,0 +1,35 @@
|
||||
# Generated by Django 5.0.6 on 2024-08-26 11:46
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('users', '0001_initial'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='UserStake',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('amount', models.DecimalField(decimal_places=4, max_digits=30, verbose_name='Сумма')),
|
||||
('percent', models.IntegerField(blank=True, null=True, verbose_name='Процент бонусов')),
|
||||
('is_active', models.BooleanField(default=True, verbose_name='Автивен')),
|
||||
('start_date', models.DateTimeField(auto_now=True, verbose_name='Время начала')),
|
||||
('duration', models.IntegerField(blank=True, null=True, verbose_name='Длительность в днях')),
|
||||
('balance', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.balance')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Пользовательский Stake',
|
||||
'verbose_name_plural': 'Пользовательские Stake',
|
||||
},
|
||||
),
|
||||
]
|
@ -0,0 +1,40 @@
|
||||
# Generated by Django 5.0.6 on 2024-08-29 07:41
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stacking', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Stake',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('stake_type', models.CharField(choices=[('DAY1', '1 день'), ('WEEK1', '1 неделя'), ('WEEK2', '2 недели'), ('MONTH1', '1 месяц'), ('MONTH3', '3 месяца'), ('MONTH6', '6 месяцев'), ('YEAR1', '1 год')], default='DAY1', max_length=250, verbose_name='Тип')),
|
||||
('percent', models.IntegerField(blank=True, null=True, verbose_name='Процент бонусов')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Stake',
|
||||
'verbose_name_plural': 'Stake',
|
||||
},
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='userstake',
|
||||
name='duration',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='userstake',
|
||||
name='percent',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='userstake',
|
||||
name='stake',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='stacking.stake'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
0
stacking/migrations/__init__.py
Normal file
BIN
stacking/migrations/__pycache__/0001_initial.cpython-310.pyc
Normal file
BIN
stacking/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
BIN
stacking/migrations/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
stacking/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
50
stacking/models.py
Normal file
@ -0,0 +1,50 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from users.models import Balance
|
||||
|
||||
class Stake(models.Model):
|
||||
class StakeEnum(models.TextChoices):
|
||||
DAY1 = 'DAY1', _('1 день')
|
||||
WEEK1 = 'WEEK1', _('1 неделя')
|
||||
WEEK2 = 'WEEK2', _('2 недели')
|
||||
MONTH1 = 'MONTH1', _('1 месяц')
|
||||
MONTH3 = 'MONTH3', _('3 месяца')
|
||||
MONTH6 = 'MONTH6', _('6 месяцев')
|
||||
YEAR1 = 'YEAR1', _('1 год')
|
||||
|
||||
|
||||
|
||||
|
||||
stake_type = models.CharField('Тип', choices=StakeEnum.choices,default=StakeEnum.DAY1, max_length=250)
|
||||
percent = models.IntegerField('Процент бонусов', null=True, blank=True)
|
||||
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.stake_type} - {self.percent}%"
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Stake'
|
||||
verbose_name_plural = 'Stake'
|
||||
|
||||
class UserStake(models.Model):
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
balance = models.ForeignKey(Balance, on_delete=models.CASCADE)
|
||||
stake = models.ForeignKey(Stake, on_delete=models.CASCADE)
|
||||
amount = models.DecimalField('Сумма',max_digits=30, decimal_places=4)
|
||||
is_active = models.BooleanField('Автивен', default=True)
|
||||
start_date = models.DateTimeField('Время начала', auto_now=True)
|
||||
|
||||
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.user.username} - {self.amount} коинов"
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Пользовательский Stake'
|
||||
verbose_name_plural = 'Пользовательские Stake'
|
14
stacking/serializers.py
Normal file
@ -0,0 +1,14 @@
|
||||
from rest_framework import serializers
|
||||
from .models import UserStake, Stake
|
||||
|
||||
class UserStakeSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = UserStake
|
||||
fields = '__all__'
|
||||
|
||||
class StakeSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Stake
|
||||
fields = '__all__'
|
||||
|
||||
|
3
stacking/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
14
stacking/views.py
Normal file
@ -0,0 +1,14 @@
|
||||
from rest_framework import viewsets
|
||||
from .models import UserStake, Stake
|
||||
from .serializers import UserStakeSerializer, StakeSerializer
|
||||
|
||||
|
||||
|
||||
class UserStakeViewSet(viewsets.ModelViewSet):
|
||||
queryset = UserStake.objects.all()
|
||||
serializer_class = UserStakeSerializer
|
||||
class StakeViewSet(viewsets.ModelViewSet):
|
||||
queryset = Stake.objects.all()
|
||||
serializer_class = StakeSerializer
|
||||
|
||||
|
BIN
static/media/levels/character1.jpg
Normal file
After Width: | Height: | Size: 61 KiB |
BIN
static/media/levels/character2.jpg
Normal file
After Width: | Height: | Size: 104 KiB |
BIN
static/media/levels/character3.jpg
Normal file
After Width: | Height: | Size: 142 KiB |
BIN
static/media/levels/character4.jpg
Normal file
After Width: | Height: | Size: 129 KiB |
BIN
static/media/levels/character5.jpg
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
static/media/levels/character6.jpg
Normal file
After Width: | Height: | Size: 138 KiB |
BIN
static/media/levels/character7.jpg
Normal file
After Width: | Height: | Size: 127 KiB |
BIN
static/media/user_photo/Снимок_экрана_2024-07-26_123831.png
Normal file
After Width: | Height: | Size: 14 KiB |
0
tapdata/__init__.py
Normal file
BIN
tapdata/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
tapdata/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
tapdata/__pycache__/admin.cpython-310.pyc
Normal file
BIN
tapdata/__pycache__/admin.cpython-311.pyc
Normal file
BIN
tapdata/__pycache__/apps.cpython-310.pyc
Normal file
BIN
tapdata/__pycache__/apps.cpython-311.pyc
Normal file
BIN
tapdata/__pycache__/models.cpython-310.pyc
Normal file
BIN
tapdata/__pycache__/models.cpython-311.pyc
Normal file
BIN
tapdata/__pycache__/serializers.cpython-310.pyc
Normal file
BIN
tapdata/__pycache__/serializers.cpython-311.pyc
Normal file
BIN
tapdata/__pycache__/views.cpython-310.pyc
Normal file
BIN
tapdata/__pycache__/views.cpython-311.pyc
Normal file
13
tapdata/admin.py
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
from django.contrib import admin
|
||||
from .models import Farming, Prizes
|
||||
|
||||
admin.site.register(Farming)
|
||||
admin.site.register(Prizes)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
6
tapdata/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class TapdataConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'tapdata'
|
50
tapdata/migrations/0001_initial.py
Normal file
@ -0,0 +1,50 @@
|
||||
# Generated by Django 5.0.6 on 2024-08-26 11:44
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Prizes',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('prize_type', models.CharField(choices=[('CN', 'Coins'), ('AL', 'Acceleration'), ('AC', 'Auto_collection')], max_length=250, verbose_name='Тип приза')),
|
||||
('time', models.IntegerField(blank=True, null=True, verbose_name='Время награды в днях')),
|
||||
('coins', models.BigIntegerField(blank=True, null=True, verbose_name='Количество MCDK (Необязательно)')),
|
||||
('percent', models.IntegerField(blank=True, null=True, verbose_name='Процент (Необязательно)')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Приз',
|
||||
'verbose_name_plural': 'Призы',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Farming',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('coins_per_min', models.BigIntegerField(blank=True, default=1, verbose_name='Монет за мин')),
|
||||
('coins', models.BigIntegerField(blank=True, default=0, verbose_name='Количество MCDK')),
|
||||
('start_time', models.DateTimeField(blank=True, null=True, verbose_name='Время и дата начала фарминга')),
|
||||
('percent', models.IntegerField(default=0, verbose_name='Дополнительные проценты фарминга')),
|
||||
('is_auto_collection_active', models.BooleanField(default=False, verbose_name='Автосбор активен')),
|
||||
('auto_collection_end_time', models.DateTimeField(blank=True, null=True, verbose_name='Время окончания автосбора')),
|
||||
('bonus_multiplier', models.FloatField(blank=True, default=1.0, verbose_name='Множитель скорости фарминга')),
|
||||
('bonus_end_time', models.DateTimeField(blank=True, null=True, verbose_name='Время окончания бонуса')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Данные фарминга',
|
||||
'verbose_name_plural': 'Данные фармингов',
|
||||
},
|
||||
),
|
||||
]
|
0
tapdata/migrations/__init__.py
Normal file
BIN
tapdata/migrations/__pycache__/0001_initial.cpython-310.pyc
Normal file
BIN
tapdata/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
BIN
tapdata/migrations/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
tapdata/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
73
tapdata/models.py
Normal file
@ -0,0 +1,73 @@
|
||||
from django.db import models
|
||||
from users.models import User
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
class Farming(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
coins_per_min = models.BigIntegerField('Монет за мин', default=1, blank=True)
|
||||
coins = models.BigIntegerField('Количество MCDK', default=0, blank=True)
|
||||
start_time = models.DateTimeField('Время и дата начала фарминга', null=True, blank=True)
|
||||
percent = models.IntegerField("Дополнительные проценты фарминга", default=0)
|
||||
is_auto_collection_active = models.BooleanField('Автосбор активен', default=False)
|
||||
auto_collection_end_time = models.DateTimeField('Время окончания автосбора', null=True, blank=True)
|
||||
bonus_multiplier = models.FloatField('Множитель скорости фарминга', default=1.0, blank=True)
|
||||
bonus_end_time = models.DateTimeField('Время окончания бонуса', null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.user.username} имеет {self.coins} MCDK'
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Данные фарминга'
|
||||
verbose_name_plural = 'Данные фармингов'
|
||||
|
||||
def apply_auto_collection(self, duration_days):
|
||||
self.is_auto_collection_active = True
|
||||
self.auto_collection_end_time = timezone.now() + timedelta(days=duration_days)
|
||||
self.save()
|
||||
|
||||
def apply_bonus_multiplier(self, percent, duration_days):
|
||||
self.bonus_multiplier = 1 + (percent / 100)
|
||||
self.bonus_end_time = timezone.now() + timedelta(days=duration_days)
|
||||
self.save()
|
||||
|
||||
def update_farming(self):
|
||||
current_time = timezone.now()
|
||||
|
||||
# Обновление авто-сбора
|
||||
if self.is_auto_collection_active and self.auto_collection_end_time < current_time:
|
||||
self.is_auto_collection_active = False
|
||||
self.auto_collection_end_time = None
|
||||
self.save()
|
||||
|
||||
# Обновление бонусного множителя
|
||||
if self.bonus_multiplier > 1.0 and self.bonus_end_time < current_time:
|
||||
self.bonus_multiplier = 1.0
|
||||
self.bonus_end_time = None
|
||||
self.save()
|
||||
|
||||
# Обновление монет с учетом бонусного множителя
|
||||
self.coins += self.coins_per_min * self.bonus_multiplier
|
||||
self.save()
|
||||
|
||||
# Призы с колеса фортуны
|
||||
class Prizes(models.Model):
|
||||
class PrizeTypeEnum(models.TextChoices):
|
||||
COINS = 'CN', _('Coins')
|
||||
ACCELERATION = 'AL', _('Acceleration')
|
||||
AUTO_COLLECTION = 'AC', _('Auto_collection')
|
||||
|
||||
prize_type = models.CharField('Тип приза', choices=PrizeTypeEnum.choices, max_length=250)
|
||||
time = models.IntegerField('Время награды в днях', null=True, blank=True)
|
||||
coins = models.BigIntegerField('Количество MCDK (Необязательно)', null=True, blank=True)
|
||||
percent = models.IntegerField('Процент (Необязательно)', null=True, blank=True)
|
||||
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f'Тип приза - {self.prize_type}'
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Приз'
|
||||
verbose_name_plural = 'Призы'
|
14
tapdata/serializers.py
Normal file
@ -0,0 +1,14 @@
|
||||
from rest_framework import serializers
|
||||
from .models import Farming, Prizes
|
||||
|
||||
class FarmingSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Farming
|
||||
fields = '__all__'
|
||||
|
||||
class PrizesSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Prizes
|
||||
fields = '__all__'
|
||||
|
||||
|
3
tapdata/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
14
tapdata/views.py
Normal file
@ -0,0 +1,14 @@
|
||||
from rest_framework import viewsets
|
||||
from .models import Farming, Prizes
|
||||
from .serializers import FarmingSerializer, PrizesSerializer
|
||||
|
||||
|
||||
|
||||
class FarmingViewSet(viewsets.ModelViewSet):
|
||||
queryset = Farming.objects.all()
|
||||
serializer_class = FarmingSerializer
|
||||
|
||||
class PrizesViewSet(viewsets.ModelViewSet):
|
||||
queryset = Prizes.objects.all()
|
||||
serializer_class = PrizesSerializer
|
||||
|