def repayment(filename, account, amount): print(mgmt.colorStr("公安机关提醒:坚决打击套现、洗钱等违法行为!", 35)) print("正在还款,请稍候...") time.sleep(1) with open(filename, 'r', encoding='utf-8') as account_file: with open(filename + '_tmp', 'w', encoding='utf-8') as tmp_file: if float(amount) < 0: print(mgmt.colorStr("无效的金额! %s" % amount, 31)) cca = checkCreditAmount(filename, account, (-float(amount))) if type(cca) != bool: for line in account_file: if line.split()[0] == account: line = line.strip().split() line[3] = str(float(line[3]) + float(amount)) debt = float(line[3]) line = " ".join(line) + '\n' tmp_file.write(line) else: return False os.remove(filename) os.rename(filename + '_tmp', filename) addJournal(BASE_DIR + '/logs/journal.log', account, amount, "repayment") print("还款成功,还款金额为:%s" % str(amount)) if debt < 0: print("仍需还款: %s " % str(abs(debt))) else: print("账户余额: %s" % str(debt)) return True
def withdraw(filename, account, amount): print(mgmt.colorStr("信用卡提现将额外收取%5的手续费,公安机关提醒:坚决打击套现、洗钱等违法行为!", 35)) print("正在提现,请稍候...") time.sleep(1) with open(filename, 'r', encoding='utf-8') as account_file: with open(filename + '_tmp', 'w', encoding='utf-8') as tmp_file: if float(amount) < 0: print(mgmt.colorStr("无效的金额! %s" % amount, 31)) fee = float(amount) * 1.05 cca = checkCreditAmount(filename, account, fee) if type(cca) != bool: for line in account_file: if line.split()[0] == account: line = line.strip().split() line[3] = str(float(line[3]) - fee) line = " ".join(line) + '\n' tmp_file.write(line) else: return False os.remove(filename) os.rename(filename + '_tmp', filename) addJournal(BASE_DIR + '/logs/journal.log', account, -fee, "withdraw") print("提现成功,提现金额为:%s" % str(amount)) print("您当前的剩余信用额度为: %s" % str(cca)) return True
def transferAccounts(filename, srcAccount, dstAccount, amount): with open(filename, 'r', encoding='utf-8') as account_file: with open(filename + '_tmp', 'w', encoding='utf-8') as tmp_file: cca = checkCreditAmount(filename, srcAccount, float(amount)) if type(cca) != bool and float(amount) > 0: for line in account_file: if line.split()[0] == srcAccount: line = line.strip().split() line[3] = str(float(line[3]) - float(amount)) line = " ".join(line) + '\n' elif line.split()[0] == dstAccount: line = line.strip().split() line[3] = str(float(line[3]) + float(amount)) line = " ".join(line) + '\n' tmp_file.write(line) elif float(amount) <= 0: print(mgmt.colorStr("无效的转账金额!", 31)) return False os.remove(filename) os.rename(filename + '_tmp', filename) addJournal(BASE_DIR + '/logs/journal.log', srcAccount, -float(amount), "transferOut>>%s" % str(dstAccount)) addJournal(BASE_DIR + '/logs/journal.log', dstAccount, float(amount), "transferIn<<%s" % str(srcAccount)) print("转账成功,转账金额为:%s" % str(amount)) print("您当前的剩余信用额度为: %s" % str(cca)) return True
def checkAccountExist(filename, account): with open(filename, 'r', encoding='utf-8') as account_file: for line in account_file: line = line.strip().split() if line[0] == account: return True else: print(mgmt.colorStr("账户不存在!", 31)) return False
def showMenu(): menu_info = """>>>ATM系统<<< 1> 提现 2> 还款 3> 历史账单 4> 转账 5> 查询 6> 退出 """ print(mgmt.colorStr(menu_info, 36))
def addAuth(filename, *args): with open(filename, 'r', encoding='utf-8') as account_file: for line in account_file: if line.split()[0] == args[0]: print(mgmt.colorStr("账户已经存在!", 31)) return False with open(filename, 'a', encoding='utf-8') as account_file: record = ' '.join(args) account_file.write(record + '\n') return True
def decorate(*args, **kwargs): with open(args[0], 'r') as account_file: for line in account_file: line = line.strip().split() if line[0] == args[1]: if line[-1] == '1': print(mgmt.colorStr("账户 %s 已被冻结!" % line[0], 31)) return False result = _func(*args, **kwargs) return result
def checkCreditAmount(filename, account, amount): with open(filename, 'r', encoding='utf-8') as account_file: for line in account_file: if line.split()[0] == account: line = line.strip().split() cur_credit = float(line[2]) + float(line[3]) - float(amount) if cur_credit > 0: return cur_credit else: print(mgmt.colorStr("您的剩余信用额度不足,请还款或控制消费金额!", 31)) return False
def payment(_list, srcAccount, dstAccount): if len(_list) == 0: print("购物车为空,无需支付!") return False else: amount = 0.0 for item in _list: amount += float(item[1]) bank.transferAccounts(BASE_DIR + '/data/account.txt', srcAccount, dstAccount, amount) print(mgmt.colorStr("购买成功,欢迎继续购物!", 32))
def showMenu(): menu_info = """>>>银行后台管理系统<<< 1> 查看账户 2> 冻结/解冻账户 3> 更改额度 4> 增加账户 5> 查看流水 6> 操作日志 7> 退出 """ print(mgmt.colorStr(menu_info, 36))
def freeze(filename, account): if checkAccountExist(filename, account): with open(filename, 'r', encoding='utf-8') as account_file: with open(filename + '_tmp', 'w', encoding='utf-8') as tmp_file: for line in account_file: if line.split()[0] == account: line = line.strip().split() line[4] = '1' line = " ".join(line) + '\n' tmp_file.write(line) print(mgmt.colorStr("账户%s已经冻结!" % str(account), 32)) os.remove(filename) os.rename(filename + '_tmp', filename)
def setLimit(filename, account, limit): if checkAccountExist(filename, account): with open(filename, 'r', encoding='utf-8') as account_file: with open(filename + '_tmp', 'w', encoding='utf-8') as tmp_file: for line in account_file: if line.split()[0] == account: line = line.strip().split() line[2] = str(limit) line = " ".join(line) + '\n' tmp_file.write(line) print(mgmt.colorStr("账户%s当前的最高信用额度为%s." % (account, limit), 32)) os.remove(filename) os.rename(filename + '_tmp', filename)
def decorate(*args, **kwargs): global g_account if g_account == '': print(mgmt.colorStr(">>>欢迎进入账户认证系统<<<", 36)) count = 0 while count < 3: card_num = input(mgmt.colorStr("请输入卡号:", 32)) password = input(mgmt.colorStr("请输入密码:", 32)) if bank.checkAuth(BASE_DIR + '/data/auth.txt', card_num, password): print(mgmt.colorStr("认证通过!", 32)) g_account = card_num break else: if count < 2: print(mgmt.colorStr("请再次尝试还有 %d 次机会!" % (2 - count), 31)) count += 1 else: print(mgmt.colorStr("认证失败!", 31)) return False result = _func(*args, **kwargs) return result
def decorate(*args, **kwargs): global admin_account if admin_account == '': print(mgmt.colorStr(">>>欢迎进入账户认证系统<<<", 36)) count = 0 while count < 3: card_num = input(mgmt.colorStr("请输入管理员账号:", 32)) admin_account = card_num password = input(mgmt.colorStr("请输入密码:", 32)) if card_num == 'admin' and password == '123': print(mgmt.colorStr("认证通过!", 32)) break else: if count < 2: print( mgmt.colorStr("请再次尝试还有 %d 次机会!" % (2 - count), 31)) count += 1 else: print(mgmt.colorStr("认证失败!", 31)) return False result = _func(*args, **kwargs) return result
if __name__ == '__main__': while True: showMenu() choice = input("请输入命令编号进行相关操作:") choice_set = set(['1', '2', '3', '4', '5', '6']) if choice in choice_set: if choice == '1': amount = input("请输入提现金额:") bank.withdraw(BASE_DIR + '/data/account.txt', g_account, amount) elif choice == '2': amount = input("请输入还款金额:") bank.repayment(BASE_DIR + '/data/account.txt', g_account, amount) elif choice == '3': bank.showJournalByAccount(BASE_DIR + '/logs/journal.log', g_account) elif choice == '4': dst_account = input("请输入转入账户:") amount = input("请输入转账金额:") if bank.checkAccountExist(BASE_DIR + '/data/account.txt', dst_account): bank.transferAccounts(BASE_DIR + '/data/account.txt', g_account, dst_account, amount) elif choice == '5': bank.showBalanceByAccount(BASE_DIR + '/data/account.txt',g_account) elif choice == '6': print(mgmt.colorStr("感谢您的使用!再见~", 32)) exit() else: print(mgmt.colorStr("选择集合一定是被改动过了!", 31)) else: print(mgmt.colorStr("无效的命令,请重新输入:", 31))
6> 操作日志 7> 退出 """ print(mgmt.colorStr(menu_info, 36)) if __name__ == '__main__': while True: showMenu() choice = input("请输入命令编号进行相关操作:") choice_set = set(['1', '2', '3', '4', '5', '6', '7']) if choice in choice_set: if choice == '1': bank.showAccounts(BASE_DIR + '/data/account.txt') elif choice == '2': account = input(mgmt.colorStr("请输入要变更的账户:", 32)) if bank.checkFreezeStatus(BASE_DIR + '/data/account.txt', account): bank.unFreeze(BASE_DIR + '/data/account.txt', account) else: bank.freeze(BASE_DIR + '/data/account.txt', account) elif choice == '3': account = input(mgmt.colorStr("请输入要变更的账户:", 32)) limit = input(mgmt.colorStr("请输入要设定的额度:", 32)) bank.setLimit(BASE_DIR + '/data/account.txt', account, limit) elif choice == '4': account = input(mgmt.colorStr("请输入要添加的新账户名:", 32)) username = input(mgmt.colorStr("请输入新用户名:", 32)) password = input(mgmt.colorStr("请输入新密码:", 32)) account_list = [account, username, '15000', '0.0', '0'] auth_list = [account, password]