def reimbursement(add_count_id, huankuan_money, all_money, jiekuan_money): """ :param add_count_id:账户ID :param huankuan_money: 还款金额 :param all_money: 账户总金额 :param jiekuan_money: 借款的金额 :return:还款 """ if huankuan_money <= jiekuan_money: if all_money - jiekuan_money >= 0: db_path = db_handle.db_handle(settings.DATABASE) account_file = f"{db_path}/{add_count_id}.json" if os.path.isfile(account_file) and add_count_id != 'admin': with open(account_file) as f: account_data = json.load(f) account_data['balance'] = all_money - huankuan_money account_data[ 'jiekuan_money'] = jiekuan_money - huankuan_money account_data['credit'] += 1 dump_account(account_data) print('还款成功,你的信用值+1') if account_data['jiekuan_money'] == 0: account_data['jiekuan_money'] = 0 account_data['jiekuan_date'] = 0 dump_account(account_data) else: print('还款后你的账户总资产将为负,所以不能进行还款,快快去搬砖存款吧') else: print('还款金额不能大于借款金额')
def brrow_moeny(add_count_id, borrowing_moeny, brrowing_yuefen): """ :param add_count_id: 账户ID :param borrowing_moeny: 借款金额 :param brrowing_yuefen: 借款的月份 :return: """ nowtime = datetime.datetime.today() brrowing_yuefen = int(brrowing_yuefen) borrowing_moeny = int(borrowing_moeny) shiji_moeny = borrowing_moeny * (1 + brrowing_yuefen / 100) db_path = db_handle.db_handle(settings.DATABASE) account_file = f"{db_path}/{add_count_id}.json" if os.path.isfile(account_file) and add_count_id != 'admin': with open(account_file) as f: account_data = json.load(f) date = nowtime + datetime.timedelta(days=30 * brrowing_yuefen) account_data['jiekuan_money'] += shiji_moeny account_data['jiekuan_date'] = str(date.date()) account_data['balance'] += shiji_moeny dump_account(account_data) print( f"借款成功,你已成功借款{account_data ['jiekuan_money']}元,还款日期是{account_data ['jiekuan_date']}" ) else: print('借款失败,原因未知')
def freeze_account(admin_id, dongjie): """ :param admin_id:管理员ID :param dongjie: 判断状态 :return: """ db_path = db_handle.db_handle(settings.DATABASE) account_file = f"{db_path}/{admin_id}.json" if os.path.isfile(account_file) and admin_id != 'admin': with open(account_file) as f: account_data = json.load(f) if account_data['Lock_the_card'] == 'True': if dongjie == 'False': account_data['Lock_the_card'] = '' dump_account(account_data) print(f'解冻{admin_id}账户成功') else: print('此账户已经被冻结') elif account_data['Lock_the_card'] == '': if dongjie == 'True': account_data['Lock_the_card'] = 'True' dump_account(account_data) print(f'冻结{admin_id}账户成功') else: print('此账户没有被冻结') else: print('没有此账户或不能冻结管理员账户')
def dump_account(account_data): """ :param account_data:用户总信息 :return: """ db_path = db_handle.db_handle(settings.DATABASE) account_file = f"{db_path}/{account_data['id']}.json" with open(account_file, 'w') as f: acc_data = json.dump(account_data, f) return acc_data
def load_current_balane(account_id): """ :param account_id:用户名 :return: """ db_path = db_handle.db_handle(settings.DATABASE) account_file = f"{db_path}/{account_id}.json" with open(account_file) as f: acc_data = json.load(f) return acc_data
def Open_account(admin_id, info_account): """ :param admin_id:开户ID :param info_account: 开户的信息 :return: """ dbs_path = db_handle.db_handle(settings.DATABASE) account_file = f"{dbs_path}/{admin_id}.json" with open(account_file, 'w') as f: acc_data = f.write(json.dumps(info_account)) return acc_data
def judge_money_date(): """ :return: 每次登陆时自动查看有无预期的账户 """ for (dirpath, dirnames, filenames) in walk(f'{BASE_DIR}/db/accounts'): for file in filenames: if file.endswith('json'): db_path = db_handle.db_handle(settings.DATABASE) account_file = f"{db_path}/{file}" with open(account_file) as f: account_data = json.load(f) account_data['jiekuan_date'] if account_data[ 'jiekuan_date'] == 0 else print( f"账户{file[:-5]}没有进行即使还款,还款金额{account_data['jiekuan_money']},最后还款日期为{account_data['jiekuan_date']},请注意及时催交\n" )
def add_account_vip(add_count_id): """ :param add_count_id:添加账户的ID :return: """ db_path = db_handle.db_handle(settings.DATABASE) account_file = f"{db_path}/{add_count_id}.json" if os.path.isfile(account_file) and add_count_id != 'admin': with open(account_file) as f: account_data = json.load(f) if account_data['VIP'] == 'True': print('此账户已经是VIP了无需重复开通') else: account_data['VIP'] = 'True' account_data['vip_level'] = "1" dump_account(account_data) print('开通VIP账户成功') else: print('没有此账户或管理员账户不能设置为VIP')
def modify_password(admin_id): """ :param admin_id:管理员ID :return: """ db_path = db_handle.db_handle(settings.DATABASE) account_file = f"{db_path}/{admin_id}.json" if os.path.isfile(account_file): with open(account_file) as f: account_data = json.load(f) true_password = input( f"你当前的密码为{account_data['password']},是否进行修改,修改输入Y不修改输入N").strip( ) if true_password == 'Y': pass_id = 3 while True: trues_password = input('请输入修改后的密码').strip() truse_too_password = input("请在输入一次密码").strip() if trues_password == truse_too_password: print('密码修改成功') account_data["password"] = trues_password dump_account(account_data) break else: pass_id -= 1 if pass_id == 0: print('你已经没有修改密码的机会了') break else: print(f'两次输入的密码不一致,请重新输入,还有{pass_id-1}次机会') continue elif true_password == 'N': print('你取消了本次密码的修改') else: print('输入有误,已退出修改密码功能') else: print('你输入的账户有误,请核对后重新输入')
def acc_auch(accout, password, pass_word): """ :param accout: 账户 :param password: 登陆密码 :param pass_word:次数的判定 :return: """ # 返回当前的路径信息,通过配置信息来验证是否正确 db_path = db_handle.db_handle(settings.DATABASE) account_file = f"{db_path}/{accout}.json" if os.path.isfile(account_file): with open(account_file) as f: account_data = json.load(f) try: if account_data["Lock_the_card"] == '': if account_data['password'] == password: exp_time_stamp = time.mktime( time.strptime(account_data['expire_date'], "%Y-%m-%d")) if time.time() > exp_time_stamp: print('你的账户已经过期,请重新补办新的银行卡或重新登陆') else: return account_data else: print('你输入的密码不正确') pass_word += 1 if pass_word == 3: print('卡的密码输入次数过多,卡已经被锁定,请联系银行工作人员进行解锁') account_data["Lock_the_card"] = 'True' dump_account(account_data) exit() elif account_data["Lock_the_card"] == 'True': print('你的卡已经被锁定不能进行操作了,请联系银行工作人员') exit() except Exception: print('没有这个账号') else: print('没有这个账户目录')