Example #1
0
def mak_transaction(account_data, tran_type, amount):
    """
	:param account_data: 账户信息
	:param tran_type: 交易类型
	:param amount:要交易的钱
	:return:
	"""
    amount = float(amount)
    if tran_type in settings.TRANSACTION_TYPE:
        interest = amount * settings.TRANSACTION_TYPE[tran_type][
            'interest']  # 利息
        old_balance = account_data['balance']
        if settings.TRANSACTION_TYPE[tran_type]['action'] == 'plus':
            new_balance = old_balance + interest + amount
            print(f'现在是{new_balance}元')
        elif settings.TRANSACTION_TYPE[tran_type]['action'] == 'minus':
            new_balance = old_balance - interest - amount
            if new_balance < 0:
                print(f"你的额度不够,你现在的余额是{new_balance}")
                return
        account_data['balance'] = new_balance
        dump_account(account_data)
        return account_data
    else:
        print("交易类型没有被找到")
Example #2
0
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('借款失败,原因未知')
Example #3
0
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 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('没有此账户或不能冻结管理员账户')
Example #5
0
def make_transaction(log_obj, account_data, tran_type, amount, **others):
    """
    # 处理所有用户的交易事务
    deal all the user transactions
    :param log_obj:
    :param account_data: user account data
    :param tran_type: transaction type
    :param amount: transaction amount
    :param others: mainly for logging usage
    :return:
    """

    amount = float(amount)
    if tran_type in settings.TRANSACTION_TYPE:
        interest = amount * settings.TRANSACTION_TYPE[tran_type]['interest']
        old_balance = account_data['Balance']
        if settings.TRANSACTION_TYPE[tran_type]['action'] == 'plus':
            new_balance = old_balance + amount + interest
        elif settings.TRANSACTION_TYPE[tran_type]['action'] == 'minus':
            new_balance = old_balance - amount - interest
            if new_balance < 0:
                print(
                    '''\033[31;1m您当前的信用额度 [%s] 不够完成这笔交易 [-%s], 您当前的余额为 [%s]'''
                    % (account_data['Credit'],
                       (amount + interest), old_balance))
                return
        account_data['Balance'] = new_balance
        accounts.dump_account(account_data)  # 将当前的余额存入数据库(文件)
        log_obj.info("account:%s   action:%s    amount:%s   interest:%s" %
                     (account_data['Account'], tran_type, amount, interest))
        return account_data
    else:
        print("\033[31;1m该交易类型 [%s] 不存在!\033[0m" % tran_type)
Example #6
0
def Save_gade_money(account_data, money):
    """
	:param account_data:
	:param money:红包的钱
	:return: 更新现有钱的金额
	"""
    account_data['balance'] -= float(money)
    dump_account(account_data)
    print('现在的金额为%s元' % account_data['balance'])
    return account_data, money
def buy_shopping(account_data, True_or_False, VIP_LEVEL):
    """

	:param account_data:账户信息
	:param True_or_False: 判断是否是VIP
	:param VIP_LEVEL: VIP的级别
	:return:
	"""
    global shiji_money
    all_money = 0
    all_moneys = []
    if True_or_False == 'True':
        dazhe = settings.BUSINESS['vip_level'][VIP_LEVEL]['discount']
        print(f"你是尊贵的VIP{VIP_LEVEL}客户买菜可以打折{dazhe}哦")
        for i in range(len(settings.shucai_menus)):
            aa = settings.shucai_menus[f'{i+1}']["action"]
            bb = settings.shucai_menus[f'{i+1}']["interest"]
            print(i + 1, aa, ":", bb, "元")
        while True:
            xuanze_id = input('请选购你的商品,每次的价格都不一样哦').strip()
            if xuanze_id.isdigit():
                danjia_money = settings.shucai_menus[xuanze_id]["interest"]
                if all_money < account_data['balance']:
                    all_moneys.append(danjia_money)
                    all_money = all_money + danjia_money
                    shiji_money = all_money * dazhe
                    shuru_info = input('输入任意键继续,结束购物请按Q').strip()
                    if shuru_info == 'Q':
                        break
                    else:
                        continue
                else:
                    print('你的账户余额不足,请及时充值')
                    break
            else:
                print('请输入正确的编号')
                continue
        print('你一共话费了%s元' % shiji_money)
        account_data['balance'] = account_data['balance'] - shiji_money
        account_data['VIP_jifen'] = round(
            account_data['VIP_jifen'] + shiji_money, 2)
        dump_account(account_data)
        VIP_jifen(account_data)
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 VIP_jifen(account_data):
    """

	:param account_data:账户总信息
	:return: 积分的多少来确定VIP的等级
	"""
    if 0 < account_data['VIP_jifen'] <= 50:
        account_data['vip_level'] = "1"
    elif 50 < account_data['VIP_jifen'] <= 100:
        account_data['vip_level'] = "2"
    elif 100 < account_data['VIP_jifen'] <= 150:
        account_data['vip_level'] = "3"
    elif 150 < account_data['VIP_jifen'] <= 200:
        account_data['vip_level'] = "4"
    elif 200 < account_data['VIP_jifen'] < 250:
        account_data['vip_level'] = "5"
    elif 250 < account_data['VIP_jifen']:
        account_data['vip_level'] = "6"
    dump_account(account_data)
    print(
        f"你的当前VIP等级为{account_data['vip_level']},积分{account_data['VIP_jifen']}")
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('你输入的账户有误,请核对后重新输入')
Example #11
0
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('没有这个账户目录')
Example #12
0
def mak_reimbursement(account_data, shoukuan_id):
    """
	:param account_id:转账人
	:param shoukuan_id: 接收人
	:return:
	"""
    now_balanes = account_data['balance']
    too_info = loads_current_balane(shoukuan_id)
    now_too_balanes = too_info['balance']
    zhuan_money = float(input("请输入要转账的金额").strip())
    if zhuan_money > 0:
        now_balanes -= float(zhuan_money)
        now_too_balanes += float(zhuan_money)
        account_data['balance'] = now_balanes
        too_info['balance'] = now_too_balanes
        dump_account(account_data)
        dumps_account(too_info)
        print(
            f"转账成功,自己金额还剩余{account_data['balance']},现在借款方为{too_info['balance']}元"
        )
        return account_data, too_info
    else:
        print("你输入的金额有误,请重新输入")