def frozen_account(admin_id): print("这是冻结账户菜单。。。") db_file = setting.ACCOUNT_DB db = db_operater.read_db(db_file) loop_flag = True while loop_flag: card_number = input("请输入要冻结的卡号(Q退出):").strip() if db.get(card_number): print("卡号:{},姓名:{},当前账单:{}".format(card_number, db[card_number]["name"], db[card_number]["bill"])) while loop_flag: option = input("确认冻结按1,B返回,Q退出:").strip() if option == "1": db[card_number]["lock_flag"] = 1 logger.my_logger(card_number, "frozen by admin:{}".format(admin_id)) db_operater.write_db(file=db_file, data=db) elif option.upper() == "B": break elif option.upper() == "Q": loop_flag = False break else: print("无效的输入,请重新输入!") elif card_number.upper() == "Q": break else: print("卡号不存在,请重新输入!")
def change_limit(admin_id): print("这是调整额度的菜单。。。") db_file = setting.ACCOUNT_DB db = db_operater.read_db(db_file) loop_flag = True while loop_flag: card_number = input("请输入要操作的卡号(Q退出):").strip() if db.get(card_number): print("{}原额度是{}。".format(card_number, db[card_number]["limit"])) while loop_flag: option = input("请输入调整后的额度,(Q退出B返回上级):").strip() if option.isdigit(): option2 = input("确认修改请按1,(Q退出B返回上级):").strip() if option2 == "1": db[card_number]["limit"] = int(option) print("卡号{}的额度修改为{}。".format(card_number, db[card_number]["limit"])) logger.my_logger(admin_id, "change the limit of card:{} to {}".format(card_number, db[card_number]["limit"])) db_operater.write_db(file=db_file, data=db) elif option2.upper() == "B": break elif option2.uooer() == "Q": loop_flag = False break elif option.upper() == "B": break elif option.upper() == "Q": loop_flag = False break else: print("无效的输入,请重新输入!") elif card_number.upper() == "Q": break else: print("卡号不存在请重新输入!")
def reset_password(admin_id): print("这是重置密码菜单。。。") db_file = setting.ACCOUNT_DB db = db_operater.read_db(db_file) loop_flag = True while loop_flag: card_number = input("请输入要重置密码的卡号,Q退出:").strip() if card_number.upper() == "Q": break elif all([card_number.isdigit(), db.get(card_number)]): while loop_flag: option = input("您要重置密码的卡号为{},用户名为{},1确认,B返回,Q退出!".format(card_number, db[card_number]["name"])) if option == "1": db[card_number]["password"] = "******" print("卡号:{}的密码已重置为初始密码!".format(card_number)) logger.my_logger(card_number, "password reset by admin:{}.".format(admin_id)) db_operater.write_db(file=db_file, data=db) elif option.upper() == "B": break elif option.upper() == "Q": loop_flag = False break else: print("无效的输入,请重新输入!") else: print("无效的输入,请重新输入!")
def change_password(card_id): print("这是修改密码的菜单。。。") # 输入原密码次数是否应该有限制? db_file = setting.ACCOUNT_DB db = db_operater.read_db(db_file) loop_flag = True while loop_flag: password = input("请输入原密码,Q退出:").strip() if md5_encryption.md5_encryption(password) == db[card_id]["password"]: new_password_1 = input("请输入新密码:").strip() new_password_2 = input("请再次输入新密码:").strip() bool_a = new_password_1 == new_password_2 bool_b = new_password_1.isdigit() bool_c = len(new_password_1) == 6 if all([bool_a, bool_b, bool_c]): new_password = new_password_1 while loop_flag: option = input("1确认,B返回,Q退出:").strip() if option == "1": db[card_id]["password"] = md5_encryption.md5_encryption(new_password) logger.my_logger(card_id, "change password.") print("密码修改完成!") # 回写数据 db_operater.write_db(file=db_file, data=db) elif option.upper() == "B": break elif option.upper() == "Q": loop_flag = False break else: print("两次密码不一致,或输入的密码不是6位数字!") elif password.upper() == "Q": break else: print("密码错误,请重试!")
def transfer_accounts(card_id): print("这是转账菜单。。。") db_file = os.path.abspath(setting.ACCOUNT_DB) db = db_operater.read_db(db_file) loop_flag = True while loop_flag: card_id_1 = input("请输入卡号,Q退出:").strip() card_id_2 = input("请再次输入卡号:").strip() bool_a = card_id_1 == card_id_2 bool_b = card_id_1.isdigit() bool_c = card_id_2.isdigit() bool_d = db.get(card_id_2) # 暂时只支持同行转账 if all([bool_a, bool_b, bool_c, bool_d]): transfer_card_id = card_id_1 if transfer_card_id != card_id: while loop_flag: print("您当前余额:{:.2f}元。".format(db[card_id]["balance"])) print("您要转账的卡号是:{}".format(transfer_card_id)) transfer_amount = input("请输入要转账的金额,B返回Q退出:").strip() if transfer_amount.upper() == "B": break elif transfer_amount.upper() == "Q": loop_flag = False break elif transfer_amount.isdigit(): # 要转账 金额肯定要大于0 if float(transfer_amount) > 0: if db[card_id]["balance"] >= float(transfer_amount): print("您要向{}账户转账{:.2f}元。。。".format(transfer_card_id, float(transfer_amount))) while loop_flag: option = input("1确认,B返回,Q退出!").strip() if option == "1": db[card_id]["balance"] -= float(transfer_amount) # 从自己卡的余额里减掉转账的金额 db[transfer_card_id]["balance"] += float(transfer_amount) # 把转账的金额加到对方卡的余额 logger.my_logger(card_id, "transfer to {} {}.".format(transfer_card_id, float(transfer_amount))) db_operater.write_db(file=db_file, data=db) elif option.upper() == "B": break elif option.upper() == "Q": loop_flag = False break else: print("无效的输入,请重新输入!") else: print("您的余额不足,请充值后再试!") else: print("别捣乱。。。") else: print("无效的输入,请重新输入!") else: print("自己不能给自己转账。。。") elif card_id_1.upper() == "Q": break else: print("两次输入的卡号不一致或卡号有误,请重新输入!")
def add_card_account(admin_id): print("这是添加信用卡账户的菜单。。。") db_file = setting.ACCOUNT_DB db = db_operater.read_db(db_file) loop_flag = True while loop_flag: db_demo = {} card_id = format(len(db)+1, "8=8") # 生成一个8位的卡号 db_demo[card_id] = {} card_name = input("请输入卡主姓名,Q退出:").strip() card_limit = input("请输入卡片额度:").strip() bool_a = re.match(r'^[a-zA-Z.]{4,26}$', card_name) # 英文名字4-26位 bool_b = re.match(r'^[\u4e00-\u9fa5]{2,4}$', card_name) # 中文名字2-4位 bool_c = re.match(r'^\d{1,8}$', card_limit) if all([(bool_a or bool_b), bool_c]): # 初始化用户信息 db_demo[card_id]["name"] = card_name db_demo[card_id]["limit"] = float(card_limit) db_demo[card_id]["current_limit"] = float(card_limit) db_demo[card_id]["cash_limit"] = float(db_demo[card_id]["current_limit"] * 0.5) db_demo[card_id]["lock_flag"] = 0 db_demo[card_id]["password"] = "******" db_demo[card_id]["bill"] = 0 db_demo[card_id]["balance"] = 0 db_demo[card_id]["retry_count"] = 0 db_demo[card_id]["created_date"] = datetime.date.today() while loop_flag: option = input("确认添加按1,B返回Q退出:") if option == "1": print("正在添加。。。") db.update(db_demo) # 更新数据 print("添加完成!") logger.my_logger(admin_id, "add a new card:{}.".format(card_id)) db_operater.write_db(file=db_file, data=db) elif option.upper() == "B": break elif option.upper() == "Q": loop_flag = False break else: print("无效的输入,请重新输入!") elif card_name.upper() == "Q": break else: print("无效的输入,请重新输入!")
def main_body(admin_id): print("欢迎来到管理员操作界面!") logger.my_logger(admin_id, "log in.") loop_flag = True while loop_flag: option = input("1.调整额度 2.添加账户 3.冻结账户 4.重置密码 5.查询ATM操作日志 Q.退出:").strip() if option == "1": change_limit(admin_id) elif option == "2": add_card_account(admin_id) elif option == "3": frozen_account(admin_id) elif option == "4": reset_password(admin_id) elif option == "5": check_log() elif option.upper() == "Q": loop_flag = False logger.my_logger(admin_id, "log out.") else: print("无效的输入!")
def enchashment(card_id): print("这是取现的菜单。。。") db_file = setting.ACCOUNT_DB db = db_operater.read_db(db_file) loop_flag = True while loop_flag: print("您目前的取现额度是:{:.2f}元".format(db[card_id]["cash_limit"])) cash_amount = input("请输入金额(100的整数),手续费5%,Q退出:").strip() if cash_amount.isdigit(): cash_amount = float(cash_amount) if cash_amount % 100 == 0: handle_charge = cash_amount * 0.05 print("您此次取款:{:.2f}元,手续费:{:.2f}元。".format(cash_amount, handle_charge)) all_amount = cash_amount + handle_charge while loop_flag: option = input("1确认,B返回,Q退出").strip() if option == "1": db[card_id]["limit"] -= all_amount db[card_id]["cash_limit"] -= all_amount db[card_id]["current_limit"] -= all_amount # db[card_id]["bill"] += all_amount # 记录交易流水 transaction_record.transaction_record(card_id, "取现", cash_amount) transaction_record.transaction_record(card_id, "手续费", handle_charge) logger.my_logger(card_id, "withdrawal {}, handle charge {}.".format(cash_amount, handle_charge)) # 回写数据 db_operater.write_db(file=db_file, data=db) elif option.upper() == "B": break elif option.upper() == "Q": loop_flag = False break else: print("无效输入,请重新输入!") elif cash_amount.upper() == "Q": break else: print("无效的输入,请重新输入!")
def main_body(card_id): print("这是用户界面:") logger.my_logger(card_id, "log in.") # 先看有没有产生利息。。。 get_interest() loop_flag = True while loop_flag: option = input("1.查询 2.还款 3.转账 4.提现 5.修改密码 Q.退出:").strip() if option == "1": print("欢迎进入查询系统:") while loop_flag: option2 = input("1.查询额度 2.查询账单 3.查询交易流水 B返回Q退出:").strip() if option2 == "1": check_info(card_id) logger.my_logger(card_id, "查询额度") elif option2 == "2": show_record(card_id) logger.my_logger(card_id, "查询账单") elif option2 == "3": while loop_flag: print("请输入要查询的起始日期:") start_date_str = input("开始日期:").strip() end_date_str = input("结束日期:").strip() a = check_tran_record(card_id, start_date_str, end_date_str) logger.my_logger(card_id, "check the transactions flowing water from {} to {}.".format(start_date_str, end_date_str)) if not a: break elif option2.upper() == "B": break elif option2.upper() == "Q": loop_flag = False break else: print("无效的输入!") elif option == "2": logger.my_logger(card_id, "还款") # 还款 repay_bill(card_id) elif option == "3": transfer_accounts(card_id) elif option == "4": enchashment(card_id) elif option == "5": change_password(card_id) elif option.upper() == "Q": logger.my_logger(card_id, "log out.") loop_flag = False else: print("无效的输入!")
def repay_bill(card_id): print("这是还款菜单。。。") db_file = setting.ACCOUNT_DB db = db_operater.read_db(db_file) loop_flag = True while loop_flag: option = input("1:自己还款,2:替别人还款,3:退出").strip() if option == "1": while loop_flag: bill = db[card_id]["bill"] print("您当前账单为:{:.2f}".format(bill)) option2 = input("请输入您要还款的金额:").strip() if re.match(r'^\d+\.?\d{1,2}$', option2): option2 = float(option2) if option2 > float(bill): while loop_flag: # 用临时变量存储 bill_temp = 0 balance_temp = option2 - float(bill) # 多的钱存入余额 current_limit_add_temp = option2 - float(bill) # 余额也算到当前额度里 option3 = input("你账单:{:.2f}元,本次还款:{:.2f}元,1确认,B返回,Q退出:".format(bill, option2)).strip() if option3 == "1": db[card_id]["bill"] = bill_temp # 还完后账单清零 db[card_id]["balance"] = balance_temp # 余额 db[card_id]["current_limit"] += current_limit_add_temp # 当前额度 print("您已成功还款{}元。".format(option3)) logger.my_logger(card_id, "repayment {}.".format(option2)) db_operater.write_db(file=db_file, data=db) elif option3.upper() == "B": break elif option3.upper() == "Q": return db else: print("无效的输入,请重新输入!") elif option2 == 0: print("别逗了,你丫根本没放钱进来。。。") else: while loop_flag: bill_temp = bill - float(option2) print("你本次还款:{:.2f}元,剩余账单:{:.2f}元".format(option2, bill_temp)) option4 = input("1确认还款,B返回,Q退出:") if option4 == "1": db[card_id]["bill"] = bill_temp return db elif option4.upper() == "B": break elif option4.upper() == "Q": return db else: print("无效的输入,请重新输入!") elif option2.upper() == "B": break elif option2.upper() == "Q": return db else: print("无效的输入,请重新输入!") elif option == "2": pass # 功能类似于转账,此处略。。。 elif option.upper() == "Q": return db else: print("无效的输入,请重新输入!")