Esempio n. 1
0
def verify_bal(admin_un, un, bal):
    user_dict = db_handler.get_user_data(un)
    user_dict['balance'] = bal
    db_handler.save_user_data(un, user_dict)
    msg = f'管理员{admin_un}将用户{un}的余额修改为{bal}。'
    admin_logger.info(msg)
    return True, msg
Esempio n. 2
0
def clear_shopping_cart(un):
    user_dict = db_handler.get_user_data(un)
    user_dict['shopping_cart'] = {}
    db_handler.save_user_data(un, user_dict)
    msg = f'用户{un}清空购物车。'
    shop_logger.info(msg)
    return True, msg
Esempio n. 3
0
def frozen_acc(admin_un, frozen_un):
    frozen_user_dict = db_handler.get_user_data(frozen_un)
    frozen_user_dict['locked'] = True
    db_handler.save_user_data(frozen_un, frozen_user_dict)
    msg = f'用户{frozen_un}已被管理员{admin_un}冻结'
    admin_logger.info(msg)
    return True, msg
Esempio n. 4
0
def check_bank_details(un):
    user_dict = db_handler.get_user_data(un)
    detail_list = user_dict['bank_details']
    if not detail_list:
        msg = f'用户{un}没有银行流水信息。'
        bank_logger.info(msg)
        return False, msg, []
    else:
        msg = f'用户查看银行流水。'
        bank_logger.info(msg)
        return True, msg, detail_list
Esempio n. 5
0
def transfer(un, target_un, cash):
    user_dict = db_handler.get_user_data(un)
    bal_float = float(user_dict['balance'])
    cash_float = float(cash)
    if bal_float < cash_float:
        msg = f'用户{un}余额不足,余额为{bal_float},转账失败。'
        bank_logger.warn(msg)
        return False, msg
    else:
        bal_float -= cash_float
        user_dict['balance'] = bal_float
        db_handler.save_user_data(un, user_dict)

        target_user_dict = db_handler.get_user_data(target_un)
        target_user_dict['balance'] += cash_float
        db_handler.save_user_data(target_un, target_user_dict)
        msg = f'用户{un}向用户{target_un}转账金额{cash_float},余额为{bal_float},转账成功。'
        bank_logger.info(msg)
        add_bank_details(un, msg)
        return True, msg
Esempio n. 6
0
def repay(un, cash):
    user_dict = db_handler.get_user_data(un)
    bal_float = float(user_dict['balance'])
    cash_float = float(cash)
    bal_float += cash_float
    user_dict['balance'] = bal_float
    db_handler.save_user_data(un, user_dict)
    msg = f'用户{un}还款金额{cash_float},余额为{bal_float},还款成功。'
    bank_logger.info(msg)
    add_bank_details(un, msg)
    return True, msg
Esempio n. 7
0
def check_admin(un):
    user_dict = db_handler.get_user_data(un)

    if not user_dict['is_admin']:
        msg = f'警告,普通用户{un}尝试使用管理员功能,强制退出。'
        admin_logger.info(msg)
        return False, msg
    else:
        msg = f'管理员{un}开始使用管理员功能。'
        admin_logger.info(msg)
        return True, msg
Esempio n. 8
0
def save_shopping_cart(un, shopping_cart_dict):
    user_dict = db_handler.get_user_data(un)
    user_shopping_cart_dict = user_dict['shopping_cart']
    for each_key, each_value in shopping_cart_dict.items():
        if each_key not in user_shopping_cart_dict:
            user_shopping_cart_dict[each_key] = each_value
        else:
            user_shopping_cart_dict[each_key]['count'] += each_value['count']
    user_dict['shopping_cart'] = user_shopping_cart_dict
    db_handler.save_user_data(un, user_dict)
    msg = f'用户{un}保存购物车成功。'
    shop_logger.info(msg)
    return True, msg
Esempio n. 9
0
def login(un, pw):
    user_dict = db_handler.get_user_data(un)
    pw_md5 = common.convert_to_md5(pw)
    if user_dict['locked']:
        msg = f'用户{un}已被锁定,禁止登录,强制退出。'
        user_logger.warn(msg)
        return None, msg
    if pw_md5 == user_dict['password']:
        msg = f'用户{un}登陆成功。'
        user_logger.info(msg)
        return True, msg
    else:
        msg = f'用户{un}的密码错误。'
        user_logger.warn(msg)
        return False, msg
Esempio n. 10
0
def get_cash(un, cash):
    user_dict = db_handler.get_user_data(un)
    bal_float = float(user_dict['balance'])
    cash_float = float(cash)
    fee_float = cash_float * 0.05  # 手续费
    total_float = cash_float + fee_float  # 总额
    if bal_float < total_float:
        msg = f'用户{un}余额不足,手续费为{fee_float},余额为{bal_float},提现失败。'
        bank_logger.warn(msg)
        return False, msg
    else:
        bal_float -= total_float
        user_dict['balance'] = bal_float
        db_handler.save_user_data(un, user_dict)
        msg = f'用户{un}提取金额{cash_float},手续费为{fee_float},余额为{bal_float},提现成功。'
        bank_logger.info(msg)
        add_bank_details(un, msg)
        return True, msg
Esempio n. 11
0
def checkout(un):
    user_dict = db_handler.get_user_data(un)
    bal = user_dict['balance']
    shopping_cart_dict = user_dict['shopping_cart']
    total_cost = 0
    for each_value in shopping_cart_dict.values():
        total_cost += each_value['count'] * each_value['price']
    if bal < total_cost:
        msg = f'用户{un}余额不足,总共消费{total_cost},余额为{bal},结账失败。'
        bank_logger.warn(msg)
        return False, msg
    else:
        bal -= total_cost
        user_dict['balance'] = bal
        user_dict['shopping_cart'] = {}
        db_handler.save_user_data(un, user_dict)
        msg = f'用户{un}总共消费{total_cost},余额为{bal},结账成功。'
        bank_logger.info(msg)
        add_bank_details(un, msg)
        return True, msg
Esempio n. 12
0
def add_bank_details(un, msg):
    user_dict = db_handler.get_user_data(un)
    user_dict['bank_details'].append(msg)
    db_handler.save_user_data(un, user_dict)
Esempio n. 13
0
def check_bal(un):
    user_dict = db_handler.get_user_data(un)
    bal = user_dict['balance']
    msg = f'用户{un}的余额为{bal}'
    bank_logger.info(msg)
    return True, msg
Esempio n. 14
0
def get_shopping_cart_dict(un):
    user_dict = db_handler.get_user_data(un)
    msg = f'用户{un}查看购物车。'
    shop_logger.info(msg)
    return user_dict['shopping_cart']