def withdrawal(username): """ 用户提现 :param username: :return: """ data = accounts.loadAccount(username) balance = int(data['money']) card_money = int(data['card_money']) print("your balance:%s" % data['money']) print("your card_balance:%s" % data['card_money']) while True: input_money = int( input("input the number you want to withdrawal>>:").strip()) if input_money <= balance: balance -= input_money card_money += input_money data['money'] = balance data['card_money'] = card_money accounts.keepMes(username, data) # 更改本地文件数据 accounts.record(username, "withdrawal", input_money, data['money']) # 记录流水 logsFunc.withdrawalLog(username, input_money) print("your balance:%s" % data['money']) print("your card_balance:%s" % data['card_money']) print("success!") main.showMenu(username) break else: print("Insufficient balance!") # 余额不足 print("your balance:%s" % data['money']) print("your card_balance:%s" % data['card_money'])
def repay(username): data = accounts.loadAccount(username) money = int(data['money']) card_money = int(data['card_money']) if money >= 0: print("you needn't to repay!") else: print("your money:\033[31m%s\033[0m" % data['money']) while True: input_money = int( input("\033[33minput the number you want to repay>>:\033[0m"). strip()) if input_money <= card_money: card_money -= input_money money += input_money data['money'] = money data['card_money'] = card_money logsFunc.repayLog(username, input_money) accounts.keepMes(username, data) accounts.record(username, "repay", input_money, data['money']) print("\033[33msuccess!!\033[0m") main.showMenu(username) break else: print("\033[31mInsufficient balance!\033[0m") print("your card_balance:%s" % data['card_money'])
def payoff(username, spendmoney) -> int: """ 结账 :param username: 用户名 :param spendmoney: 所花费的钱 :return: 1-->success,0-->fail(余额不足) """ data = accounts.loadAccount(username) balance = data['money'] quota = int(data['quota']) # 额度 if balance - spendmoney + quota >= 0: # 钱足够 balance -= spendmoney data['money'] = balance accounts.keepMes(username, data) # 更新账户余额 accounts.record(username, "shopping", spendmoney, balance) # 流水记录 logsFunc.shoppingLog(username, spendmoney) return 1 return 0
def transfer(username): data = accounts.loadAccount(username) while True: print("\033[1;31;40minput the username you want to transfer>>:\033[0m", end="") input_username = input().strip() transfer_data = accounts.loadAccount(input_username) if transfer_data == 0: print("the account is not found") break else: name = transfer_data['name'] age = transfer_data['age'] print("\033[31mname:%s age:%s\033[0m" % (name, age)) transfer_balance = int(transfer_data['money']) user_money = int(data['money']) input_money = int(input("input the number of money>>:").strip()) if input_money <= user_money: user_money -= input_money transfer_balance += input_money transfer_data['money'] = transfer_balance data['money'] = user_money logsFunc.transferLog(username, input_username, input_money) accounts.keepMes(username, data) accounts.record(username, "transfer to " + str(input_username), input_money, data['money']) # 记录流水 accounts.keepMes(input_username, transfer_data) accounts.record(input_username, "transfer from " + str(username), input_money, transfer_data['money']) # 记录流水 print('\033[33msuccess!!\033[0m') main.showMenu(username) break else: print("Insufficient balance!") print("your balance:%s" % data['money'])