def repay_interface(username): """ 还款接口 :param username: 还款用户 """ username_dic = dbhandler.read_josn(username) extra = username_dic['extra'] if extra >= 15000: return False, '无需还款!\n' else: username_dic['extra'] = 15000 dbhandler.save_json(username, username_dic) return True, f'还款{(15000 - extra) * 1.005: .1f}成功\n'
def locked_interface(username): """ 如果账户存在用户输入错我三次, 将对用户枷锁 :param username: :return: """ # 判断用户是否存在,存在对用户枷锁 flag = common.is_username(username) if flag: user_dic = dbhandler.read_josn(username) user_dic['locked'] = 1 # 保存枷锁信息 dbhandler.save_json(username, user_dic) return True, '账号已被锁定, 请找管理员解锁!\n' else: return False, '用户不存在!\n'
def withdraw_interface(username, money): """ 取款接口 :param username: 取款用户名 :param money: 取款金额 :return: 成功True,否则False """ username_dic = dbhandler.read_josn(username) # 判读用户金额是否打印取款金额 if username_dic['extra'] >= money: # 修改金额 username_dic['extra'] -= money dbhandler.save_json(username, username_dic) return True, f'取款成功,取款金额为{money}\n' else: return False, f'取款失败\n'
def tranfer_interface(from_username, to_username, moey): """ 转账接口 :param from_username: 要转账的人 :param to_username: 向谁转账 :param moey: 转账多少钱 :return: 成功返回True,否则返回False """ from_username_dic = dbhandler.read_josn(from_username) to_username_dic = dbhandler.read_josn(to_username) if from_username_dic['extra'] > moey: from_username_dic['extra'] -= moey to_username_dic['extra'] += moey dbhandler.save_json(from_username, from_username_dic) dbhandler.save_json(to_username, to_username_dic) return True, "转账成功" else: return False, "账户余额不足\n"
def register_interface(username, pwd): """ 实现用户注册功能接口 :param username: 用户名 :param pwd: 密码 :return: 返回是否注册成功 """ # 判断用户是否存在 flag = common.is_username(username) # 判断用户是否存在,进行逻辑处理 if flag: return False, '用户已经存在!\n' else: # 保存用户信息 contend = {'username': username, 'pwd': pwd, 'extra': 15000, 'locked': 0} dbhandler.save_json(username, contend) return True, '注册成功!\n'