Exemplo n.º 1
0
def transfer_interface(to_name, from_name, balance):
    to_dic = handler.select(to_name)
    if to_dic:
        from_dic = handler.select(from_name)
        if from_dic['balance'] >= balance:
            to_dic['balance'] += balance
            from_dic['balance'] -= balance
            to_dic['bank_flow'].append('%s 向您转账 %s 元' % (from_name, balance))
            from_dic['bank_flow'].append('您向 %s 转账 %s 元' % (to_name, balance))
            user_log.info('%s 给 %s 转账 %s 元' % (from_name, to_name, balance))
            handler.save(to_dic)
            handler.save(from_dic)
            return True, '转账成功 %s 元' % balance
        return False, '余额不足'
    return False, '对方账户不存在'
Exemplo n.º 2
0
def login_interface(name, password):
    user_dic = handler.select(name)
    if user_dic:
        if password == user_dic['pwd']:
            return True, '%s 登录成功' % name
        else:
            return False, '密码错误'
    return False, '该用户不存在'
Exemplo n.º 3
0
def cost_interface(name, cost):
    dic = handler.select(name)
    if dic['balance'] >= cost:
        dic['balance'] -= cost
        dic['bank_flow'].append('购物消费 %s 元' % cost)
        user_log.info('购物消费 %s 元' % cost)
        return True, 'success'
    return False, 'fail'
Exemplo n.º 4
0
def shopping_interface(name, cost, shopping_cart):
    flg, msg = bank_inter.cost_interface(name, cost)
    if flg:
        user_dic = handler.select(name)
        user_dic['shopping_cart'] = shopping_cart
        handler.save(user_dic)
        return True, '购买成功,静待发货'
    return False, 'nothing'
Exemplo n.º 5
0
def repay_interface(name, balance):
    dic = handler.select(name)
    if dic:
        dic['balance'] += balance
        dic['bank_flow'].append('还款 %s 元' % balance)
        handler.save(dic)
        user_log.info('还款 %s 元' % balance)
        return True, '还款成功 %s 元' % balance
    return False, 'fail'
Exemplo n.º 6
0
def withdraw_interface(name, balance):
    dic = handler.select(name)
    money = balance * 1.05
    if dic['balance'] >= money:
        dic['balance'] -= money
        dic['bank_flow'].append('取款 %s 元' % balance)
        user_log.info('取款 %s 元' % balance)
        handler.save(dic)
        return True, '取款成功 %s 元' % balance
    return False, '余额不足'
Exemplo n.º 7
0
def register_interface(name, password):
    user_dic = handler.select(name)
    if user_dic:
        return False, '用户已存在'
    else:
        dic = {
            'name': name,
            'pwd': password,
            'balance': 20000,
            'locked': False,
            'bank_flow': [],
            'shopping_cart': {}
        }
        handler.save(dic)
        user_log.info('%s 注册成功' % name)
        return True, '%s 注册成功' % name
Exemplo n.º 8
0
def check_flow_interface(name):
    dic = handler.select(name)
    user_log.info('%s 查看了流水' % name)
    return dic['bank_flow']
Exemplo n.º 9
0
def check_balance_interface(name):
    dic = handler.select(name)
    return dic['balance']
Exemplo n.º 10
0
def unlock_interface(name):
    user_dic = handler.select(name)
    if user_dic:
        user_dic['locked'] = False
        handler.save(user_dic)
Exemplo n.º 11
0
def locked_interface(name):
    user_dic = handler.select(name)
    if user_dic:
        user_dic['locked'] = True
        handler.save(user_dic)
Exemplo n.º 12
0
def check_shopping_cart_interface(name):
    dic = handler.select(name)
    return dic['shopping_cart']