|
|
|
@ -4,6 +4,7 @@ from max_bot.models import Client, PromoCode
|
|
|
|
from restoran_max_bot.common import common_get_data
|
|
|
|
from restoran_max_bot.common import common_get_data
|
|
|
|
from restoran_max_bot.message_sender import send_text, send_image
|
|
|
|
from restoran_max_bot.message_sender import send_text, send_image
|
|
|
|
from restoran_max_bot.settings import STATICFILES_DIRS, BASE_URL
|
|
|
|
from restoran_max_bot.settings import STATICFILES_DIRS, BASE_URL
|
|
|
|
|
|
|
|
from restoran_max_bot.user_logger import log_user_action
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def bot_promo(client: Client, message: dict, settings_max: dict) -> bool:
|
|
|
|
def bot_promo(client: Client, message: dict, settings_max: dict) -> bool:
|
|
|
|
@ -13,8 +14,27 @@ def bot_promo(client: Client, message: dict, settings_max: dict) -> bool:
|
|
|
|
messenger = 'max-bot'
|
|
|
|
messenger = 'max-bot'
|
|
|
|
client_id = client.id
|
|
|
|
client_id = client.id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Логируем начало обработки промокода
|
|
|
|
|
|
|
|
log_user_action(
|
|
|
|
|
|
|
|
client=client,
|
|
|
|
|
|
|
|
chat_id=chat_id,
|
|
|
|
|
|
|
|
action_type='promo_start',
|
|
|
|
|
|
|
|
details={
|
|
|
|
|
|
|
|
'promo': promo,
|
|
|
|
|
|
|
|
'client_id': client_id,
|
|
|
|
|
|
|
|
'messenger': messenger
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
data = common_get_data(client=client, key=promo)
|
|
|
|
data = common_get_data(client=client, key=promo)
|
|
|
|
if not data:
|
|
|
|
if not data:
|
|
|
|
|
|
|
|
# Логируем, что промокод не найден в системе
|
|
|
|
|
|
|
|
log_user_action(
|
|
|
|
|
|
|
|
client=client,
|
|
|
|
|
|
|
|
chat_id=chat_id,
|
|
|
|
|
|
|
|
action_type='promo_not_found',
|
|
|
|
|
|
|
|
details={'promo': promo}
|
|
|
|
|
|
|
|
)
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
promo_obj, created = PromoCode.objects.get_or_create(
|
|
|
|
promo_obj, created = PromoCode.objects.get_or_create(
|
|
|
|
@ -27,8 +47,20 @@ def bot_promo(client: Client, message: dict, settings_max: dict) -> bool:
|
|
|
|
if not created:
|
|
|
|
if not created:
|
|
|
|
if promo_obj.used:
|
|
|
|
if promo_obj.used:
|
|
|
|
send_text(chat_id, settings_max['token'], "⚠️ Этот промокод уже был использован.")
|
|
|
|
send_text(chat_id, settings_max['token'], "⚠️ Этот промокод уже был использован.")
|
|
|
|
|
|
|
|
log_user_action(
|
|
|
|
|
|
|
|
client=client,
|
|
|
|
|
|
|
|
chat_id=chat_id,
|
|
|
|
|
|
|
|
action_type='promo_already_used',
|
|
|
|
|
|
|
|
details={'promo': promo, 'used_at': promo_obj.used_at}
|
|
|
|
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
send_text(chat_id, settings_max['token'], "ℹ️ QR-код уже был отправлен.")
|
|
|
|
send_text(chat_id, settings_max['token'], "ℹ️ QR-код уже был отправлен.")
|
|
|
|
|
|
|
|
log_user_action(
|
|
|
|
|
|
|
|
client=client,
|
|
|
|
|
|
|
|
chat_id=chat_id,
|
|
|
|
|
|
|
|
action_type='promo_already_sent',
|
|
|
|
|
|
|
|
details={'promo': promo}
|
|
|
|
|
|
|
|
)
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
# Генерируем QR
|
|
|
|
# Генерируем QR
|
|
|
|
@ -39,6 +71,20 @@ def bot_promo(client: Client, message: dict, settings_max: dict) -> bool:
|
|
|
|
img.save(f"{STATICFILES_DIRS[0]}/client_qr/{file_name}")
|
|
|
|
img.save(f"{STATICFILES_DIRS[0]}/client_qr/{file_name}")
|
|
|
|
qr_url = f"{BASE_URL}/static/client_qr/{file_name}"
|
|
|
|
qr_url = f"{BASE_URL}/static/client_qr/{file_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Логируем сформированные ссылки
|
|
|
|
|
|
|
|
log_user_action(
|
|
|
|
|
|
|
|
client=client,
|
|
|
|
|
|
|
|
chat_id=chat_id,
|
|
|
|
|
|
|
|
action_type='promo_qr_generated',
|
|
|
|
|
|
|
|
details={
|
|
|
|
|
|
|
|
'promo': promo,
|
|
|
|
|
|
|
|
'qr_url': qr_url,
|
|
|
|
|
|
|
|
'status_url': url_promo,
|
|
|
|
|
|
|
|
'file_name': file_name,
|
|
|
|
|
|
|
|
'created': created
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
send_image(chat_id, settings_max['token'], qr_url, 'Ваш QR-код.')
|
|
|
|
send_image(chat_id, settings_max['token'], qr_url, 'Ваш QR-код.')
|
|
|
|
|
|
|
|
|
|
|
|
# Отправляем дополнительный контент
|
|
|
|
# Отправляем дополнительный контент
|
|
|
|
|