示例#1
0
    def put(self, id):
        merchant = Merchant.objects.with_id(id)
        if not merchant:
            return Ans(-1, msg='商户不存在')

        merchant.status = 2
        merchant.settled_time = time.time()

        # 将商户联系人设为管理员
        # 联系人不在自动创建
        user = User.objects.filter(phone=merchant.phone).first()
        if not user:
            user = User(
                phone=merchant.phone,
                name=merchant.contacts,
                gender=1,
            )
            user.pwd = user.hash_password('123456')
            user.nickname = user.init_nick_name()

        user_merchant = UserMerchant(
            merchant_id=merchant.get_id(),
            merchant_name=merchant.name,
            name=merchant.contacts,
            roles=[1],
        )

        user.merchants.append(user_merchant)
        user.save()

        cache.delete('merchant-{}-employees'.format(id))  # 删除商户下的员工缓存
        return Ans(0)
示例#2
0
文件: user.py 项目: bbbaiT/house
    def post(self):
        req = request.get_json()
        pwd = req.get('pwd', None)

        if pwd is None or pwd == "":
            return Ans(-1, msg='密码不得为空')

        if req.get('name', None) is None or req.get('gender', None) is None:
            return Ans(-1, msg='姓名与性别不得为空')

        if not re.match('^1\d{10}$', req.get('phone')):
            return Ans(-1, msg='手机号码格式错误')
        if req.get('email', None):
            if not re.match(
                    '^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+){0,4}@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+){0,4}$',
                    req.get('email')):
                return Ans(-1, msg='邮箱格式错误')

        user = User(
            phone_area=req.get('phone_area', None),
            phone=req.get('phone', None),
            name=req.get('name', None),
            email=req.get('email', None),
            icon=req.get('icon', None),
            signature=req.get('signature', None),
            gender=req.get('gender', None),
            province=req.get('province', None),
            city=req.get('city', None),
            country=req.get('country', None),
        )
        user.pwd = user.hash_password(pwd)
        user.nickname = user.init_nick_name()
        user.save()

        return Ans(0, data=user.to_json())
示例#3
0
文件: admin.py 项目: bbbaiT/house
    def get(self, id):
        merchant = Merchant.objects.with_id(id)
        if not merchant:
            return Ans(-1, msg='商户不存在')

        cache_data = cache.get('merchant-{}-employees'.format(id))
        if cache_data:
            return Ans(0, data=cache_data)

        data = []
        users = User.objects.all()
        for user in users:
            for m in user.merchants:
                user_merchant = {}
                if m.merchant_id == id:
                    user_merchant['id'] = user.get_id()
                    user_merchant['name'] = user.name
                    user_merchant['phone'] = user.phone
                    user_merchant['roles'] = m.roles
                    user_merchant['position'] = m.position
                    user_merchant['logo'] = m.logo
                    user_merchant['brief'] = m.brief
                    data.append(user_merchant)

        cache.set('merchant-{}-employees'.format(id), data)
        return Ans(0, data=data)
示例#4
0
    def get(self, id):
        merchant = Merchant.objects.with_id(id)

        if not merchant:
            return Ans(-1, msg='商户不存在')

        return Ans(0, data=merchant.to_json())
示例#5
0
文件: admin.py 项目: bbbaiT/house
    def post(self, id):
        req = request.get_json()
        merchant = Merchant.objects.with_id(id)
        phone = req.get('phone', None)
        if not merchant or not phone:
            return Ans(-1, msg='参数错误')

        user_merchant = UserMerchant(
            merchant_id=merchant.get_id(),
            merchant_name=merchant.name,
            name=merchant.contacts,
            roles=req.get('roles', None),
            position=req.get('position', None),
            logo=req.get('logo', None),
            brief=req.get('brief', None),
        )

        user = User.objects.filter(phone=phone).first()
        if not user:
            user = User(
                phone=phone,
                name=req.get('name', None),
                gender=1,
            )
            user.pwd = user.hash_password('123456')
            user.nickname = user.init_nick_name()

        user.merchants.append(user_merchant)
        user.save()
        cache.delete('merchant-{}-employees'.format(id))
        return Ans(0)
示例#6
0
    def delete(self, id):
        merchant = Merchant.objects.with_id(id)
        if not merchant:
            return Ans(-1, msg='参数错误')
        if not self.filterUser(merchant):
            return Ans(-1, msg='无权限')
        merchant.delete()

        return Ans(0)
示例#7
0
    def delete(self):
        req = request.get_json()
        action_type = int(req.get('a', 1))
        object_id = req.get('object_id', None)

        action = Action.objects(user=g.user, action_type=action_type, object_id=object_id, is_del=False).first()
        if not action:
            return Ans(-1, msg='不存在该记录')
        action.is_del = True
        action.save()
        return Ans(0)
示例#8
0
    def get(self):
        # 管理员返回所有,不是管理员返回名下商户
        user = g.user
        cache_data = cache.get('merchant_list_{}'.format(user.get_id()))
        if cache_data:
            return Ans(0, data=cache_data)
        if user.is_admin:
            merchant = Merchant.objects.all()
        else:
            merchant = Merchant.objects.filter(create_user=user)
        merchant_list = [data.to_json() for data in merchant]

        cache.set('merchant_list_{}'.format(user.get_id()), merchant_list)
        return Ans(0, data=merchant_list)
示例#9
0
    def put(self, id):
        req = request.get_json()
        merchant = Merchant.objects.with_id(id)
        if not merchant:
            return Ans(-1, msg='商户不存在')

        if not self.filterUser(merchant):
            return Ans(-1, msg='无权限')

        for key in req.keys():
            merchant[key] = req[key]
        merchant.update_time = time.time()
        merchant.save()
        return Ans(0, data=merchant.to_json())
示例#10
0
文件: user.py 项目: bbbaiT/house
    def post(self):
        req = request.get_json()
        phone = req.get('phone', None)
        pwd = req.get('pwd', None)

        if pwd is None or pwd == "" or phone is None:
            return Ans(-1, msg='用户名或密码不得为空')

        user = User.objects(phone=phone).first()
        if not user or not user.verify_password(pwd):
            return Ans(-1, msg='用户名或密码不正确')

        user.token = user.generate_auth_token()
        user.save()
        return Ans(0, data={'token': user.token})
示例#11
0
文件: house.py 项目: bbbaiT/house
    def put(self, id):
        req = request.get_json()
        house = House.objects.with_id(id)

        if not house:
            return Ans(-1, msg='商户不存在')

        if not self.filterUser(house):
            return Ans(-1, msg='无权限')

        for key in req.keys():
            house[key] = req[key]
        house.update_time = time.time()
        house.save()
        return Ans(0, data=house.to_json())
示例#12
0
文件: admin.py 项目: bbbaiT/house
    def delete(self, id):
        req = request.get_json()
        merchant = Merchant.objects.with_id(id)
        user_id = req.get('user_id', None)

        if not merchant:
            return Ans(-1, msg='商户不存在')

        user = User.objects.with_id(user_id)
        for m in user.merchants:
            if m.merchant_id == id:
                user.merchants.remove(m)
        user.save()

        cache.delete('merchant-{}-employees'.format(id))
        return Ans(0)
示例#13
0
文件: house.py 项目: bbbaiT/house
    def post(self):
        req = request.get_json()
        user = g.user
        prices = req.get('prices', None)
        addresses = req.get('address', None)
        merchant_id = req.get("merchant_id", None)
        merchant = Merchant.objects.with_id(merchant_id)
        if merchant is None:
            return Ans(-1, '商户不存在')

        # 商户中有管理员权限
        if not user.HasMerchantRole(merchant_id, 1):
            return Ans(-1, '无权限')

        house = House(
            merchant=merchant,
            create_user=user,
            build_merchant_id=req.get("build_merchant_id", None),
            name=req.get("name", None),
            tags=req.get("tags", []),
            brief=req.get("brief", None),
            category=req.get('category', None),
            sales_status=req.get('sales_status', None),
            renovation=req.get('renovation', None),
            build_area=req.get('build_area', None),
            house_hold=req.get('house_hold', None),
        )

        if prices is not None:
            for price in prices:
                house_price = HousePrice(
                    country=price.get('country', None),
                    price=price.get('price', None),
                    price_min=price.get('price_min', None),
                    price_max=price.get('price_max', None),
                )
                house.prices.append(house_price)
        if addresses is not None:
            for address in addresses:
                house_add = HouseAddress(country=address.get('country', None),
                                         province=address.get(
                                             'province', None))
                house.address.append(house_add)
        house.save()

        return Ans(0, data=house.to_json())
示例#14
0
    def post(self):
        req = request.get_json()
        object_id = req.get('object_id', None)

        if object_id:
            if not House.objects.with_id(object_id) and not Merchant.objects.with_id(object_id):
                return Ans(-1, msg='对象不存在')

        if Action.objects(user=g.user, action_type=req.get('action_type', None), object_id=object_id, is_del=False).first():
            return Ans(-1, msg='记录已存在')

        action = Action(
            user=g.user,
            action_type=req.get('action_type', None),
            object_id=object_id,

            addition=req.get('addition', None),
        ).save()
        return Ans(0, data=action.to_json())
示例#15
0
文件: auth.py 项目: bbbaiT/house
    def wrapper(*args, **kwargs):
        token_req = request.headers.get('Token')
        if token_req is None:
            return Ans(-1, msg='请登录后操作')
        try:
            s = Serializer(secret_key=SECRET_KEY)
            data = s.loads(token_req)
            if data['id'] == 'None':
                return Ans(-1, '请登录后操作')
            user = User.objects(id=data['id']).first()
            g.user = user
        except SignatureExpired:
            # token正确,但过期了
            return Ans(-1, msg='请重新登录')
        except BadSignature:
            # token错误
            return Ans(-1, msg='请登录后操作')

        return func(*args, **kwargs)
示例#16
0
文件: house.py 项目: bbbaiT/house
    def get(self):
        '''
        不加p参数,默认第一页,不加s参数,默认一页10个
        :return:
        '''
        try:
            page = int(request.args.get('p', 1))
            size = int(request.args.get('s', 10))
        except:
            return Ans(-1, msg='参数错误')

        cache_data = cache.get('houses:{}-{}'.format(page, size))
        if cache_data:
            return Ans(0, data=cache_data, count=House.objects.count())

        house_list = House.objects.all()[(page - 1) * size:page * size]
        data = [house.to_json() for house in house_list]

        cache.set('houses:{}-{}'.format(page, size), data)
        return Ans(0, data=data, count=House.objects.count())
示例#17
0
    def get(self, id):
        merchant = Merchant.objects.with_id(id)
        if not merchant:
            return Ans(-1, msg='商户不存在')

        try:
            page = int(request.args.get('p', 1))
            size = int(request.args.get('s', 10))
        except:
            return Ans(-1, msg='参数错误')

        cache_data = cache.get('merchant_house:{}-{}'.format(page, size))
        if cache_data:
            return Ans(0, data=cache_data)

        house_list = House.objects.filter(merchant=merchant)[(page - 1) *
                                                             size:page * size]

        data = [house.to_json() for house in house_list]

        cache.set('merchant_house:{}-{}'.format(page, size), data)
        return Ans(0, data=data)
示例#18
0
    def post(self):
        req = request.get_json()
        user = g.user

        merchant = Merchant(
            create_user=user,
            is_self=req.get('is_self', False),
            name=req.get('name', None),
            brief=req.get('brief', None),
            logo=req.get('logo', None),
            htype=req.get('htype', 0),
            service=req.get('service', 0),
            status=req.get('status', ),
            contacts=req.get('contacts', user.name),
            phone=req.get('phone', user.phone),
        ).save()
        cache.delete('merchant_list_{}'.format(user.get_id()))
        return Ans(0, data=merchant.to_json())
示例#19
0
    def get(self):
        action_type = int(request.args.get('a', 1))

        action_list = Action.objects.filter(user=g.user, action_type=action_type, is_del=False)
        data = [action.to_json() for action in action_list]
        return Ans(0, data=data)
示例#20
0
文件: house.py 项目: bbbaiT/house
 def get(self, id):
     house = House.objects.with_id(id)
     if not house:
         return Ans(-1, msg='房源不存在')
     return Ans(0, data=house.to_json())
示例#21
0
文件: user.py 项目: bbbaiT/house
 def get(self):
     user = g.user
     return Ans(0, data=user.to_json())
示例#22
0
文件: auth.py 项目: bbbaiT/house
 def wrapper(*args, **kwargs):
     if not g.user.is_admin:
         return Ans(-1, msg='无权限,请联系管理员')
     return func(*args, **kwargs)
示例#23
0
文件: house.py 项目: bbbaiT/house
 def delete(self, id):
     house = House.objects.with_id(id)
     house.delete()
     return Ans(0)