Пример #1
0
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
Пример #2
0
async def whots_in_cart(cht_id, arr_in_cart):
    all_price = 0
    dict_values = {}
    string_output = str()

    db_table = ['imgfolga', 'imggelii', 'imgkmpzc']
    db_obj = db_hendler.DB_select()
    for elem in arr_in_cart:
        for table in db_table:
            info_value = [0, 0]
            info_product = db_obj.string_with_value('*', table, 'file_id',
                                                    elem)
            if len(info_product) > 0:
                name_product = info_product[0][1]
                price_product = info_product[0][3]
                info_value[0], info_value[1] = price_product, 1
                if name_product in dict_values:
                    dict_values[name_product][1] += 1
                else:
                    dict_values[name_product] = info_value
                all_price += int(price_product)

    string_output = ''
    i = 1
    for x, y in dict_values.items():
        sum = int(y[0]) * int(y[1])
        string_output += str(i) + '. <b>' + str(x) + '</b> \n' + str(
            y[0]) + ' x ' + str(y[1]) + ' = ' + str(sum) + '\n'
        i += 1

    ret = [string_output, all_price]
    return ret
Пример #3
0
def get_callback_fo_user_id(user_id):
    get_callback_fo_user = db_hendler.DB_select()
    callback_user = get_callback_fo_user.string_with_value(
        '*', 'user_data', 'user_id', user_id)
    print('get_callback_fo_user_id')
    print(callback_user[0])
    return callback_user[0]
Пример #4
0
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
Пример #5
0
    async def redact_card(cht_id, callback):
        table = callback[7:15]
        id_card = callback[16:]
        db_obj = db_hendler.DB_select()

        count_card = db_obj.count_string('id', table)[0][0]
        message_id = int(
            db_obj.string_with_value('message_id', 'user_data', 'user_id',
                                     cht_id)[0][0])
        for i in range(0, int(count_card) * 2):
            try:
                await server_bot.bot.delete_message(cht_id, message_id)
            except:
                message_id -= 0
            message_id -= 1
            print(message_id)
            sleep(0.1)

        data_card = db_obj.string_with_value('*', table, 'id', id_card)[0]
        redact_card_kb = await RedactCartKB.made_kb(id_card, table)
        text = 'Описание карточки "' + str(
            data_card[1]) + '" Цена товара "' + str(data_card[3]) + '"'
        await server_bot.bot.send_message(cht_id, text)
        await server_bot.bot.send_photo(cht_id,
                                        data_card[2],
                                        reply_markup=redact_card_kb)
Пример #6
0
 async def set_product(cht_id, callback, fwd):
     try:
         #await server_bot.bot.delete_message(cht_id, int(fwd) + 1)
         db_sel = db_hendler.DB_select()
         cache = db_sel.string_with_value('cache', 'user_data', 'user_id',
                                          cht_id)[0][0]
         arr_cache = cache.split(';')
         print(callback, arr_cache)
         build_card = CardProduct(categ=callback[12:-2],
                                  description=arr_cache[0],
                                  price=arr_cache[1],
                                  image=arr_cache[2])
         if build_card.add_product() == 'ok':
             await server_bot.bot.send_message(
                 cht_id,
                 'Новая карточка успешно создана',
                 reply_markup=admin_menu_kb)
     except:
         print('set_product ' + callback)
         callback = callback[:-1] + '3'
         enter_product_kb = await RedactCartKB.enter_product_kb(callback)
         await server_bot.bot.send_message(
             cht_id,
             'ОШИБКА (фото не отправлено). Карточка не создана',
             reply_markup=enter_product_kb)
Пример #7
0
async def add_user(user_id):
    db_obj = db_hendler.DB_select()
    info_user = db_obj.string_with_value('*', 'user_data', 'user_id', user_id)
    arr_user_id = [user_id]
    if len(info_user) == 0:
        print(arr_user_id)
        in_obj = db_hendler.DB_insert()
        in_obj.full_string('user_data', ['user_id'], arr_user_id)
Пример #8
0
def get_string_fo_id(name_table, id):
    db_obj = db_hendler.DB_select()
    it_be = db_obj.string_with_value('price', name_table, 'id', str(id))
    if len(it_be) == 0:
        new_id = int(id) + 1
        return get_string_fo_id(name_table, new_id)
    row = db_obj.string_with_value('*', str(name_table), 'id', str(id))
    ret_info = [row[0], id]
    print('get_string_fo_id')
    print(ret_info)
    return ret_info
Пример #9
0
async def get_data(call_back, cht_id, fowd):
    db_sell = db_hendler.DB_select()
    admin_do = db_sell.string_with_value('callback_in', 'user_data', 'user_id',
                                         cht_id)
    if admin_do[0][0] == 'add_prod':
        await AdminAddProdukt.enter_product(cht_id, call_back)
    elif admin_do[0][0] == 'del_prod':
        await ProductCard.send_list_card(cht_id, call_back, fowd, 'del_prod')
    elif admin_do[0][0] == 'red_prod':
        await ProductCard.send_list_card(cht_id, call_back, fowd, 'red_prod')
    print('get_data ' + admin_do[0][0])
Пример #10
0
async def cmd_start(message: types.Message):
    con2 = db_hendler.DB_select()
    con = db_hendler.DB_insert()
    tut = con2.string_with_value('user_id', 'user_data', "user_id",
                                 str(message.chat.id))
    print(tut[0][0])
    if str(tut[0][0]) != str(message.chat.id):
        con.full_string('user_data', ['user_id'], [str(message.chat.id)])
    await bot.send_message(message.chat.id,
                           'Выбери нужное действие',
                           reply_markup=admin_menu_kb)
Пример #11
0
 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
Пример #12
0
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)
Пример #13
0
 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)
Пример #14
0
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)