def account_info_manage(acc_data): account_id = acc_data["account_id"] account_data = acc_data["account_data"] status = account_data["status"] if status == 8: # 管理员 new_account_id = input("\033[32;1m请输入查找用户的ID:\033[0m>>>:").strip() new_account_data = auth.acc_check(new_account_id) # 管理员获取普通用户信息 new_status = new_account_data["status"] if new_status == 8 and account_id != new_account_id: return True display_account_info_manage(new_account_data) return True
def transfer(acc_data): ''' 打印当前余额,并转帐 :param acc_data: :return: ''' account_data = accounts.load_current_balance(acc_data['account_id']) current_balance = ''' --------- BALANCE INFO -------- Credit : %s Balance: %s (Tip: input [b] to back)''' % (account_data['credit'], account_data['balance']) print(current_balance) back_flag = False while not back_flag: receiver = input("\033[33;1mInput receiver:\033[0m").strip() # 收款人 if receiver == account_data["id"]: # 判断帐号是否为自己 print("\033[31;1mThe receiver is yourself!\033[0m") continue elif receiver == "b": break else: receiver_account_data = auth.acc_check(receiver) # 判断收款人帐号是否存在和过期 status = receiver_account_data['status'] if status == 0: # 只有收款人为普通帐户,且状态正常,才能转帐 transfer_amount = input( "\033[33;1mInput transfer amount:\033[0m").strip() if len(transfer_amount) > 0 and transfer_amount.isdigit(): new_balance = transaction.make_transaction( trans_logger, account_data, 'transfer', transfer_amount) transaction.make_transaction(trans_logger, receiver_account_data, 'receive', transfer_amount) if new_balance: print('''\033[42;1mNew Balance:%s\033[0m''' % (new_balance['balance'])) else: print( '[\033[31;1m%s\033[0m] is not a valid amount, only accept integer!' % transfer_amount) if transfer_amount == 'b': back_flag = True
def transfer(acc_data): ''' 打印当前余额,并转帐 :param acc_data: :return: ''' account_data = accounts.load_current_balance(acc_data['account_id']) current_balance = ''' -*-*-*-*-*-*-*-*- 账户信息 -*-*-*-*-*-*-*-*- Credit : %s Balance: %s ''' % (account_data['credit'], account_data['balance']) print(current_balance) back_flag = False while not back_flag: receiver = input("\033[33;1m收款人:\033[0m[q=quit]>>>:").strip() # 收款人 if receiver == account_data["id"]: print("\033[31;1m收款人不能为自己\033[0m") continue elif receiver == "q": break else: receiver_account_data = auth.acc_check(receiver) status = receiver_account_data['status'] if status == 0: transfer_amount = input( "\033[33;1m收款金额:\033[0m[q=quit]").strip() if len(transfer_amount) > 0 and transfer_amount.isdigit(): new_balance = transaction.make_transaction( trans_logger, account_data, 'transfer', transfer_amount) transaction.make_transaction(trans_logger, receiver_account_data, 'receive', transfer_amount) if new_balance: print('''\033[42;1m帐号余额:%s\033[0m''' % (new_balance['balance'])) else: print('[\033[31;1m输入不合法,请重新输入\033[0m]') if transfer_amount == 'q': back_flag = True if transfer == 'q': back_flag = True
def get_all_bill(): ''' 生成全部可用用户的帐单 :return: ''' db_path = db_handler.db_handler(settings.DATABASE) for root, dirs, files in os.walk(db_path): for file in files: if os.path.splitext(file)[1] == '.json': account_id = os.path.splitext(file)[0] account_data = auth.acc_check(account_id) # status = account_data['status'] print("\033[33;1m帐单已经生成,请查看transactions.log\033[0m~~") # if status == 8: # display_account_info(account_data) # get_bill(account_id) # else: # pass return True
def get_all_bill(): ''' 生成全部可用用户的帐单 :return: ''' db_path = db_handler.db_handler(settings.DATABASE) for root, dirs, files in os.walk(db_path): for file in files: if os.path.splitext(file)[1] == '.json': # 以.json结尾的文件 account_id = os.path.splitext(file)[0] # 帐户id # account_file = "%s/%s.json" % (db_path, account_id) account_data = auth.acc_check(account_id) # 获取用户信息 status = account_data['status'] print("Account bill:".center(50, "-")) # 除了管理员,普通帐户都应该出帐单,即使帐户禁用 if status != 8: display_account_info(account_data) # 显示帐户详情 get_bill(account_id) # 获取帐单 print("End".center(50, "-")) return True
def account_info(acc_data): """ 打印登录用户帐户信息 :param acc_data: 登录信息 :return: """ account_id = acc_data["account_id"] account_data = acc_data["account_data"] status = account_data["status"] if status == 8: # 管理员 new_account_id = input( "\033[32;1mPlease input your query account id:\033[0m").strip() # 管理员之间不能相互查看对方 new_account_data = auth.acc_check(new_account_id) # 管理员获取普通用户信息 new_status = new_account_data["status"] if new_status == 8 and account_id != new_account_id: # 另一管理员,禁止查看 print("\033[31;1mGet account [%s] info pemission denied!\033[0m" % new_account_id) return True display_account_info(account_data) return True