logistics/app/api/controller/VehicleController.php
2023-08-23 16:34:42 +08:00

125 lines
4.1 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','tricycle','multipleRent','singleRent'];
/*
*获取平台公司接口
*/
public function getCompany():Json {
$result = VehicleLogic::company();
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','start_time','end_time']);
//验证参数
if(empty($params['party_a']) || empty($params['party_b']) || empty($params['num']) || empty($params['start_time']) || empty($params['end_time'])){
return $this->fail('缺少必要的参数');
}
//验证时间格式
if(!checkDateIsValid($params['start_time']) || !checkDateIsValid($params['end_time'])){
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::recordInfo($params);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
/*
* 获取去未出租的三轮车列表
*/
public function tricycle():Json
{
//获取参数
$params = $this->request->get(['page_no','page_size']);
//获取数据
$data = VehicleLogic::lists($params);
//返回数据
return $this->success('请求成功',$data);
}
/*
* 三轮车批量出租
*/
public function multipleRent():Json
{
//获取参数
$params = $this->request->post(['company_id','contract_id','car_ids','start_time','end_time']);
//验证参数
if(empty($params['company_id']) || empty($params['contract_id']) || empty($params['car_ids']) || empty($params['start_time']) || empty($params['end_time'])) {
return $this->fail('缺少必要参数');
}
if(!checkDateIsValid($params['start_time']) || !checkDateIsValid($params['end_time'])){
return $this->fail('时间格式错误');
}
//写入数据
$result = VehicleLogic::oneLevelRent($params);
//返回结果
if($result['code'] == 1){
return $this->success($result['msg']);
}else{
return $this->fail($result['msg']);
}
}
/*
* 三轮车单辆出租
*/
public function singleRent():Json
{
//获取参数
$params = $this->request->post(['lessor_company_id','tenant_company_id','contract_id','car_id','start_time','end_time']);
//验证参数
if(empty($params['lessor_company_id']) || empty($params['tenant_company_id']) || empty($params['contract_id']) || empty($params['car_id']) || empty($params['start_time']) || empty($params['end_time'])){
return $this->fail('缺少必要参数');
}
if(!checkDateIsValid($params['start_time']) || !checkDateIsValid($params['end_time'])){
return $this->fail('时间格式错误');
}
//写入数据
$result = VehicleLogic::twoLevelRent($params);
//返回结果
if($result['code'] == 1){
return $this->success($result['msg']);
}else{
return $this->fail($result['msg']);
}
}
}