def inner(*args,**kwargs): while True: pay_account = input("Please enter your account name:").strip() global pay_account pay_passwd = input("Please enter your account password:"******"passwd"] if md5.hash_md5(pay_passwd) == pay_passwd_file: logger.info('Payment password verified successfully') func(*args,**kwargs) else: logger.error( "Payment password error.The account will be locked after 3 errors!") count += 1 else: func(*args, **kwargs) else: logger.error('Account does not exist')
def comp_money(shopping_record): data = getter.json_data_get(shopping_record) shop_money = 0 for i in data: shop_money += data[i]["count"] * data[i]["price"] print(shop_money) return shop_money
def check_out(money, username, passwd, username_in,logger_obj): """ :param money: repayment amount :param username: Transfer accounts :param passwd: pay password :param username_in: transfer into the account :param logger_obj: logging object :return: None """ if username_in is None: username_in = input("Please enter the transfer account:").strip() if money is None: money = input("Please enter the amount of transfer:").strip() if passwd is None: passwd = input("Please enter the payment password:"******"passwd"] == md5.hash_md5(passwd): if int(money) < bank_data[username]["balance"]: bank_data[username]["balance"] -= int(money) bank_data[username_in]["balance"] += int(money) getter.json_data_put(bank_data, settings.BANK_FILE) logger_obj.info('%s扣款成功' % username) logger_obj.info('%s入账成功' % username_in) else: logger_obj.error('%s账户余额不足' % username) else: logger_obj.error('%s支付密码错误' % username)
def repay(username,logger_obj): """ :param username: :param logger_obj: :return: """ bank_data = getter.json_data_get(settings.BANK_FILE) debt = bank_data[username]["limit"] - bank_data[username]["balance"] print("欠款:%s" % debt) while True: repay_money = input("请输入还款金额:").strip() if not repay_money: continue elif repay_money.isdigit() and int(repay_money) > 0: bank_data[username]["balance"] += int(repay_money) getter.json_data_put(bank_data, settings.BANK_FILE) debt = bank_data[username]["limit"] - bank_data[username]["balance"] if debt == 0: logger_obj.info("欠款已还清") break else: logger_obj.info("已还金额:%s,欠款:%s" % (repay_money, debt)) break else: logger_obj.error("输入额度错误")
def diff_md5(account, passwd, file_name): md5_new = hash_md5(passwd) data = getter.json_data_get(file_name) if data[account]['password'] == md5_new: return True else: return False
def shopping_cart(products, logger_obj): file_name = "%s/account/%s_shop_cart.json" % (settings.BASE_DIR, user_login.user_input) if os.path.exists(file_name): shop_cart = getter.json_data_get(file_name) else: shop_cart = {} while True: for goods_key, goods_value in enumerate(products): print('%s\t%s\t%s\t' % (goods_key, goods_value['name'], goods_value['price'])) choice = input('请输入产品编号进行购买,退出请输入Q:').strip() if not choice: continue elif choice.isdigit() and 0 <= int(choice) < len(products): good_buy = products[int(choice)] if good_buy['name'] in shop_cart.keys(): count = shop_cart[good_buy['name']]["count"] + 1 shop_cart[good_buy['name']]["count"] = count logger_obj.info('已经商品%s添加进购物车' % good_buy['name']) else: shop_cart[good_buy['name']] = { "count": 1, "price": good_buy['price'] } logger_obj.info('已经商品 %s 添加进购物车' % good_buy['name']) elif choice.upper() == "Q": print("1. 结账") print("2. 保存退出") input_choice = input('请选择:') getter.json_data_put(shop_cart, file_name) if int(input_choice) == 1: print(shop_cart) out_money = comp_money(file_name) logger_obj.info("本次共消费%s元" % out_money) pay_account = input("请输入支付账号:").strip() pay_passwd = input("请输入支付密码:").strip() check_out.check_out(out_money, pay_account, pay_passwd, "tesla", logger_obj) shop_cart = {} logger_obj.info("购物车已无商品") getter.json_data_put(shop_cart, file_name) exit() elif int(input_choice) == 2: exit() logger_obj.info("保存退出购物结束")
def info_account(account_name,logger_obj): """ :param account_name: :param logger_obj: logging object :return: None print account information, argument is account name """ bank_data = getter.json_data_get(settings.BANK_FILE) for i in bank_data[account_name]: if i == "passwd": continue print("%s:%s"%(i,bank_data[account_name][i])) logger_obj.info("print account information")
def increase_credit_limit(account_name,logger_obj): """ :param account_name: :return: None increase credit limit """ bank_data = getter.json_data_get(settings.BANK_FILE) while True: limit_imput = input("请输入增加的额度:").strip() if not limit_imput: continue elif limit_imput.isdigit() and int(limit_imput) > 0: bank_data[account_name]["limit"] += int(limit_imput) bank_data[account_name]["balance"] += int(limit_imput) getter.json_data_put(bank_data, settings.BANK_FILE) logger_obj.info("increase credit limit %s success"%limit_imput) break else: logger_obj.info("%s账户已冻结" % account_name)
def with_draw(money, username,logger_obj): """ :param money: :param username: :param logger_obj: :return: """ bank_data = getter.json_data_get(settings.BANK_FILE) card_balance = bank_data[username]["balance"] if money is None: money = input("Please enter the withdrawal amount:").strip() cash_adv_money = int(money) * 1.05 if cash_adv_money <= card_balance: service_charge = int(money) * 0.05 bank_data[username]["balance"] = card_balance - cash_adv_money getter.json_data_put(bank_data, settings.BANK_FILE) logger_obj.info("%s 取现%s,手续费%s" % (username, money, service_charge)) else: logger_obj.error("余额不足")
def add_account(logger_obj): """ :param logger_obj: logging object :return: None add account information """ user_moudle = settings.USER_MOD bank_data = getter.json_data_get(settings.BANK_FILE) input_acc_name = input("请输入账户名:").strip() for i in user_moudle: while True: val = input("请输入%s 信息:" % i).strip() if not val: continue elif i == "passwd": val_passwd = input("请再次输入%s 信息:" % i).strip() if val == val_passwd: val = md5.hash_md5(val) user_moudle[i] = val break else: logger_obj.info("密码两次结果不一致") continue else: if user_moudle[i] == int: if val.isdigit() and int(val) >= 0: user_moudle[i] = int(val) break else: logger_obj.info("数据输入有误") else: user_moudle[i] = val break bank_data[input_acc_name] = user_moudle getter.json_data_put(bank_data,settings.BANK_FILE) logger_obj.info("%s信息添加成功"%input_acc_name)
def frozen_account(account_name,logger_obj, status=1): """ :param account_name: :param logger_obj: :param status: :return: """ bank_data = getter.json_data_get(settings.BANK_FILE) if status == 1: bank_data[account_name]["status"] = 1 getter.json_data_put(bank_data, settings.BANK_FILE) logger_obj.info("%s账户已冻结" % account_name) else: if bank_data[account_name]["status"] == 0: logger_obj.info("%s账户为解冻状态,无需解冻" % account_name) else: bank_data[account_name]["status"] = 0 getter.json_data_put(bank_data, settings.BANK_FILE) logger_obj.info("%s账户已解冻" % account_name) #add_account()
def inner(*args, **kwargs): global user_status count = 0 if not user_status: while count < 3: user_input = input("user:"******"passwd:").strip() file_name = "%s/account/%s.json" % ( settings.BASE_DIR, user_input) if os.path.exists(file_name): data = getter.json_data_get(file_name) #username = data.keys passwd = data[user_input]['password'] if user_input in data.keys() and md5.hash_md5(passwd_input) == passwd: local_time = time.strftime( "%Y-%m-%d", time.localtime()) if data[user_input]["expire_date"] > local_time and data[user_input]["status"] == 0: user_status = True logger.info("user loggin") func(*args, **kwargs) else: logger.error("expire_date or status error") else: logger.error('user/passwd input Error') count += 1 else: logger.info('user loggin') func(*args, **kwargs)