Пример #1
0
def display_bills(acc_data):
    '''
    显示用户账单
    :param acc_data:
    :return:
    '''
    check_date = input(
        "请输入查询日期 \033[31;1meg:[2018-02] \033[0m>>:".strip())  #输入查询日期年月
    log_path = db_handler.db_handler(settings.LOG_DATABASE)  # 日志路径
    bill_file = "%s/%s.bills" % (log_path, acc_data['account_id'])  # 日志文件路径
    print(bill_file)
    # 判断账单文件是否为空
    if os.path.isfile(bill_file):
        print("账户 [\033[32;1m%s\033[0m] 账单:".center(60, '-') %
              acc_data["account_id"])
        with open(bill_file, 'r') as f:
            for bill in f:
                # print("for bills:",bill)
                bill_date = bill.split(' ')[1]  # 取账单月份
                # print(bill_date)

                # 核对查询月份,打印相应账单信息
                if check_date == bill_date:
                    print("\033[33;1m%s\033[0m" % bill.strip())

        log_type = "transaction"
        # 传入account_id 转换成int型,比较大小,获取用户操作日志
        # 根据查询,显示账单
        logger.show_log(int(acc_data['account_id']), log_type, check_date)
        return True

    else:
        print("你的账号[%s]不存在账单" % acc_data['account_id'])
        return True
Пример #2
0
def pay_check(acc_data):
    """
    查询帐单详情
    :param acc_data:
    :return:
    """
    bill_date = input("Please input the date you will query "
                      "like [\033[32;1m2016-12\033[0m]>>>").strip()
    log_path = db_handler.db_handler(settings.LOG_DATABASE)
    bill_log = "%s/%s.bills" % (log_path, acc_data['account_id'])
    if not os.path.exists(bill_log):
        print("Account [\033[32;1m%s\033[0m] is no bills." %
              acc_data["account_id"])
        return

    print("Account [\033[32;1m%s\033[0m] bills:" % acc_data["account_id"])
    print("-".center(50, "-"))
    with open(bill_log, "r") as f:
        for bill in f:
            print(bill)
            b_date = bill.split(" ")[0]  # 帐单月份
            if bill_date == b_date:
                print("\033[33;1m%s\033[0m" % bill.strip())

    log_type = "transaction"
    print("Account [\033[32;1m%s\033[0m] history log:" %
          acc_data["account_id"])
    logger.show_log(acc_data['account_id'], log_type, bill_date)
Пример #3
0
def show_shopping_history(user_name, log_type):
    """
    显示购物历史函数,如果需要显示购物历史,则显示
    :param user_name: 用户名
    :param log_type: 购物日志的logger对象
    :return:
    """ ""
    log_file = "%s/log/%s_%s" % (settings.BASE_DIR, user_name,
                                 settings.LOG_TYPES[log_type])  # 生成购物日志的路绝对路径
    if os.path.getsize(log_file):
        logger.show_log(user_name, log_type)
    else:
        print("没有购物历史记录,日志文件%s_%s为空" %
              (user_name, settings.LOG_TYPES[log_type]))
Пример #4
0
def show_shopping_history(user_name, log_type):
    """
    存在购物历史数据则提醒用户是否打印输出
    :return:
    """
    log_file = "%s/log/%s_%s" % (settings.BASE_DIR, user_name,
                                 settings.LOG_TYPES[log_type])
    if os.path.getsize(log_file):  # 日志文件存在内容时
        # 只有输入y或者yes才读取显示购物历史,否则不显示
        print(
            "Input \033[1;33m[y|yes]\033[0m to view your purchase history,\033[1;33m[others]\033[0m means not."
        )
        see_history = input("Please input:").strip()
        if see_history == "y" or see_history == "yes":
            # 显示用户购物历史
            logger.show_log(user_name, log_type)  # 显示购物历史
        else:
            print("You are not to view your purchase history!")
            print("-".center(50, "-"))