From 286b722c0f83a3c0b236ff29bd18650d4f8fbe0a Mon Sep 17 00:00:00 2001 From: pilot <657434@03b.ru> Date: Fri, 7 Aug 2026 18:54:39 +0800 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=BA=D0=BE=D0=B4=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- restoran_max_bot/max_bot/views.py | 17 ++++++----- .../restoran_max_bot/bot_message.py | 3 -- .../restoran_max_bot/bot_started.py | 28 +------------------ restoran_max_bot/restoran_max_bot/common.py | 12 ++++++++ 4 files changed, 21 insertions(+), 39 deletions(-) diff --git a/restoran_max_bot/max_bot/views.py b/restoran_max_bot/max_bot/views.py index c51d5d3..2cfc905 100644 --- a/restoran_max_bot/max_bot/views.py +++ b/restoran_max_bot/max_bot/views.py @@ -9,7 +9,7 @@ from max_bot.models import Partner, Integration, Client, BonusTransaction, App from restoran_max_bot.bot_started import bot_started from restoran_max_bot.bot_stopped import bot_stopped from restoran_max_bot.bot_message import bot_message, bot_promo -from restoran_max_bot.common import common_get_contact +from restoran_max_bot.common import common_get_contact, common_check_registration from restoran_max_bot.settings import DEBUG from restoran_max_bot.utils import is_json, has_key @@ -72,13 +72,6 @@ def api_start_max_v1(request, token, **kwargs): rt = {'success': False, 'error': 'data update_type not found', 'data': ''} return JsonResponse(rt, status=200) - # обработчик промо кодов с запросов - # https://dev.max.ru/docs/chatbots/bots-coding/prepare - # https://max.ru/id032606883607_2_bot?start=source_site - if data.get("payload", None): - print(data['payload']) - bot_promo(client=client, message=data, settings_max=settings_max) - # получение сообщения из бота if data['update_type'] == 'message_created': bot_message(client=client, message=data, settings_max=settings_max, message_type='message_created') @@ -88,7 +81,13 @@ def api_start_max_v1(request, token, **kwargs): # start - запуск бота if data['update_type'] == 'bot_started': - bot_started(client=client, message=data, settings=settings_max) + # https://dev.max.ru/docs/chatbots/bots-coding/prepare + # https://max.ru/id032606883607_2_bot?start=source_site + # роверка на промокод + if data.get("payload", None): + bot_promo(client=client, message=data, settings_max=settings_max) + if not common_check_registration(client=client, chat_id=data['chat_id']): + bot_started(client=client, message=data, settings=settings_max) # выход из бота if data['update_type'] == 'bot_stopped': diff --git a/restoran_max_bot/restoran_max_bot/bot_message.py b/restoran_max_bot/restoran_max_bot/bot_message.py index 1ecae07..21d2a76 100644 --- a/restoran_max_bot/restoran_max_bot/bot_message.py +++ b/restoran_max_bot/restoran_max_bot/bot_message.py @@ -282,7 +282,4 @@ def bot_promo(client: Client, message: dict, settings_max: dict): if dt.url: maxbot_send_text_message(chat_id=chat_id, max_token=settings_max['token'], message=dt.url) - - # сохранение в meta информации о коде - # ПРОВЕРКА НА РЕГИСТРАЦИЮ ??? return True diff --git a/restoran_max_bot/restoran_max_bot/bot_started.py b/restoran_max_bot/restoran_max_bot/bot_started.py index 0cb8f30..64ae5f9 100644 --- a/restoran_max_bot/restoran_max_bot/bot_started.py +++ b/restoran_max_bot/restoran_max_bot/bot_started.py @@ -21,8 +21,7 @@ def bot_started(client: Client, message: dict, settings: dict): text='Согласен на обработку персональных данных.') return True - -# проверка есть ли регистрация клиента номер телефона +# проверка есть ли регистрация клиента номер телефона, запись создается после отправки ноера телефона def get_registration_phone(client: Client, chat_id: str, settings: dict): contact = common_get_contact(client=client, uid_client=chat_id) if not contact: @@ -41,31 +40,6 @@ def get_registration_phone(client: Client, chat_id: str, settings: dict): return False return contact - -# проверка есть ли регистрация клиента день рождение -def get_registration_birthday(client: Client, chat_id: str, settings: dict): - contact = common_get_contact(client=client, uid_client=chat_id) - if not contact: - data = common_get_data(client=client, key='start'.lower()) - if data: - for dt in data: - if dt.img: - url = f"https://cdn.telefon-ip.ru/{dt.img}?thumb=600" - maxbot_send_img_message(chat_id=chat_id, max_token=settings['token'], img=url, message=dt.descr) - else: - maxbot_send_text_message(chat_id=chat_id, max_token=settings['token'], message=dt.descr) - if dt.url: - maxbot_send_text_message(chat_id=chat_id, max_token=settings['token'], message=dt.url) - - maxbot_get_phone(chat_id=chat_id, max_token=settings['token'], text='Подтвердите согласие') - return False - - if not contact.field1: - return False - - return contact - - # проверка регистрации в боте (что все данные получены) def check_registration(client: Client, chat_id: str, message: dict, settings: dict): contact = get_registration_phone(client=client, chat_id=chat_id, settings=settings) diff --git a/restoran_max_bot/restoran_max_bot/common.py b/restoran_max_bot/restoran_max_bot/common.py index ed8eda0..4de324f 100644 --- a/restoran_max_bot/restoran_max_bot/common.py +++ b/restoran_max_bot/restoran_max_bot/common.py @@ -88,3 +88,15 @@ def send_message_all_manager(client: Client, message: str): return response +def common_check_registration(client: Client, chat_id: str) -> None | bool | Contact: + # функция проверяет все ли данные заполнены клиентом + contact = common_get_contact(client=client, uid_client=chat_id) + if not contact: + return None + + if contact.field1 is None or contact.field1 == '': + return None + + if contact.field2 is None or contact.field2 == '': + return None + return contact \ No newline at end of file