示例#1
0
def atm_list():
    print(
        "\033[1;36m----欢迎来到ATM操作系统!----\n\033[1;32m请输入用户名密码进入到相对应的管理界面!\033[0m"
    )
    dic = public.op_file(USER_JSON)
    user_name = input("\033[1;36m请输入您的用户名\033[0m")
    pass_word = input("\033[1;36m请输入您的密码\033[0m")
    if user_name in dic:
        if dic[user_name]['type'] == 'manager' and dic[user_name][
                'passwd'] == pass_word:
            print(
                "\033[1;36m欢迎回到管理员操作平台,您具有以下操作权限:\n\033[1;32m[0]冻结账户\n[1]额度调整\n[2]添加账户\n[3]解锁用户\n[4]注销\033[0m"
            )
            manager.manager()
        elif dic[user_name]['type'] == 'user' and dic[user_name][
                'passwd'] == pass_word:
            print(
                "\033[1;36m欢迎回到用户管理平台,您具有以下操作权限:\n\033[1;32m[0]额度查询\n[1]账单查询\n[2]转账\n[3]还款\033[0m"
            )
            user.user()
        else:
            print("\033[1;31m用户名或密码错误,请重新输入!\033[0m")
            atm_list()
    else:
        print("\033[1;31m用户名不存在!请重新输入!\033[0m")
        atm_list()
示例#2
0
def deblocking():
    deblocking_card_user = input("\033[1;36m请输入您要解锁的账户姓名:\033[0m")
    deblocking_card_list = public.op_file(USER_JSON)
    try:
        deblocking_info = deblocking_card_list[deblocking_card_user]
        user_info_status = deblocking_info['status']
        if deblocking_card_user in deblocking_card_list and user_info_status == 1:
            deblocking_card_new = deblocking_info.update({'status': 0})
            dic_new = deblocking_card_list.update(
                {deblocking_card_user: deblocking_info})
            f = open(USER_JSON, 'w')
            f.write(json.dumps(deblocking_card_list))
            f.close()
            print("\033[1;32m解冻成功,该账户可正常登录!\033[0m")
            return deblocking()
        elif deblocking_card_user in deblocking_card_list and user_info_status == 0:
            print("\033[1;31m账户为解锁状态,无需重复解锁\033[0m")
            return deblocking()
    except KeyError:
        print("\033[1;31m用户名不存在!\033[0m")
        reply_choice = input("\033[1;32m请问您是否继续操作?y确定操作,q退出程序\033[0m")
        if reply_choice == 'y':
            print("\033[1;32m您选择了继续操作\033[0m")
            return deblocking()
        elif reply_choice == 'q':
            print("\033[1;31m欢迎下次光临,再见!\033[0m")
            exit()
        else:
            print("\033[1;31m输入错误,回到大厅。。。\033[0m")
            atm.atm_list()
示例#3
0
def insert_card():
    insert_user = input('\033[1;36m请输入您要添加的账户名:\033[0m')
    insert_user_list = public.op_file(USER_JSON)
    if len(insert_user) > 0:
        if insert_user in insert_user_list:
            print("\033[1;31m用户名已存在!\033[0m")
            return insert_card()
        else:
            dic = {
                insert_user: {
                    "passwd": "123123",
                    "status": 0,
                    "type": "user",
                    "credit": 15200,
                    "base_credit": 15200,
                    "balance": 0
                }
            }
            dic_new = insert_user_list.update(dic)
            f = open(USER_JSON, 'w')
            f.write(json.dumps(insert_user_list))
            f.flush()
            print("\033[1;31m用户名%s添加成功!\033[0m" % insert_user)
            next_step = input("\033[1;34m请问您是否要继续操作?继续请输入y,退出请输入q!\033[0m")
            if next_step == 'y':
                return insert_card()
            elif next_step == 'q':
                print("\033[1;31m欢迎下次光临,再见!\033[0m")
                exit()
            else:
                print("\033[1;31m输入错误,回到上级页面。。。\033[0m")
                return insert_card()
    else:
        print("\033[1;31m输入错误,请重新操作!\033[0m")
        return insert_card()
示例#4
0
def login():
    '''登录程序'''
    error_users = []  #记录错误用户信息
    error_count = 0  #记录错误次数
    users = public.op_file(user_json)  #打开用户信息文件
    while error_count < 3:
        user_name = input("\033[1;36m请输入您的用户名:\033[0m")
        passwd = input("\033[1;36m请输入您的密码:\033[0m")
        if len(user_name) > 0:
            user_status = users[user_name]['status']  #读取当前用户锁定信息
            if user_name in users:
                if passwd == users[user_name]['passwd'] and user_status == 0:
                    #当前账户密码输入正确且未被锁定,则写入登录状态文件,记录用户信息
                    fw = open(db_path + 'user_status.txt', 'w')
                    fw.write(user_name)
                    fw.close()
                    return user_name
                elif passwd == users[user_name]['passwd'] and user_status == 1:
                    #当前账户密码输入正确,但已被锁定,给出提示信息
                    print("\033[1;31m用户已被锁定!\033[0m")
                    exit()
                else:
                    error_users.append(user_name)  #输入错误则追加错误用户到错误用户文件中
                    print("\033[1;31m用户名或密码输入错误,请重新输入!\033[0m")
                    error_count += 1
                    continue
        else:
            print("\033[1;31m账户不存在,请重新输入!\033[0m")
            continue
    else:
        if error_users.count(
                user_name) >= 3:  #错误文件中某个用户出现的次数大于等于3次,则讲用户文件中该用户的锁定值置为锁定
            users[user_name]['status'] = 1
            fw = public.op_file(db_path + 'user_status.txt')
            fw.seek(0)
            fw.truncate()
            json.dump(users, fw)
            fw.close()
        exit('\033[1;31m失败次数超过3次,程序退出!\033[0m')
示例#5
0
def cced():
    '''查询余额和信息'''
    cced_user = input("\033[1;36m请输入您要查询的账户姓名:\033[0m")  #获取用户名
    cced_list = public.op_file(user_json)  #获取所有用户信息
    try:
        cced_info = cced_list[cced_user]  # 获取当前用户账户信息
        if cced_info in cced_list:
            user_info_credit = cced_info['credit']  #用户额度
            user_balance = cced_info['balance']  #用户余额
            print("\033[1;32m用户%s的额度是:%s,余额是:%s\033[0m" %
                  (cced_user, user_info_credit, user_balance))
            user()
    except KeyError:
        print("\033[1;31m您要查询的账户不存在,请重新输入!")
        cced()
示例#6
0
def repay():
    '''还款'''
    repay_user = input("\033[1;36m请输入您要还款的账户姓名:\033[0m")  #获取用户名
    repay_list = public.op_file(user_json)  # 获取所有用户信息
    try:
        repay_info = repay_list[repay_user]  # 获取当前用户账户信息
        if repay_user in repay_list:
            # user_credit = repay_info['credit']  # 用户信用额度
            # user_base_credit = repay_info['base_credit']#用户基础额度
            repay_money = repay_info['base_credit'] - repay_info['credit']  #欠款
            user_balance = repay_info['balance']  # 用户余额
            money = input("\033[1;36m请输入您的还款金额:\033[0m")
            if money.isdigit():
                money = int(money)
                if money > 0:
                    if repay_money == 0:  #若不欠款,还款加入余额
                        repay_info['balance'] += money
                    elif money >= repay_money:  #若还款大于等于欠款,恢复信用额度,余额等于余额+还款-欠款
                        repay_info['credit'] = repay_info['base_credit']
                        repay_info['balance'] += money - repay_money
                    elif money < repay_money and repay_money <= money + user_balance:
                        #若欠款大于还款,且欠款小于等于还款+余额;恢复信用额度,余额等于余额+还款-欠款
                        repay_info['credit'] = repay_info['base_credit']
                        repay_info['balance'] += money - repay_money
                    elif money < repay_money and user_balance == 0:
                        repay_info['credit'] += money
                    elif repay_money > money + user_balance:
                        repay_info['credit'] += money + user_balance
                        repay_info['balance'] = 0
                    f = open(user_json, 'w')
                    f.write(json.dumps(repay_list))
                    f.close()
                    print("\033[1;32m还款成功,还款%s元,账户额度%s元,余额%s元" %
                          (money, repay_info['credit'], repay_info['balance']))
                    public.write_atm_log(
                        '%s %s 还款 %s元' %
                        (repay_user, time.strftime("%Y-%m-%d %H:%M:%S"),
                         money))  #还款信息写入日志
                else:
                    print("\033[1;31m金额不能输入为0!\033[0m")
                    repay()
            else:
                print("\033[1;31m金额输入错误!请输入正确的数字!\033[0m")
                repay()
    except KeyError:
        print("\033[1;31m用户名不存在!请重新输入!\033[0m")
        repay()
示例#7
0
def update_card():
    update_card_info = input("\033[1;36m请输入您要调整的账户姓名:\033[0m")
    update_info = public.op_file(USER_JSON)  #获取所有账户信息
    try:
        if update_card_info in update_info:
            new_credit = input("\033[1;36m请输入您增加的额度:\033[0m")
            if new_credit.isdigit():
                new_credit = int(new_credit)
                if new_credit % 100 == 0:
                    update_info[update_card_info]['base_credit'] += new_credit
                    update_info[update_card_info]['credit'] += new_credit
                    update_credit = update_info[update_card_info].update(
                        {'credit': update_info[update_card_info]['credit']})
                    update_base_credit = update_info[update_card_info].update({
                        'base_credit':
                        update_info[update_card_info]['base_credit']
                    })
                    dic_new = update_info.update(
                        {update_card_info: update_info[update_card_info]})
                    f = open(USER_JSON, 'w')
                    f.write(json.dumps(update_info))
                    print("\033[1;31m用户名%s添加成功!\033[0m" % update_card_info)
                    next_step = input(
                        "\033[1;34m请问您是否要继续操作?继续请输入y,退出请输入q!\033[0m")
                    if next_step == 'y':
                        return update_card()
                    elif next_step == 'q':
                        print("\033[1;31m欢迎下次光临,再见!\033[0m")
                        exit()
                    else:
                        print("\033[1;31m输入错误,回到上级页面。。。\033[0m")
                        return update_card()
            else:
                print("\033[1;31m请输入正整数,且为100的倍数!\033[0m")
                return update_card()
    except KeyError:
        print("\033[1;31m用户名不存在!\033[0m")
        reply_choice = input("\033[1;32m请问您是否继续操作?y确定操作,q退出程序\033[0m")
        if reply_choice == 'y':
            print("\033[1;32m您选择了继续操作\033[0m")
            return update_card()
        elif reply_choice == 'q':
            print("\033[1;31m欢迎下次光临,再见!\033[0m")
            exit()
        else:
            print("\033[1;31m输入错误,回到大厅。。。\033[0m")
            atm.atm_list()
示例#8
0
def freeze_card():
    freeze_card_user = input("\033[1;36m请输入您要冻结的账户姓名:\033[0m")
    free_card_list = public.op_file(USER_JSON)
    try:
        freeze_info = free_card_list[freeze_card_user]
        user_info_status = freeze_info['status']
        if freeze_card_user in free_card_list and user_info_status == 0:
            free_card_new = freeze_info.update({'status': 1})
            dic_new = free_card_list.update({freeze_card_user: freeze_info})
            f = open(USER_JSON, 'w')
            f.write(json.dumps(free_card_list))
            f.close()
            print("\033[1;32m冻结操作成功,该用户已被冻结且无法登录!\033[0m")
            return freeze_card()
        elif freeze_card_user in free_card_list and user_info_status == 1:
            print("\033[1;31m账户已被锁定,无需重复操作!\033[0m")
            reply_choice = input("\033[1;32m请问您是否继续操作?y确定操作,q退出程序\033[0m")
            if reply_choice == 'y':
                print("\033[1;32m您选择了继续操作\033[0m")
                return freeze_card()
            elif reply_choice == 'q':
                print("\033[1;31m欢迎下次光临,再见!\033[0m")
                exit()
            else:
                print("\033[1;31m输入错误,回到大厅。。。\033[0m")
                atm.atm_list()
    except KeyError:
        print("\033[1;31m用户名不存在!\033[0m")
        reply_choice = input("\033[1;32m请问您是否继续操作?y确定操作,q退出程序\033[0m")
        if reply_choice == 'y':
            print("\033[1;32m您选择了继续操作\033[0m")
            return freeze_card()
        elif reply_choice == 'q':
            print("\033[1;31m欢迎下次光临,再见!\033[0m")
            exit()
        else:
            print("\033[1;31m输入错误,回到大厅。。。\033[0m")
            atm.atm_list()
示例#9
0
def billing():
    '''查询账单'''
    bill_user = input("\033[1;36m请输入您要查询的账户姓名:\033[0m")
    bill_month = input("\033[1;36m请输入您要查询的月份:\033[0m")
    bill_list = public.op_file(bill_json)  #获取所有用户的账单信息
    try:
        bill_info = bill_list[bill_user]  # 获取当前用户的账单信息
        if bill_month.isdigit():
            bill_month = int(bill_month)
            if 1 <= bill_month <= 12:
                if bill_user in bill_list and bill_month in bill_info:
                    for bill in bill_info[bill_month]:
                        print("\033[1;32m您%s月份的账单信息是:\033[1;33m%s\033[0m" %
                              (bill_month, bill))
                        user()
                else:
                    bill_choice = input(
                        "\033[1;31m本月无账单!是否继续操作?y or q?\033[0m")
                    if bill_choice == 'y':
                        print("\033[1;32m您选择了继续操作\033[0m")
                        billing()
                    elif bill_choice == 'q':
                        print("\033[1;31m欢迎下次光临,再见!\033[0m")
                        exit()
                    else:
                        print("\033[1;31m输入错误,回到大厅。。。\033[0m")
                        user()
            else:
                print("\033[1;31m查询月份输入错误,请重新输入!\033[0m")
                billing()
        else:
            print("\033[1;31m查询月份输入错误,请重新输入!\033[0m")
            billing()
    except KeyError:
        print("\033[1;31m您要查询的账户不存在,请重新输入!")
        billing()