async def add_produkt(cht_id, forw_id, uniq_id): info_of_user = get_callback_fo_user_id(cht_id) table = info_of_user[1] in_cart = info_of_user[3] if info_of_user[4] != None: price = int(info_of_user[4]) else: price = 0 db_select = db_hendler.DB_select() all_product_info = db_select.string_with_value('*', table, 'uniq_id', str(uniq_id))[0] product_file_id = all_product_info[2] product_price = all_product_info[3] db_obj = db_hendler.DB_update() if price == 0 or price == 'Null': db_obj.string_with_value('user_data', 'in_cart', 'user_id', cht_id, product_file_id) db_obj.string_with_value('user_data', 'price', 'user_id', cht_id, product_price) elif price > 0: new_in_cart = in_cart + ' ' + product_file_id new_price = int(price) + int(product_price) db_obj.string_with_value('user_data', 'in_cart', 'user_id', cht_id, new_in_cart) db_obj.string_with_value('user_data', 'price', 'user_id', cht_id, new_price) print('add_product') print(product_file_id) return product_file_id
async def remove_produkt(cht_id, forw_id, uniq_id): info_of_user = get_callback_fo_user_id(cht_id) table = info_of_user[1] in_cart = info_of_user[3] if info_of_user[4] != None: price = int(info_of_user[4]) else: price = 0 db_select = db_hendler.DB_select() all_product_info = db_select.string_with_value('*', table, 'uniq_id', str(uniq_id))[0] product_file_id = all_product_info[2] product_price = all_product_info[3] if price == 0 or price == 'Null': print('0 - 0') elif price > 0: arr_in_cart = [str(s) for s in in_cart.split(' ')] if len(arr_in_cart) > 1: arr_in_cart.remove(product_file_id) new_in_cart = ' '.join(elem for elem in arr_in_cart) new_price = int(price) - int(product_price) else: new_in_cart = None new_price = None db_obj = db_hendler.DB_update() db_obj.string_with_value('user_data', 'in_cart', 'user_id', cht_id, new_in_cart) db_obj.string_with_value('user_data', 'price', 'user_id', cht_id, new_price) return product_file_id
async def modify_card(cht_id, callback, forw_id): table = callback[7:15] do = callback[-1] callback = callback[:-2] id_card = callback[16:] await app.nav_back(cht_id, forw_id, 'one_one') print('modify_card ' + table + ' ' + id_card + ' ' + do) do_redact_kb = await RedactCartKB.choose_card_kb(id_card, table, do) if do == '1': await server_bot.bot.send_message( cht_id, 'Введите новое описание и нажмите применить', reply_markup=do_redact_kb) elif do == '2': await server_bot.bot.send_message( cht_id, 'Введите новую цену и нажмите применить', reply_markup=do_redact_kb) elif do == '3': update_cache = db_hendler.DB_update() update_cache.string_with_value('user_data', 'cache', 'user_id', cht_id, 'photo') await server_bot.bot.send_message( cht_id, 'Отправьте новую фотографию и нажмите применить', reply_markup=do_redact_kb)
async def enter_product(cht_id, callback, fwd=None): print('enter_product ' + callback) text_stap_1 = 'Шаг 1. Отправьте сообщение с описанием товара и нажмите "Готово"' text_stap_1_err = 'Пустое сообщение. Отправьте сообщение с описанием товара и нажмите "Готово"' text_stap_2 = 'Шаг 2. Отправьте сообщение с ценой товара и нажмите "Готово"' text_stap_2_err = 'Пустое сообщение. Отправьте сообщение с ценой товара и нажмите "Готово"' text_stap_3 = 'Шаг 3. Отправьте фото товара и нажмите "Готово"' db_up = db_hendler.DB_update() if callback[:12] == 'admin_select': db_up.string_with_value('user_data', 'cache', 'user_id', cht_id, None) enter_product_kb = await RedactCartKB.enter_product_kb( callback[13:] + '_1') await server_bot.bot.send_message(cht_id, text_stap_1, reply_markup=enter_product_kb) elif callback[-1] == '2': try: db_up.string_with_value('user_data', 'callback_in', 'user_id', cht_id, callback) enter_product_kb = await RedactCartKB.enter_product_kb(callback ) await server_bot.bot.delete_message(cht_id, int(fwd) + 1) await server_bot.bot.send_message( cht_id, text_stap_2, reply_markup=enter_product_kb) except: callback = callback[-10:-2] + '_1' enter_product_kb = await RedactCartKB.enter_product_kb(callback ) await server_bot.bot.send_message( cht_id, text_stap_1_err, reply_markup=enter_product_kb) elif callback[-1] == '3': try: db_up.string_with_value('user_data', 'callback_in', 'user_id', cht_id, callback) await server_bot.bot.delete_message(cht_id, int(fwd) + 1) enter_product_kb = await RedactCartKB.enter_product_kb(callback ) await server_bot.bot.send_message( cht_id, text_stap_3, reply_markup=enter_product_kb) except: callback = callback[:-1] + '2' enter_product_kb = await RedactCartKB.enter_product_kb(callback ) await server_bot.bot.send_message( cht_id, text_stap_2_err, reply_markup=enter_product_kb) print('enter_product ' + callback)
async def send_list_card(cht_id, callback, fowd, method): print('AddCardForRedact.send_card') table = callback[-8:] db_sel = db_hendler.DB_select() count_card = db_sel.count_string('id', table) real_id_card = 1 print(count_card) if count_card[0][0] == 0: await server_bot.bot.send_message(cht_id, 'В этой категории нет товара', reply_markup=admin_sel_cat) return False for i in range(1, int(count_card[0][0]) + 1): get_card = app.get_string_fo_id(table, real_id_card) real_id_card = get_card[1] data_card = get_card[0] text_card = str(data_card[1]) + '" Цена "' + str( data_card[3]) + '"' if method == 'red_prod': text_card = 'Описание карточки "' + str( data_card[1]) + '" Цена товара "' + str(data_card[3]) + '"' if i == int(count_card[0][0]): if method == 'red_prod': redact_kard_kb = await RedactCartKB.choose_card_kb( real_id_card, table, do=None, end='yes') else: redact_kard_kb = await c_b_card_del( real_id_card, table, 'end') num_mes = int(fowd) + i * 2 db_upd = db_hendler.DB_update() db_upd.string_with_value('user_data', 'message_id', 'user_id', cht_id, num_mes) else: if method == 'red_prod': redact_kard_kb = await RedactCartKB.choose_card_kb( real_id_card, table) else: redact_kard_kb = await c_b_card_del( real_id_card, table, 'no_end') await server_bot.bot.send_message(cht_id, text_card) await server_bot.bot.send_photo(cht_id, data_card[2], reply_markup=redact_kard_kb) real_id_card += 1
async def send_product_kart(call_back, cht_id, for_id): await server_bot.bot.delete_message(cht_id, for_id) get_card = db_hendler.DB_select() count_cart = get_card.count_string('id', str(call_back))[0][0] print(count_cart) num_mes1 = int(for_id) db_obj = db_hendler.DB_update() db_obj.string_with_value('user_data', 'callback_in', 'user_id', cht_id, call_back) db_obj.string_with_value('user_data', 'message_id', 'user_id', cht_id, str(num_mes1)) print('Chat_id produkt cart: ' + str(cht_id)) start_index = 1 for i in range(1, int(count_cart) + 1): if i == 1: num_mes1 += 1 else: num_mes1 += 2 num_mes = str(num_mes1) info_about_prod = get_string_fo_id(call_back, start_index) if start_index != int(info_about_prod[1]): start_index = int(info_about_prod[1]) start_index += 1 descript = info_about_prod[0] file_id = info_about_prod[0][2] vsego = await number_of_added(cht_id, file_id) text = str(descript[1]) + '\n Цена ' + str(descript[3]) await server_bot.bot.send_message(cht_id, text) if i < int(count_cart): product_card_kb = await assemble_keyboard('🛒 ' + str(vsego), None, descript[4]) else: product_card_kb = await assemble_keyboard('🛒 ' + str(vsego), back_categories, descript[4]) await server_bot.bot.send_photo(cht_id, file_id, reply_markup=product_card_kb, reply_to_message_id=num_mes) await server_bot.bot.delete_message(cht_id, num_mes) sleep(0.1)
async def do_redact(cht_id, callback, fwd): do = callback[-1] callback = callback[:-2] table = callback[9:17] id_card = callback[18:] try: await server_bot.bot.delete_message(cht_id, int(fwd) + 1) callback = callback[:-2] db_obj = db_hendler.DB_select() update_table = db_hendler.DB_update() set_value = db_obj.string_with_value('cache', 'user_data', 'user_id', cht_id)[0][0] if do == '1': mad_row = 'description' update_table.string_with_value(table, mad_row, 'id', id_card, set_value) elif do == '2': mad_row = 'price' update_table.string_with_value(table, mad_row, 'id', id_card, set_value) else: mad_row = 'file_id' valid = ValidationInput.photo(set_value) if valid == True: update_table.string_with_value(table, mad_row, 'id', id_card, set_value) else: do_redact_kb = await RedactCartKB.choose_card_kb( id_card, table, do) await server_bot.bot.send_message( cht_id, 'ОШИБКА! Отправленные данные не являются изображением! Повторите попытку', reply_markup=do_redact_kb) return 'false' return 'ok' except: do_redact_kb = await RedactCartKB.choose_card_kb( id_card, table, do) await server_bot.bot.send_message( cht_id, 'ОШИБКА! Пустой ввод! Повторите попытку', reply_markup=do_redact_kb)
async def remove_all_cart(cht_id): db_obj = db_hendler.DB_update() db_obj.string_with_value('user_data', 'price', 'user_id', cht_id, None) db_obj.string_with_value('user_data', 'in_cart', 'user_id', cht_id, None)
async def cmd_menu(message: types.Message): print(message.md_text) cht_id = message.chat.id forw_id = message.message_id db_obj = db_hendler.DB_update() db_select = db_hendler.DB_select() callback_in = db_select.string_with_value('callback_in', 'user_data', 'user_id', cht_id) if message.md_text == '✅ Подтвердить ✅': status = await app.verifi_phone(cht_id, forw_id) print(status) if status == 'done': await app.format_order(cht_id) await app.nav_back(cht_id, forw_id, 'four') await bot.send_message( cht_id, 'Заказ успешно отправлен. Спасибо за покупку!', reply_markup=back_categories_kb) await app.remove_all_cart(cht_id) else: db_obj.string_with_value('user_data', 'phone', 'user_id', cht_id, None) elif message.md_text != '✅ Подтвердить ✅' and callback_in[0][ 0] != 'add_prod' and callback_in[0][ 0] != 'red_prod' and callback_in[0][0][:11] != 'enter_field': in_cart = db_select.string_with_value('in_cart', 'user_data', 'user_id', cht_id) print(in_cart) if in_cart[0][0] != None and callback_in[0][0] != 'red_prod': db_obj.string_with_value('user_data', 'phone', 'user_id', cht_id, message.md_text) elif callback_in[0][0] == 'add_prod' or callback_in[0][ 0][:11] == 'enter_field': cache = db_select.string_with_value('cache', 'user_data', 'user_id', cht_id)[0][0] if cache != None: if cache.count(';') == 0: valid = admin.ValidationInput.price(message.md_text) if valid == True: new_cache = cache + ';' + message.md_text else: await app.nav_back(message.chat.id, int(message.message_id), 'one_one') print(callback_in[0][0]) callback = callback_in[0][0][:-1] + '2' enter_product_kb = await RedactCartKB.enter_product_kb( callback) await bot.send_message( cht_id, 'Отправленое сообщение должно состоять из цифр', reply_markup=enter_product_kb) new_cache = cache elif cache.count(';') == 1: await app.nav_back(message.chat.id, int(message.message_id), 'four') print(callback_in[0][0]) enter_product_kb = await RedactCartKB.enter_product_kb( callback_in[0][0]) await bot.send_message( cht_id, 'Отправленое сообщение не является изображением', reply_markup=enter_product_kb) new_cache = cache else: new_cache = message.md_text db_obj.string_with_value('user_data', 'cache', 'user_id', message.chat.id, new_cache) elif 1 < len(message.md_text) < 100: print(callback_in) if callback_in[0][0] == 'red_prod': db_obj.string_with_value('user_data', 'cache', 'user_id', cht_id, message.md_text)