Exemplo n.º 1
0
def change_balance_interface(login_user, username, newbalance):
    user_dict = db_handler.check(username)
    user_dict['balance'] = float(newbalance)
    flow = f"{common.gettime()}: {username}的余额被{login_user}条整为{user_dict['balance']}."
    user_dict['flow'].append(flow)
    db_handler.save(user_dict)
    return True, flow
Exemplo n.º 2
0
def check_shop_car_interface(login_user):
    user_dict = db_handler.check(login_user)
    shop_car = user_dict['shop_car']
    if not shop_car:
        msg = f"账户[{login_user}]未添加购物车。"
        ATM_logger.info(msg)
        return False, msg
    return True, shop_car
Exemplo n.º 3
0
def repay_interface(login_user, money):
    user_dict = db_handler.check(login_user)
    user_dict['balance'] += money
    flow = f"{common.gettime()}: {login_user} 还款成功,还款金额{money},账户余额{user_dict['balance']}."
    user_dict['flow'].append(flow)
    ATM_logger.info(flow)
    db_handler.save(user_dict)
    return True, flow
Exemplo n.º 4
0
def transfer_interface(login_user, to_user, money):
    to_user_dict = db_handler.check(to_user)
    if to_user_dict:
        login_user_dict = db_handler.check(login_user)
        if login_user_dict['balance'] >= money:
            login_user_dict['balance'] -= money
            to_user_dict['balance'] += money
            login_user_flow = f"{common.gettime()}: 转账成功,{login_user}给{to_user} 转账,金额为{money},账户余额为{login_user_dict['balance']}."
            login_user_dict['flow'].append(login_user_flow)
            to_user_flow = f"{common.gettime()}: 转账成功,{to_user}收到{login_user} 转账,金额为{money},账户余额为{to_user_dict['balance']}."
            to_user_dict['flow'].append(to_user_flow)
            ATM_logger.info(login_user_flow)
            db_handler.save(login_user_dict)
            db_handler.save(to_user_dict)
            return True, login_user_flow
        else:
            flow = f"转账失败,余额不足。,账户余额为{login_user_dict['balance']}."
            ATM_logger.info(flow)
            return False, flow
    else:
        return False, f"{login_user}{to_user}不存在,请重新输入。"
Exemplo n.º 5
0
def add_shop_car_interface(login_user, name, price):
    user_dict = db_handler.check(login_user)
    shop_car = user_dict['shop_car']
    if name in shop_car:
        shop_car[name][1] += 1

    else:
        add_product = {name: [price, 1]}
        shop_car.update(add_product)
    user_dict['shop_car'] = shop_car
    flow = f"{common.gettime()}: 商品[{name}]已加入购物车。"

    ATM_logger.info(flow)
    db_handler.save(user_dict)
    return True, flow
Exemplo n.º 6
0
def lock_interface(login_user, username):
    user_dict = db_handler.check(username)
    if user_dict:
        choice = input('1. 冻结账户。/n2. 解锁账户。 /n请选择:')
        if choice == '1':
            user_dict['locked'] = True
            flow = f"{username}账户已冻结。"
            user_dict['flow'].append(flow)
        else:
            user_dict['locked'] = False
            flow = f"{username}账户已解冻。"
            user_dict['flow'].append(flow)
        db_handler.save(user_dict)
        return True, flow
    return False, f"用户不存在,请重新输入:"
Exemplo n.º 7
0
def withdraw_interface(login_user, money):
    #手续费5%
    money2 = float(money) * 1.05
    user_dict = db_handler.check(login_user)
    balance = user_dict["balance"]
    if float(balance) >= money2:
        user_dict["balance"] -= money2
        flow = f"{common.gettime()}: {login_user} 提现成功,提现金额为{money},余额为{user_dict.get('balance')}, 本次手续费为{money2-float(money)}"
        user_dict['flow'].append(flow)
        ATM_logger.info(flow)
        db_handler.save(user_dict)
        return True, flow
    flow = f"{login_user} 提现失败,余额不足,余额为{user_dict.get('balance')},请重新输入提现金额。"
    ATM_logger.warning(flow)
    return False, flow
Exemplo n.º 8
0
def login_interface(username, password):
    user_dict = db_handler.check(username)
    if user_dict:
        if user_dict['locked']:
            return False, f"{username}账户已冻结,无法登录"
        password = common.get_pwd_md5(password)
        if password == user_dict.get('password'):
            msg=f"{username} 登录成功。"
            ATM_logger.info(msg)
            return True, msg
        msg=f"{username} 登录失败,密码不正确,请重新输入"
        ATM_logger.error(msg)
        return False, msg
    msg = f"账户{username}不存在。"
    # ATM_logger.error(msg)
    return False, msg
Exemplo n.º 9
0
def pay_shop_car_interface(login_user):
    cost = 0
    user_dict = db_handler.check(login_user)
    if user_dict['shop_car']:
        for product in user_dict['shop_car'].values():
            print(product)
            cost += int(product[0]) * int(product[1])
        if user_dict['balance'] >= cost:
            user_dict['balance'] -= cost
            user_dict['shop_car'] = {}
            flow = f"{common.gettime()}: [{login_user}]已支付金额[{cost}]"
            db_handler.save(user_dict)
            ATM_logger.info(flow)
            return True, flow
        return False, f"余额不足,无法支付。"
    else:
        return False, f"未购买任何商品。"
Exemplo n.º 10
0
def register_interface(username, password, balance=15000):
    user_dict = db_handler.check(username)
    if user_dict:
        msg=f"{username} 用户已经存在,请重新输入用户名:"
        ATM_logger.error(msg)
        return False, msg
    else:
        password = common.get_pwd_md5(password)
        user_dict = {
            "username": username,
            "password": password,
            'balance': balance,
            'flow': [],  # 用户流水
            'shop_car': {},
            'locked': False,  # 用户是否被冻结
        }
        msg=f"{username} 用户创建成功"
        db_handler.save(user_dict)
        # ATM_logger.info(msg)
        return True, msg
Exemplo n.º 11
0
def check_balance_interface(username):
    user_dict = db_handler.check(username)
    return user_dict.get('balance')
Exemplo n.º 12
0
def check_flow_interface(login_user):
    user_dict = db_handler.check(login_user)
    flow_list = user_dict['flow']
    return flow_list