增加车辆当前位置接口
This commit is contained in:
parent
7016b66c56
commit
c74b01a1c8
@ -11,7 +11,7 @@ use think\response\Json;
|
||||
*/
|
||||
class VehicleController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = ['getCompany','setContract','getRentRecord','updateRentRecord','getCompanyCars'];
|
||||
public array $notNeedLogin = ['getCompany','setContract','getRentRecord','updateRentRecord','getCompanyCars','getCarLocal'];
|
||||
|
||||
/*
|
||||
*获取平台公司接口
|
||||
@ -99,4 +99,19 @@ class VehicleController extends BaseApiController
|
||||
return $this->fail($result['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
//获取车辆当前位置
|
||||
public function getCarLocal() {
|
||||
$params = $this->request->get(['car_id','gps_imei']);
|
||||
if(empty($params['car_id']) || empty($params['gps_imei'])){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
$result = VehicleLogic::getCarLocal($params);
|
||||
//返回数据
|
||||
if($result['code'] == 1){
|
||||
return $this->success($result['msg'],$result['data']);
|
||||
}else{
|
||||
return $this->fail($result['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class GpsLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
public function status():array {
|
||||
public function status($car_id):array {
|
||||
//获取token
|
||||
$token = $this->token();
|
||||
//请求地址
|
||||
@ -85,7 +85,7 @@ class GpsLogic extends BaseLogic
|
||||
//请求参数
|
||||
$data = [
|
||||
'token' => $token,
|
||||
'carId' => '629942',
|
||||
'carId' => $car_id,
|
||||
'mapType' => 1
|
||||
];
|
||||
//发起请求
|
||||
|
@ -198,4 +198,23 @@ class VehicleLogic extends BaseLogic
|
||||
return ['code'=>1,'msg'=>'请求失败'];
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCarLocal($params):array {
|
||||
$car = Vehicle::field('gps_carid')->where('id',$params['car_id'])->where('gps_imei',$params['gps_imei'])->find();
|
||||
if(!$car){
|
||||
return ['code'=>0,'msg'=>'车辆不存在'];
|
||||
}
|
||||
//获取车辆当前位置
|
||||
$local = (new GpsLogic()) -> status($car['gps_carid']);
|
||||
if($local['code'] == 1){
|
||||
$data = [
|
||||
'car_id' => $params['car_id'],
|
||||
'lat' => $local['data']['carStatus']['latc'],
|
||||
'lon' => $local['data']['carStatus']['lonc'],
|
||||
];
|
||||
return ['code'=>1,'msg'=>'请求成功','data'=>$data];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>$local['msg']];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,4 +35,5 @@ Route::rule('getCompany','Vehicle/getCompany','get');
|
||||
Route::rule('setContract','Vehicle/setContract','post');
|
||||
Route::rule('getRentRecord','Vehicle/getRentRecord','get');
|
||||
Route::rule('updateRentRecord','Vehicle/updateRentRecord','post');
|
||||
Route::rule('getCompanyCars','Vehicle/getCompanyCars','get');
|
||||
Route::rule('getCompanyCars','Vehicle/getCompanyCars','get');
|
||||
Route::rule('getCarLocal','Vehicle/getCarLocal','get');
|
Loading…
x
Reference in New Issue
Block a user