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_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 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 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 check_out(arg): db_file = setting.ACCOUNT_DB info = db_operater.read_db(db_file) while True: card_id = input("请输入信用卡卡号(8位数字):").strip() if re.match(r'^\d{8}$', card_id): if info.get(card_id, None): card_passwd = input("请输入密码:") if md5_encryption.md5_encryption(card_passwd) == info[card_id].get("password", None): if info[card_id]["current_limit"] - arg >= 0: info[card_id]["current_limit"] -= arg print("结算完成!") transaction_record.transaction_record(card_id, "消费", arg) db_operater.write_db(file=db_file, data=info) break else: print("余额不足!") break else: print("密码错误,请重新输入!") else: print("无效的卡号!请重新输入!") elif card_id == "B": 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 wrapper(): print("想购物,先登录。。。") db_file = setting.MALL_ACCOUNT_DB info = db_operater.read_db(db_file) for i in info: if info[i]["unlock_date"] <= datetime.date.today(): info[i]["unlock_date"] = datetime.date.today() info[i]["retry_count"] = 0 loop_flag = True while loop_flag: option = input("1.登录 2.注册 Q.退出:") if option == "1": while loop_flag: user_name = input("请输入用户名,B返回Q退出:").strip() password = input("请输入密码, B返回Q退出:").strip() if info.get(user_name, None): if info[user_name]["retry_count"] < 3: if md5_encryption.md5_encryption( password) == info[user_name].get( "password", None): print("welcome you {}!".format(user_name)) func() break else: info[user_name]["retry_count"] += 1 print("密码错误,请重新输入!") else: print("该用户名已被锁定,请明天再试!") if info[user_name][ "unlock_date"] <= datetime.date.today(): info[user_name][ "unlock_date"] += datetime.timedelta( days=1) break else: break elif user_name.upper() == "B": break elif user_name.upper() == "Q": loop_flag = False break else: print("用户名不存在,请重新输入!") elif option == "2": print("这是qimi商城注册界面:") mall_register.user_register() elif option.upper() == "Q": break db_operater.write_db(file=db_file, data=info)
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 wrapper(): print("想购物,先登录。。。") db_file = setting.MALL_ACCOUNT_DB info = db_operater.read_db(db_file) for i in info: if info[i]["unlock_date"] <= datetime.date.today(): info[i]["unlock_date"] = datetime.date.today() info[i]["retry_count"] = 0 loop_flag = True while loop_flag: option = input("1.登录 2.注册 Q.退出:") if option == "1": while loop_flag: user_name = input("请输入用户名,B返回Q退出:").strip() password = input("请输入密码, B返回Q退出:").strip() if info.get(user_name, None): if info[user_name]["retry_count"] < 3: if md5_encryption.md5_encryption(password) == info[user_name].get("password", None): print("welcome you {}!".format(user_name)) func() break else: info[user_name]["retry_count"] += 1 print("密码错误,请重新输入!") else: print("该用户名已被锁定,请明天再试!") if info[user_name]["unlock_date"] <= datetime.date.today(): info[user_name]["unlock_date"] += datetime.timedelta(days=1) break else: break elif user_name.upper() == "B": break elif user_name.upper() == "Q": loop_flag = False break else: print("用户名不存在,请重新输入!") elif option == "2": print("这是qimi商城注册界面:") mall_register.user_register() elif option.upper() == "Q": break db_operater.write_db(file=db_file, data=info)
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 show_record(card_id): print("这是计算账单的功能。。。") # 将字符串格式的时间转换为日期格式 today = datetime.date.today().timetuple() cur_year = today.tm_year cur_mon = today.tm_mon cur_day = today.tm_mday if cur_day >= 22: print("您本月账单已出。。。") last_mon = datetime.date(cur_year, cur_mon, 1) - datetime.timedelta(days=1) last_tm_mon = last_mon.timetuple().tm_mon # 前一个月的月份 last_tm_year = last_mon.timetuple().tm_year # 前一个月的年份 start_date_str = "{}-{}-{}".format(last_tm_year, last_tm_mon, 22) end_date_str = "{}-{}-{}".format(cur_year, cur_mon, 21) # 调用查询流水的菜单 print("您本期账单{}至{}交易详情:".format(start_date_str, end_date_str)) bill_amount = check_tran_record(card_id, start_date_str, end_date_str) print("本期应还:{}元。".format(bill_amount)) db_file = setting.ACCOUNT_DB db = db_operater.read_db(db_file) db[card_id]["bill"] = bill_amount db_operater.write_db(file=db_file, data=db) else: print("您本月账单还没出。。。")
def user_register(): db_file = setting.ACCOUNT_DB # 读取用户数据库信息 info = db_operater.read_db(db_file) global name loop_flag = True while loop_flag: name = input("请输入用户名:").strip() if re.match(r'^[_a-zA-Z][_0-9a-zA-Z]{3,25}$', name): if not info.get(name, None): info[name] = {} while loop_flag: password = input("请输入密码,Q退出:").strip() if re.match(r'^\S{8,26}$', password): if password: password_tmp = password password = input("请确认您的密码:") if password == password_tmp: info[name][ "password"] = md5_encryption.md5_encryption( password) while loop_flag: email = input("请输入您的邮箱地址, Q退出:").strip() if re.match( r'^([a-z.0-9]{1,26})@([a-z.0-9]{1,20})(.[a-z0-9]{1,8})$', email.lower()): info[name]["email"] = email.lower() info[name]["age"] = None info[name]["retry_count"] = 0 info[name][ "created_date"] = datetime.date.today( ) info[name][ "unlock_date"] = datetime.date.today( ) # 将注册信息写入数据库 db_operater.write_db(file=db_file, data=info) elif email.upper() == "Q": loop_flag = True break else: print("无效的输入,请重新输入!") else: print("两次输入的密码不一致,请重新输入!") else: print("无效的输入!请重新输入!") elif password.upper() == "Q": loop_flag = False break else: print("格式错误,密码必须为8-26位非空字符") else: print("用户名已存在!") else: print("格式错误,用户名格式必须为字母或下划线开头,由字母数字组成的4-26位") while loop_flag: password = input("请输入密码,Q退出:").strip() if re.match(r'^\S{8,26}$', password): if password: password_tmp = password password = input("请确认您的密码:") if password == password_tmp: info[name]["password"] = md5_encryption.md5_encryption( password) break else: print("两次输入的密码不一致,请重新输入!") else: print("无效的输入!请重新输入!") elif password.upper() == "Q": break else: print("格式错误,密码必须为8-26位非空字符")
def user_register(): db_file = setting.ACCOUNT_DB # 读取用户数据库信息 info = db_operater.read_db(db_file) global name loop_flag = True while loop_flag: name = input("请输入用户名:").strip() if re.match(r'^[_a-zA-Z][_0-9a-zA-Z]{3,25}$', name): if not info.get(name, None): info[name] = {} while loop_flag: password = input("请输入密码,Q退出:").strip() if re.match(r'^\S{8,26}$', password): if password: password_tmp = password password = input("请确认您的密码:") if password == password_tmp: info[name]["password"] = md5_encryption.md5_encryption(password) while loop_flag: email = input("请输入您的邮箱地址, Q退出:").strip() if re.match(r'^([a-z.0-9]{1,26})@([a-z.0-9]{1,20})(.[a-z0-9]{1,8})$', email.lower()): info[name]["email"] = email.lower() info[name]["age"] = None info[name]["retry_count"] = 0 info[name]["created_date"] = datetime.date.today() info[name]["unlock_date"] = datetime.date.today() # 将注册信息写入数据库 db_operater.write_db(file=db_file, data=info) elif email.upper() == "Q": loop_flag = True break else: print("无效的输入,请重新输入!") else: print("两次输入的密码不一致,请重新输入!") else: print("无效的输入!请重新输入!") elif password.upper() == "Q": loop_flag = False break else: print("格式错误,密码必须为8-26位非空字符") else: print("用户名已存在!") else: print("格式错误,用户名格式必须为字母或下划线开头,由字母数字组成的4-26位") while loop_flag: password = input("请输入密码,Q退出:").strip() if re.match(r'^\S{8,26}$', password): if password: password_tmp = password password = input("请确认您的密码:") if password == password_tmp: info[name]["password"] = md5_encryption.md5_encryption(password) break else: print("两次输入的密码不一致,请重新输入!") else: print("无效的输入!请重新输入!") elif password.upper() == "Q": break else: print("格式错误,密码必须为8-26位非空字符")
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("无效的输入,请重新输入!")