示例#1
0
async def send_order_button(call: types.CallbackQuery, state: FSMContext,
                            callback_data: dict):
    mes = config.adminMessage["order_missing"]
    order = orderModel.get_order(callback_data.get("id"))
    keyboard = None
    if order and not order.active:
        mes = config.adminMessage["order_completed"]
    elif order:
        PRICE = types.LabeledPrice(label="Работа на заказ",
                                   amount=int(order.price / 2) * 100)
        secret_key = hashlib.md5("{nameProduct}{time}".format(
            nameProduct="Работа на заказ", time=time.time()).encode())
        await bot.send_message(order.userID, config.payMessage["payment_two"])
        await bot.send_invoice(chat_id=order.userID,
                               title=config.payMessage["title"],
                               description=config.payMessage["description"],
                               provider_token=config.PAYMENT_TOKEN,
                               currency=config.currency,
                               is_flexible=False,
                               prices=[PRICE],
                               start_parameter='time-machine-example',
                               payload=secret_key.hexdigest())
        order.set_paymentKey_order(secret_key.hexdigest())
        paymentModel.create_payment(call.from_user.id, order.description,
                                    order.document,
                                    order.separate_payment, order.price / 2,
                                    secret_key.hexdigest(), True)
        mes = "Отправленно"
    await call.message.answer(mes)
    await menu_info_order(callback_data.get("id"), call.message)
    await call.message.delete()
示例#2
0
async def message_send_yes(call: types.CallbackQuery, state: FSMContext):
    await call.answer(cache_time=2)
    data = await state.get_data()
    order = orderModel.get_order(data.get("orderID"))
    if not order or (order and not order.active):
        await state.finish()
        await call.message.edit_text(config.adminMessage["order_completed"])
        return
    keys = data.keys()
    chatID = data.get("message_sendID")
    mes = data.get("description") if "description" in keys else ""
    doc = data.get("document") if "document" in keys else []
    img = data.get("img") if "img" in keys else []
    await bot.send_message(chat_id=chatID,
                           text=config.message["order_complete"])
    if len(doc) == 0 and mes != "":
        await bot.send_message(chat_id=chatID, text=mes)
    elif len(doc) == 1:
        await bot.send_document(chat_id=chatID,
                                caption=mes,
                                document=doc[0].file_id)
    elif len(doc) > 1:
        for document in doc:
            await bot.send_document(chat_id=chatID, document=document.file_id)
        if mes != "":
            await bot.send_message(chat_id=chatID, text=mes)
    for item in img:
        await bot.send_photo(chat_id=chatID, photo=item.file_id)
    await state.finish()
    await call.message.edit_text(config.adminMessage["message_yes_send"])
示例#3
0
async def close_order(call: types.CallbackQuery, callback_data: dict):
    staffs = departmentModel.get_all_staffs()
    if call.from_user.id in staffs:
        mes = config.adminMessage["order_missing"]
        keyboard = None
        task = tasksModel.get_task(callback_data.get("id"))
        if not task:
            await call.message.edit_text(text="Задача отсутствует")
            return
        order = orderModel.get_order(task.orderID)
        if order and check_tasks(call.from_user.id, order.id):
            mes = config.departmentMessage["task_info"].format(orderID=order.id, price=order.price,
                                                               description=order.description,
                                                               descriptionA=task.message)
            if task.departmentTag == config.department_courier_tag:
                keyboard = await buttons.getActionKeyboard(task.id,
                                                           departmentTaskDelivery="Начать доставку",
                                                           departmentTaskCancel="Назад")
            else:
                keyboard = await buttons.getActionKeyboard(task.id, departmentTaskSend="Сдать работу",
                                                           departmentTaskCancel="Назад")
            if len(order.document) == 1:
                await call.message.delete()
                await call.message.answer_document(caption=mes, document=order.document[0], reply_markup=keyboard)
                return
            elif len(order.document) > 1:
                await call.message.delete()
                for document in order.document:
                    await call.message.answer_document(document=document)
        await call.message.edit_text(mes, reply_markup=keyboard)
示例#4
0
async def menu_close_order(orderID, message, state):
    mes = config.adminMessage["order_missing"]
    order = orderModel.get_order(orderID)
    if order and not order.active:
        mes = config.adminMessage["order_completed"]
    elif order:
        mes = config.adminMessage["order_confirm"]
        await state.update_data(orderID=order.id)
        await AdminCloseOrder.wait.set()
    await message.answer(mes,
                         reply_markup=await buttons.getConfirmationKeyboard())
示例#5
0
async def menu_send_order(orderID, message, state):
    mes = config.adminMessage["order_missing"]
    order = orderModel.get_order(orderID)
    keyboard = None
    if order and not order.active:
        mes = config.adminMessage["order_completed"]
    elif order:
        await state.update_data(message_sendID=order.userID, orderID=order.id)
        await AdminMesOrder.message.set()
        mes = config.adminMessage["message_send"]
        keyboard = await buttons.getCustomKeyboard(cancel="Отмена")
    await message.answer(text=mes, reply_markup=keyboard)
示例#6
0
async def message_send_yes(call: types.CallbackQuery, state: FSMContext):
    mes = config.adminMessage["order_missing"]
    data = await state.get_data()
    order = orderModel.get_order(data.get("orderID"))
    if order and not order.active:
        mes = config.adminMessage["order_completed"]
    elif order:
        order.updateActive_order()
        tasksModel.del_task_orderID(order.id)
        mes = config.adminMessage["order_close"].format(id=order.id)
        await bot.send_message(chat_id=order.userID,
                               text=config.message["order_close"])
    await state.finish()
    await call.message.edit_text(mes)
示例#7
0
async def start_edit_code(message: types.Message, state: FSMContext):
    mes = "В работе"
    tags = function.check_all_tag(message.text)
    staff = {}
    for tag in tags:
        tag_temporary = tag.split(".")[0] if "." in tag else tag
        department = departmentModel.get_department(tag_temporary)
        if department:
            try:
                staff_temporary = [department.staff[int(tag.split(".")[1]) - 1]] if "." in tag else department.staff
                if tag_temporary in staff.keys():
                    staff[tag_temporary] = sorted(staff[tag_temporary] + staff_temporary)
                else:
                    staff[tag_temporary] = staff_temporary
            except:
                pass
        else:
            await message.answer(text=config.adminMessage["department_missing"])
            return
    orderID = function.check_number(message.text)
    text = function.string_handler(function.check_text(message.text))
    order = orderModel.get_order(orderID)
    if orderID is None or not order:
        await message.answer("Вы не указали номер заказа или указали на несуществующий заказ")
        return
    elif not order.active:
        await message.answer("Заказ уже закрыт")
        return
    elif not staff:
        await message.answer("Вы неверно указали сотрудников")
        return

    for departmentTag in staff:
        for userID in staff[departmentTag]:
            tasksModel.del_task_duplicate(userID, departmentTag, orderID)
            tasksCompletesModel.del_task_duplicate(userID, departmentTag, orderID)
            await bot.send_message(chat_id=userID, text=config.adminMessage["new_task_staff"])
        tasksModel.create_task(orderID, staff[departmentTag], departmentTag, text)
    await message.answer(mes)
示例#8
0
async def send_task(call: types.CallbackQuery, state: FSMContext, callback_data: dict):
    staffs = departmentModel.get_all_staffs()
    if call.from_user.id in staffs:
        mes = config.adminMessage["order_missing"]
        keyboard = None
        task = tasksModel.get_task(callback_data.get("id"))
        if not task:
            await call.message.delete()
            await call.message.answer(text="Задача отсутствует")
            return
        order = orderModel.get_order(task.orderID)
        if order:
            keyboard = await buttons.getCustomKeyboard(cancel="Отменить")
            mes = config.departmentMessage["task_add_comment"]
            await state.update_data(orderID=order.id, taskID=task.id)
            await TaskComplete.description.set()
            await function.set_state_active(state)

        if call.message.document is None:
            await call.message.edit_text(text=mes, reply_markup=keyboard)
        else:
            await call.message.delete()
            await call.message.answer(text=mes, reply_markup=keyboard)
示例#9
0
async def menu_info_order(orderID, message):
    mes = config.adminMessage["order_missing"]
    order = orderModel.get_order(orderID)
    keyboard = None
    if order:
        payment = paymentModel.get_payment(order.payment_key)
        mes = config.adminMessage["order_detailed_info"].format(
            orderID=order.id,
            price=order.price,
            description=order.description,
            payment="половина суммы"
            if order.separate_payment else "вся сумма",
            date=time.strftime('%Y-%m-%d %H:%M:%S',
                               time.localtime(order.date)))
        mes += "" if order.active else "<b>Заказ выполнен</b>"
        mes += "<b>Ожидает оплаты второй части</b>" if payment else ""
        if order.active and order.separate_payment and not payment:
            keyboard = await buttons.getActionKeyboard(
                order.id,
                OrderSend="Отправить ответ",
                OrderClose="Закрыть заказ",
                OrderPaymentTwo="Отправить вторую оплату")
        elif order.active:
            keyboard = await buttons.getActionKeyboard(
                order.id,
                OrderSend="Отправить ответ",
                OrderClose="Закрыть заказ")
        if len(order.document) == 1:
            await message.answer_document(caption=mes,
                                          document=order.document[0],
                                          reply_markup=keyboard)
            return
        elif len(order.document) > 1:
            for document in order.document:
                await message.answer_document(document=document)
    await message.answer(text=mes, reply_markup=keyboard)
示例#10
0
async def send_task(call: types.CallbackQuery, state: FSMContext, callback_data: dict):
    orderId = tasksModel.get_task(callback_data.get("id")).orderID
    user = await bot.get_chat(orderModel.get_order(orderId).userID)
    tasksModel.del_task_duplicate(call.from_user.id, config.department_courier_tag, orderId)
    await call.message.delete()
    await call.message.answer(text=config.departmentMessage["delivery_send"].format(user.mention))