change Gps API
This commit is contained in:
parent
4e5a3f84fc
commit
2de53c0ae8
@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
|
||||||
// | 开源版本可自由商用,可去除界面版权logo
|
|
||||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
|
||||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
|
||||||
// | 访问官网:https://www.likeadmin.cn
|
|
||||||
// | likeadmin团队 版权所有 拥有最终解释权
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | author: likeadminTeam
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace app\api\controller;
|
|
||||||
|
|
||||||
use app\api\logic\GpsLogic;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文章管理
|
|
||||||
* Class ArticleController
|
|
||||||
* @package app\api\controller
|
|
||||||
*/
|
|
||||||
class GpsController extends BaseApiController
|
|
||||||
{
|
|
||||||
public array $notNeedLogin = ['getCarInfo','getCarStatus','getCarHistory','test'];
|
|
||||||
|
|
||||||
public function getCarInfo() {
|
|
||||||
//获取参数
|
|
||||||
$params = $this -> request -> get('imei');
|
|
||||||
//验证参数
|
|
||||||
if(empty($params)) return $this->fail('参数错误');
|
|
||||||
//获取数据
|
|
||||||
$result = (new GpsLogic()) -> info($params);
|
|
||||||
return $result['code'] == 1 ? $this->success($result['msg'],$result['data']) : $this->fail($result['msg']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCarStatus() {
|
|
||||||
$result = (new GpsLogic()) -> status();
|
|
||||||
return $result['code'] == 1 ? $this->success($result['msg'],$result['data']) : $this->fail($result['msg']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCarHistory() {
|
|
||||||
//获取参数
|
|
||||||
$params = $this->request->get(['car_id','start_time','end_time']);
|
|
||||||
//验证参数
|
|
||||||
if(empty($params['car_id']) || empty($params['start_time']) || empty($params['end_time'])){
|
|
||||||
return $this->fail('参数错误');
|
|
||||||
}
|
|
||||||
//获取车辆行驶历史信息
|
|
||||||
$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 $this->success($result['msg'],$data);
|
|
||||||
}else{
|
|
||||||
return $this->fail($result['msg']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,7 +11,7 @@ use think\response\Json;
|
|||||||
*/
|
*/
|
||||||
class VehicleController extends BaseApiController
|
class VehicleController extends BaseApiController
|
||||||
{
|
{
|
||||||
public array $notNeedLogin = ['getCompany','setContract','getRentRecord','updateRentRecord','getCompanyCars','getCarLocal'];
|
public array $notNeedLogin = ['getCompany','setContract','getRentRecord','updateRentRecord','getCompanyCars','getCarLocal','getCarHistory'];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*获取平台公司接口
|
*获取平台公司接口
|
||||||
@ -28,6 +28,7 @@ class VehicleController extends BaseApiController
|
|||||||
public function setContract():Json {
|
public function setContract():Json {
|
||||||
//获取参数
|
//获取参数
|
||||||
$params = $this->request->post(['party_a','party_b','num','rent_type','car_id']);
|
$params = $this->request->post(['party_a','party_b','num','rent_type','car_id']);
|
||||||
|
|
||||||
//验证参数
|
//验证参数
|
||||||
if(empty($params['party_a']) || empty($params['party_b']) || empty($params['num']) || empty($params['rent_type'])){
|
if(empty($params['party_a']) || empty($params['party_b']) || empty($params['num']) || empty($params['rent_type'])){
|
||||||
return $this->fail('缺少必要的参数');
|
return $this->fail('缺少必要的参数');
|
||||||
@ -110,4 +111,25 @@ class VehicleController extends BaseApiController
|
|||||||
return $this->fail($result['msg']);
|
return $this->fail($result['msg']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCarHistory():Json {
|
||||||
|
//获取参数
|
||||||
|
$params = $this->request->get(['car_id','start_time','end_time']);
|
||||||
|
//验证参数
|
||||||
|
if(empty($params['car_id']) || empty($params['start_time']) || empty($params['end_time'])){
|
||||||
|
return $this->fail('缺少必要参数');
|
||||||
|
}
|
||||||
|
//验证时间格式
|
||||||
|
if(!checkDateIsValid($params['start_time'],['Y-m-d H:i:s']) || !checkDateIsValid($params['end_time'],['Y-m-d H:i:s'])) {
|
||||||
|
return $this->fail('日期格式错误');
|
||||||
|
}
|
||||||
|
//获取数据
|
||||||
|
$result = VehicleLogic::getCarHistory($params);
|
||||||
|
//返回数据
|
||||||
|
if($result['code'] == 1){
|
||||||
|
return $this->success($result['msg'],$result['data']);
|
||||||
|
}else{
|
||||||
|
return $this->fail($result['msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,129 +0,0 @@
|
|||||||
<?php
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
|
||||||
// | 开源版本可自由商用,可去除界面版权logo
|
|
||||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
|
||||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
|
||||||
// | 访问官网:https://www.likeadmin.cn
|
|
||||||
// | likeadmin团队 版权所有 拥有最终解释权
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | author: likeadminTeam
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace app\api\logic;
|
|
||||||
|
|
||||||
use app\common\logic\BaseLogic;
|
|
||||||
use app\common\model\vehicle\Vehicle;
|
|
||||||
use think\facade\Cache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录逻辑
|
|
||||||
* Class GpsLogic
|
|
||||||
* @package app\api\logic
|
|
||||||
*/
|
|
||||||
class GpsLogic extends BaseLogic
|
|
||||||
{
|
|
||||||
|
|
||||||
private string $authName = 'lihai';
|
|
||||||
private string $authPwd = 'a123456';
|
|
||||||
private int $expTime = 432000;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 获取请求token
|
|
||||||
*/
|
|
||||||
private function token() {
|
|
||||||
//获取缓存数据
|
|
||||||
$gps_token = Cache::get('gps_token');
|
|
||||||
//验证缓存数据是否存在,如果缓存数据存在则直接返回缓存数据
|
|
||||||
if(!empty($gps_token)) return $gps_token;
|
|
||||||
//缓存数据不存在,从新请求touken
|
|
||||||
$url = 'https://www.gpsnow.net/user/login.do';
|
|
||||||
$result = curl_post($url,[],[
|
|
||||||
'name' => $this->authName,
|
|
||||||
'password' => $this->authPwd
|
|
||||||
]);
|
|
||||||
//验证请求结果
|
|
||||||
if(!empty($result['ret']) && isset($result['data'])){
|
|
||||||
//设置缓存数据
|
|
||||||
Cache::set('gps_user_id', $result['data']['userId'], $this->expTime);
|
|
||||||
Cache::set('gps_token', $result['data']['token'], $this->expTime);
|
|
||||||
return $result['data']['token'];
|
|
||||||
}else{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 获取车辆信息
|
|
||||||
*/
|
|
||||||
public function info($imei):array {
|
|
||||||
//获取token
|
|
||||||
$token = $this->token();
|
|
||||||
//请求地址
|
|
||||||
$url = 'https://www.gpsnow.net/car/getByImei.do';
|
|
||||||
//请求参数
|
|
||||||
$data = [
|
|
||||||
'token' => $token,
|
|
||||||
'imei' => $imei
|
|
||||||
];
|
|
||||||
//发起请求
|
|
||||||
$result = curl_post($url,[],$data);
|
|
||||||
//返回数据
|
|
||||||
if(!empty($result['ret']) && isset($result['data'])){
|
|
||||||
return ['code'=>1,'msg'=>'请求成功','data'=>$result['data']];
|
|
||||||
}else{
|
|
||||||
return ['code'=>0,'msg'=>$result['msg']];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function status($car_id):array {
|
|
||||||
//获取token
|
|
||||||
$token = $this->token();
|
|
||||||
//请求地址
|
|
||||||
$url = 'https://www.gpsnow.net/car/getCarAndStatus.do';
|
|
||||||
//请求参数
|
|
||||||
$data = [
|
|
||||||
'token' => $token,
|
|
||||||
'carId' => $car_id,
|
|
||||||
'mapType' => 1
|
|
||||||
];
|
|
||||||
//发起请求
|
|
||||||
$result = curl_post($url,[],$data);
|
|
||||||
//返回数据
|
|
||||||
if(!empty($result['ret']) && isset($result['data'])){
|
|
||||||
return ['code'=>1,'msg'=>'请求成功','data'=>$result['data']];
|
|
||||||
}else{
|
|
||||||
return ['code'=>0,'msg'=>$result['msg']];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function history($params):array {
|
|
||||||
//获取车辆信息
|
|
||||||
$carInfo = Vehicle::where('id',$params['car_id'])->find();
|
|
||||||
if(empty($carInfo)) return ['code'=>0,'msg'=>'车辆不存在'];
|
|
||||||
//获取token
|
|
||||||
$token = $this->token();
|
|
||||||
//请求地址
|
|
||||||
$url = 'https://www.gpsnow.net/position/queryHistory.do';
|
|
||||||
//请求参数
|
|
||||||
$data = [
|
|
||||||
'token' => $token,
|
|
||||||
'carId' => $carInfo['gps_carid'],
|
|
||||||
'startTime' => $params['start_time'],
|
|
||||||
'endTime' => $params['end_time'],
|
|
||||||
'filter' => true,
|
|
||||||
'interval' => 1,
|
|
||||||
'pointType' => 2,
|
|
||||||
];
|
|
||||||
//发起请求
|
|
||||||
$result = curl_post($url,[],$data);
|
|
||||||
//返回数据
|
|
||||||
if(!empty($result['ret']) && isset($result['data'])){
|
|
||||||
return ['code'=>1,'msg'=>'请求成功','data'=>$result['data']];
|
|
||||||
}else{
|
|
||||||
return ['code'=>0,'msg'=>$result['msg']];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,6 +16,7 @@ namespace app\api\logic;
|
|||||||
|
|
||||||
|
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
|
use app\common\logic\GpsLogic;
|
||||||
use app\common\model\vehicle\Company;
|
use app\common\model\vehicle\Company;
|
||||||
use app\common\model\vehicle\Vehicle;
|
use app\common\model\vehicle\Vehicle;
|
||||||
use app\common\model\vehicle\VehicleRent;
|
use app\common\model\vehicle\VehicleRent;
|
||||||
@ -45,6 +46,7 @@ class VehicleLogic extends BaseLogic
|
|||||||
Cache::set('task_token', $getToken['data']['token'], 86400);
|
Cache::set('task_token', $getToken['data']['token'], 86400);
|
||||||
return $getToken['data']['token'];
|
return $getToken['data']['token'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function companyInfo():array {
|
public static function companyInfo():array {
|
||||||
$data = Company::field('id,company_name')->where('company_name',30)->select();
|
$data = Company::field('id,company_name')->where('company_name',30)->select();
|
||||||
if($data){
|
if($data){
|
||||||
@ -75,7 +77,7 @@ class VehicleLogic extends BaseLogic
|
|||||||
],[
|
],[
|
||||||
'id' => $params['party_b'],
|
'id' => $params['party_b'],
|
||||||
'party_a' => $params['party_a'],
|
'party_a' => $params['party_a'],
|
||||||
'contract_type' => 29
|
'contract_type' => 29,
|
||||||
]);
|
]);
|
||||||
if($setContract['code'] == 0){
|
if($setContract['code'] == 0){
|
||||||
return ['code'=>0,'msg'=>$setContract['msg']];
|
return ['code'=>0,'msg'=>$setContract['msg']];
|
||||||
@ -226,4 +228,27 @@ class VehicleLogic extends BaseLogic
|
|||||||
return ['code'=>0,'msg'=>$local['msg']];
|
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'=>'车辆不存在'];
|
||||||
|
}else{
|
||||||
|
$params['gps_car_id'] = $car['gps_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']];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,12 +24,6 @@ Route::rule('courierData','Logistics/courierData','get');
|
|||||||
Route::rule('hasCourier','Logistics/hasCourier','get');
|
Route::rule('hasCourier','Logistics/hasCourier','get');
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
|
||||||
Route::rule('getCarInfo','Gps/getCarInfo','get');
|
|
||||||
Route::rule('getCarStatus','Gps/getCarStatus','get');
|
|
||||||
Route::rule('getCarHistory','Gps/getCarHistory','get');
|
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
Route::rule('getCompany','Vehicle/getCompany','get');
|
Route::rule('getCompany','Vehicle/getCompany','get');
|
||||||
Route::rule('setContract','Vehicle/setContract','post');
|
Route::rule('setContract','Vehicle/setContract','post');
|
||||||
@ -37,3 +31,4 @@ Route::rule('getRentRecord','Vehicle/getRentRecord','get');
|
|||||||
Route::rule('updateRentRecord','Vehicle/updateRentRecord','post');
|
Route::rule('updateRentRecord','Vehicle/updateRentRecord','post');
|
||||||
Route::rule('getCompanyCars','Vehicle/getCompanyCars','get');
|
Route::rule('getCompanyCars','Vehicle/getCompanyCars','get');
|
||||||
Route::rule('getCarLocal','Vehicle/getCarLocal','get');
|
Route::rule('getCarLocal','Vehicle/getCarLocal','get');
|
||||||
|
Route::rule('getCarHistory','Vehicle/getCarHistory','get');
|
71
app/common/logic/GpsLogic.php
Normal file
71
app/common/logic/GpsLogic.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\logic;
|
||||||
|
|
||||||
|
use think\facade\Cache;
|
||||||
|
|
||||||
|
class GpsLogic extends BaseLogic
|
||||||
|
{
|
||||||
|
private string $authName = 'lihai';
|
||||||
|
private string $authPwd = 'a123456';
|
||||||
|
private int $expTime = 432000;
|
||||||
|
private string $domain = 'https://www.gpsnow.net';
|
||||||
|
|
||||||
|
private function token() {
|
||||||
|
//获取缓存数据
|
||||||
|
$gps_token = Cache::get('gps_token');
|
||||||
|
//验证缓存数据是否存在,如果缓存数据存在则直接返回缓存数据
|
||||||
|
if(!empty($gps_token)) return $gps_token;
|
||||||
|
//缓存数据不存在,从新请求token
|
||||||
|
$result = curl_post($this->domain.'/user/login.do',[],[
|
||||||
|
'name' => $this->authName,
|
||||||
|
'password' => $this->authPwd
|
||||||
|
]);
|
||||||
|
//验证请求结果
|
||||||
|
if(!empty($result['ret']) && isset($result['data'])){
|
||||||
|
//设置缓存数据
|
||||||
|
Cache::set('gps_token', $result['data']['token'], $this->expTime);
|
||||||
|
return $result['data']['token'];
|
||||||
|
}else{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function status($car_id):array {
|
||||||
|
//获取token
|
||||||
|
$token = $this->token();
|
||||||
|
//发起请求
|
||||||
|
$result = curl_post($this->domain.'/car/getCarAndStatus.do',[],[
|
||||||
|
'token' => $token,
|
||||||
|
'carId' => $car_id,
|
||||||
|
'mapType' => 1
|
||||||
|
]);
|
||||||
|
//返回数据
|
||||||
|
if(!empty($result['ret']) && isset($result['data'])){
|
||||||
|
return ['code'=>1,'msg'=>'请求成功','data'=>$result['data']];
|
||||||
|
}else{
|
||||||
|
return ['code'=>0,'msg'=>$result['msg']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function history($params):array {
|
||||||
|
//获取token
|
||||||
|
$token = $this->token();
|
||||||
|
//发起请求
|
||||||
|
$result = curl_post($this->domain.'/position/queryHistory.do',[],[
|
||||||
|
'token' => $token,
|
||||||
|
'carId' => $params['gps_car_id'],
|
||||||
|
'startTime' => $params['start_time'],
|
||||||
|
'endTime' => $params['end_time'],
|
||||||
|
'filter' => true,
|
||||||
|
'interval' => 1,
|
||||||
|
'pointType' => 2,
|
||||||
|
]);
|
||||||
|
//返回数据
|
||||||
|
if(!empty($result['ret']) && isset($result['data'])){
|
||||||
|
return ['code'=>1,'msg'=>'请求成功','data'=>$result['data']];
|
||||||
|
}else{
|
||||||
|
return ['code'=>0,'msg'=>$result['msg']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user