Exemple #1
0
def make_transaction(account_data, tran_type, amount, **others):
    amount = float(amount)
    if tran_type in settings.TRANSACTION_TYPE:

        interest = amount * settings.TRANSACTION_TYPE[tran_type]['interest']
        old_balance = account_data['balance']
        if settings.TRANSACTION_TYPE[tran_type]['action'] == 'plus':
            new_balance = old_balance + amount + interest
            account_data['balance'] = new_balance
            accounts.dump_account(account_data)
            logger.card_log(account_data['username'], 'transaction').info(
                "用户:%s   操作:%s    金额:%s   利息:%s" %
                (account_data['username'], tran_type, amount, interest))
            return account_data
        elif settings.TRANSACTION_TYPE[tran_type]['action'] == 'minus':
            new_balance = old_balance - amount - interest
            # check credit
            if new_balance < 0:
                print('''\033[31;1m账号[%s] 不够 [-%s], 你现在的余额:
                [%s]''' % (account_data['username'],
                           (amount + interest), old_balance))
                logger.card_log(account_data['username'], 'transaction').info(
                    "用户:%s  操作:%s  金额:%s   利息:%s 现在账户余额:%s 不够" %
                    (account_data['username'], tran_type, amount, interest,
                     account_data['balance']))
            else:
                account_data['balance'] = new_balance
                accounts.dump_account(
                    account_data)  # save the new balance back to file
                logger.card_log(account_data['username'], 'transaction').info(
                    "用户:%s   操作:%s    金额:%s   利息:%s" %
                    (account_data['username'], tran_type, amount, interest))
                return account_data
    else:
        print("交易类型 [%s] 不存在!" % tran_type)
Exemple #2
0
def defrosting(account):
    # 定义一个解冻函数
    choice_user()
    username = now_username
    if username:
        data = accounts.load_current_balance(username)
        if data['status'] == 1:
            print('\033[31;1m当前信用卡未冻结\033[0m')
        if data['status'] == 0:
            free = input('\033[33;1m当前信用卡已解冻,按任意键选择解冻 按b返回>>>\033[0m')
            if free != 'b':
                data['status'] = 1
                accounts.dump_account(data)
                print('\033[31;1m当前信用卡已解冻\033[0m')
Exemple #3
0
def freezing(account):
    # 定义一个冻结信用卡函数
    choice_user()
    username = now_username
    if username:
        data = accounts.load_current_balance(username)
        if data['status'] == 0:
            print('\033[31;1m当前信用卡已冻结\033[0m')
        if data['status'] == 1:
            free = input('\033[33;1m当前信用卡未冻结,按任意键选择冻结 按b返回>>>\033[0m')
            if free != 'b':
                data['status'] = 0
                accounts.dump_account(data)
                print('\033[31;1m当前信用卡已冻结\033[0m')
Exemple #4
0
def transfer(user_account):
    # 定义一个用户转账的函数
    count = 0
    while count < 3:
        transfer = input('\033[33;1m请输入需转账人用户名,取消转账c>>>\033[0m')
        if transfer == 'c':
            break
        db_path_user1 = db_path + '\%s.json' % transfer  # 需被转账用户
        login_account_username = user_account['account_data']["username"]
        if transfer == login_account_username:
            print('\033[31;1m转账不能转给自己\033[0m')
        else:
            if os.path.isfile(db_path_user1):
                # 判断用户文件是否存在
                account_data_transfer = accounts.load_current_balance(transfer)  # 转账用户
                account_data_user = accounts.load_current_balance(login_account_username)  # 当前用户
                print('\033[33;1m转账用户信用卡号为:\033[0m \033[32;1m %s \033[0m' % transfer)
                while True:
                    inputs = input('\033[33;1m取消转账:按Q|q取消>>>\033[0m')
                    if inputs.capitalize() == 'Q':
                        break
                    money = input('\033[33;1m请输入需转账金额:\033[0m')
                    if money.isdigit():
                        money = int(money)
                        if money > account_data_user["balance"]:  # 判断转账金额是否大于存款
                            print('\033[31;1m对不起您的存款不足,无法转账\033[0m')
                        else:
                            print('\033[31;1m转账用户卡号: %s 转账金额:¥%s\033[0m'
                                  % (account_data_transfer["username"], money))
                            inputs = input('\033[33;1m请再次确认转账信息数据:按Q|q取消>>>\033[0m')
                            if inputs.capitalize() == 'Q':
                                break
                            else:
                                data = transaction.make_transaction(account_data=account_data_user,
                                                                    tran_type='transfer',
                                                                    amount=money)
                                print('ok')
                                if data:
                                    account_data_transfer['balance'] = account_data_transfer['balance'] + money
                                    accounts.dump_account(account_data_transfer)


                    else:
                        print('\033[31;1m请输入有效转账金额\033[0m')
            else:
                count += 1
                print('\033[31;1m该用户不存在,请重新输入还剩 %s 次机会\033[0m' % (3 - count))
Exemple #5
0
def limit(account):
    # 定义一个提升信用额度函数
    choice_user()
    username = now_username
    if username:
        data = accounts.load_current_balance(username)
        print('\033[33;1m尊敬的用户您当前信用额度是 %s元' % data["credit"])
        limit = input('\033[34;1m是否选择提升信用额度  按任意键确认提示  按Q取消提升>>>')
        if limit.capitalize() != 'Q':
            while True:
                lines = input('\033[35;1m请输入提升信用额度>>>\033[0m')
                if lines.isdigit():
                    lines = int(lines)
                    if lines <= 2000:
                        data['credit'] = data['credit'] + lines
                        accounts.dump_account(data)
                        print('\033[31;1m当前信用额度提升为:%s元 \033[0m' %
                              data['credit'])
                        break
                    else:
                        print('\033[31;1m提升额度超出提升范围\033[0m')
                else:
                    print('\033[31;1m请输入有效提升额度\033[0m')