Пример #1
0
 def get(self):
     _lng_lat = self.get_argument("lng_lat", False)
     _geohash = geohash_neighbors(
         generate_geohash(_lng_lat)) if _lng_lat else {
             '$ne': None
         }
     goods_community = self.db.Goods_Community.find({'geohash': _geohash})
     data = []
     for i in filter_distance(goods_community, _lng_lat, settings.DISTANCE):
         i.pop('_id')
         data.append(i)
     return self.write_success(data)
Пример #2
0
    def get(self):
        search = self.get_argument('search', '')
        page = int(self.get_argument("page", 1))
        review = self.get_argument("review", None)
        page = 1 if page <= 1 else page
        if review == "1" or review == "2":
            review_query = review
        else:
            # 未审核或被举报
            review = "0"
            review_query = {'$in': ['0', '3']}
        sele = self.db.Goods.find({
            '$or': [{
                'goods_name': {
                    '$regex': search
                }
            }, {
                'seller_id': self.get_user_id(search)
            }],
            'review':
            review_query,
            'status': {
                '$ne': '2'
            }
        }).sort("_id", -1)
        num = sele.count()
        if page <= 1:
            sele = sele.limit(PAGE_LIMIT)
        else:
            sele = sele.skip((page - 1) * PAGE_LIMIT).limit(PAGE_LIMIT)
        data = self.fix_goods(sele)

        # 缓存community map
        community = []
        for goods in data:
            community.append(
                filter_distance(
                    self.db_find_all(
                        'Goods_Community',
                        {'geohash': geohash_neighbors(goods['geohash'])}),
                    goods['lng_lat'], DISTANCE))

        return self.render("review.html",
                           data=data,
                           community=json.dumps(community),
                           review=review,
                           tabs=REVIEW_TABS,
                           num=num,
                           pagination=self.pagination(num, page))
Пример #3
0
    def get(self):
        data = []
        _lng_lat = self.get_argument("lan_lat", '')
        last_count = int(self.get_argument('last_count', 0))  #上次加载到第几条

        _geohash = geohash_neighbors(
            generate_geohash(_lng_lat)) if _lng_lat else {
                '$ne': None
            }
        filter_data = self.db.QtZone.find({
            'geohash': _geohash
        }).sort('time', -1).skip(last_count).limit(settings.PAGE_LIMIT)
        #filter_data = self.db.QtZone.find().sort('time', -1).skip(last_count).limit(settings.PAGE_LIMIT)
        for item in filter_data:
            item['_id'] = str(item['_id'])
            item['goods_id'] = str(item['goods_id'])
            # 用户信息
            user_info = self.get_cache_user_info(item['user_id'])
            user_extends = self.db.User_extend.find_one(
                {'user_id': item['user_id']})
            if user_extends:
                user_info['hx_username'] = self.db.User_extend.find_one({
                    'user_id':
                    item['user_id']
                }).get('hx_username')

            item['user_info'] = user_info
            # 商品信息, type 0 发布,1评论,2 求购,求购时没有goods_id
            item['goods_info'] = {}
            if item['goods_id']:
                goods_info = self.get_cache_goods_info(item['goods_id'])
                goods_info['seller_name'] = self.get_cache_user_info(
                    goods_info['seller_id']).get('nickname')
                item['goods_info'] = goods_info
            # 获取评论信息
            if item.get('comment_id'):
                item['comment_id'] = str(item['comment_id'])
                comment_info = self.db.Goods_comment.find_one(
                    {'_id': ObjectId(item['comment_id'])})
                comment_info = comment_info or {}
                if comment_info:
                    comment_info.pop('_id')
                item['comment_info'] = comment_info
            item['buy_info'] = {'buy_msg': item['buy_msg']}
            item.pop('buy_msg')
            data.append(item)
        return self.write_json({'errno': 0, 'msg': 'success', 'data': data})
Пример #4
0
 def get(self):
     _lng_lat = self.get_argument("lng_lat", False)
     _goods = self.get_argument("keyword", '')
     last_count = int(self.get_argument('last_count', 0)) #上次加载到第几条
     data = []
     #print _goods
     #print type(_goods)
     query = {
         "goods_name": {'$regex': _goods},
         'status': '0',
         'review': {'$in': ['0', '1']}
     }
     if _lng_lat:
        query['geohash'] = geohash_neighbors(generate_geohash(_lng_lat))
     datas = self.db.Goods.find(query).skip(last_count).limit(settings.PAGE_LIMIT)
     if _lng_lat:
         datas = filter_distance(datas, _lng_lat, settings.DISTANCE)
     goods = Goods(self)
     for i in datas:
         goods.setdata(i)
         goods.strid()
         goods.import_seller_info()
         data.append(goods._data)
     self.write_success(data)
Пример #5
0
    def get(self):
        user_id = self.request.headers.get("userid", "").strip()
        if user_id:
            # 修改最后更新时间
            self.db.User.update({'_id': ObjectId(user_id)},
                                {'$set': {
                                    'last_update': int(time.time())
                                }})
            # 清除缓存
            self.clear_cache('UserInfo:%s' % user_id)

        _lng_lat = self.get_argument("lng_lat", '')
        _community = self.get_argument("community", '')
        goods_type = self.get_argument("goods_type", '')
        _geohash = geohash_neighbors(
            generate_geohash(_lng_lat)) if _lng_lat else {
                '$ne': None
            }
        last_count = int(self.get_argument('last_count', 0))  #上次加载到第几条
        # 过滤下架、删除商品的功能
        find_data = {'status': '0', 'review': {'$in': ['0', '1']}}
        if _community:
            find_data['community'] = _community
        else:
            find_data['geohash'] = _geohash

        if goods_type:
            find_data['goods_type'] = goods_type
        else:
            # 首页精选
            find_data['is_select'] = '1'

        data = []
        goods = Goods(self)
        # select = {k: 1 for k in ("lng_lat", "can_pay_online", "introduce", "goods_name", "images", "price", "seller_id")}
        if last_count > 0:
            last_count = last_count + 1

        goods_list = self.db.Goods.find(find_data).sort('last_update_at', -1)

        goods_list = goods_list.skip(last_count).limit(settings.PAGE_LIMIT)
        if _lng_lat:
            goods_list = filter_distance(goods_list, _lng_lat,
                                         settings.DISTANCE)

        if not len(list(goods_list)):
            # 当位置没有商品时,取全局推送的商品
            find_data = {
                'status': '0',
                'review': {
                    '$in': ['0', '1']
                },
                'is_global': '1',
                'is_select': '1'
            }
            #find_data = {'is_global': '1'}
            goods_list = self.db.Goods.find(find_data).sort(
                'last_update_at', -1)

            goods_list = goods_list.skip(last_count).limit(settings.PAGE_LIMIT)

        for item in goods_list:
            #item['images'] = [img+"?imageMogr2/thumbnail/140x140!" for img in item['images'] ]
            goods.setdata(item)
            goods.strid()
            goods.import_seller_info()
            goods.can_pay_online = goods.can_pay_online
            del goods.lng_lat
            data.append(goods._data)
        self.write_json({"errno": 0, "msg": "ok", "data": data})