示例#1
0
def transfer(acc_data):
    account_data = account.load_account(acc_data['account_id'])
    current_balance = ''' --------- BALANCE INFO --------
        Credit :    %s
        Balance:    %s''' % (account_data['credit'], account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        trans_account = input("\033[33;1mInput trans account:\033[0m").strip()
        trans_amount = input("\033[33;1mInput withdraw amount:\033[0m").strip()
        if len(trans_amount) > 0 and trans_amount.isdigit() \
                and len(trans_account) == 4 and trans_account.isdigit():
            db_file = "%s/%s.json" % (setting.DATABASE['path'], trans_account)
            if os.path.isfile(db_file):
                new_balance = trans.trans(trans_logger, account_data,
                                          'transfer', trans_amount)
                if new_balance:
                    trans_account_data = account.load_account(trans_account)
                    trans_account_balance = trans.trans(
                        trans_logger, trans_account_data, 'repay',
                        trans_amount)
                    print("\033[31m [%s] Transfer successful\033[0m" %
                          trans_account)
                    print('''\033[42;1mNew Balance:%s\033[0m''' %
                          (new_balance['balance']))
                    back_flag = True
        elif trans_amount == 'b' or trans_account == 'b':
            back_flag = True
        else:
            print(
                '\033[31;1mA valid amount[%s] or account[%s], only accept integer!\033[0m'
                % (trans_amount, trans_account))
示例#2
0
def limit(account_id, log_obj=access):
    account_file = "%s/%s.json" % (setting.DATABASE['path'], account_id)
    if os.path.isfile(account_file):
        account_data = account.load_account(account_id)
        current_account_limit = account_data['credit']
        current_account_balance = account_data['balance']
        while True:
            change_account_limit = input(
                "\033[32;1m[%s] current credit limit [%s], change credit limit:\033[0m"
                % (account_id, current_account_limit))
            if change_account_limit.isdigit(
            ) and len(change_account_limit) > 0:
                account_data['credit'] = change_account_limit
                plus_account_limit = float(change_account_limit) - float(
                    current_account_limit)
                current_account_balance = float(
                    current_account_balance) + float(plus_account_limit)
                account_data['balance'] = current_account_balance

                user_status = account.dump_account(account_data)
                if user_status:
                    log_obj.info("[%s] credit card limit [%s]" %
                                 (account_id, change_account_limit))
                    break
            elif change_account_limit == 'b':
                break
    else:
        print("\033[41mUnable to change,[%s] is not exist\033[0m")

    print()
示例#3
0
def withdraw(acc_data):
    '''
    print current balance and let user do the withdraw action
    :param acc_data:
    :return:
    '''
    account_data = account.load_account(acc_data['account_id'])
    current_balance = ''' --------- BALANCE INFO --------
        Credit :    %s
        Balance:    %s''' % (account_data['credit'], account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        withdraw_amount = input(
            "\033[33;1mInput withdraw amount:\033[0m").strip()
        if len(withdraw_amount) > 0 and withdraw_amount.isdigit():
            new_balance = trans.trans(trans_logger, account_data, 'withdraw',
                                      withdraw_amount)
            if new_balance:
                print('''\033[42;1mNew Balance:%s\033[0m''' %
                      (new_balance['balance']))
                back_flag = True
        elif withdraw_amount == 'b':
            back_flag = True
        else:
            print(
                '\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m'
                % withdraw_amount)
示例#4
0
def repay(acc_data):
    '''
    print current balance and let user repay the bill
    :return:
    '''
    account_data = account.load_account(acc_data['account_id'])

    current_balance = ''' --------- BALANCE INFO --------
        Credit :    %s
        Balance:    %s''' % (account_data['credit'], account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        repay_amount = input("\033[33;1mInput repay amount:\033[0m").strip()
        if len(repay_amount) > 0 and repay_amount.isdigit():
            new_balance = trans.trans(trans_logger, account_data, 'repay',
                                      repay_amount)
            if new_balance:
                print('''\033[42;1mNew Balance:%s\033[0m''' %
                      (new_balance['balance']))
                back_flag = True
        elif repay_amount == 'b':
            back_flag = True
        else:
            print(
                '\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m'
                % repay_amount)
示例#5
0
def freeze(account_id, log_obj=access):
    account_file = "%s/%s.json" % (setting.DATABASE['path'], account_id)
    if os.path.isfile(account_file):
        account_data = account.load_account(account_id)
        account_data['status'] = 1
        account.dump_account(account_data)
        log_obj.info(
            "[%s] credit card is locked, please contact administrator" %
            account_id)
    else:
        print("\033[41mUnable to lock,[%s] is not exist\033[0m")

    print()
示例#6
0
def shopping(acc_data):
    account_data = account.load_account(acc_data['account_id'])
    current_balance = ''' --------- BALANCE INFO --------
        Credit :    %s
        Balance:    %s''' % (account_data['credit'], account_data['balance'])
    print(current_balance)
    while True:
        goods_amount = shoping.shop(setting.goods)
        new_balance = trans.trans(trans_logger, account_data, 'consumer',
                                  goods_amount)
        if new_balance:
            print('''\033[42;1mShopping Success, New balance:%s\033[0m''' %
                  (new_balance['balance']))
            break
示例#7
0
def unfreeze(account_id, log_obj=access):
    account_file = "%s/%s.json" % (setting.DATABASE['path'], account_id)
    if os.path.isfile(account_file):
        account_data = account.load_account(account_id)
        if account_data['status'] == 2:
            print("\033[33;1mCan not unfreeze,account [%s] is disable\033[0m" %
                  account_id)
        else:
            account_data['status'] = 0
            account.dump_account(account_data)
            log_obj.info("Unfreeze success,account [%s] can be used normally" %
                         account_id)
    else:
        print("\033[41mUnable to unfreeze,[%s] is not exist\033[0m")

    print()
示例#8
0
文件: auth.py 项目: nmap1208/s14
def access_auth(account_name, password):
    db_path = db_handle.handle(setting.DATABASE)
    account_file = "%s/%s.json" % (db_path, account_name)
    if os.path.isfile(account_file):
        account_data = account.load_account(account_name)
        if password == account_data['password']:
            expire_time = time.mktime(
                time.strptime(account_data["expire_date"], "%Y-%m-%d"))
            if time.time() > expire_time:
                print('account %s has expired,pls contact the bank' %
                      account_name)
                exit('exit for expired')
            else:
                print('login success')
                print(account_data)
                return account_data
        else:
            print('password not correct')
    print('account not exist')
示例#9
0
def transfer(access_data):
    """
    转帐
    :return:
    """
    print(access_data)
    print("transfer")
    # 调用account模块的load_account方法,从数据库从load出用户信息
    account_data = account.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 transfer amount(b=back):\033[0m").strip()
        # 如果用户输入整型数字
        if len(transfer_amount) > 0 and transfer_amount.isdigit():
            # 调用transaction模块的方法,参数分别是用户帐户信息,交易类型,交易金额
            new_account_data = transaction.make_transaction(
                account_data, "transfer", transfer_amount, transaction_logger)
            if new_account_data:
                print("\033[42;1mNew Balance:%s\033[0m" %
                      new_account_data["balance"])
            new_account_data2 = transaction.make_transaction(
                account_data, "repay", new_account_data["balance"],
                transaction_logger)
            if new_account_data2:
                print("\033[42;1mNew Balance2:%s\033[0m" %
                      new_account_data2["balance"])

        else:
            print(
                "\033[31;1m%s is not valid amount,Only accept interger!\033[0m"
                % transfer_amount)

        if transfer_amount == "b" or transfer_amount == "back":
            back_flag = True
示例#10
0
def repay(access_data):
    """
    access_data:包括ID,is_authenticaed,用户帐号信息
    还款
    :return:
    """
    print(access_data)
    print("repay")
    #调用account模块的load_account方法,从数据库从load出用户信息
    account_data = account.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_amount = input(
            "\033[31;1mInput repay amount(b=back):\033[0m").strip()
        #如果用户输入整型数字
        if len(repay_amount) > 0 and repay_amount.isdigit():
            #调用transaction模块的方法,参数分别是用户帐户信息,交易类型,交易金额
            new_account_data = transaction.make_transaction(
                account_data, "repay", repay_amount, transaction_logger)
            if new_account_data:
                print("\033[42;1mNew Balance:%s\033[0m" %
                      new_account_data["balance"])

        else:
            print(
                "\033[31;1m%s is not valid amount,Only accept interger!\033[0m"
                % repay_amount)

        if repay_amount == "b" or repay_amount == "back":
            back_flag = True