def pay_back(username): '''还款''' flag = True while flag: single_user_info = operate_user_info_file(username, 'read') current_amount = single_user_info['balance'] total_amount = single_user_info['quota'] pay_bak_amount = total_amount - current_amount pay_bak_amount = float('%.1f' % pay_bak_amount) print("您应还金额为:", pay_bak_amount) while True: actual_pay_bak = input("您还款金额为,退出(B):").strip() if actual_pay_bak == 'B': flag = False break if not actual_pay_bak.isdigit(): continue if int(actual_pay_bak) > pay_bak_amount: print("实际还款金额应小于等于应还款金额") break current_amount = current_amount + int(actual_pay_bak) single_user_info['balance'] = current_amount operate_user_info_file(username, 'write', data=single_user_info) print("余额:", current_amount) message = "Your repayment amount is %s,The balance is %s;" % ( actual_pay_bak, current_amount) log_output(username, 'atm', "INFO", message=message) choice = input("是否继续还款,继续(Y),返回(B):").strip() if choice == 'Y': break else: flag = False break
def modify_user_status(): operate_info_dict = { 'F': ['冻结', 'freeze', 1], 'A': ['激活', 'activation', 0] } flag = True while flag: choice = input("冻结用户(F),激活账户(A),退出(B):").strip() if choice == 'B': break if choice == 'F' or choice == 'A': while True: username = input("%s的账户名为,返回(B):" % (operate_info_dict[choice][0])).strip() if username == 'B': flag = False break judge_user = operate_user_info_file(username, 'read') if judge_user: user_info_dict = operate_user_info_file(username, 'read') user_info_dict['status'] = operate_info_dict[choice][2] operate_user_info_file(user_info_dict, 'write', data=user_info_dict) message = "%s user is %s " % (operate_info_dict[choice][1], username) print(message) log_output('administrator', 'manage', "INFO", message=message) break else: print("用户不存在,请重新输入")
def transfer(username): '''转账''' flag = True while flag: single_user_info = operate_user_info_file(username, 'read') current_amount = single_user_info['balance'] print("您最大转账金额为:", current_amount) while True: recv_username = input("请输入收款方用户名:").strip() judge_exist = operate_user_info_file(recv_username, 'read') if judge_exist: actual_tran_amount = input("您转账金额为,退出(B):").strip() if actual_tran_amount == 'B': flag = False break if not actual_tran_amount.isdigit(): continue if int(actual_tran_amount) > current_amount: print("转账金额过大") break current_amount -= int(actual_tran_amount) single_user_info['balance'] = current_amount operate_user_info_file(username, 'write', data=single_user_info) print("您的余额为", current_amount) recv_user_info = operate_user_info_file(recv_username, 'read') recv_user_info['balance'] += int(actual_tran_amount) operate_user_info_file(recv_username, 'write', data=recv_user_info) #转账方写日志 message = "your transfer user is %s,the transfer amount is %s,The balance is %s;" % ( recv_username, actual_tran_amount, current_amount) log_output(username, 'atm', "INFO", message=message) #收账方写日志 recv_message = "You received %s %s yuan,your banlance is %s" % ( username, actual_tran_amount, recv_user_info['balance']) log_output(recv_username, 'atm', "INFO", message=recv_message) choice = input("是否继续转账,继续(Y),退出(Q):").strip() if choice == 'Y': break else: operate_user_info_file(username, 'write', data=single_user_info) flag = False break else: choice = input("该用户在本系统不存在,是否继续,继续(Y),退出(Q):") if choice == 'Y': break else: flag = False break
def view_account_info(username): single_info = operate_user_info_file(username, 'read') for key, val in single_info.items(): if key != 'password' and key != 'status': print(key, ':', val) message = "Check account information" log_output(username, 'atm', "INFO", message=message) return True
def inner(*args, **kwargs): global user_login_status login_times_dict = {} count = 0 while count < 3: login_name = input("login>>:").strip() count += 1 if login_name in login_times_dict: login_times_dict[login_name] += 1 else: login_times_dict.setdefault(login_name, 1) user_info_dict = operate_user_info_file(login_name, 'read') if not user_info_dict: print("用户名不存在,请重新输入") continue expire_date_file = time.mktime( time.strptime(user_info_dict["expire_date"], "%Y-%m-%d")) last_time = expire_date_file - time.time() if last_time < 0: print("用户已过期") break if user_info_dict['status'] == 1: print("用户被锁,请联系管理员:[email protected]") break password = input("password>>:").strip() hash_password = manage.hash_val(password) if hash_password == user_info_dict['password']: # print("欢迎来到本系统") user_login_status = True if user_login_status == True: username = login_name func(login_name, *args, **kwargs) else: print("密码错误!") if login_times_dict[login_name] == 3: print(login_times_dict) user_info_dict['status'] = 1 operate_user_info_file(login_name, 'write', data=user_info_dict)
def modify_user_quota(): flag = True while flag: username = input("请输入提升额度的账户,返回(B):").strip() if username == 'B': break judge_user = operate_user_info_file(username, 'read') if judge_user: while True: user_quota = judge_user['quota'] add_user_quota = input("提升用户额度(RMB),退出(Q)").strip() if add_user_quota == 'Q': flag = False break if not add_user_quota.isdigit(): continue now_user_quota = user_quota + int(add_user_quota) judge_user['quota'] = now_user_quota operate_user_info_file(username, 'write', data=judge_user) message = "increase user quota,%s old quota is %s,now quota is %s" % ( username, user_quota, now_user_quota) log_output('administrator', 'manage', "INFO", message=message) break
def user_registration(): while True: regist_user = input("注册用户名:").strip() verification_user = operate_user_info_file(regist_user, 'read') if not verification_user: regist_password = input("密码:").strip() passwd_hash_value = hash_val(regist_password) user_info_dict = { 'username': regist_user, 'password': passwd_hash_value, 'status': 0, 'expire_date': '2020-01-01', 'quota': 15000.0, 'balance': 15000.0, } operate_user_info_file(regist_user, 'write', data=user_info_dict) message = "create user,the user is %s" % (regist_user) log_output('administrator', 'manage', "INFO", message=message) return True else: print("用户名已存在") continue
def modify_password(): count = 0 while count < 3: name = input("请输入需要修改密码的用户,退出(B):").strip() if name == 'B': break judge_user = operate_user_info_file(name, 'read') if judge_user: old_password = input("旧密码:") count += 1 old_password_value = hash_val(old_password) user_info_dict = operate_user_info_file(name, 'read') if old_password_value == user_info_dict['password']: new_password = input("新密码:").strip() new_password = hash_val(new_password) user_info_dict['password'] = new_password operate_user_info_file(name, 'write', data=user_info_dict) message = "modify %s password" % (name) log_output('administrator', 'manage', "INFO", message=message) return else: print("密码错误,请重新输入。") else: print("用户不存在")
def with_draw(username): single_user_info = operate_user_info_file(username, 'read') while True: current_amount = single_user_info['balance'] float_current_amount = float('%.1f' % current_amount) max_withdraw = '%.1f' % (current_amount - current_amount * 0.05) print("您当前的金额为 %s,最大提现金额为 %s " % (float_current_amount, max_withdraw)) withdraw_amount = input("您提现的金额为,返回(B):").strip() if withdraw_amount == 'B': return True if not withdraw_amount.isdigit(): print("提现金额必须是整数") continue withdraw_amount = int(withdraw_amount) settlement_amount = withdraw_amount + withdraw_amount * 0.05 float_settlement_amount = float('%.1f' % settlement_amount) if float_settlement_amount > float_current_amount: choice_input = input("您当前金额已不足,继续(Y),返回(B):").strip() if choice_input == 'B': return True else: continue else: float_current_amount -= float_settlement_amount single_user_info['balance'] = float_current_amount print("您提现的金额为:", withdraw_amount) print("您的余额为:", float_current_amount) operate_user_info_file(username, 'write', data=single_user_info) message = "Your cash withdrawal amount is %s,The balance is %s;" % ( withdraw_amount, float_current_amount) log_output(username, 'atm', "INFO", message=message) choice = input("是否继续提现,继续(Y),退出(B):").strip() if choice == 'Y': continue else: return True