示例#1
0
def example():
    ac_log = {}
    tr_log = {}

    ac_log['tjy'] = logger.set_ac_logger('tjy')
    ac_log['hao'] = logger.set_ac_logger('hao')
    ac_log['tjy'] = logger.set_ac_logger('tjy')
    ac_log['tjy'] = logger.set_ac_logger('tjy')
    ac_log['tjy'] = logger.set_ac_logger('tjy')
    ac_log['tjy'] = logger.set_ac_logger('tjy')

    tr_log['tjy'] = logger.set_tr_logger('tjy')
    tr_log['hao'] = logger.set_tr_logger('hao')

    ac_log_obj = logger.set_ac_logger('tjy')

    ac_log_obj.info('23')
    ac_log['tjy'].info('%(name)s ')
    ac_log['tjy'].info('2')
    ac_log['tjy'].info('3')
    ac_log['hao'].info('1')
    ac_log['hao'].info('2')

    tr_log['tjy'].info('1')
    tr_log['tjy'].info('2')
    tr_log['tjy'].info('3')
    tr_log['hao'].info('1')
    tr_log['hao'].info('2')
示例#2
0
def transfer(acc_data):
    '''
    转账
    :param acc_data: 
    :return: 
    '''
    account_data = data_handler.get_user_db(acc_data['account_id'])
    tr_log_obj = logger.set_tr_logger(account_data['id'])
    all_user = data_handler.get_all_username()  # 存在data/accounts文件夹下的所有用户
    current_balance = '''---------------- BALABCE INFO --------------
        Credit :  %s
        Balance:  %s
-------------------------------------------''' % (account_data['credit'],
                                                  account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        tran_id = input(
            '\033[1;34mInput what account you want transfer: \033[0m').strip()
        if tran_id in all_user:  # 用户存在
            tran_amount = input(
                '\033[1;34mInput withdraw amount: \033[0m').strip()
            if tran_amount.isdigit():  # 数字
                new_balance = transaction.make_transaction(
                    tr_log_obj, account_data, 'withdraw', tran_amount)
                if new_balance:  # 返回的 new_balance 有效,即钱够
                    # 汇款方进行相关操作并进行相关日志记录
                    tran_data = data_handler.get_user_db(tran_id)
                    tran_data['balance'] += int(tran_amount)
                    data_handler.set_user_db(tran_id, tran_data)
                    traned_log_obj = logger.set_tr_logger(tran_id)
                    traned_log_obj.info(
                        'Received account %s transfer amount %s' %
                        (account_data['id'], tran_amount))

                    print('New:Balance:\033[32;1m %s \033[0m' %
                          new_balance['balance'])
            elif tran_amount == 'b':  # 返回
                back_flag = True
            elif tran_amount == 'q':  # 退出程序
                exit('请保管好您的信用卡,欢迎下次使用!')
            else:  # 错误输入
                print(
                    '\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m'
                    % tran_amount)
        elif tran_id == 'b':  # 返回
            back_flag = True
        elif tran_id == 'q':  # 退出程序
            exit('请保管好您的信用卡,欢迎下次使用!')
        else:  # 错误输入
            print('\033[31;1m[%s] is not a valid id' % tran_id)
示例#3
0
def repay(acc_data):
    '''
    还款
    :param acc_data:   包含user_db和用户是否登陆 的字典
    :return: 
    '''
    account_data = data_handler.get_user_db(acc_data['account_id'])
    tr_log_obj = logger.set_tr_logger(account_data['id'])
    current_balance = '''---------------- BALABCE 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[1;34mInput repay amount: \033[0m').strip()
        if len(repay_amount) > 0 and repay_amount.isdigit():
            new_balance = transaction.make_transaction(tr_log_obj,
                                                       account_data, 'repay',
                                                       repay_amount)
            if new_balance:
                print('New:Balance:\033[32;1m %s \033[0m' %
                      new_balance['balance'])
        elif repay_amount == 'b':  # 返回
            back_flag = True
        elif repay_amount == 'q':  # 退出程序
            exit('请保管好您的信用卡,欢迎下次使用!')
        else:  # 错误输入
            print(
                '\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m'
                % repay_amount)
示例#4
0
def pay_for(acc_data, goods_list):
    account_data = data_handler.get_user_db(acc_data['account_id'])
    tr_log_obj = logger.set_tr_logger(account_data['id'])
    balance = account_data['balance']
    print('Your balance is: %s' % balance)
    buy_flag = input('Do you really want to buy the goods(Y/N): ').strip()
    if buy_flag == 'Y':  # 确定购买
        all_goods_price = 0  # 所有商品的价格
        for goods in goods_list:
            all_goods_price += goods[1]
        if all_goods_price <= account_data['balance']:
            account_data['balance'] -= all_goods_price
            for val in goods_list:
                tr_log_obj.info('Buy %s ,cost %s$' % (val[0], val[1]))
            print(
                '\033[33;1mYou have bought all the goods! Thanks for your Custom\033[0m'
            )
        else:
            print(
                'Your credit card have no enough money to pay for the goods!')
    elif buy_flag == 'N':
        exit()
    else:
        exit('Invalid input, see you next time!')
示例#5
0
def account_info(acc_data):
    '''
    查询账户信息
    :param acc_data: 
    :return: 
    '''
    account_data = data_handler.get_user_db(acc_data['account_id'])
    tr_log_obj = logger.set_tr_logger(account_data['id'])
    info_title = ("\033[31;m %s's Bank info\033[0m" %
                  acc_data['account_id']).center(55, '-')
    info_body = '''\033[32;m
    username:           %s
    credit:             %s
    balance:            %s
    enroll date:        %s
    expire date:        %s
    last logout data:   %s
\033[0m''' % (account_data['id'], account_data['credit'],
              account_data['balance'], account_data['enroll_date'],
              account_data['expire_date'], account_data['last_login_time'])

    info = info_title + info_body + '-' * 45
    print(info)
    tr_log_obj.info('query the account information')