|
|
|
from urllib.parse import quote
|
|
|
|
import requests
|
|
|
|
from django.db import models
|
|
|
|
from bot_sys.config import GetTelegramBotApiToken
|
|
|
|
|
|
|
|
|
|
|
|
class Users(models.Model):
|
|
|
|
user_id = models.CharField(max_length=100, primary_key=True)
|
|
|
|
userName = models.CharField(max_length=100, verbose_name='Имя пользователя')
|
|
|
|
userFirstName = models.CharField(max_length=100, verbose_name='Имя')
|
|
|
|
userLastName = models.CharField(max_length=100, verbose_name='Фамилия')
|
|
|
|
userIsBot = models.BooleanField(verbose_name='Является ботом')
|
|
|
|
userLanguageCode = models.CharField(max_length=100, verbose_name='Код языка')
|
|
|
|
userPhoto = models.ImageField(verbose_name='Фото пользователя')
|
|
|
|
userAccess = models.CharField(max_length=100, verbose_name='Доступ')
|
|
|
|
createDateTime = models.DateTimeField(auto_now_add=True, verbose_name='Дата и время создания')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name_plural = 'Заказы'
|
|
|
|
managed = False
|
|
|
|
db_table = 'users'
|
|
|
|
|
|
|
|
|
|
|
|
class Orders(models.Model):
|
|
|
|
orderID = models.AutoField(primary_key=True, verbose_name='id заказа')
|
|
|
|
userID = models.CharField(max_length=100, verbose_name='id пользователя в tg', null=True)
|
|
|
|
orderName = models.CharField(max_length=100, verbose_name='наименование', null=True)
|
|
|
|
orderDesc = models.TextField(verbose_name='описание', null=True)
|
|
|
|
orderPhoto = models.ImageField(verbose_name='фото', null=True)
|
|
|
|
orderPhotoPay = models.ImageField(verbose_name='чек')
|
|
|
|
orderAddress = models.CharField(max_length=100, verbose_name='адрес доставки', blank=True, null=True)
|
|
|
|
orderAccess = models.CharField(max_length=100, verbose_name='доступ', blank=True, null=True)
|
|
|
|
orderCreateDateTime = models.DateTimeField(auto_now_add=True, null=True, verbose_name='дата и время создания')
|
|
|
|
orderStatus = models.CharField(max_length=100, verbose_name='статус заказа', blank=True, null=True)
|
|
|
|
catID = models.CharField(max_length=100, verbose_name='категория', blank=True, null=True)
|
|
|
|
|
|
|
|
def get_photo_html(self, width=100, height=100, large_width=400, large_height=400):
|
|
|
|
file_id = self.orderPhoto
|
|
|
|
token = GetTelegramBotApiToken()
|
|
|
|
url = f"https://api.telegram.org/bot{token}/getFile?file_id={file_id}"
|
|
|
|
|
|
|
|
response = requests.get(url)
|
|
|
|
data = response.json()
|
|
|
|
|
|
|
|
if data['ok']:
|
|
|
|
file_path = data["result"]["file_path"]
|
|
|
|
photo_url = f"https://api.telegram.org/file/bot{token}/{quote(file_path, safe='')}"
|
|
|
|
|
|
|
|
html = f"""
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<img src="{photo_url}" width="{width}" height="{height}" class="small-photo">
|
|
|
|
<img src="{photo_url}" width="{large_width}" height="{large_height}" class="large-photo">
|
|
|
|
<a href="#" onclick="togglePhoto(event)" class="button">Увеличить фото</a>
|
|
|
|
<script>
|
|
|
|
function togglePhoto(event) {{
|
|
|
|
var toggleButton = event.target;
|
|
|
|
var container = toggleButton.parentNode;
|
|
|
|
var smallPhoto = container.querySelector(".small-photo");
|
|
|
|
var largePhoto = container.querySelector(".large-photo");
|
|
|
|
|
|
|
|
if (smallPhoto.style.display === "none") {{
|
|
|
|
smallPhoto.style.display = "block";
|
|
|
|
largePhoto.style.display = "none";
|
|
|
|
toggleButton.innerHTML = "Увеличить фото";
|
|
|
|
}} else {{
|
|
|
|
smallPhoto.style.display = "none";
|
|
|
|
largePhoto.style.display = "block";
|
|
|
|
toggleButton.innerHTML = "Уменьшить фото";
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
</script>
|
|
|
|
<style>
|
|
|
|
.large-photo {{
|
|
|
|
display: none;
|
|
|
|
}}
|
|
|
|
.button {{
|
|
|
|
display: inline-block;
|
|
|
|
padding: 10px 20px;
|
|
|
|
background-color: #4CAF50;
|
|
|
|
color: white;
|
|
|
|
text-align: center;
|
|
|
|
text-decoration: none;
|
|
|
|
font-size: 16px;
|
|
|
|
border: none;
|
|
|
|
border-radius: 5px;
|
|
|
|
cursor: pointer;
|
|
|
|
}}
|
|
|
|
</style>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
"""
|
|
|
|
return html
|
|
|
|
|
|
|
|
|
|
|
|
def get_photopay_html(self, width=100, height=100, large_width=400, large_height=400):
|
|
|
|
token = GetTelegramBotApiToken()
|
|
|
|
file_id = self.orderPhotoPay
|
|
|
|
url = f"https://api.telegram.org/bot{token}/getFile?file_id={file_id}"
|
|
|
|
|
|
|
|
response = requests.get(url)
|
|
|
|
data = response.json()
|
|
|
|
|
|
|
|
if data['ok']:
|
|
|
|
file_path = data["result"]["file_path"]
|
|
|
|
photo_url = f"https://api.telegram.org/file/bot{token}/{quote(file_path, safe='')}"
|
|
|
|
|
|
|
|
html = f"""
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<img src="{photo_url}" width="{width}" height="{height}" class="small-photo">
|
|
|
|
<img src="{photo_url}" width="{large_width}" height="{large_height}" class="large-photo">
|
|
|
|
<a href="#" onclick="togglePhoto(event)" class="button">Увеличить фото</a>
|
|
|
|
<script>
|
|
|
|
function togglePhoto(event) {{
|
|
|
|
var toggleButton = event.target;
|
|
|
|
var container = toggleButton.parentNode;
|
|
|
|
var smallPhoto = container.querySelector(".small-photo");
|
|
|
|
var largePhoto = container.querySelector(".large-photo");
|
|
|
|
|
|
|
|
if (smallPhoto.style.display === "none") {{
|
|
|
|
smallPhoto.style.display = "block";
|
|
|
|
largePhoto.style.display = "none";
|
|
|
|
toggleButton.innerHTML = "Увеличить фото";
|
|
|
|
}} else {{
|
|
|
|
smallPhoto.style.display = "none";
|
|
|
|
largePhoto.style.display = "block";
|
|
|
|
toggleButton.innerHTML = "Уменьшить фото";
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
</script>
|
|
|
|
<style>
|
|
|
|
.large-photo {{
|
|
|
|
display: none;
|
|
|
|
}}
|
|
|
|
.button {{
|
|
|
|
display: inline-block;
|
|
|
|
padding: 10px 20px;
|
|
|
|
background-color: #4CAF50;
|
|
|
|
color: white;
|
|
|
|
text-align: center;
|
|
|
|
text-decoration: none;
|
|
|
|
font-size: 16px;
|
|
|
|
border: none;
|
|
|
|
border-radius: 5px;
|
|
|
|
cursor: pointer;
|
|
|
|
}}
|
|
|
|
</style>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
"""
|
|
|
|
return html
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
|
|
verbose_name_plural = 'Заказы'
|
|
|
|
managed = False
|
|
|
|
db_table = 'orders'
|
|
|
|
|
|
|
|
|