Example #1
0
def repay(user_data):
    """
    实现还款功能
    :param user_data:
    :return:
    """
    back_flag = True  # 标志位
    while back_flag:
        account_data = accounts.load_account(
            user_data['account_id'])  # 加载用户最新的数据
        current_balance = ''' ----- BALANCE INFO -----
            Credit_limit :    %s
            Credit_balance:   %s''' % (account_data['credit_limit'],
                                       account_data['credit_balance'])
        print(current_balance)
        repay_amount = input("请输入还款金额:").strip()
        # 用户输入整型数字
        if len(repay_amount) > 0 and repay_amount.isdigit():
            # 如果信用卡余额跟信用卡额度一致则证明没花过钱,则不用还款
            if account_data['credit_balance'] == account_data['credit_limit']:
                print("信用卡已还清,无需还款")
                continue
            elif account_data['credit_balance'] + float(
                    repay_amount) > account_data['credit_limit']:
                print("当前还款金额大于信用卡已使用金额,请输入正确还款金额")
                continue
            new_account_data = transaction.make_transaction(
                account_data, "repay", repay_amount, transaction_logger)
            if new_account_data:
                print("最新余额为:%s" % new_account_data['credit_balance'])
        elif repay_amount == "b" or repay_amount == "back":  # 返回功能
            back_flag = False
        else:
            print("请合法输入数字或者返回键b")
Example #2
0
File: auth.py Project: nmap1208/s14
def access_auth(account, password, log_obj):
    db_path = db_handle.handle(setting.DATABASE)
    print(db_path)
    account_file = '%s/%s.json' % (db_path, account)
    if os.path.isfile(account_file):
        account_data = accounts.load_account(account)
        print(account_data)
        if account_data['password'] == password:
            expire_time = time.mktime(
                time.strptime(account_data['expire_date'], '%Y-%m-%d'))
            if time.time() > expire_time:
                log_obj.error('Account %s had expired,pls contach the bank' %
                              (account))
                print('Account %s had expired,pls contach the bank' %
                      (account))
            else:
                log_obj.info('Account %s logging success' % (account))
                return account_data
        else:
            log_obj.error('Account or  Password does not correct!')
            print('Account or  Password does not correct!')

    else:
        log_obj.error('Account %s does not exist' % (account))
        print('Account %s does not exist' % (account))
Example #3
0
File: main.py Project: nmap1208/s14
def repay(access_data):
    print(access_data)
    print('repay')
    account_data = accounts.load_account(access_data['account_id'])
    print(account_data)
    current_balance = '''
    ---------Balance Info-----------
    Credit:%s
    Balance:%s

    ''' % (account_data['credit'], account_data['balance'])
    back_flag = False
    while not back_flag:
        print(current_balance)
        repay_mount = input(
            '\033[31;1mInput repay amount(b=back):\033[0m').strip()
        if len(repay_mount) > 0 and repay_mount.isdigit():
            new_account_data = transaction.make_transaction(
                account_data, 'repay', repay_mount, transaction_logger)
            if new_account_data:
                print('\033[42;1mNew Balance:%s\033[0m' %
                      new_account_data['balance'])
        elif repay_mount == 'b' or repay_mount == 'back':
            back_flag = True
        else:
            print(
                '\033[31;1m%s is not valid amount,Only accept interger!\033[0m'
                % (repay_mount))
Example #4
0
File: main.py Project: nmap1208/s14
def transfer(access_data):
    print(access_data)
    print('withraw')
    account_data = accounts.load_account(access_data['account_id'])
    print(account_data)
    current_balance = '''
    ---------Balance Info-----------
    Credit:%s
    Balance:%s

    ''' % (account_data['credit'], account_data['balance'])
    back_flag = False
    while not back_flag:
        print(current_balance)
        transfer_amount = input(
            '\033[31;1mInput withdraw amount(b=back);\033[0m').strip()
        if len(transfer_amount) > 0 and transfer_amount.isdigit():
            new_accmount_data = transaction.make_transaction(
                account_data, 'withdraw', transfer_amount, transaction_logger)
            if new_accmount_data:
                print('\033[43;1mNew Balance:%s\033[0m' %
                      new_accmount_data['balance'])
        elif transfer_amount == 'b' or transfer_amount == 'back':
            back_flag = True
        else:
            print(
                '\033[31;1m%s is not valid amount,Only accept interger!\033[0m'
                % (transfer_amount))
Example #5
0
def withdraw(user_data):
    """
    实现取款功能
    :param user_data:
    :return:
    """
    back_flag = True  # 标志位
    while back_flag:
        account_data = accounts.load_account(
            user_data['account_id'])  # 加载用户最新信息
        current_balance = ''' ----- BALANCE INFO -----
                    Credit_limit :    %s
                    Credit_balance:   %s''' % (account_data['credit_limit'],
                                               account_data['credit_balance'])
        print(current_balance)
        withdraw_amount = input("请输入取款金额:").strip()  # 用户输入取款金额
        # 判断用户是否输入整型数字
        if len(withdraw_amount) > 0 and withdraw_amount.isdigit():
            # 取款计算,返回取款后的值
            new_account_data = transaction.make_transaction(
                account_data, "withdraw", withdraw_amount, transaction_logger)
            if new_account_data:
                print("最新余额为:%s" % new_account_data['credit_balance'])
        elif withdraw_amount == "b" or withdraw_amount == "back":  # 返回功能
            back_flag = False
        else:
            print("请合法输入数字或者返回键b")
Example #6
0
def mod_credit(id):
    acc_data = accounts.load_account(id)
    credit = input('Please input the new credit:')
    if credit.isdigit():
        acc_data['credit']=credit
        accounts.dump_account(acc_data)
        management_logger.info('Account [%s] credit is changed successfully' % acc_data['id'])
    else:
        print("Invalid credit number.")
Example #7
0
def mod_passwd(id):
    acc_data=accounts.load_account(id)
    password=input('Please input the new password:'******'Password cannot be empty.')
    else:
        acc_data['password'] = password
        accounts.dump_account(acc_data)
        management_logger.info('Account [%s] password is changed successfully'%acc_data['id'])
Example #8
0
def transfer(user_data):
    """
    实现转账功能
    :param user_data:
    :return:
    """
    back_flag = True  # 标志位
    while back_flag:
        account_data = accounts.load_account(
            user_data['account_id'])  # 加载用户最新信息
        current_balance = ''' ----- BALANCE INFO -----
                        Credit_limit :    %s
                        Credit_balance:   %s''' % (
            account_data['credit_limit'], account_data['credit_balance'])
        print(current_balance)
        transfer_account = input("请输入收款人账号:").strip()  # 用户输入收款人账号
        if transfer_account.isdigit():
            transfer_account_data = accounts.load_account(
                int(transfer_account))  # 加载收款人用户信息
            if not transfer_account_data:  # 判断是否存在该卡号
                print("你输入的卡号有误,请重新输入")
                continue
            transfer_amount = input("请输入转账金额:").strip()  # 用户输入转账金额
            # 判断用户是否输入整型数字
            if len(transfer_amount) > 0 and transfer_amount.isdigit():
                # 当前卡转账后剩余的钱
                new_account_data = transaction.make_transaction(
                    account_data, "withdraw", transfer_amount,
                    transaction_logger)
                if new_account_data:
                    # 收款方进账的钱
                    new_transfer_account_data = transaction.make_transaction(
                        transfer_account_data, "accept", transfer_amount,
                        transaction_logger)
                    print("当前卡最新余额为:%s" % new_account_data['credit_balance'])
            elif transfer_amount == "b" or transfer_amount == "back":  # 返回功能
                back_flag = False
            else:
                print("请合法输入数字或者返回键b")
        elif transfer_account == "b" or transfer_account == "back":  # 返回功能
            back_flag = False
        else:
            print("请合法输入数字或者返回键b")
Example #9
0
def active_account():
    mod_acc = input("请输入您要解除冻结的账户名:").strip()
    mod_acc_data = accounts.load_account(mod_acc)
    if mod_acc_data:
        mod_acc_data['status'] = 1
        accounts.dump_account(mod_acc_data)
        logger.logger('operation', mod_acc, "账户 %s 被管理员解除冻结" % mod_acc)
        print("账户 %s 已成功解除冻结,现为普通用户!" % mod_acc)
        return
    else:
        print("账户 %s 不存在!" % mod_acc)
Example #10
0
def freeze_account():
    mod_acc = input("请输入您要冻结的账户名:").strip()
    mod_acc_data = accounts.load_account(mod_acc)
    if mod_acc_data:
        mod_acc_data['status'] = 2
        accounts.dump_account(mod_acc_data)
        logger.logger('operation', mod_acc, "账户 %s 被管理员冻结" % mod_acc)
        print("账户 %s 已成功冻结!" % mod_acc)
        return
    else:
        print("账户 %s 不存在!" % mod_acc)
Example #11
0
def mod_pay_day(id):
    acc_data = accounts.load_account(id)
    pay_day = input('Please input the new pay day:')
    if pay_day.isdigit():
        if int(pay_day) > 0 and int(pay_day) < 31:
            acc_data['pay_day']=pay_day
            accounts.dump_account(acc_data)
            management_logger.info('Account [%s] pay day is changed successfully' % acc_data['id'])
        else:
            print('It must be a day number(1-30)')
    else:
        print('Invalid day number')
Example #12
0
def change_user():
    back_flag = True
    while back_flag:
        account_id = input("请输入卡id:")
        if len(account_id) > 0 and account_id.isdigit():
            account_data = accounts.load_account(account_id)
            if account_data:
                menu = u'''
                      ------ Change Menu --------
                      \033[32;1m   1.  账户名称
                      2.  账户密码
                      3.  账户额度
                      4.  账户状态
                      5.  账户角色
                      6.  返回
                      \033[0m'''
                menu_dict = {
                    "1": "username",
                    "2": "password",
                    "3": "credit_limit",
                    "4": "status",
                    "5": "role",
                    "6": "b",
                }
                exit_flag = True
                while exit_flag:
                    print(menu)
                    user_choice = input(">>:").strip()
                    if user_choice in menu_dict:
                        if user_choice == "6":  # 退出修改
                            exit_flag = False
                        else:
                            # 目前修改未做任何限制
                            user_info = input("请输入修改后的信息:").strip()
                            account_data[menu_dict[user_choice]] = user_info
                            print(account_data)
                            accounts.dump_account(account_data)  # 写入修改后的数据
                    else:
                        print("你选择的菜单有误,请重新选择")
                # username = input("请输入用户名:")
                # if len(username) > 0 and username.isalpha():
                #     account_data = account_info(account_id, username)  # 返回创建的用户信息
                #     accounts.dump_account(account_data)
                #     back_flag = False
                # else:
                #     print("用户名只能是数字和字母")
            else:
                print("卡号不存在")
        elif account_id == "b" or account_id == "back":  # 返回功能
            back_flag = False
        else:
            print("请合法输入卡号或者返回键b")
Example #13
0
def lock_auth(account):
    """
    锁定用户
    :param account:
    :return:
    """
    account_data = accounts.load_account(account)
    if account_data:
        if account_data['status'] == 2: # 已经被注销的用户无需锁定
            return None
        else:
            account_data['status'] = 1             # 锁定该用户,1为锁定状态
            # print(account_data)
            accounts.dump_account(account_data)     # 将更新的数据写入文件
            return account_data
    else:
        pass
Example #14
0
def mod_account():
    while True:
        mod_acc = input("请输入您要修改额度的账户名:").strip()
        mod_acc_data = accounts.load_account(mod_acc)
        if mod_acc_data:
            print("账户 %s 当前的信用额度为:%s 元。" % (mod_acc, mod_acc_data['credit']))
            break
        else:
            print("账户 %s 不存在!" % mod_acc)
    while True:
        new_credit = input("请输入新的信用额度:").strip()
        if new_credit.isdigit():
            new_credit = int(new_credit)
            break
        else:
            print("请输入数字!")
    mod_acc_data['credit'] = new_credit
    accounts.dump_account(mod_acc_data)
    logger.logger('operation', mod_acc,
                  "账户 %s 的信用额度已调整至 %s 元" % (mod_acc, mod_acc_data['credit']))
    print("账户 %s 的信用额度已修改成功,目前为 %s 元。" % (mod_acc, mod_acc_data['credit']))
Example #15
0
def transfer(acc_data):
    flag = True
    while flag:
        tran_id = input('\033[33;1mInput the account to transfer:\033[0m').strip()
        tran_acc_data = accounts.load_account(tran_id)
        if not tran_acc_data:
            return
        tran_amount = input("\033[33;1mInput transfer amount(Press b to cancel):\033[0m").strip()
        if len(tran_amount) > 0 and tran_amount.isdigit():
            new_acc_data = transaction.make_transaction(transaction_logger, acc_data, 'transfer', tran_amount)
            if new_acc_data:
                transaction.make_transaction(transaction_logger, tran_acc_data, 'transfer_in', tran_amount)
                flag = False
        elif tran_amount == 'b':
            return
        else:
            input('\033[33;1mInvalid transfer amount!\033[0m')
    balance_info = '''-------Current Balance Info--------
    Balance: %s
    Credit: %s
    ''' % (new_acc_data['balance'], new_acc_data['credit'])
    print(balance_info)
Example #16
0
def transfer(user_data):
    # 转账
    account_info(user_data)
    account_data = user_data['account_data']
    while True:
        # 录入转账目标账户
        transfer_account = input("请输入您要转账的账户卡号:").strip()
        if transfer_account == account_data['account']:
            print(account_data['account'])
            print("请不要输入自己的账户!")
            return
        trans_acc_data = accounts.load_account(transfer_account)
        if trans_acc_data:
            break
        else:
            print("您要转账的账户 %s 不存在,请重新输入!" % transfer_account)
    print(trans_acc_data)
    while True:
        transfer_amount = input("请输入您要转账的金额:").strip()
        if transfer_amount.isdigit() or type(eval(transfer_amount)) == float:
            account_data, interest = transaction.transaction(
                account_data, 'transfer', transfer_amount)
            transaction.transaction(trans_acc_data, 'repayment',
                                    transfer_amount)
            if account_data:
                logger.logger(
                    'transaction', account_data['account'],
                    "成功向账户 %s 转账 %s 元,手续费 %s 元" %
                    (account_data['account'], transfer_amount, interest))
                logger.logger(
                    'transaction', transfer_account,
                    "账户 %s 向您转账 %s 元" % (transfer_account, transfer_amount))
                print("转账操作完成,成功向 %s 转账 %s 元。您当前的剩余额度为:%s 元,本次转账收取手续费 %s 元。" %
                      (transfer_account, transfer_amount,
                       account_data['balance'], interest))
        else:
            print("%s 不是一个有效的数字,请您确认是否输入正确。")
Example #17
0
def acc_auth(account, password):
    """
    用户登录过程的认证
    :param account:
    :param password:
    :return:
    """
    account_data = accounts.load_account(account)   # 从文件中读取个人信息
    if account_data:
        exp_time_stamp = time.mktime(time.strptime(account_data["expire_date"], "%Y-%m-%d"))    # 读取个人过期时间
        if time.time() > exp_time_stamp:
            print("当前用户已过期,请联系管理员")
        elif account_data['status'] == 0:
            if password == account_data['password']:
                return account_data
            else:
                print("用户名或密码错误")
        else:
            if account_data['status'] == 1:
                print("该用户已被锁定")
            elif account_data['status'] == 2:
                print("该用户已被注销")
    else:
        print("该用户不存在")
Example #18
0
def account_info(acc_data):
    account_id=input("Account id:")
    print(accounts.load_account(account_id))