public function location_list() { /** $_POST['lng'] = "119.025595"; $_POST['lat'] = "33.596043"; * */ if (!empty($_POST['lng']) && !empty($_POST['lat'])) { $distance = !empty($_POST['distance']) ? $_POST['distance'] : 5000; $lng = $_POST['lng']; $lat = $_POST['lat']; $num = empty($_POST['num']) ? 30 : $_POST['num']; // page size $prepage = empty($_POST['prepage']) ? 0 : $_POST['prepage']; $start = $prepage * $num + 0; $sql = "select id,name,xpoint as lng,ypoint as lat,index_img from " . DB_PREFIX . "supplier_location where openchatroom <> 1 and " . search_where_radius($distance, $lng, $lat, "location") . " limit " . $start . "," . $num; $sql_count = "select count(*) from " . DB_PREFIX . "supplier_location where openchatroom <> 1 and " . search_where_radius($distance, $lng, $lat, "location"); $result = $GLOBALS['db']->getAll($sql); $count = $GLOBALS['db']->getOne($sql_count); if ($result !== false) { $result = array('ret' => '0', 'location_list' => $result, 'count' => $count, 'page' => $prepage + 1); array_recursive($result, 'strval', true); echo json_encode($result); } else { echo json_encode(array('ret' => '157')); } } else { echo json_encode(array('ret' => '102')); } }
public function filter() { if (!empty($_POST['plat']) && $_POST['plat'] === APP_PLAT) { $plat = APP_PLAT; } if ($plat === APP_PLAT) { $city_id = $_POST['city_id']; } else { $city_id = $_COOKIE['deal_city']; } $lng = empty($_POST['lng']) ? '119.025595' : $_POST['lng']; $lat = empty($_POST['lat']) ? '33.596043' : $_POST['lat']; $ajax = !empty($_POST['ajax']) ? intval($_POST['ajax']) : 0; $area_id = !empty($_POST['area_id']) ? $_POST['area_id'] : 0; $subcate_id = !empty($_POST['subcate_id']) ? $_POST['subcate_id'] : 0; $cate_id = !empty($_POST['cate_id']) ? $_POST['cate_id'] : 0; // 如果有筛选条件 $sql = ""; $distance = !empty($_POST['distance']) ? $_POST['distance'] : 5000; $flag = 0; if ($area_id > 0) { // 如果有城市的选项 $sql .= " where verify = 1 and (area_id = " . $area_id . " "; if (!empty($_POST['lng']) && !empty($_POST['lat'])) { $lng = $_POST['lng']; $lat = $_POST['lat']; $sql .= " or " . search_where_radius($distance, $lng, $lat, "location") . ")"; } else { $sql .= ")"; } $flag = 1; $GLOBALS['tmpl']->assign("selected_area_id", $area_id); } else { if ($city_id > 1) { $sql .= " where verify = 1 and (city_id = " . $city_id . " "; if (!empty($_POST['lng']) && !empty($_POST['lat'])) { $lng = $_POST['lng']; $lat = $_POST['lat']; $sql .= " or " . search_where_radius($distance, $lng, $lat, "location") . ")"; } else { $sql .= ")"; } $flag = 1; } } if ($subcate_id > 1) { if ($flag == 1) { $sql .= " and cate_id = " . $subcate_id . " "; } else { $sql .= " where verify = 1 and cate_id = " . $subcate_id . " "; } $GLOBALS['tmpl']->assign("selected_subcate_id", $subcate_id); } else { if ($cate_id > 1) { if ($flag == 1) { $sql .= " and (cate_id in (select id from " . DB_PREFIX . "taoxin_cate where pid = " . $cate_id . ") or cate_id = " . $cate_id . ")"; } else { $sql .= " where verify = 1 and (cate_id in (select id from " . DB_PREFIX . "taoxin_cate where pid = " . $cate_id . ") or cate_id =" . $cate_id . ")"; $flag = 1; } $GLOBALS['tmpl']->assign("selected_cate_id", $cate_id); } } $num = empty($_POST['num']) ? 30 : $_POST['num']; // page size $prepage = empty($_POST['prepage']) ? 0 : $_POST['prepage']; $start = $prepage * $num + 0; $sql_count = "select count(*) from tb_taoxin " . $sql; $sql .= " order by sort,create_time desc limit " . $start . "," . $num; $sql = "select *,ROUND(SQRT(POW(ABS(X(location)-" . $lng . ")/0.001024*100,2)+POW(ABS(Y(location)-" . $lat . ")/0.000886*100,2))) AS `dis` from " . DB_PREFIX . "taoxin " . $sql; $count = $GLOBALS['db']->getOne($sql_count); $start = $prepage * $num + 0; $pageCount = intval($count / $num); if ($count % $num != 0) { $pageCount++; } //是否为最后一页 $is_last_page = 0; if ($start + $num >= $count) { $is_last_page = 1; } $result = $GLOBALS['db']->getAll($sql); foreach ($result as $index => $value) { $result[$index]['photos'] = empty($value['goods_photos']) ? array() : json_decode($value['goods_photos'], true); $result[$index]['create_time'] = date("Y-m-d H:i:s", $value['create_time']); $pcate = $GLOBALS['db']->getRow("select id,name from " . DB_PREFIX . "taoxin_cate where id=(select pid from " . DB_PREFIX . "taoxin_cate where id=" . $value['cate_id'] . ")"); if (intval($pcate['id']) == 1) { // 如果已经是一级分类,请求自己作为一级分类 $pcate = $GLOBALS['db']->getRow("select id,name from " . DB_PREFIX . "taoxin_cate where id=" . $value['cate_id']); } $result[$index]['pcate_name'] = $pcate['name']; $result[$index]['pcate_id'] = strval($pcate['id']); $result[$index]['uid'] = strval($value['uid']); $result[$index]['pl_uid'] = $GLOBALS['db']->getOne("select pl_user_id from " . DB_PREFIX . "user where id=" . $value['uid']); $result[$index]['city_id'] = strval($value['city_id']); $result[$index]['area_id'] = strval($value['area_id']); $result[$index]['cate_id'] = strval($value['cate_id']); $result[$index]['lng'] = $value['longitude']; $result[$index]['lat'] = $value['latitude']; } //地区列表 $area_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "area where pid=0 and city_id=" . $city_id . " order by sort"); $taoxin_cate_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "taoxin_cate where is_effect=1 and is_delete = 0"); if ($plat == APP_PLAT || $ajax === 1) { $ret = array('ret' => '0', 'num' => strval($num), 'page' => strval($prepage + 1), 'count' => strval($count), 'pageCount' => strval($pageCount), 'is_last_page' => strval($is_last_page), 'inforlist' => $result); array_recursive($ret, 'strval'); echo json_encode($ret); } else { $GLOBALS['tmpl']->assign("area_list", $area_list); $GLOBALS['tmpl']->assign("cate_list", $taoxin_cate_list); $GLOBALS['tmpl']->assign("num", $num); $GLOBALS['tmpl']->assign("page", $prepage + 1); //当前页 $GLOBALS['tmpl']->assign("count", $count); //总数量 $GLOBALS['tmpl']->assign("pageCount", $pageCount); //总数量 $GLOBALS['tmpl']->assign("is_last_page", $is_last_page); //总数量 $GLOBALS['tmpl']->assign("result", $result); $GLOBALS['tmpl']->display("taoxin_index.html"); } }
public function malllist() { $condition = " is_effect = 1 and is_delete = 0 and d.buy_type<>1 and supplier_id<>0 "; //条件 $join_str = ""; $sort_field = "current_price"; $sort_type = intval($_POST['price_sort']) === 1 ? "ASC" : "desc"; if ($_POST['cate_id']) { $cate_id = $_POST['cate_id']; $shop_cate_grade = $GLOBALS['db']->getOne("select grade from " . DB_PREFIX . "shop_cate where id =" . $cate_id); switch ($shop_cate_grade) { case "0": // 一级分类 $condition .= " and ( shop_cate_id=" . $cate_id . " or p_shop_cate_id=" . $cate_id . ")"; break; case "1": // 二级分类 $condition .= " and ( shop_cate_id=" . $cate_id . " or shop_cate_id in (select id from " . DB_PREFIX . "shop_cate where pid=" . $cate_id . "))"; break; default: $condition .= " and shop_cate_id=" . $cate_id; } } if (isset($_POST['city_id']) && $_POST['city_id'] > 1) { $condition .= " and city_id=" . $_POST['city_id']; } $distance = !empty($_POST['distance']) ? $_POST['distance'] : 10000000; //$distance = 10000000; $lng = '119.025595'; $lat = '33.596043'; if (!empty($_POST['lng']) && $_POST['lng'] != "" && !empty($_POST['lat']) && $_POST['lat'] != "") { $lng = $_POST['lng']; $lat = $_POST['lat']; $condition .= " and id in ( select deal_id from " . DB_PREFIX . "deal_location_link where location_id in (select id from " . DB_PREFIX . "supplier_location where " . search_where_radius($distance, $lng, $lat, "location") . "))"; } $num = empty($_POST['num']) ? 30 : $_POST['num']; // page size $prepage = empty($_POST['prepage']) ? 0 : $_POST['prepage']; $start = $prepage * $num + 0; $limit = $start . "," . $num; $kw = addslashes(htmlspecialchars(trim($_REQUEST['keyword']))); if ($kw != '') { $GLOBALS['tmpl']->assign('keyword', $kw); if ($add_title != '') { $add_title .= "-"; } $add_title .= $kw; $kws_div = div_str($kw); foreach ($kws_div as $k => $item) { $kws[$k] = str_to_unicode_string($item); } $ukeyword = implode(" ", $kws); $condition .= " and (match(d.tag_match,d.name_match,d.locate_match,d.shop_cate_match) against('" . $ukeyword . "' IN BOOLEAN MODE))"; //$condition.=" and (d.name like '%".$kw."%' or d.sub_name like '%".$kw."%' or d.brief like '%".$kw."%' or d.description like '%".$kw."%')"; } // file_put_contents("/tmp/mall.log", "\n".json_encode($_POST)."\n",FILE_APPEND); // file_put_contents("/tmp/mall.log", "\n condition:$condition\n",FILE_APPEND); $result = search_goods_list($limit, intval($cate_id), $condition, "d." . $sort_field . " " . $sort_type, false, $join_str); if ($result === FALSE) { $result = array('ret' => '102'); } else { $result['ret'] = '0'; $result['goodslist'] = array(); foreach ($result['list'] as $index => $val) { $result['goodslist'][$index]['brand_name'] = $GLOBALS['db']->getOne("select name from tb_brand where id =" . $val['brand_id']); $sql = "select xpoint as lng,ypoint as lat,ROUND(SQRT(POW(ABS(X(location)-" . $lng . ")/0.001024*100,2)+POW(ABS(Y(location)-" . $lat . ")/0.000886*100,2))) AS `dis` from " . DB_PREFIX . "supplier_location where id in (select location_id from " . DB_PREFIX . "deal_location_link where deal_id=" . $val['id'] . ") order by dis desc limit 1"; $location = $GLOBALS['db']->getAll($sql); $result['goodslist'][$index]['xpoint'] = '119.025595'; $result['goodslist'][$index]['ypoint'] = '33.596043'; if (!$location) { $result['goodslist'][$index]['location_list'] = array(); } else { $result['goodslist'][$index]['location_list'] = $location; $result['goodslist'][$index]['xpoint'] = $location[0]['lng']; $result['goodslist'][$index]['ypoint'] = $location[0]['lat']; $result['goodslist'][$index]['dis'] = $location[0]['dis']; } $result['goodslist'][$index]['id'] = $val['id']; $result['goodslist'][$index]['name'] = $val['name']; $result['goodslist'][$index]['sub_name'] = $val['sub_name']; $result['goodslist'][$index]['cate_id'] = $val['cate_id']; $result['goodslist'][$index]['img'] = $val['img']; //$result['goodslist'][$index]['description'] = $val['description']; $result['goodslist'][$index]['origin_price'] = $val['origin_price']; $result['goodslist'][$index]['current_price'] = $val['current_price']; $result['goodslist'][$index]['city_id'] = $val['city_id']; $result['goodslist'][$index]['icon'] = $val['icon']; $result['goodslist'][$index]['create_time'] = $val['create_time']; $result['goodslist'][$index]['brand_id'] = $val['brand_id']; $result['goodslist'][$index]['url'] = $val['url']; $result['goodslist'][$index]['is_delivery'] = $val['is_delivery']; $result['goodslist'][$index]['is_can_buy'] = is_can_buy($val['shop_cate_id']) ? '1' : '0'; $result['goodslist'][$index]['is_cash_pay'] = $val['is_cash_pay']; } $result['num'] = strval($num); $result['page'] = strval($prepage + 1); unset($result['list']); } echo json_encode($result); }
public function app_search() { // //file_put_contents("/tmp/ss.log", "\n".date("Y-m-d H:i:s")." post:".json_encode($_POST)."\n",FILE_APPEND); // $_POST['keyword'] = "电台灯"; // $_POST['s_type'] = "taoxin,deal"; // if (empty($_POST['keyword']) || empty($_POST['s_type'])) { echo json_encode(array('ret' => '102')); } else { // 搜索类型,all为搜索所有 $s_type = $_POST['s_type']; $s_type_arr = explode(",", $s_type); $kw = addslashes(htmlspecialchars(trim($_POST['keyword']))); $kws_div = div_str($kw); // $kws = array(); foreach ($kws_div as $k => $item) { $kws_div[] = str_to_unicode_string($item); } $ukeyword = implode(" ", $kws_div); $num = empty($_POST['num']) ? 10 : $_POST['num']; // page size $prepage = empty($_POST['prepage']) ? 0 : $_POST['prepage']; $start = $prepage * $num + 0; $limit = $start . "," . $num; if (!empty($_POST['lng']) && !empty($_POST['lat'])) { $distance = !empty($_POST['distance']) ? $_POST['distance'] : 1000000; $lng = $_POST['lng']; $lat = $_POST['lat']; } if (in_array("deal", $s_type_arr)) { $sort_type = intval($_POST['price_sort']) === 1 ? "ASC" : "desc"; // 搜索商品 $sql = "select id,name,shop_cate_id,current_price,origin_price,icon,is_delivery,is_cash_pay from " . DB_PREFIX . "deal where is_effect=1 and supplier_id<>0 "; $sql_count = "select count(*) from " . DB_PREFIX . "deal where is_effect=1 and supplier_id<>0 "; $condition = "and match(`name_match`,`deal_cate_match`,`locate_match`,`tag_match`,`shop_cate_match`) against('" . $ukeyword . "') and is_delete=0 "; if (!empty($_POST['lng']) && !empty($_POST['lat'])) { $condition .= "and id in ( select deal_id from " . DB_PREFIX . "deal_location_link as dll left join " . DB_PREFIX . "deal as d on d.id=dll.deal_id where dll.location_id in (select id from " . DB_PREFIX . "supplier_location where " . search_where_radius($distance, $lng, $lat, "location") . ") and d.is_effect=1 and d.is_delete=0)"; } $condition .= " order by current_price " . $sort_type; $condition .= " limit " . $limit; $sql = $sql . $condition; $sql_count = $sql_count . $condition; //file_put_contents("/tmp/ss.log", "\n".date("Y-m-d H:i:s")." sql:".$sql."\n",FILE_APPEND); $result['deal_list'] = $GLOBALS['db']->getAll($sql); $result['deal_count'] = $GLOBALS['db']->getOne($sql_count); if ($result['deal_list'] !== false) { foreach ($result['deal_list'] as $index => $v) { $sql = "select id,name,address,tel from " . DB_PREFIX . "supplier_location where id in (select location_id from " . DB_PREFIX . "deal_location_link where deal_id=" . $v['id'] . ")"; $result['deal_list'][$index]['location_list'] = $GLOBALS['db']->getAll($sql); $sql = "select id,name from " . DB_PREFIX . "supplier where id =" . $v['supplier_id']; $result['deal_list'][$index]['supplier'] = $GLOBALS['db']->getRow($sql); $result['deal_list'][$index]['is_can_buy'] = is_can_buy($v['shop_cate_id']) ? '1' : '0'; } } } if (in_array("taoxin", $s_type_arr)) { // 搜索淘信 $sql = "select id,title,price,contact,address,longitude as lng,latitude as lat from " . DB_PREFIX . "taoxin where match(title,detail) against('" . $ukeyword . "') and verify=1 limit " . $limit; $sql_count = "select count(*) from " . DB_PREFIX . "taoxin where verify=1 and match(title,detail) against('" . $ukeyword . "')"; $result['taoxin_list'] = $GLOBALS['db']->getAll($sql); if (empty($result['taoxin_list'])) { $result['taoxin_list'] = array(); } else { foreach ($result['taoxin_list'] as $i => $v) { $result['taoxin_list'][$i]['photos'] = empty($v['goods_photos']) ? array() : json_decode($v['goods_photos'], true); $result['taoxin_list'][$i]['create_time'] = date("Y-m-d H:i:s", $v['create_time']); $pcate = $GLOBALS['db']->getRow("select id,name from " . DB_PREFIX . "taoxin_cate where id=(select pid from " . DB_PREFIX . "taoxin_cate where id=" . $v['cate_id'] . ")"); if (intval($pcate['id']) == 1) { // 如果已经是一级分类,请求自己作为一级分类 $pcate = $GLOBALS['db']->getRow("select id,name from " . DB_PREFIX . "taoxin_cate where id=" . $v['cate_id']); } $result['taoxin_list'][$i]['pcate_name'] = $pcate['name']; $result['taoxin_list'][$i]['pcate_id'] = strval($pcate['id']); } } $result['taoxin_count'] = $GLOBALS['db']->getOne($sql_count); } if (in_array("supplier", $s_type_arr)) { // 搜索商家 $sql = "select id,name from " . DB_PREFIX . "supplier where match(name_match) against('" . $ukeyword . "') and is_effect=1 limit " . $limit; $sql_count = "select count(*) from " . DB_PREFIX . "supplier where match(name_match) against('" . $ukeyword . "') and is_effect=1"; $result['supplier_list'] = $GLOBALS['db']->getAll($sql); $result['supplier_count'] = $GLOBALS['db']->getOne($sql_count); if (empty($result['supplier_list'])) { $result['supplier_list'] = array(); } } if (in_array("location", $s_type_arr)) { //搜索未认证商家,即网络商家 $sql = "select id,name from " . DB_PREFIX . "supplier_location where match(name_match) against('" . $ukeyword . "') and is_verify=0 and is_effect=1 limit " . $limit; $sql_count = "select count(*) from " . DB_PREFIX . "supplier_location where match(name_match) against('" . $ukeyword . "') and is_verify=0 and is_effect=1"; $result['location_list'] = $GLOBALS['db']->getAll($sql); $result['location_count'] = $GLOBALS['db']->getOne($sql_count); if (empty($result['location_list'])) { $result['location_list'] = array(); } } if (in_array("event", $s_type_arr)) { // 搜索活动 $sql = "select id,name,address,icon from " . DB_PREFIX . "event where match(`locate_match`,`cate_match`,`name_match`) against('" . $ukeyword . "') and is_effect=1 limit " . $limit; $sql_count = "select count(*) from " . DB_PREFIX . "event where match(`locate_match`,`cate_match`,`name_match`) against('" . $ukeyword . "') and is_effect=1"; $result['event_list'] = $GLOBALS['db']->getAll($sql); $result['event_count'] = $GLOBALS['db']->getOne($sql_count); if (empty($result['event_list'])) { $result['event_list'] = array(); } } $result['ret'] = '0'; array_recursive($result, 'strval', true); //file_put_contents("/tmp/xiao.log", "\n result ".json_encode($result)."\n",FILE_APPEND); echo json_encode($result); } }