def main():
    """
    主函数
    :return:
    """
    dtd=time.strftime('%d')
    dtd=int(dtd)
    if dtd<=22: #判断时间是否过22日,如果未到22日,提醒用户
        print('本月生成账单日期未到,操作退出!')
        time.sleep(1)
    else:
        user_data=data_op.load()
        bill={}
        for item in user_data:
            bills_contect=generate_bills(item)
            bill[item]=bills_contect
        # print(bill)
        file_month=check_file_month()
        #如果过22日,遍历相关日期内的数据,并将数据写入文件,生产新的文件
        json.dump(bill,open('../db/{}_bills.json'.format(file_month),'w'),
                  ensure_ascii=False,indent=1)
        print('账单已生成,目录为:\033[31;1m../db/\033[0m,'
              '文件名称为:\033[31;1m{}_bills.json\033[0m'.format(file_month))
        log_admin.info('生成账单文件{}_bills.json'.format(file_month))
        time.sleep(1)
Exemple #2
0
def login():
    user_data = data_op.load()
    user_name = input('请输入用户名:')
    if user_data[user_name][0] == None:
        print('{}账户错误,请重新输入..'.format(user_name))
    elif user_data[user_name][0] == 0:
        print('您的账户{}已被冻结,请联系管理员'.format(user_name))
        log_access.warning('已冻结用户{}尝试登陆'.format(user_name))
        return False
    else:
        i = 0
        while i < 4:
            if i == 3:
                freeze_count(user_name)
                print('您的账户{}已被冻结,请联系管理员'.format(user_name))
                log_access.warning('用户{}被冻结'.format(user_name))
                return False
            pwd_input = input('请输入{}的密码:'.format(user_name))
            pwd = pass_handler.md5_pwd(pwd_input)
            if pwd == user_data[user_name][1]:
                tip['user_name'] = user_name
                tip['login_state'] = True
                print('登录成功!')
                log_access.info('用户{}登录成功'.format(user_name))
                return True
            else:
                print('密码输入有误,请重新输入.')
                i += 1
Exemple #3
0
def record(user_name, TransType, business, amounts):
    user_data = data_op.load()
    rates = trans_rate[TransType] * amounts
    user_data[user_name][4].append(
        {date_time: [TransType, business, amounts, rates]})
    data_op.flush_db(user_data)
    return True
def transfers(username):
    """
    :param username:
    :return:
    """
    user_data = data_op.load()
    #剩余可用额度
    able_amount = user_data[username][3]
    # 标准可转账额度 = 标准可用额度 / 2
    max_amount = user_data[username][2] / 2
    if able_amount >= max_amount:
        able_wd_amount = max_amount
    else:
        able_wd_amount = able_amount
    print('您的可用转账额度为:{}'.format(format_num.format_num(able_wd_amount)))
    t_user_name = input('请输入您要转入的账户名称:')
    if user_data.get(t_user_name) == None:
        print('本银行无此账户信息,请核实信息后再进行转账...')
    else:
        # 转账操作
        for i in range(4):
            if i == 3:
                print('输入错误格式超过三次,退出!')
                break
            amount_inp = input('请输入转账额度:')
            if amount_inp.isdigit():
                amount = int(amount_inp)
                if amount > able_wd_amount:
                    print('最高转账额度为{},已超支,'
                          '退出操作!'.format(
                              format_num.format_num(able_wd_amount)))
                    log_trans.info('{}转账操作失败'.format(username))
                    break
                else:
                    # 如不超支,转账,先验证码验证
                    res = verification_code.check_veri()
                    if res:
                        user_data[username][3] -= amount
                        user_data[username][3] -= amount * trans_rate['转账']
                        user_data[t_user_name][3] += amount
                        data_op.flush_db(user_data)
                        print('现可消费额度为:'
                              '{}'.format(
                                  format_num.format_num(
                                      user_data[username][3])))
                        # record(args, '转账', '终端机', amount)
                        # record(t_user_name, '收款', args, amount)
                        log_trans.info('{}向{}成功转账{}'.format(
                            username, t_user_name, amount))
                        break
                    else:
                        print('验证失败!转账操作失败!!')
                        log_trans.info('{}向{}转账失败'.format(
                            username, t_user_name))
                        break
            else:
                i += 1
                print('输入格式错误,还有{}次机会'.format(3 - i))
Exemple #5
0
def repay(username):
    """
    还款函数
    :param username:
    :return:
    """

    user_data = data_op.load()
    #如果还款额度大于等于信用额度,提示无需还款
    if user_data[username][3] >= user_data[username][2]:
        print('没有消费,就不用还款 ^_^ !!!')
    else:
        #计算还款额度
        need_repay = user_data[username][2] - user_data[username][3]
        print('你所需还款金额为:\033[31;1m{}\033[m'.format(
            format_num.format_num(need_repay)))
        while True:
            input_num = input('请输入还款金额:')
            if input_num.isdigit():
                amount = int(input_num)
                # 判断如果大于需还款金额,用户选择
                if amount > need_repay:
                    inp = input('有钱人,你的还款大于所需还款金额,是否继续?'
                                '\033[32;1m 回车 或 Y 继续,back 或 b 为返回 \033[m:')
                    if len(inp) == 0 or inp.lower() == 'y':
                        # 修改用户账户信息
                        user_data[username][3] += amount
                        data_op.flush_db(user_data)
                        print('有钱人还多了...还款完成!,目前可用信用金额为'
                              '\033[31;1m{}\033[m'.format(
                                  format_num.format_num(
                                      user_data[username][3])))
                        # record(username, '还款', '终端机', amount)
                        # log_trans.info('{}成功还款{}'.format(username, amount))
                        break
                    else:
                        break
                else:
                    # 修改用户账户信息
                    user_data[username][3] += amount
                    data_op.flush_db(user_data)
                    print('还款完成!,目前可用信用金额为'
                          '\033[31;1m{}\033[m'.format(
                              format_num.format_num(user_data[username][3])))
                    # record(username, '还款', '终端机', amount)
                    # log_trans.info('{}成功还款{}'.format(username, amount))
                    break
            else:
                print('输入有误,请重新输入.')
def view_credit(user_name):
    """
    查看用户信息,加载数据,并将相关数据显示至屏幕
    :param user_name:
    :return:
    """
    user_data = data_op.load()
    if user_data[user_name][0] == None:
        print(" no such user !")
    else:
        # balance = user_data[username][3]
        balance = format_num.format_num(user_data[user_name][3])
        credit = format_num.format_num(user_data[user_name][2])
        print('你的信用额度为:\033[31;1m{}\033[0m,'
              '目前可用额度为:\033[31;1m{}\033[0m'.format(credit, balance))
def show_record(user_name):
    """
    user_data = data_op.load()
    :param user_name:
    :return:
    """
    user_data = data_op.load()
    records = user_data[user_name][4]
    if len(records) == 0:
        print(" no record !")
    else:
        row = prettytable.PrettyTable()
        row.field_names = ['时间','交易','商家','交易金额','利息']
        for item in records :
            for record in item :
                row.add_row([record,item[record][0],item[record][1],
                             item[record][2],item[record][3]])
        print(row)
def generate_bills(args):
    """
    用户账单内容生成函数
    :param args: 用户名
    :return: 指定用户的欠款和消费记录内容
    """
    user_data=data_op.load()
    records=user_data.get(args)[4]
    #上月22日,本月22日的时间戳生成
    last_22=time_cal.get_22nd_of_last_month()
    last_22_stamp=time_cal.time_s_to_stamp(last_22)
    current_22=time_cal.get_22nd_of_current_month()
    current_22_stamp=time_cal.time_s_to_stamp(current_22)
    time_range_records=[]
    for item in records:
        for key in item:
            key_stamp=time_cal.str_to_stamp(key)
            if last_22_stamp < key_stamp < current_22_stamp:
                time_range_records.append({key:item[key]})
    # print(time_range_records)
    if len(time_range_records)==0:
        bills=0
    else:
        income_records=[]   #入账记录
        expend_records=[]   #消费记录
        for item in time_range_records:
            for ite in item:
                if '还款' in item[ite] or '收款' in item[ite]:
                    income_records.append(item[ite][2])
                else:
                    expend_records.append(item[ite][3])
                    expend_records.append(item[ite][2])
        if len(income_records)==0:income=0
        else:income=sum(income_records)
        if len(expend_records)==0:
            expend=0
        else:
            expend=sum(expend_records)
        if income>=expend:
            bills=0
        else:
            bills=expend-income
    bills_contect=[bills,time_range_records]    #相关信息生成列表
    return bills_contect
def withdraw(username):
    """
    提现函数,与转账模块基本一致,但无需验证目标用户,金额有所变动
    :param username:
    :return:
    """

    user_data = data_op.load()
    #剩余可用额度
    able_amount = user_data[username][3]
    # 标准可转账额度 = 标准可用额度 / 2
    max_amount = user_data[username][2] / 2
    if able_amount >= max_amount:
        able_wd_amount = max_amount
    else:
        able_wd_amount = able_amount
    print('您的可用提现额度为:{}'.format(format_num.format_num(able_wd_amount)))
    for i in range(4):
        if i == 3:
            print('输入错误格式超过三次,退出!')
            break
        amount_inp = input('请输入提现额度:')
        if amount_inp.isdigit():
            amount = int(amount_inp)
            if amount > able_wd_amount:
                print('最高取现额度为{},已超支,'
                      '退出操作!'.format(format_num.format_num(able_wd_amount)))
                log_trans.info('{}提现操作失败'.format(username))
                break
            else:
                user_data[username][3] -= amount
                user_data[username][3] -= amount * trans_rate['提现']
                data_op.flush_db(user_data)
                print('现可消费额度为:'
                      '{}'.format(format_num.format_num(
                          user_data[username][3])))
                # record(args, '提现', '终端机', amount)
                log_trans.info('{}提现成功'.format(username))
                break
        else:
            i += 1
            print('输入格式错误,还有{}次机会'.format(3 - i))
Exemple #10
0
def freeze_count(user_name):
    user_data = data_op.load()
    user_data[user_name][0] = 0
    data_op.flush_db(user_data)
def inquire_rates(args):
    """
    查询账单利息函数
    :param args: 用户名
    :return: None
    """
    user_data = data_op.load()
    user_record = user_data[args][4]
    last_22nd_stamp = last_22nd()
    current_10th_stamp = current_10th()
    today = datetime.datetime.today()
    today_stamp = time_cal.time_s_to_stamp(today)
    if today_stamp <= current_10th_stamp:
        # 如未到10日,提醒用户利息为0
        print('未到本月10号,目前利率为0,如果已还款请飘过,如未还款,请速还款')
        time.sleep(1)
    else:
        #计算入账的总和
        income_list = []
        for item in user_record:
            for key in item:  #判断目前时间是否在上月22日到本月10日之间
                if last_22nd_stamp < time_cal.str_to_stamp(
                        key) <= current_10th_stamp:
                    income_list.append(item.get(key))
        income = []
        for item in income_list:
            if '收款' in item or '还款' in item:
                income.append(item[2])
        income_amount = sum(income)
        current_file_month = generate_bills.check_file_month()
        bills_db_list = terminal_discover_bills.check_exist_bills()
        if len(bills_db_list) == 0:  #判断是否存在账单文件
            print('暂无账单生成,请联系客服或者银行行长,每月22日生成账单')
            time.sleep(1)
        else:
            dates = []
            for item in bills_db_list:
                dates.append(item.split('_')[0])
            if current_file_month in dates:
                bills_data = json.load(
                    open('../db/{}_bil'
                         'ls.json'.format(current_file_month), 'r'))
                should_amount = bills_data[args][0]
                if income_amount >= should_amount:
                    # 判断入账的费用是否大于消费的费用总和
                    print('已全部还清,无逾期!')
                    time.sleep(1)
                else:  #否则进行逾期天数和利息计算
                    out_rate = 0.0005
                    print('有逾期还款,逾期利率为每日万分之五')
                    td = int(time.strftime('%Y%m%d'))
                    current_10th_time = time_cal.get_10th_of_current_month()
                    dead_line = []
                    dead_line.extend(
                        str(current_10th_time).split(' ')[0].split('-'))
                    dead_line = int(''.join(dead_line))
                    days = td - dead_line
                    interest = days * out_rate * bills_data.get(args)[0]
                    interest = format_num.format_num(interest)
                    print('您有逾期费用产生,'
                          '逾期天数\033[31;1m{}\033[0m,逾期利率为万分之五,'
                          '截止到今天的逾期利息'
                          '为\033[31;1m{}\033[0m'.format(days, interest))
                    time.sleep(1)
            else:
                print('暂无账单生成')