Commit 60294d82 by 白满斌

周边

parent 0534b2b3
......@@ -26,6 +26,9 @@ class SchoolController extends BaseController{
public function getConfig(Request $request){
$examid = (int)$request->input('exam_id', 0);
if (empty($examid)) {
return $this->respondError(10001, 'exam_id参数错误');
}
$result = $this->schoolService->selectConfigService($examid);
return $this->respond($result);
}
......@@ -33,7 +36,14 @@ class SchoolController extends BaseController{
//获取考点列表
public function getPlaceInfo(Request $request){
$placeid = (int)$request->input('place_id', 0);
$result = $this->schoolService->getPlaceInfoService($placeid);
$aroundName = $request->input('around_name', '');
if (empty($placeid)) {
return $this->respondError(10001, 'place_id参数错误');
}
if (empty($aroundName)) {
return $this->respondError(10001, 'around_name参数错误');
}
$result = $this->schoolService->getPlaceInfoService($placeid, $aroundName);
return $this->respond($result);
}
......
......@@ -24,10 +24,65 @@ use App\Models\SchoolMajorScore;
use App\Models\SchoolPlanBefore;
use App\Models\PlaceModel;
use App\Models\ExamModel;
use App\Models\PlaceAroundModel;
use Illuminate\Support\Facades\Http;
class SchoolService extends BaseService{
public static $local = 'https://restapi.amap.com/v3/geocode/geo?';
public static $localAround = 'https://restapi.amap.com/v5/place/around?';
public static $around = [
'美食'=>'050000',
'住宿'=>'100000',
'文具'=>'060000',
'打印'=>'070000',
'充电'=>'010000',
'公厕'=>'200300',
'交通'=>'150104|150200',
];
public static function sendGet($url){
try {
//专业对应检索条件
$response = Http::get($url);
$bodyData = $response->json(); // 如果响应是 JSON 格式,解析为数组或对象
if($bodyData['status'] == 0){
return ['code'=>20001, 'msg'=>'地图数据请求失败', 'data'=>$bodyData];
}
if($bodyData['info'] != 'OK'){
return ['code'=>20001, 'msg'=>'地图信息获取失败', 'data'=>$bodyData];
}
return ['code'=>0, 'msg'=>'success', 'data'=>$bodyData['geocodes']];
} catch (\Exception $e) {
return ['code'=>20009, 'msg'=>$e->getMessage(), 'data'=>[]];
}
}
public static function sendGetAround($url){
try {
//专业对应检索条件
$response = Http::get($url);
$bodyData = $response->json(); // 如果响应是 JSON 格式,解析为数组或对象
if($bodyData['status'] == 0){
return ['code'=>20001, 'msg'=>'地图数据请求失败', 'data'=>$bodyData];
}
if($bodyData['info'] != 'OK'){
return ['code'=>20001, 'msg'=>'地图信息获取失败', 'data'=>$bodyData];
}
return ['code'=>0, 'msg'=>'success', 'data'=>$bodyData['pois']];
} catch (\Exception $e) {
return ['code'=>20009, 'msg'=>$e->getMessage(), 'data'=>[]];
}
}
public function selectExamService(){
$ExamModel = new ExamModel();
......@@ -50,11 +105,12 @@ class SchoolService extends BaseService{
return ['code'=>0, 'msg'=>'success', 'data'=>array_values($data)];
}
public function getPlaceInfoService($placeid){
public function getPlaceInfoService($placeid, $aroundName){
$PlaceAroundModel = new PlaceAroundModel();
$PlaceModel = new PlaceModel();
$res = $PlaceModel->findData(['id'=>$placeid]);
$gdKey = env('GD_KEY');
$data = [
'id'=>$res['id'],
'name'=>$res['name'],
......@@ -62,12 +118,50 @@ class SchoolService extends BaseService{
'area'=>$res['area'],
'img'=>'/uploads/tianjin/'.$res['img'],
];
$location = $res['location'];
//获取周边信息,美食、住宿、文具、打印、充电、公厕、交通
if($res['location'] == ""){
$url = self::$local.'key='.$gdKey.'&address='. $res['addr'].'&city='.$res['p_code'];
$requestRet = self::sendGet($url);
if($requestRet['code'] != 0){
return $requestRet;
}
if(empty($requestRet['data'])){
return ['code'=>10001, 'msg'=>'暂未获取到地址信息', 'data'=>[]];
}
$location = $requestRet['data'][0]['location'];
if(empty($location)){
return ['code'=>10002, 'msg'=>'位置获取失败', 'data'=>[]];
}
$PlaceModel->updateData(['id'=>$placeid], ['location'=>$location]);
}
$data['location'] = $location;
$data['around_name'] = $aroundName;
if(!isset(self::$around[$aroundName])){
return ['code'=>10002, 'msg'=>'请传入正确的周边名称', 'data'=>[]];
}
//获取周边:
$aroundData = $PlaceAroundModel->findData(['place_id'=>$placeid, 'name'=>$aroundName]);
if(!empty($aroundData)){
$data['around'] = json_decode($aroundData['data'], true);
return ['code'=>0, 'msg'=>'success', 'data'=>$data];
}
//么有就去获取
$aroundUrl = self::$localAround .'key='.$gdKey.'&keywords='. $aroundName.'&types='.self::$around[$aroundName].'&location='.$location.'&radius=20000&region='.$res['p_code'].'&city_limit=true';
$requestRetAround = self::sendGetAround($aroundUrl);
$aroundData = [
'place_id'=>$placeid,
'name'=>$aroundName,
'data'=>json_encode($requestRetAround['data'])
];
$PlaceAroundModel->insertData($aroundData);
$data['around'] = $requestRetAround['data'];
return ['code'=>0, 'msg'=>'success', 'data'=>[]];
return ['code'=>0, 'msg'=>'success', 'data'=>$data];
}
public function listService($search, $pageId, $pageSize)
......
<?php
/**
* Created by PhpStorm.
* User: bmb369
* Date: 2024-05-07
* Time: 14:20
*/
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
class PlaceAroundModel extends Base {
protected $table = 'gz_place_around';
use SoftDeletes;
protected $dates = ['deleted_at'];
protected $primaryKey = 'id';
}
\ No newline at end of file
......@@ -38,12 +38,13 @@ Route::group(['prefix'=> 'student'], function () {
Route::group(['prefix'=> 'school'], function () {
Route::get('exam_list', ['uses' => 'SchoolController@selectExam', 'label' => '列表',]);
Route::get('place_list', ['uses' => 'SchoolController@getConfig', 'label' => '列表',]);
Route::get('list', ['uses' => 'SchoolController@lst', 'label' => '列表',]);
Route::get('special_list', ['uses' => 'SchoolController@specialList', 'label' => '列表',]);
Route::get('special_detail', ['uses' => 'SchoolController@specialDetail', 'label' => '列表',]);
Route::get('score_province', ['uses' => 'SchoolController@specialProvince', 'label' => '院校分数线',]);
Route::get('score_major_province', ['uses' => 'SchoolController@specialMajorProvince', 'label' => '专业分数线',]);
Route::get('plan_before', ['uses' => 'SchoolController@planBefore', 'label' => '招生信息',]);
Route::get('place_info', ['uses' => 'SchoolController@getPlaceInfo', 'label' => '列表',]);
// Route::get('list', ['uses' => 'SchoolController@lst', 'label' => '列表',]);
// Route::get('special_list', ['uses' => 'SchoolController@specialList', 'label' => '列表',]);
// Route::get('special_detail', ['uses' => 'SchoolController@specialDetail', 'label' => '列表',]);
// Route::get('score_province', ['uses' => 'SchoolController@specialProvince', 'label' => '院校分数线',]);
// Route::get('score_major_province', ['uses' => 'SchoolController@specialMajorProvince', 'label' => '专业分数线',]);
// Route::get('plan_before', ['uses' => 'SchoolController@planBefore', 'label' => '招生信息',]);
});
......
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