public function index()
 {
     $ytop = $latitude_top = floatval($GLOBALS['request']['latitude_top']);
     //最上边纬线值 ypoint
     $ybottom = $latitude_bottom = floatval($GLOBALS['request']['latitude_bottom']);
     //最下边纬线值 ypoint
     $xleft = $longitude_left = floatval($GLOBALS['request']['longitude_left']);
     //最左边经度值  xpoint
     $xright = $longitude_right = floatval($GLOBALS['request']['longitude_right']);
     //最右边经度值 xpoint
     $ypoint = $m_latitude = doubleval($GLOBALS['request']['m_latitude']);
     //ypoint
     $xpoint = $m_longitude = doubleval($GLOBALS['request']['m_longitude']);
     //xpoint
     $type = intval($GLOBALS['request']['type']);
     //-1:全部,0:优惠券;1:活动;2:团购;3:代金券;4:商家
     $pi = 3.14159265;
     //圆周率
     $r = 6378137;
     //地球平均半径(米)
     $field_append = ", (ACOS(SIN(({$ypoint} * {$pi}) / 180 ) *SIN((ypoint * {$pi}) / 180 ) +COS(({$ypoint} * {$pi}) / 180 ) * COS((ypoint * {$pi}) / 180 ) *COS(({$xpoint} * {$pi}) / 180 - (xpoint * {$pi}) / 180 ) ) * {$r}) as distance ";
     $condition = "  ypoint > {$ybottom} and ypoint < {$ytop} and xpoint > {$xleft} and xpoint < {$xright} ";
     $limit = 10;
     if ($type == -1 || $type == 0) {
         //查优惠
         $now = get_gmtime();
         $sql = "select id,name,icon,xpoint,ypoint {$field_append} from " . DB_PREFIX . "youhui";
         $where = " where is_effect = 1 and begin_time<" . $now . " and (end_time = 0 or end_time > " . $now . ") ";
         $where .= " and " . $condition;
         $sql .= $where;
         $sql .= " limit {$limit} ";
         $list = $GLOBALS['db']->getAll($sql);
         $youhui_list = array();
         foreach ($list as $item) {
             $item['icon'] = get_abs_img_root($item['icon']);
             $item['type'] = 0;
             $item['distance'] = round($item['distance']);
             $youhui_list[] = $item;
         }
     }
     if ($type == -1 || $type == 1) {
         //查活动
         $res = m_search_event_list($limit, 0, 0, $condition, " distance asc ", $field_append);
         $event_list = array();
         foreach ($res['list'] as $item) {
             $item['icon'] = get_abs_img_root($item['icon']);
             $item['type'] = 1;
             $item['distance'] = round($item['distance']);
             $event_list[] = $item;
         }
     }
     if ($type == -1 || $type == 2) {
         //查团购
         $res = m_get_deal_list($limit, 0, 0, array(DEAL_ONLINE), $condition, "distance asc", 0, $field_append);
         $tuan_list = array();
         foreach ($res['list'] as $item) {
             $item['icon'] = get_abs_img_root($item['icon']);
             $item['type'] = 2;
             $item['distance'] = round($item['distance']);
             $tuan_list[] = $item;
         }
     }
     if ($type == -1 || $type == 3) {
         //查代金
         $res = m_search_youhui_list($limit, 0, $condition, " distance asc ", 0, $field_append);
         $dianjin_list = array();
         foreach ($res['list'] as $item) {
             $item['icon'] = get_abs_img_root($item['icon']);
             $item['type'] = 3;
             $item['distance'] = round($item['distance']);
             $dianjin_list[] = $item;
         }
     }
     if ($type == -1 || $type == 4) {
         //查商家
         $sql = "select id,supplier_id,name,address,preview as icon,xpoint,ypoint {$field_append} from   " . DB_PREFIX . "supplier_location  ";
         $sql .= " where " . $condition;
         $sql .= " order by distance asc limit " . $limit;
         $list = $GLOBALS['db']->getAll($sql);
         $merchant_list = array();
         foreach ($list as $item) {
             $item['icon'] = get_abs_img_root($item['icon']);
             $item['type'] = 4;
             $item['id'] = $item['supplier_id'];
             $item['distance'] = round($item['distance']);
             $merchant_list[] = $item;
         }
     }
     if ($type == -1) {
         $result_list = array_merge($youhui_list, $event_list, $tuan_list, $dianjin_list, $merchant_list);
     } elseif ($type = 0) {
         $result_list = $youhui_list;
     } elseif ($type = 1) {
         $result_list = $event_list;
     } elseif ($type = 2) {
         $result_list = $tuan_list;
     } elseif ($type = 3) {
         $result_list = $dianjin_list;
     } elseif ($type = 4) {
         $result_list = $merchant_list;
     }
     if ($result_list) {
         $root['item'] = $result_list;
     } else {
         $root['item'] = array();
     }
     output($root);
 }
 public function index()
 {
     require_once APP_ROOT_PATH . 'app/Lib/youhui_lib.php';
     $catalog_id = intval($GLOBALS['request']['catalog_id']);
     //商品分类ID
     $city_id = intval($GLOBALS['request']['city_id']);
     //城市分类ID
     $page = intval($GLOBALS['request']['page']);
     //分页
     $keyword = strim($GLOBALS['request']['keyword']);
     $page = $page == 0 ? 1 : $page;
     $ytop = $latitude_top = floatval($GLOBALS['request']['latitude_top']);
     //最上边纬线值 ypoint
     $ybottom = $latitude_bottom = floatval($GLOBALS['request']['latitude_bottom']);
     //最下边纬线值 ypoint
     $xleft = $longitude_left = floatval($GLOBALS['request']['longitude_left']);
     //最左边经度值  xpoint
     $xright = $longitude_right = floatval($GLOBALS['request']['longitude_right']);
     //最右边经度值 xpoint
     $ypoint = $m_latitude = doubleval($GLOBALS['request']['m_latitude']);
     //ypoint
     $xpoint = $m_longitude = doubleval($GLOBALS['request']['m_longitude']);
     //xpoint
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kws[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kws);
         $condition = "  (match(tag_match,name_match,locate_match,deal_cate_match) against('" . $ukeyword . "' IN BOOLEAN MODE) or name like '%" . $keyword . "%') ";
     }
     if ($xpoint > 0) {
         $pi = 3.14159265;
         //圆周率
         $r = 6378137;
         //地球平均半径(米)
         $field_append = ", (ACOS(SIN(({$ypoint} * {$pi}) / 180 ) *SIN((ypoint * {$pi}) / 180 ) +COS(({$ypoint} * {$pi}) / 180 ) * COS((ypoint * {$pi}) / 180 ) *COS(({$xpoint} * {$pi}) / 180 - (xpoint * {$pi}) / 180 ) ) * {$r}) as distance ";
         if ($ybottom != 0 && $ytop != 0 && $xleft != 0 && $xright != 0) {
             if ($condition != "") {
                 $condition .= " and ";
             }
             $condition .= "  ypoint > {$ybottom} and ypoint < {$ytop} and xpoint > {$xleft} and xpoint < {$xright} ";
         }
         $order = " distance asc ";
     } else {
         $field_append = "";
         $order = " sort desc ";
     }
     $deals = m_search_youhui_list($limit, intval($catalog_id), $condition, $order, $city_id, $field_append);
     //		$deals = get_goods_list($limit,$catalog_id,"","sort desc",false,$city_id);
     $list = $deals['list'];
     $count = $deals['count'];
     $page_total = ceil($count / $page_size);
     $root = array();
     $root['return'] = 1;
     $goodses = array();
     foreach ($list as $item) {
         //$goods = array();
         $goods = getGoodsArray($item);
         $goods['distance'] = round($goods['distance']);
         $goodses[] = $goods;
     }
     $root['item'] = $goodses;
     $root['page'] = array("page" => $page, "page_total" => $page_total);
     output($root);
 }