Commit 83df13eb by 白满斌

周边

parent 09297445
...@@ -30,17 +30,17 @@ use Illuminate\Support\Facades\Http; ...@@ -30,17 +30,17 @@ use Illuminate\Support\Facades\Http;
class SchoolService extends BaseService{ class SchoolService extends BaseService{
public static $local = 'https://restapi.amap.com/v3/geocode/geo?'; public static $local = 'https://apis.map.qq.com/ws/geocoder/v1/?';
public static $localAround = 'https://restapi.amap.com/v5/place/around?'; public static $localAround = 'https://apis.map.qq.com/ws/place/v1/search?';
public static $around = [ public static $around = [
'美食'=>'050000', '美食'=>'100000',
'住宿'=>'100000', '住宿'=>'210000',
'文具'=>'060000', '文具'=>'133400',
'打印'=>'070000', '打印'=>'133400',
'充电'=>'010000', '充电'=>'191014',
'公厕'=>'200300', '公厕'=>'271110',
'交通'=>'150104|150200', '交通'=>'271016',
]; ];
...@@ -50,13 +50,10 @@ class SchoolService extends BaseService{ ...@@ -50,13 +50,10 @@ class SchoolService extends BaseService{
//专业对应检索条件 //专业对应检索条件
$response = Http::get($url); $response = Http::get($url);
$bodyData = $response->json(); // 如果响应是 JSON 格式,解析为数组或对象 $bodyData = $response->json(); // 如果响应是 JSON 格式,解析为数组或对象
if($bodyData['status'] == 0){ if($bodyData['status'] != 0){
return ['code'=>20001, 'msg'=>'地图数据请求失败', 'data'=>$bodyData]; return ['code'=>20001, 'msg'=>'地图数据请求失败', 'data'=>$bodyData];
} }
if($bodyData['info'] != 'OK'){ return ['code'=>0, 'msg'=>'success', 'data'=>$bodyData['result']];
return ['code'=>20001, 'msg'=>'地图信息获取失败', 'data'=>$bodyData];
}
return ['code'=>0, 'msg'=>'success', 'data'=>$bodyData['geocodes']];
} catch (\Exception $e) { } catch (\Exception $e) {
return ['code'=>20009, 'msg'=>$e->getMessage(), 'data'=>[]]; return ['code'=>20009, 'msg'=>$e->getMessage(), 'data'=>[]];
...@@ -68,13 +65,10 @@ class SchoolService extends BaseService{ ...@@ -68,13 +65,10 @@ class SchoolService extends BaseService{
//专业对应检索条件 //专业对应检索条件
$response = Http::get($url); $response = Http::get($url);
$bodyData = $response->json(); // 如果响应是 JSON 格式,解析为数组或对象 $bodyData = $response->json(); // 如果响应是 JSON 格式,解析为数组或对象
if($bodyData['status'] == 0){ if($bodyData['status'] != 0){
return ['code'=>20001, 'msg'=>'地图数据请求失败', 'data'=>$bodyData]; return ['code'=>20001, 'msg'=>'周边数据请求失败', 'data'=>$bodyData];
}
if($bodyData['info'] != 'OK'){
return ['code'=>20001, 'msg'=>'地图信息获取失败', 'data'=>$bodyData];
} }
return ['code'=>0, 'msg'=>'success', 'data'=>$bodyData['pois']]; return ['code'=>0, 'msg'=>'success', 'data'=>$bodyData['data']];
} catch (\Exception $e) { } catch (\Exception $e) {
return ['code'=>20009, 'msg'=>$e->getMessage(), 'data'=>[]]; return ['code'=>20009, 'msg'=>$e->getMessage(), 'data'=>[]];
...@@ -121,7 +115,7 @@ class SchoolService extends BaseService{ ...@@ -121,7 +115,7 @@ class SchoolService extends BaseService{
$location = $res['location']; $location = $res['location'];
//获取周边信息,美食、住宿、文具、打印、充电、公厕、交通 //获取周边信息,美食、住宿、文具、打印、充电、公厕、交通
if($res['location'] == ""){ if($res['location'] == ""){
$url = self::$local.'key='.$gdKey.'&address='. $res['name'].'&city='.$res['p_code']; $url = self::$local.'key='.$gdKey.'&address=天津市'. $res['name'];
$requestRet = self::sendGet($url); $requestRet = self::sendGet($url);
if($requestRet['code'] != 0){ if($requestRet['code'] != 0){
return $requestRet; return $requestRet;
...@@ -129,10 +123,10 @@ class SchoolService extends BaseService{ ...@@ -129,10 +123,10 @@ class SchoolService extends BaseService{
if(empty($requestRet['data'])){ if(empty($requestRet['data'])){
return ['code'=>10001, 'msg'=>'暂未获取到地址信息', 'data'=>[]]; return ['code'=>10001, 'msg'=>'暂未获取到地址信息', 'data'=>[]];
} }
$location = $requestRet['data'][0]['location']; if(empty($requestRet['data']['location'])){
if(empty($location)){
return ['code'=>10002, 'msg'=>'位置获取失败', 'data'=>[]]; return ['code'=>10002, 'msg'=>'位置获取失败', 'data'=>[]];
} }
$location = $requestRet['data']['location']['lat'].','. $requestRet['data']['location']['lng'];
$PlaceModel->updateData(['id'=>$placeid], ['location'=>$location]); $PlaceModel->updateData(['id'=>$placeid], ['location'=>$location]);
} }
...@@ -149,14 +143,10 @@ class SchoolService extends BaseService{ ...@@ -149,14 +143,10 @@ class SchoolService extends BaseService{
} }
//么有就去获取 //么有就去获取
if($aroundName == '交通'){ $keyword= $aroundName == '打印' ? '打印店' : $aroundName;
$aroundUrl = self::$localAround .'key='.$gdKey.'&keywords=火车站'.'&types='.self::$around[$aroundName].'&location='.$location.'&radius=50000&region='.$res['p_code'].'&city_limit=true&page_size=10&page_num=1&show_fields=children,business,navi'; $boundary = 'nearby(' . $location . ',50000,1)';
$requestRetAround = self::sendGetAround($aroundUrl); $aroundUrl = self::$localAround . 'key=' . $gdKey . '&keyword=' . $keyword . '&boundary=' . $boundary . '&filter=category=' . self::$around[$aroundName];
}else{ $requestRetAround = self::sendGetAround($aroundUrl);
$aroundUrl = self::$localAround .'key='.$gdKey.'&keywords='. $aroundName.'&types='.self::$around[$aroundName].'&location='.$location.'&radius=20000&region='.$res['p_code'].'&city_limit=true&show_fields=children,business,navi';
$requestRetAround = self::sendGetAround($aroundUrl);
}
$aroundData = [ $aroundData = [
'place_id'=>$placeid, 'place_id'=>$placeid,
'name'=>$aroundName, 'name'=>$aroundName,
...@@ -164,7 +154,6 @@ class SchoolService extends BaseService{ ...@@ -164,7 +154,6 @@ class SchoolService extends BaseService{
]; ];
$PlaceAroundModel->insertData($aroundData); $PlaceAroundModel->insertData($aroundData);
$data['around'] = $requestRetAround['data']; $data['around'] = $requestRetAround['data'];
return ['code'=>0, 'msg'=>'success', 'data'=>$data]; return ['code'=>0, 'msg'=>'success', 'data'=>$data];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment