Exemplo n.º 1
0
def doing(bot, update):
    try:
        from_user = update.message.from_user
        cmd, text = parse_cmd(update.message.text)
        if text.find('#') == -1:
            update.message.reply_text()
            return ConversationHandler.END

        id, price = text.split("#")
        member = member_service.select_by_id(id)
        logger.info("member:%s", member)
        if len(member) == 0:
            update.message.reply_text()
            return ConversationHandler.END
        balance_service.update_amount(tele_id=member[0]["tele_id"],
                                      price=price,
                                      driver_tele_id=from_user.id)

        send_text = balance_service.select_by_tele_id(member[0], from_user.id)
        bot.send_message(chat_id=from_user.id, text=send_text)
        send_text = deposit_send_text.format(from_user.first_name,
                                             price) + send_text

        bot.send_message(chat_id=member[0]['tele_id'], text=send_text)
        logger.info('doing over')
        return ConversationHandler.END
    except:
        return ConversationHandler.END
Exemplo n.º 2
0
def handle(bot, update):
    logger.info("chatId: %s,first_name: %s,text: %s", update.message.chat_id, update.message.from_user.first_name,
                update.message.text)
    from_user = update.message.from_user

    # 司机校验
    driver = driver_dao.select_by_teleId(from_user.id)
    if len(driver) == 0:
        update.message.reply_text(driver_role_notice_text)
        return
    cmd, text = parse_cmd(update.message.text)
    if text.find('#') == -1:
        update.message.reply_text()
        return

    id, price = text.split("#")
    member = member_service.select_by_id(id)
    logger.info("member:%s", member)
    if len(member) == 0:
        update.message.reply_text()
        return
    balance_service.update_amount(tele_id=member[0]["tele_id"],
                                  price=price,
                                  driver_tele_id=from_user.id)

    send_text = balance_service.select_by_tele_id(member[0], from_user.id)
    bot.send_message(chat_id=from_user.id,
                     text=send_text)
    send_text = deposit_send_text.format(from_user.first_name, price) + send_text

    bot.send_message(chat_id=member[0]['tele_id'],
                     text=send_text)
Exemplo n.º 3
0
def cancel_order(bot, from_user, order, send_msg):
    logging.info("cancel orders:{0}".format(order))
    if len(order) == 0:
        bot.send_message(chat_id=from_user.id,
                         text=null_notice_send_text.format(order[0]['id']))
        return
    driver = driver_dao.select_by_id(order[0]['driver_id'])
    tele_id = order[0]['member_id']
    if order[0]['order_status'] == '1':
        bot.send_message(chat_id=from_user.id,
                         text=status_note_msg.format(order[0]['id']))
        return
    if order[0]['order_status'] == '0':
        order_info_dao.update_status(status='1', id=order[0]['id'])
    if (order[0]['order_status'] == "2" or order[0]['order_status']
            == "3") and len(driver) == 1 and order[0]['driver_id'] == str(
                driver[0]['id']):
        order_info_dao.update_status(status='1', id=order[0]['id'])
        balance_service.update_amount(order[0]['member_id'], order[0]['price'],
                                      from_user.id)
        bot.send_message(chat_id=from_user.id,
                         text='订单:{0}\n清退金额:{1}'.format(
                             order[0]['id'], order[0]['price']))
        bot.send_message(chat_id=order[0]['member_id'],
                         text='订单:{0}\n清退金额:{1}'.format(
                             order[0]['id'], order[0]['price']))

    if order[0]['order_status'] == "2" and (
            len(driver) == 0 or order[0]['driver_id'] != str(driver[0]['id'])):
        bot.send_message(chat_id=from_user.id,
                         text='订单<{0}>状态为已接单,请联系司机处理'.format(order[0]['id']))

    order = order_info_dao.select_by_id(order[0]['id'])
    logging.info("cancel orders:{0}".format(order))
    send_msg = send_msg + order_info_msg.format(
        order[0]['id'], order[0]['item'], order[0]['price'],
        order_status[order[0]['order_status']], order[0]['create_time'])
    return tele_id, send_msg
Exemplo n.º 4
0
def handle(bot, update):
    logger.info("chatId: %s,first_name: %s,text: %s", update.message.chat_id,
                update.message.from_user.first_name, update.message.text)
    from_user = update.message.from_user
    cmd, text = parse_cmd(update.message.text)

    # 司机校验
    driver = driver_dao.select_by_teleId(from_user.id)
    if len(driver) == 0:
        update.message.reply_text(driver_role_notice_text)
        return

    member = member_dao.select_by_id(text)

    balance = balance_service.select_by_tele_id(member[0], from_user.id)

    order_list = order_info_dao.select_init_driver_id(driver[0]['id'])
    if len(order_list) == 0:
        update.message.reply_text(order_over_notice_msg)
        return

    send_msg_list = []
    for order in order_list:
        logger.info("over order id:%s,nick_name:%s,price:%s,driver_id:%s",
                    order["id"], order["nick_name"], order["price"],
                    order["driver_id"])
        balance = balance_service.update_amount(order["member_id"],
                                                -order["price"], from_user.id)
        status = "3" if balance["amount"] >= 0 else "2"
        order_info_dao.update_status(status=status, id=order["id"])
        send_msg_list.append({
            "id": balance["id"],
            "amount": balance["amount"],
            "order_id": order["id"],
            "tele_id": order["member_id"],
            "nick_name": order["nick_name"],
            "price": order["price"],
            "create_time": order["create_time"],
            "item": order["item"],
            "status": status
        })

    send_msg = over_title_msg
    total_price = 0
    for send_msg_info in send_msg_list:
        send_order_msg = over_info_msg.format(send_msg_info["nick_name"],
                                              send_msg_info["item"],
                                              send_msg_info["price"])
        send_msg = send_msg + send_order_msg
        total_price = total_price + int(send_msg_info["price"])
        try:
            bot.send_message(chat_id=send_msg_info["tele_id"],
                             text=over_title_msg + send_order_msg +
                             "\n余额:{0}".format(send_msg_info["amount"]))
        except:
            logger.warning(send_order_msg)
    number = int(text) if text != None and text.isdigit() else int(
        len(order_list) / 10) - 1
    for x in range(number):
        random_order = random_send_msg(send_msg_list, from_user)
        bot.send_message(chat_id=update.message.chat_id,
                         text="请 <{0}> 协助拿饭".format(random_order["nick_name"]))
        bot.send_message(chat_id=random_order["tele_id"],
                         text="请 <{0}> 协助拿饭".format(random_order["nick_name"]))
    send_msg = send_msg + "\n合计:{0} \t份数:{1}".format(total_price,
                                                     len(order_list))
    bot.send_message(chat_id=update.message.chat_id, text=send_msg)