logistics/app/api/logic/VehicleLogic.php
2023-09-01 16:14:22 +08:00

93 lines
3.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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\logic\GpsLogic;
use app\common\model\vehicle\Vehicle;
use app\common\model\vehicle\VehicleRent;
use Exception;
/**
* 车辆逻辑
* Class VehicleLogic
* @package app\api\logic
*/
class VehicleLogic extends BaseLogic
{
public static function getCarLocal($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']);
//获取车辆当前位置
$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']];
}
}
}