예제 #1
0
파일: bank.py 프로젝트: fengfumin/maple
def repay_lib(name, account):
    user_dic = db_handler.select_user(name)
    user_dic['balance'] += account
    user_dic['bankflow'].append('%s还款%s元' % (name, account))
    db_handler.save_user(user_dic)
    bank_logger.info('%s还款%s元' % (name, account))
    return True, '还款成功'
예제 #2
0
def add_group_interface(name):
    user = select_user(name)
    if user:
        group_list = get_group_chat_list()
        print("群列表")
        print(group_list)

        group_name = input("输入群名:")

        group = select_group_chat(group_name)
        if group is not None:
            group.add_user(name)
            save_group_chat(group)
            user.add_group_chat(group_name)
            save_user(user)
            user_logger.info('%s 加入了%s' % (name, group_name))
        else:
            flg = input("是否建群? 1 yes, 2 no")
            if flg == '1':
                from lib.GroupChat import GroupChat
                group = GroupChat(group_name)
                group.add_user(name)
                save_group_chat(group)
                user.add_group_chat(group_name)
                save_user(user)
            elif flg == '2':
                pass
            else:
                pass
예제 #3
0
파일: bank.py 프로젝트: fengfumin/maple
def pay_lib(name, cost):
    user_dic = db_handler.select_user(name)
    if user_dic['balance'] > cost:
        user_dic['balance'] -= cost
        user_dic['bankflow'].append('%s购物支付了%s' % (name, cost))
        db_handler.save_user(user_dic)
        bank_logger.info('%s购物支付了%s' % (name, cost))
        return True, '支付成功'
    else:
        return False, '余额不足'
예제 #4
0
파일: bank.py 프로젝트: fengfumin/maple
def withdraw_lib(name, account):
    user_dic = db_handler.select_user(name)
    if user_dic['balance'] > account:
        user_dic['balance'] -= account
        user_dic['bankflow'].append('%s取款:%s' % (name, account))
        db_handler.save_user(user_dic)
        bank_logger().info('取款:%s' % account)
        return True, '取款功能'
    else:
        return False, '您的余额不足'
예제 #5
0
def register_interface(name, password):
    user = select_user(name)
    if user:
        return False, '用户已经存在'
    else:
        from lib.User import User
        new_user = User(name, password)
        save_user(new_user)
        user_logger.info('%s 注册了' % name)
        return True, '注册成功'
예제 #6
0
def unlock():
    print('解锁账户')
    name = input('请输入你要解锁的账户名(q退出)>>>:').strip()
    if name == 'q': return
    user_dic = db_handler.select_user(name)
    if user_dic:
        if user_dic['locked'] == False:
            print('该账户已经解锁')
            return
        else:
            user_dic['locked'] = False
            db_handler.save_user(user_dic)
            print('该账户解锁成功')
            return
    else:
        print('账户名不存在')
예제 #7
0
def lock():
    print('锁定账户')
    name = input('请输入你要锁定的账户名(q退出)>>>:').strip()
    if name == 'q': return
    user_dic = db_handler.select_user(name)
    if user_dic:
        if user_dic['locked'] == True:
            print('该账户已经锁定')
            return
        else:
            user_dic['locked'] = True
            db_handler.save_user(user_dic)
            print('该账户锁定成功')
            return
    else:
        print('账户名不存在')
예제 #8
0
def add_friend_interface(name):
    user = select_user(name)
    if user:
        users_list = get_user_list()
        print("用户列表")
        print(users_list)
        friend_name = input('输入朋友姓名')
        if friend_name in users_list:
            user.add_friend(friend_name)
            save_user(user)
            friend = select_user(friend_name)
            friend.add_friend(name)
            save_user(friend)

            return True, '添加成功'
        else:
            return False, '没有该用户'
예제 #9
0
파일: user.py 프로젝트: fengfumin/maple
def register_lib(name, password):
    user_dic = db_handler.select_user(name)
    if user_dic:
        return False, '账户已存在'
    else:
        user_dic = {
            'name': name,
            'password': password,
            'locked': False,
            'balance': 2000,
            'credit': 2000,
            'bankflow': []
        }
        db_handler.save_user(user_dic)
        user_shop = {'name': name, 'shoppingcart': {}}
        db_handler.save_user_shop(user_shop)
        user_logger.info('%s注册成功' % name)
        return True, '注册成功'
예제 #10
0
파일: bank.py 프로젝트: fengfumin/maple
def transfer_lib(from_name, to_name, account):
    if from_name == to_name:
        return False, '不能给自己转账'
    to_dic = db_handler.select_user(to_name)
    if to_dic:
        from_dic = db_handler.select_user(from_name)
        if account > from_dic['balance']:
            return False, '你的余额不足'
        else:
            from_dic['balance'] -= account
            from_dic['bankflow'].append('您向%s转账%s元' %
                                        (to_dic['name'], account))
            to_dic['balance'] += account
            to_dic['bankflow'].append('您收到%s转账%s元' %
                                      (from_dic['name'], account))
            db_handler.save_user(from_dic)
            db_handler.save_user(to_dic)
            bank_logger.info('向%s转账%s元' % (to_dic['name'], account))
            return True, '转账成功'
    else:
        return False, '对方账户不存在'
예제 #11
0
파일: bank.py 프로젝트: fengfumin/maple
def change_password_lib(name, pwd):
    user_dic = db_handler.select_user(name)
    user_dic['password'] = pwd
    db_handler.save_user(user_dic)
    return True, '密码修改成功'
예제 #12
0
파일: user.py 프로젝트: fengfumin/maple
def lock_user(name):
    user_dic = db_handler.select_user(name)
    user_dic['locked'] = True
    db_handler.save_user(user_dic)
예제 #13
0
def un_lock_user_interface(name):
    user = select_user(name)
    if user:
        user.unlock()
        save_user(user)
        user_logger.info('%s解锁了' % name)
예제 #14
0
def lock_user_interface(name):
    user = select_user(name)
    if user:
        user.lock()
        save_user(user)
        user_logger.info('%s被锁定了' % name)