Beispiel #1
0
 public function show()
 {
     $offset = $this->input['offset'] ? $this->input['offset'] : 0;
     //$count = $this->input['count'] ? intval($this->input['count']) : 20;
     $count = $this->input['count'];
     $condition = $this->get_condition();
     $orderby = '  ORDER BY c.order_id DESC,c.id DESC ';
     if ($count) {
         $limit = ' LIMIT ' . $offset . ' , ' . $count;
     } else {
         $limit = '';
     }
     $ret = $this->mode->show($condition, $orderby, $limit);
     if (!empty($ret)) {
         foreach ($ret as $k => $v) {
             //传过来的是GPS坐标
             if ($this->input['jd'] || $this->input['wd']) {
                 //计算距离
                 if ($v['GPS_x'] && $v['GPS_y']) {
                     $v['distance'] = GetDistance($v['GPS_y'], $v['GPS_x'], $this->input['wd'], $this->input['jd']);
                     $v['distance_format'] = distance_change_unit($v['distance']);
                 } else {
                     $v['distance'] = '距离不详';
                 }
             }
             $this->addItem($v);
         }
     } else {
         $this->addItem(array());
     }
     $this->output();
 }
Beispiel #2
0
 public function get_carpark_by_district($city_name, $wd = '', $jd = '', $type_id = '')
 {
     //查询出城市id
     $sql = "SELECT * FROM " . DB_PREFIX . "carpark_district WHERE name = '" . $city_name . "'";
     $city_arr = $this->db->query_first($sql);
     if (!$city_arr) {
         return false;
     }
     //查询出该城市里面的区域
     $sql = "SELECT * FROM " . DB_PREFIX . "carpark_district WHERE fid = '" . $city_arr['id'] . "'";
     $q = $this->db->query($sql);
     $district = array();
     $district_ids = array();
     while ($r = $this->db->fetch_array($q)) {
         $district[$r['id']] = $r;
         $district_ids[] = $r['id'];
     }
     $sql = "SELECT * FROM " . DB_PREFIX . "carpark WHERE status=2 AND district_id IN (" . implode(',', $district_ids) . ")";
     //如果类型id存在,连上类型id
     if ($type_id) {
         $sql .= " AND type_id = " . $type_id;
     }
     $q = $this->db->query($sql);
     $carpark = array();
     while ($r = $this->db->fetch_array($q)) {
         $r['district_name'] = $district[$r['district_id']]['name'];
         $r['carpark_num'] = $district[$r['district_id']]['carpark_num'];
         if ($wd && $jd) {
             $r['distance'] = GetDistance($r['GPS_y'], $r['GPS_x'], $wd, $jd);
         }
         $carpark[$r['district_id']][$r['id']] = $r;
     }
     //如果存在当前的经纬度(GPS),算出某个区域内最近的停车场
     $carpark_nearest = array();
     if ($wd && $jd) {
         foreach ($carpark as $k => $v) {
             $_k = 0;
             //记录最近的停车场id
             $flag = 1;
             $_distance_tmp = 0;
             foreach ($v as $kk => $vv) {
                 if (intval($vv['distance']) < $_distance_tmp || $flag) {
                     $_distance_tmp = intval($vv['distance']);
                     $_k = $vv['id'];
                 }
                 $flag = 0;
             }
             $v[$_k]['distance_format'] = distance_change_unit($v[$_k]['distance']);
             $carpark_nearest[] = $v[$_k];
         }
     }
     //如果存在返回给个区域最近的停车场,不存在就返回所有区里面所有的停车场
     if ($carpark_nearest) {
         return $carpark_nearest;
     } else {
         return $carpark;
     }
 }