2023-08-19 13:30:28 +08:00
|
|
|
|
<?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;
|
2023-08-24 17:50:08 +08:00
|
|
|
|
use app\common\logic\GpsLogic;
|
2023-08-19 13:30:28 +08:00
|
|
|
|
use app\common\model\vehicle\Vehicle;
|
2023-08-21 16:16:22 +08:00
|
|
|
|
use app\common\model\vehicle\VehicleRent;
|
2023-08-25 13:55:18 +08:00
|
|
|
|
use Exception;
|
2023-08-19 13:30:28 +08:00
|
|
|
|
|
2023-08-21 12:00:22 +08:00
|
|
|
|
|
2023-08-19 13:30:28 +08:00
|
|
|
|
/**
|
|
|
|
|
* 车辆逻辑
|
|
|
|
|
* Class VehicleLogic
|
|
|
|
|
* @package app\api\logic
|
|
|
|
|
*/
|
|
|
|
|
class VehicleLogic extends BaseLogic
|
|
|
|
|
{
|
2023-08-23 19:17:01 +08:00
|
|
|
|
public static function getCarLocal($params):array {
|
2023-08-30 14:12:13 +08:00
|
|
|
|
$car = Vehicle::field('gps_imei')->where('id',$params['car_id'])->find();
|
2023-08-23 19:17:01 +08:00
|
|
|
|
if(!$car){
|
|
|
|
|
return ['code'=>0,'msg'=>'车辆不存在'];
|
|
|
|
|
}
|
2023-08-30 14:12:13 +08:00
|
|
|
|
//获取车辆在gps系统中的id
|
|
|
|
|
$gps_car_id = (new GpsLogic()) -> info($car['gps_imei']);
|
2023-08-23 19:17:01 +08:00
|
|
|
|
//获取车辆当前位置
|
2023-08-30 17:46:29 +08:00
|
|
|
|
$local = (new GpsLogic()) -> status($gps_car_id['data']['carId']);
|
2023-08-23 19:17:01 +08:00
|
|
|
|
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']];
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-24 17:50:08 +08:00
|
|
|
|
|
|
|
|
|
public static function getCarHistory($params):array {
|
|
|
|
|
//获取车辆信息
|
|
|
|
|
$car = Vehicle::where('id',$params['car_id'])->find();
|
|
|
|
|
if(empty($car)){
|
|
|
|
|
return ['code'=>0,'msg'=>'车辆不存在'];
|
|
|
|
|
}
|
2023-08-30 17:37:26 +08:00
|
|
|
|
//获取车辆在gps系统中的id
|
|
|
|
|
$gps_car_id = (new GpsLogic()) -> info($car['gps_imei']);
|
2023-09-09 21:15:35 +08:00
|
|
|
|
if($gps_car_id['code'] == 0){
|
2023-09-09 21:16:20 +08:00
|
|
|
|
return ['code'=>0,'msg'=>$gps_car_id['msg']];
|
2023-09-09 21:15:35 +08:00
|
|
|
|
}
|
2023-08-30 17:45:26 +08:00
|
|
|
|
$params['gps_car_id'] = $gps_car_id['data']['carId'];
|
2023-08-24 17:50:08 +08:00
|
|
|
|
//获取车辆行驶历史信息
|
|
|
|
|
$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']];
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-01 16:14:22 +08:00
|
|
|
|
|
|
|
|
|
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']];
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-19 13:30:28 +08:00
|
|
|
|
}
|