def post(self): location = self.get_argument('location') lng_lat = self.get_argument("lng_lat") geohash = generate_geohash(lng_lat) self.db.Users.update({"_id": ObjectId(self.user_id)}, {"$set": {"lng_lat": lng_lat, "geohash": geohash, "location": location}}) # 清除缓存 self.clear_cache("UserInfo:%s" % self.user_id) return self.write_json({"errno": 0, "msg": "success"})
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)
def post(self): kv = {k: ''.join(v) for k, v in self.request.arguments.iteritems()} num = kv.pop('num') target = kv.pop('target') community = self.db.Goods_Community.find_one({'name': target}) users = {} for k in kv: s = k.split('_') if not users.has_key(s[1]): users[s[1]] = {} users[s[1]][s[0]] = kv[k] for user in users: _t = int(time.time()) _lng_lat = community['lng_lat'] # TODO au = self.db.User.insert({ "device_id": None, "phone": '13000000000', #TODO "nickname": users[user]['name'], "avatar": users[user]['avatar'], "location": u'详细地址', #TODO "sex": users[user]['sex'], "age": random.randint(16, 36), #TODO "email": '*****@*****.**', #TODO "lng_lat": _lng_lat, "geohash": generate_geohash(_lng_lat), "ftag": [], "level": 0, "create_at": _t, "last_update": _t }) user_id = str(au) self.user_id = user_id # 记录用户微信openid self.db.Wechat_extend.insert({ "user_id": user_id, "openid": 'adsfadsfasdfadfasf' }) #TODO #User_extend 用户拓展表,存放用户环信信息 _token = generate_access_token(user_id) self.db.User_extend.insert({ "user_id": user_id, "hx_username": '******', #TODO "hx_password": '******' }) #TODO self.write_json(users)
def post(self): buy_msg = self.get_argument('msg', '') u = self.get_cache_user_info(self.user_id) lng_lat = self.get_argument('lng_lat') or u.get('lng_lat', '') _geohash = generate_geohash(lng_lat) self.db.QtZone.insert({ 'type': 2, # 0 发布,1 评论,2 求购 'goods_id': '', # 空 'user_id': self.user_id, 'time': int(time.time()), 'buy_msg': buy_msg, "lng_lat": lng_lat, "geohash": _geohash, }) return self.write_json({'errno': 0, 'msg': 'success'})
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})
def post(self): type = self.get_argument('type') if type == 'goods_type': id = self.get_argument('id') #logo = self.get_argument('logo') name = self.get_argument('name') cat = self.get_argument('cat') seq = self.get_argument('seq') seq = int(seq) data = {'name': name, 'cat': cat, 'seq': seq} logo = self.request.files.get('logo') print(logo, ">>>>>>>>") if logo: logo = self.save_file_to_qiniu(logo[0]) data['logo'] = logo logo2 = self.request.files.get('logo2') if logo2: logo2 = self.save_file_to_qiniu(logo2[0]) data['logo2'] = logo2 self.db.Goods_Type.update({"_id": ObjectId(id)}, {'$set': data}) return self.redirect('/manager/goods/type/') if type == 'goods_community': id = self.get_argument('id') logo = self.get_argument('logo') name = self.get_argument('name') lng_lat = self.get_argument('lng_lat') desc = self.get_argument('desc') geohash = generate_geohash(lng_lat) self.db.Goods_Community.update({"_id": ObjectId(id)}, { '$set': { 'logo': logo, 'name': name, 'lng_lat': lng_lat, 'desc': desc, 'geohash': geohash } }) # return self.redirect('/manager/goods/community/') return self.write_json({ "errno": 0, "msg": "修改成功" }) return self.redirect('/manager/goods/type/')
def post(self): # 默认使用用户的位置,可以选择实时位置 goods_id = self.get_argument("id", '') goods_name = self.get_argument("title") goods_type = self.get_argument("goods_type") introduce = self.get_argument("introduce") price = self.get_argument("price") is_new = self.get_argument("is_new", 0) u = self.db.User.find_one({"_id": ObjectId(self.user_id)}) location = self.get_argument('location') or u['location'] lng_lat = self.get_argument('lng_lat') or u['lng_lat'] _geohash = generate_geohash(lng_lat) tag = self.get_argument("tag", '') file_count = int(self.get_argument('file_count', 0)) images = self.get_argument('images', '').split(',') can_pay_online = self.get_argument('can_pay_online', "0") self.attach = [] self.db.Goods.update({"_id": ObjectId(goods_id)}, {"$set": { "goods_name": goods_name, "goods_type": goods_type, "introduce": introduce, "price": price, "location": location, "lat_lng": lng_lat, "geohash": _geohash, "images": images, "can_pay_online": can_pay_online, "seller_id": self.user_id, "tag": [], "review": '0', # 0 刚发布未审核, 1审核通过 2不通过 3被举报 "status": '0', # 0:上架(默认),1:下架,2:归档(所有用户不可见) "last_update_at": int(time.time()), "is_new": is_new, } }) # 清除缓存 self.clear_cache("GoodsInfo:%s" % goods_id) self.write_json({"errno": 0, "msg": "success"})
def post(self): type = self.get_argument('type') if type == 'goods_type': #logo = self.get_argument('logo') logo = self.request.files.get('logo') if logo: logo = self.save_file_to_qiniu(logo[0]) logo2 = self.request.files.get('logo2') if logo2: logo2 = self.save_file_to_qiniu(logo2[0]) name = self.get_argument('name') cat = self.get_argument('cat') seq = self.get_argument('seq') seq = int(seq) self.db.Goods_Type.insert({ 'logo': logo, 'logo2': logo2, 'name': name, 'cat': cat, 'seq': seq }) return self.redirect('/manager/goods/type/') #return self.write_success(); elif type == 'goods_community': logo = self.get_argument('logo') name = self.get_argument('name') lng_lat = self.get_argument('lng_lat') desc = self.get_argument('desc') geohash = generate_geohash(lng_lat) self.db.Goods_Community.insert({ 'logo': logo, 'num': '0', 'name': name, 'lng_lat': lng_lat, 'desc': desc, 'geohash': geohash }) return self.redirect('/manager/goods/community/')
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)
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})
def post(self): # 默认使用用户的位置,可以选择实时位置 goods_name = self.get_argument("title") goods_type = self.get_argument("goods_type") introduce = self.get_argument("introduce") price = self.get_argument("price") is_new = self.get_argument("is_new", "0") u = self.get_cache_user_info(self.user_id) # hx = self.db.User_extend.find_one({"user_id": self.user_id}) location = self.get_argument('location') or u.get('location', '') lng_lat = self.get_argument('lng_lat') or u.get('lng_lat', '') _geohash = generate_geohash(lng_lat) tag = self.get_argument("tag", '') file_count = int(self.get_argument('file_count', 0)) images = self.get_argument('images', '').split(',') can_pay_online = self.get_argument('can_pay_online', "0") self.attach = [] #for f in range(file_count): # _file = self.request.files.get("pic%s" % f) # if bool(_file): # fname = _file[0]["filename"] # extn = os.path.splitext(fname)[1] # cname = str(uuid.uuid4()).replace("-", '') + extn # with open(PIC_PATH + cname, 'wb') as f: # f.write(_file[0]['body']) # self.attach.append(cname.strip()) goods_id = self.db.Goods.insert({ "goods_name": goods_name, "goods_type": goods_type, "introduce": introduce, "price": price, "location": location, "lng_lat": lng_lat, "community": '', "geohash": _geohash, "images": images, "can_pay_online": can_pay_online, "collect_count": 0, "seller_id": self.user_id, # "seller_nickname": u['nickname'], # "seller_hx_name": hx['hx_username'], # "seller_avatar": u['avatar'], "tag": [], "review": '0', # 0: 刚发布未审核, 1: 审核通过, 2: 不通过, 3: 被举报 "status": '0', # 0: 上架(默认), 1: 下架, 2: 归档(所有用户不可见) "is_new": is_new, 'is_global': '0', "last_update_at": int(time.time()), "create_at": int(time.time()) }) # 发布到趣淘圈 self.db.QtZone.insert({ 'type': 0, # 0 发布,1 评论,2 求购 'goods_id': goods_id, 'user_id': self.user_id, 'time': int(time.time()), 'buy_msg': '', "lng_lat": lng_lat, "geohash": _geohash, }) self.write_json({"errno": 0, "msg": "success"})