예제 #1
0
 private function get_condition()
 {
     if ($this->input['jd'] || $this->input['wd']) {
         //gps坐标转百度坐标
         $baidu_zuobiao = GpsToBaidu($this->input['jd'], $this->input['wd']);
         $this->input['baidu_longitude'] = $baidu_zuobiao['x'];
         $this->input['baidu_latitude'] = $baidu_zuobiao['y'];
     }
     $distance = $this->input['distance'];
     if ($this->input['baidu_longitude'] && $this->input['baidu_latitude'] && $distance) {
         $baidu_longitude = $this->input['baidu_longitude'];
         $baidu_latitude = $this->input['baidu_latitude'];
         $range = 180 / pi() * $distance / 6372.797;
         //里面的 $distance 就代表搜索 $distance 之内,单位km
         $lngR = $range / cos($baidu_latitude * pi() / 180);
         //echo $range;exit()
         $maxLat = $baidu_latitude + $range;
         //最大纬度
         $minLat = $baidu_latitude - $range;
         //最小纬度
         $maxLng = $baidu_longitude + $lngR;
         //最大经度
         $minLng = $baidu_longitude - $lngR;
         //最小经度
         $condition .= ' AND t1.baidu_longitude >=' . $minLng . ' AND t1.baidu_longitude <=' . $maxLng . ' AND t1.baidu_latitude >=' . $minLat . ' AND t1.baidu_latitude <= ' . $maxLat . ' AND t1.baidu_latitude != "" AND t1.baidu_longitude != ""';
     }
     return $condition;
 }
예제 #2
0
 public function detail()
 {
     $id = intval($this->input['id']);
     if (!$id) {
         $this->errorOutput(NOID);
     }
     $sql = "SELECT t1.name,t1.level,t1.address,t1.baidu_longitude,t1.baidu_latitude,t1.hospital_id,t1.telephone,t1.traffic,t2.content FROM " . DB_PREFIX . "hospital t1 \n\t\t\t\tLEFT JOIN " . DB_PREFIX . "content t2 \n\t\t\t\t\tON t1.id = t2.cid \n\t\t\t\tWHERE t1.status =1 AND t1.id = {$id}";
     $data = $this->db->query_first($sql);
     if ($data['telephone']) {
         $data['telephone'] = @unserialize($data['telephone']);
     } else {
         $data['telephone'] = array();
     }
     //ios传入gps坐标,转百度坐标
     if ($this->input['jd'] || $this->input['wd']) {
         //gps坐标转百度坐标
         $baidu_zuobiao = GpsToBaidu($this->input['jd'], $this->input['wd']);
         $this->input['baidu_longitude'] = $baidu_zuobiao['x'];
         $this->input['baidu_latitude'] = $baidu_zuobiao['y'];
     }
     if ($data['baidu_longitude'] && $data['baidu_latitude'] && $this->input['baidu_longitude'] && $this->input['baidu_latitude']) {
         //计算距离
         $data['distance'] = GetDistance($data['baidu_latitude'], $data['baidu_longitude'], $this->input['baidu_latitude'], $this->input['baidu_longitude'], 2);
         $data['distance'] .= 'KM';
     } else {
         $data['distance'] = '距离不祥';
     }
     //医院等级
     if ($data['level']) {
         $data['level'] = $this->settings['hospital_leval'][$data['level']];
     }
     //获取图片信息
     $sql = 'SELECT host,dir,filepath,filename FROM ' . DB_PREFIX . 'materials  WHERE cid = ' . $id . ' ORDER BY id DESC';
     $q = $this->db->query($sql);
     while ($row = $this->db->fetch_array($q)) {
         $data['pic_info'][] = $row;
     }
     $this->addItem($data);
     $this->output();
 }
예제 #3
0
 public function show()
 {
     //ios传入gps坐标,转百度坐标
     if ($this->input['jd'] || $this->input['wd']) {
         //gps坐标转百度坐标
         $baidu_zuobiao = GpsToBaidu($this->input['jd'], $this->input['wd']);
         $this->input['baidu_longitude'] = $baidu_zuobiao['x'];
         $this->input['baidu_latitude'] = $baidu_zuobiao['y'];
     }
     $cond = $this->get_condition();
     $offset = $this->input['offset'] ? intval($this->input['offset']) : 0;
     $count = $this->input['count'] ? intval($this->input['count']) : 20;
     $limit = ' LIMIT ' . $offset . ',' . $count;
     $sql = "SELECT t1.id,t1.name,t1.company_id,t1.currentnum,t1.totalnum,t1.station_id,t1.address,t1.stationx, t1.stationy, t1.baidu_latitude, t1.baidu_longitude, t3.station_icon FROM " . DB_PREFIX . "station t1 \n\t\t\t\tLEFT JOIN " . DB_PREFIX . "company t3 \n\t\t\t\t\tON t1.company_id = t3.id \n\t\t\t\tWHERE 1 " . $cond;
     $q = $this->db->query($sql);
     while ($row = $this->db->fetch_array($q)) {
         if ($row['baidu_longitude'] && $row['baidu_latitude']) {
             if ($this->input['baidu_longitude'] || $this->input['baidu_latitude']) {
                 //计算距离
                 $row['distance'] = GetDistance($row['baidu_latitude'], $row['baidu_longitude'], $this->input['baidu_latitude'], $this->input['baidu_longitude'], 1);
             }
         }
         $row['station_icon'] = unserialize($row['station_icon']);
         if (!$row['station_icon']['filename']) {
             $row['station_icon'] = array();
         }
         if ($row['totalnum'] && $row['totalnum'] >= $row['currentnum']) {
             $row['park_num'] = $row['totalnum'] - $row['currentnum'];
         } else {
             $row['park_num'] = 0;
         }
         $row['currentnum'] = intval($row['currentnum']);
         unset($row['totalnum']);
         $info[] = $row;
     }
     if ($info) {
         //按距离由近到远排序
         $len = count($info);
         for ($i = 1; $i < $len; $i++) {
             for ($j = $len - 1; $j >= $i; $j--) {
                 if ($info[$j]['distance'] < $info[$j - 1]['distance']) {
                     $x = $info[$j - 1];
                     $info[$j - 1] = $info[$j];
                     $info[$j] = $x;
                 }
             }
         }
         //根据偏移量返回结果
         if ($offset) {
             $station_num = 0;
             foreach ($info as $k => $v) {
                 if ($station_num == $count) {
                     break;
                 }
                 if ($k >= $offset) {
                     $station_num = $station_num + 1;
                     $info_limit[] = $v;
                 }
             }
         } else {
             foreach ($info as $k => $v) {
                 if ($station_num == $count) {
                     break;
                 }
                 $station_num = $station_num + 1;
                 $info_limit[] = $v;
             }
         }
         $info = array();
         $info = $info_limit;
         //单位换算
         foreach ($info as $k => $row) {
             if ($row['distance']) {
                 if ($row['distance'] > 1000) {
                     $row['distance'] /= 1000;
                     $row['distance'] .= 'km';
                 } else {
                     $row['distance'] .= 'm';
                 }
             } else {
                 $row['distance'] .= '距离不详';
             }
             $this->addItem($row);
         }
     }
     $this->output();
 }
예제 #4
0
 public function show()
 {
     $id = intval($this->input['station_id']);
     if (!$id) {
         $this->errorOutput('NOID');
     }
     $cond = " AND t1.id = " . $id;
     $sql = "SELECT t1.id, t1.name, t1.company_id, t1.station_id, t1.totalnum, t1.currentnum, t1.address, t1.brief, t1.dateline, t1.baidu_latitude, t1.baidu_longitude, t2.host, t2.dir, t2.filepath, t2.filename, t3.name company_name, t3.customer_hotline, t3.api_url, t3.brief as company_brief, t3.station_icon, t4.name as region_name FROM " . DB_PREFIX . "station t1 \n\t\t\tLEFT JOIN " . DB_PREFIX . "material t2 \n\t\t\t\tON t1.material_id=t2.id \n\t\t\tLEFT JOIN " . DB_PREFIX . "company t3 \n\t\t\t\tON t1.company_id=t3.id \n\t\t\tLEFT JOIN " . DB_PREFIX . "region t4\n\t\t\t\tON t1.region_id = t4.id\n\t\t\tWHERE 1 " . $cond;
     $ret = $this->db->query_first($sql);
     //hg_pre($ret,0);
     if (!$ret) {
         $this->errorOutput('NOCONTENT');
     }
     //查询站点下的实景照片数目
     $sql = "SELECT count(*) as total FROM " . DB_PREFIX . "material WHERE cid = " . $id;
     $pho_total = $this->db->query_first($sql);
     //实景照片数目
     $ret['img_num'] = $pho_total['total'];
     //如果运营单位有更新数据接口,请求接口替换总数,可借自行车数量
     if ($ret['api_url']) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $ret['api_url']);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $response = curl_exec($ch);
         if ($response) {
             $response = json_decode($response, 1);
             $info = $response['date'];
         }
         curl_close($ch);
         //关闭
         if ($info) {
             foreach ($info as $k => $v) {
                 if ($ret['station_id'] == ltrim($v['stationid'], '0')) {
                     $ret['dateline'] = $v['dateline'];
                     $ret['totalnum'] = $v['totalnum'];
                     $ret['currentnum'] = $v['currentnum'];
                     break;
                 }
             }
         }
     }
     unset($ret['api_url']);
     //可停车位
     if ($ret['totalnum'] && $ret['totalnum'] >= $ret['currentnum']) {
         $ret['park_num'] = $ret['totalnum'] - $ret['currentnum'];
         unset($ret['totalnum']);
     } else {
         $ret['park_num'] = 0;
     }
     if ($ret['host'] && $ret['dir'] && $ret['filepath'] && $ret['filename']) {
         //索引图
         $ret['indexpic'] = array('host' => $ret['host'], 'dir' => $ret['dir'], 'filepath' => $ret['filepath'], 'filename' => $ret['filename']);
     } else {
         if ($ret['station_icon']) {
             $icon = '';
             $icon = unserialize($ret['station_icon']);
             if (is_array($icon) && !empty($icon)) {
                 $ret['indexpic'] = array('host' => $icon['host'], 'dir' => $icon['dir'], 'filepath' => $icon['filepath'], 'filename' => $icon['filename']);
             } else {
                 $ret['indexpic'] = array();
             }
         } else {
             $ret['indexpic'] = array();
         }
     }
     unset($ret['host'], $ret['dir'], $ret['filepath'], $ret['filename'], $ret['station_icon']);
     //数据更新时间
     if ($ret['dateline']) {
         $ret['dateline'] = date('m-d H:i', $ret['dateline']);
     } else {
         $ret['dateline'] = date('m-d H:i', TIMENOW);
     }
     if ($ret['baidu_longitude'] && $ret['baidu_latitude']) {
         //ios传入gps坐标,转百度坐标
         if ($this->input['jd'] && $this->input['wd']) {
             //gps坐标转百度坐标
             $baidu_zuobiao = GpsToBaidu($this->input['jd'], $this->input['wd']);
             $this->input['baidu_longitude'] = $baidu_zuobiao['x'];
             $this->input['baidu_latitude'] = $baidu_zuobiao['y'];
         }
         if ($this->input['baidu_longitude'] || $this->input['baidu_latitude']) {
             //计算距离
             $ret['distance'] = GetDistance($ret['baidu_latitude'], $ret['baidu_longitude'], $this->input['baidu_latitude'], $this->input['baidu_longitude'], 1);
             if ($ret['distance']) {
                 if ($ret['distance'] > 1000) {
                     $ret['distance'] /= 1000;
                     $ret['distance'] .= 'km';
                 } else {
                     $ret['distance'] .= 'm';
                 }
             } else {
                 $ret['distance'] = '距离不详';
             }
         }
     }
     if ($ret['baidu_latitude'] != '0.00000000000000') {
         $ret['latitude'] = $ret['baidu_latitude'];
     }
     if ($ret['baidu_longitude'] != '0.00000000000000') {
         $ret['longitude'] = $ret['baidu_longitude'];
     }
     unset($ret['baidu_longitude'], $ret['baidu_latitude']);
     $this->addItem($ret);
     $this->output();
 }