Ejemplo n.º 1
0
def repay_interface(name, money):
    user_dic = db_hander.select(name)
    user_dic['balance'] += money
    user_dic['flow'].append('还款[%s¥]成功!' % money)
    logger.info('用户[%s]还款[%s¥]成功!' % (name, money))
    db_hander.save(user_dic)
    return '还款成功'
Ejemplo n.º 2
0
def check_user_interface(name):
    user_dic = db_hander.select(name)
    if user_dic:
        logger.warning('用户[%s]已存在,注册失败' % name)
        return False
    else:
        return True
Ejemplo n.º 3
0
def pay(name, money):
    user_dic = db_hander.select(name)
    if user_dic['balance'] >= money:
        user_dic['balance'] -= money
        user_dic['flow'].append('用户[%s]购物支出[%s¥]' % (name, money))
        logger.info('用户[%s]购物支出[%s¥]' % (name, money))
        db_hander.save(user_dic)
        return True, '购物成功'
Ejemplo n.º 4
0
def transfer_interface(from_user, to_user, money):
    from_user_dic = db_hander.select(from_user)
    to_user_dic = db_hander.select(to_user)
    if not to_user_dic:
        return False, '对方账户不存在'
    if from_user_dic['balance'] >= money:
        from_user_dic['balance'] -= money
        to_user_dic['balance'] += money
        from_user_dic['flow'].append('给用户[%s]转账[%s¥]成功' % (to_user, money))
        to_user_dic['flow'].append('收到用户[%s]转账[%s¥]' % (from_user, money))
        logger.info('用户[%s]给用户[%s]转账[%s¥]成功' % (from_user, to_user, money))
        db_hander.save(from_user_dic)
        db_hander.save(to_user_dic)
        return True, '转账成功!'
    else:
        logger.warning('用户[%s]给用户[%s]转账[%s¥]失败' % (from_user, to_user, money))
        return False, '余额不足,转账失败'
Ejemplo n.º 5
0
def login_interface(name, pwd):
    user_dic = db_hander.select(name)
    if not user_dic:
        return False, '用户不存在'
    md5_pwd = common.get_md5(pwd)
    if md5_pwd == user_dic['pwd']:
        logger.info('用户[%s]登录成功' % name)
        return True, '登录成功'
    else:
        return False, '密码错误'
Ejemplo n.º 6
0
def withdraw_interface(name, money):
    user_dic = db_hander.select(name)
    money2 = money * 1.05
    money3 = money * 0.05
    if user_dic['balance'] >= money2:
        user_dic['balance'] -= money2
        info = '用户[%s]提现[%s]¥,手续费:%s¥' % (name, money, money3)
        logger.info(info)
        user_dic['flow'].append(info)
        db_hander.save(user_dic)
        return True, info
    else:
        return False, '余额不足'
Ejemplo n.º 7
0
def pay_shoppingcar_interface(name):
    user_dic = db_hander.select(name)
    price_map = {'凤爪': 50, 'T-shirt': 150, 'macbook': 21800, 'iphoneX': 7000}
    # 商品价格:
    cost = 0
    for i in user_dic['shopping_car']:
        cost += price_map[i] * user_dic['shopping_car'][i]
    if user_dic['balance'] >= cost:
        user_dic['balance'] -= cost
        user_dic['flow'].append('支付[%s¥]成功' % cost)
        logger.info('用户[%s]支付[%s¥]成功' % (name, cost))
        user_dic['shopping_car'] = {}
        db_hander.save(user_dic)
        return True, '支付[%s¥]成功' % cost
    else:
        logger.warning('余额不足,支付失败')
        return False, '余额不足,支付失败'
Ejemplo n.º 8
0
 def get_obj_by_name(cls,name):
     return db_hander.select(name,cls.__name__.lower())
Ejemplo n.º 9
0
 def select(cls, username):
     obj = db_hander.select(cls, username)
     return obj
Ejemplo n.º 10
0
def select_t(name):
    return db_hander.select(name)
Ejemplo n.º 11
0
def check_balance_interface(name):
    user_dic = db_hander.select(name)
    logger.info('用户[%s]进行了余额查询操作' % name)
    return user_dic['balance']
Ejemplo n.º 12
0
def check_flow_interface(name):
    user_dic = db_hander.select(name)
    return user_dic['flow']
Ejemplo n.º 13
0
def add_shopping_car_interface(name, shopping_car):
    user_dic = db_hander.select(name)
    user_dic['shopping_car'] = shopping_car
    logger.info('用户[%s]添加商品至购物车成功')
    db_hander.save(user_dic)
    return True, '添加购物车成功'
Ejemplo n.º 14
0
def check_shop_interface(name):
    user_dic = db_hander.select(name)
    if user_dic:
        return True, user_dic['shopping_car']
    else:
        return False, '购物车已清空'
Ejemplo n.º 15
0
 def select(cls, name):
     return db_hander.select(cls, name)