where('id',$params['car_id'])->find(); if(!$car){ return ['code'=>0,'msg'=>'车辆不存在']; } //获取车辆在gps系统中的id $gps_car_id = (new GpsLogic()) -> info($car['gps_imei']); //获取车辆当前位置 $local = (new GpsLogic()) -> status($gps_car_id['data']['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']]; } } public static function getCarHistory($params):array { //获取车辆信息 $car = Vehicle::where('id',$params['car_id'])->find(); if(empty($car)){ return ['code'=>0,'msg'=>'车辆不存在']; } //获取车辆在gps系统中的id $gps_car_id = (new GpsLogic()) -> info($car['gps_imei']); $params['gps_car_id'] = $gps_car_id['data']['carId']; //获取车辆行驶历史信息 $result = (new GpsLogic()) -> history($params); //返回数据 if($result['code'] == 1){ $data = []; foreach ($result['data'] as $k => $v) { $data[$k]['lat'] = $v['latc']; $data[$k]['lon'] = $v['lonc']; } return ['code'=>1,'msg'=>$result['msg'],'data'=>$data]; }else{ return ['code'=>0,'msg'=>$result['msg']]; } } public static function getCarMileage($params):array { $car = Vehicle::field('gps_imei')->where('id',$params['car_id'])->find(); if(!$car){ return ['code'=>0,'msg'=>'车辆不存在']; } //获取车辆在gps系统中的id $gps_car_id = (new GpsLogic()) -> info($car['gps_imei']); //获取车辆当前位置 $res = (new GpsLogic()) -> mileage($gps_car_id['data']['carId'],$params['start_time'],$params['end_time']); if($res['code'] == 1){ return ['code'=>1,'msg'=>'请求成功','data'=>$res['data']]; }else{ return ['code'=>0,'msg'=>$res['msg']]; } } }