def get(self): user_log.info("QueryShopInfoHandler GET.") shop_id = self.get_argument("sid", None) uid = self.get_current_user() if shop_id is None: user_log.error("Query recommend shop info protocol data error!") rep_json = {} rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR self.set_header("Content-type", "application/json") self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder)) return info = dao.queryShopInfo(shop_id) info['isFans'] = dao.isFans(uid, shop_id) if info is None: user_log.error("Query recommend shop info failed!") rep_json = {} rep_json["err"] = FD_ERR_USER_QUERY_RECOMMEND_SHOP_INFO_FAILED self.set_header("Content-type", "application/json") self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder)) return # Query shop fans count shop_fans_count = dao.queryShopFansCount(shop_id) info["fans"] = shop_fans_count # Query shop current customer count try: shop_customer_dict = {} url = CONFIG.FD_CHAT_SERVER + "/chat/shops/usernum?shop_id=" + shop_id request = HTTPRequest(url, "GET") http = AsyncHTTPClient() response = yield http.fetch(request) rep_json = json.loads(response.body) is_success = rep_json["is_success"] if is_success: shop_customer_dict = rep_json["shop_dict"] info["customers"] = shop_customer_dict[str(shop_id)] except Exception, e: user_log.warn("Query shop current customer count error!")
def get(self): user_log.info("QueryShopsByCategoryHandler GET.") category_id = self.get_argument("category", None) category_id = int(category_id) if category_id else None city_id = self.get_argument("city", None) city_id = int(city_id) if city_id else None longitude = self.get_argument("long", None) longitude = float(longitude) if longitude else None latitude = self.get_argument("lat", None) latitude = float(latitude) if latitude else None offset = self.get_argument("offset", None) offset = int(offset) if offset else None count = self.get_argument("count", None) count = int(count) if count else None if category_id is None or city_id is None or offset is None or count is None: user_log.error("Query shops by category protocol data error!") rep_json = {} rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR self.set_header("Content-type", "application/json") self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder)) return shop_id_list = geo.getShopList(city_id, category_id, longitude, latitude, offset, count) if shop_id_list is None: user_log.error("Query shop id list by geo info failed! City ID: %s, category ID: %s", city_id, category_id) rep_json = {} rep_json["err"] = FD_ERR_USER_QUERY_SHOP_ID_LIST_BY_GEO_FAILED self.set_header("Content-type", "application/json") self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder)) return # Select shops which are used nornally, shop service status is 2 shop_id_list = get_userful_shop(shop_id_list) # Query shop brief info shop_list_tmp = dao.queryShopBriefInfo(shop_id_list) if shop_list_tmp is None: user_log.error("Query shop brief info failed!") rep_json = {} rep_json["err"] = FD_ERR_USER_QUERY_SHOP_BRIEF_INFO_FAILED self.set_header("Content-type", "application/json") self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder)) return # Query shop fans count shop_fans_dict = dao.queryShopListFansCount(shop_id_list) #Query shop current customer count try: shop_customer_dict = {} shop_id_list_str = "" for shop_id in shop_id_list: shop_id_list_str = shop_id_list_str + "shop_id=" + str(shop_id) + "&" if shop_id_list_str: shop_id_list_str = shop_id_list_str[0:len(shop_id_list_str) - 1] url = CONFIG.FD_CHAT_SERVER + "/chat/shops/usernum?" + shop_id_list_str request = HTTPRequest(url, "GET") http = AsyncHTTPClient() response = yield http.fetch(request) rep_json = json.loads(response.body) is_success = rep_json["is_success"] if is_success: shop_customer_dict = rep_json["shop_dict"] except Exception, e: user_log.warn("Query shop current customer count error!")