New features
This commit is contained in:
@@ -1,35 +1,95 @@
|
||||
from aiogram import types
|
||||
from aiogram.dispatcher import FSMContext
|
||||
|
||||
import config
|
||||
from load import dp, bot, messages
|
||||
from utils.database.cart import get_user_cart
|
||||
from utils.database.market import Catalog
|
||||
from utils.database.ordering import save_info
|
||||
from keyboard.default.main_menu import back_to_main_menu
|
||||
from keyboard.default.checkout import checkout_btn
|
||||
from state.state import UserState
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.checkout)
|
||||
async def checkout(message: types.Message):
|
||||
async def checkout(message: types.Message, state: FSMContext):
|
||||
items = get_user_cart(message.from_user.id)
|
||||
output: str = ""
|
||||
output: list[str] = [""]
|
||||
cost = 0
|
||||
|
||||
for index, count in items:
|
||||
i = Catalog.get_catalog(index)
|
||||
output += f'Имя: {i["name"]} цена: {i["price"]} - {count}шт.\n'
|
||||
|
||||
product_info = (
|
||||
f'Имя: {i["name"]} '
|
||||
f'цена: {i["price"]} - {count}шт.\n'
|
||||
)
|
||||
|
||||
if (len(output[-1]) + len(product_info)) >= 4095:
|
||||
output.append("")
|
||||
output[-1] += product_info
|
||||
cost += i["price"] * count
|
||||
output += f"Общая сумма: {cost}\nВсё верно? Следующий этап: заполнение заявки"
|
||||
await bot.send_message(message.chat.id, output, reply_markup=checkout_btn())
|
||||
await UserState.confirm.set()
|
||||
|
||||
total_amount = (
|
||||
f"Общая сумма: {cost}\n"
|
||||
"Всё верно? Следующий этап: заполнение заявки"
|
||||
)
|
||||
if (len(output[-1]) + len(total_amount)) >= 4095:
|
||||
output.append("")
|
||||
output[-1] += total_amount
|
||||
|
||||
for msg in output:
|
||||
await bot.send_message(message.chat.id, msg, reply_markup=checkout_btn())
|
||||
|
||||
await state.set_state("load_or_create_profile")
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.all_right_message, state="save_or_continue")
|
||||
async def continue_user_form():
|
||||
pass
|
||||
async def continue_user_form(message: types.Message, state: FSMContext):
|
||||
chat_id = config.service_chat
|
||||
items = get_user_cart(message.from_user.id)
|
||||
data = await state.get_data()
|
||||
|
||||
output: list[str] = [
|
||||
(f"Имя: {data['first_name']}\n"
|
||||
f"Фамилия: {data['last_name']}\n"
|
||||
f"Номер телефона: {data['phone_number']}\n"
|
||||
f"Адрес: {data['address']}\n\n"
|
||||
)
|
||||
]
|
||||
cost = 0
|
||||
|
||||
for index, count in items:
|
||||
i = Catalog.get_catalog(index)
|
||||
|
||||
product_info = (
|
||||
f'ID: {i["id"]} '
|
||||
f'Имя: {i["name"]} '
|
||||
f'цена: {i["price"]} - {count}шт.\n'
|
||||
)
|
||||
|
||||
if (len(output[-1]) + len(product_info)) >= 4095:
|
||||
output.append("")
|
||||
output[-1] += product_info
|
||||
cost += i["price"] * count
|
||||
|
||||
total_amount = (
|
||||
f"\nИтоговая сумма: {cost}"
|
||||
)
|
||||
if (len(output[-1]) + len(total_amount)) >= 4095:
|
||||
output.append("")
|
||||
output[-1] += total_amount
|
||||
await bot.send_message(message.chat.id, messages.order, reply_markup=back_to_main_menu)
|
||||
for msg in output:
|
||||
await bot.send_message(
|
||||
chat_id,
|
||||
msg,
|
||||
parse_mode='Markdown'
|
||||
)
|
||||
await state.finish()
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.save_and_continue, state="save_or_continue")
|
||||
async def save_user_info(message: types.Message):
|
||||
state = dp.current_state(chat=message.chat.id, user=message.from_user.id)
|
||||
async def save_user_info(message: types.Message, state: FSMContext):
|
||||
info = await state.get_data()
|
||||
save_info(user_id=message.from_user.id, **info)
|
||||
await continue_user_form()
|
||||
await continue_user_form(message, state)
|
||||
|
@@ -5,12 +5,11 @@ from load import dp, bot, messages
|
||||
from keyboard.default.checkout import confirm_all_info
|
||||
from keyboard.default.main_menu import cancel_btn, get_phone_number, continue_btn
|
||||
from keyboard.default.ordering import load_info
|
||||
from state.state import UserState
|
||||
from state.checkout import Checkout
|
||||
from utils.database.ordering import get_info
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.all_right_message, state=UserState.confirm)
|
||||
@dp.message_handler(lambda x: x.text == messages.all_right_message, state="load_or_create_profile")
|
||||
async def confirm(message: types.Message, state: FSMContext):
|
||||
await state.finish()
|
||||
info = get_info(message.from_user.id)
|
||||
@@ -30,15 +29,15 @@ async def load_form(message: types.message, state: FSMContext):
|
||||
first_name=info["first_name"],
|
||||
last_name=info["last_name"],
|
||||
phone_number=info["phone_number"],
|
||||
address=info["address"]
|
||||
address=info["address"],
|
||||
load=True
|
||||
)
|
||||
await bot.send_message(message.chat.id, "Ваши данные загружены!", reply_markup=continue_btn)
|
||||
await state.set_state("finish_send_form")
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.rewrite_data, state="load_data")
|
||||
async def new_form(message: types.Message, state: FSMContext = None):
|
||||
await state.update_data(loaded=False)
|
||||
async def new_form(message: types.Message):
|
||||
await bot.send_message(
|
||||
message.chat.id,
|
||||
"Напишите вашу фамилию",
|
||||
@@ -100,11 +99,10 @@ async def finish_form(message: types.Message, state: FSMContext):
|
||||
text = (f"Имя: {data['first_name']}\n"
|
||||
f"Фамилия: {data['last_name']}\n"
|
||||
f"Номер телефона: {data['phone_number']}\n"
|
||||
f"Адрес: {data['address']}\n"
|
||||
)
|
||||
f"Адрес: {data['address']}\n")
|
||||
await bot.send_message(
|
||||
message.chat.id,
|
||||
text,
|
||||
reply_markup=confirm_all_info()
|
||||
reply_markup=confirm_all_info(load=data.pop("load", False))
|
||||
)
|
||||
await state.set_state("save_or_continue")
|
||||
|
@@ -1,10 +1,11 @@
|
||||
from aiogram import types
|
||||
from aiogram.dispatcher.filters import CommandStart
|
||||
from aiogram.dispatcher.filters import CommandStart, CommandHelp
|
||||
|
||||
from load import dp, bot, messages
|
||||
from keyboard.default.main_menu import main_menu
|
||||
from utils.database.base import get_admins, get_operator
|
||||
from utils.database.user import Register
|
||||
from utils.database.market import Catalog
|
||||
|
||||
|
||||
@dp.message_handler(CommandStart())
|
||||
@@ -30,6 +31,38 @@ async def back_to_menu(message: types.Message):
|
||||
)
|
||||
|
||||
|
||||
@dp.message_handler(commands='get')
|
||||
async def get_item(message: types.Message):
|
||||
args = message.get_args()
|
||||
if not args and not args.isdigit():
|
||||
await bot.send_message(message.chat.id, "Неверные данные")
|
||||
return
|
||||
item = Catalog.get_catalog(args)
|
||||
if not item:
|
||||
await bot.send_message(message.chat.id, "Товар не найден!")
|
||||
return
|
||||
|
||||
await bot.send_photo(
|
||||
chat_id=message.chat.id,
|
||||
photo=item["image"],
|
||||
caption=messages.product_message.format(
|
||||
name=item["name"],
|
||||
description=item["description"],
|
||||
price=item['price']
|
||||
),
|
||||
parse_mode="Markdown",
|
||||
)
|
||||
|
||||
|
||||
@dp.message_handler(CommandHelp())
|
||||
async def help_cmd(message: types.Message):
|
||||
await bot.send_message(
|
||||
message.chat.id,
|
||||
("/sos - попросить помощь в оператора\n"
|
||||
"/get <ID> - получить товар по ID")
|
||||
)
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.cancel_message, state="*")
|
||||
async def cancel(message: types.Message):
|
||||
state = dp.current_state(chat=message.chat.id, user=message.from_user.id)
|
||||
@@ -44,8 +77,3 @@ async def userinfo(message: types.Message):
|
||||
"User_id: <code>{user_id}</code>".format(user_id=message.from_user.id),
|
||||
parse_mode="HTML"
|
||||
)
|
||||
|
||||
|
||||
@dp.message_handler(commands=['test'])
|
||||
async def test(message: types.Message):
|
||||
Register.register_admin(message.from_user)
|
||||
|
Reference in New Issue
Block a user