logistics/app/api/controller/VehicleController.php
2023-08-26 11:13:14 +08:00

105 lines
3.6 KiB
PHP

<?php
namespace app\api\controller;
use app\api\logic\VehicleLogic;
use think\response\Json;
/**
* 车辆管理
* Class VehicleController
* @package app\api\controller
*/
class VehicleController extends BaseApiController
{
public array $notNeedLogin = ['checkNum','vehicleRent','companyCarList','getCarLocal','getCarHistory'];
//验证租赁数量
public function checkNum() {
//获取参数
$param = $this->request->get(['num']);
if(empty($param['num'])){
return $this->fail('缺少必要参数');
}
if(!intval($param['num'])){
return $this->fail('参数格式错误');
}
$result = VehicleLogic::checkNum($param['num']);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
public function vehicleRent():Json {
//获取参数
$param = $this->request->post(['contract_id','car_id','company_id','company_name','company_user_id','company_user_name','company_user_phone','rent_type']);
if(empty($param['contract_id']) || empty($param['car_id']) || empty($param['company_id']) || empty($param['company_name']) || empty($param['company_user_id']) || empty($param['company_user_name']) || empty($param['company_user_phone']) || empty($param['rent_type'])){
return $this->fail('缺少必要参数');
}
//获取数据
$result = VehicleLogic::setRent($param);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg']);
}else{
return $this->fail($result['msg']);
}
}
public function companyCarList():Json {
//获取参数
$params = $this->request->post(['company_id','is_rent','license','company_name','page_no','page_size']);
//验证参数
if(empty($params['company_id']) || empty($params['is_rent'])){
return $this->fail('缺少必要参数');
}
//获取数据
$result = VehicleLogic::companyCarList($params);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
//获取车辆当前位置
public function getCarLocal():Json {
$params = $this->request->get(['car_id']);
if(empty($params['car_id'])){
return $this->fail('缺少必要参数');
}
$result = VehicleLogic::getCarLocal($params);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
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']);
}
}
}