logistics/app/api/controller/VehicleController.php
2023-08-24 17:50:08 +08:00

136 lines
4.3 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 = ['getCompany','setContract','getRentRecord','updateRentRecord','getCompanyCars','getCarLocal','getCarHistory'];
/*
*获取平台公司接口
*/
public function getCompany():Json {
$result = VehicleLogic::companyInfo();
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
public function setContract():Json {
//获取参数
$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'])){
return $this->fail('缺少必要的参数');
}
if(!in_array($params['rent_type'],[1,2])){
return $this->fail('rent_type数据格式错误');
}
if($params['rent_type'] == 2){
if(empty($params['car_id'])){
return $this->fail('缺少必要参数');
}
}
//生成数据
$result = VehicleLogic::rentRecord($params);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg']);
}else{
return $this->fail($result['msg']);
}
}
public function getRentRecord():Json {
//获取参数
$params = $this -> request -> get('contract_id');
if(empty($params)){
return $this->fail('确实必要参数');
}
//获取数据
$result = VehicleLogic::rendRecordInfo($params);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
public function updateRentRecord():Json {
//获取参数
$param = $this->request->post('contract_id');
if(empty($param)){
return $this->fail('缺少必要参数');
}
//获取数据
$result = VehicleLogic::rendRecordEdit($param);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg']);
}else{
return $this->fail($result['msg']);
}
}
public function getCompanyCars():Json {
$params = $this->request->get(['company_id','company_type']);
if(empty($params['company_id']) || empty($params['company_type'])){
return $this->fail('缺少必要参数');
}
$result = VehicleLogic::getCompanyCars($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']);
}
}
}