logistics/app/api/controller/VehicleController.php

118 lines
3.8 KiB
PHP
Raw Normal View History

2023-08-19 13:30:28 +08:00
<?php
namespace app\api\controller;
use app\api\logic\VehicleLogic;
2023-08-22 17:25:38 +08:00
use think\response\Json;
2023-08-19 13:30:28 +08:00
/**
* 车辆管理
* Class VehicleController
* @package app\api\controller
*/
class VehicleController extends BaseApiController
{
2023-08-23 19:17:01 +08:00
public array $notNeedLogin = ['getCompany','setContract','getRentRecord','updateRentRecord','getCompanyCars','getCarLocal'];
2023-08-23 15:29:10 +08:00
/*
*获取平台公司接口
*/
public function getCompany():Json {
2023-08-23 17:26:44 +08:00
$result = VehicleLogic::companyInfo();
2023-08-23 15:29:10 +08:00
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
2023-08-23 16:34:42 +08:00
public function setContract():Json {
2023-08-23 17:26:44 +08:00
//获取参数
$params = $this->request->post(['party_a','party_b','num','start_time','end_time','rent_type','car_id']);
2023-08-23 15:29:10 +08:00
//验证参数
2023-08-23 17:26:44 +08:00
if(empty($params['party_a']) || empty($params['party_b']) || empty($params['num']) || empty($params['start_time']) || empty($params['end_time']) || empty($params['rent_type'])){
2023-08-23 15:29:10 +08:00
return $this->fail('缺少必要的参数');
}
//验证时间格式
if(!checkDateIsValid($params['start_time']) || !checkDateIsValid($params['end_time'])){
return $this->fail('时间格式错误');
}
2023-08-23 17:26:44 +08:00
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('缺少必要参数');
}
}
2023-08-23 15:29:10 +08:00
//生成数据
$result = VehicleLogic::rentRecord($params);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg']);
}else{
return $this->fail($result['msg']);
}
}
2023-08-21 12:00:22 +08:00
2023-08-23 16:34:42 +08:00
public function getRentRecord():Json {
//获取参数
$params = $this -> request -> get('contract_id');
if(empty($params)){
return $this->fail('确实必要参数');
}
//获取数据
2023-08-23 17:26:44 +08:00
$result = VehicleLogic::rendRecordInfo($params);
2023-08-21 12:00:22 +08:00
//返回数据
if($result['code'] == 1){
2023-08-23 17:57:14 +08:00
return $this->success($result['msg'],$result['data']);
2023-08-21 16:16:22 +08:00
}else{
return $this->fail($result['msg']);
}
}
2023-08-23 17:26:44 +08:00
public function updateRentRecord():Json {
2023-08-21 16:16:22 +08:00
//获取参数
2023-08-23 17:26:44 +08:00
$param = $this->request->post('contract_id');
if(empty($param)){
2023-08-21 16:16:22 +08:00
return $this->fail('缺少必要参数');
}
2023-08-23 17:26:44 +08:00
//获取数据
$result = VehicleLogic::rendRecordEdit($param);
//返回数据
2023-08-21 16:16:22 +08:00
if($result['code'] == 1){
2023-08-23 18:07:52 +08:00
return $this->success($result['msg']);
2023-08-21 12:00:22 +08:00
}else{
return $this->fail($result['msg']);
}
}
2023-08-23 18:58:45 +08:00
2023-08-24 14:15:32 +08:00
public function getCompanyCars():Json {
2023-08-23 18:58:45 +08:00
$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']);
}
}
2023-08-23 19:17:01 +08:00
//获取车辆当前位置
2023-08-24 14:15:32 +08:00
public function getCarLocal():Json {
2023-08-23 19:17:01 +08:00
$params = $this->request->get(['car_id','gps_imei']);
if(empty($params['car_id']) || empty($params['gps_imei'])){
return $this->fail('缺少必要参数');
}
$result = VehicleLogic::getCarLocal($params);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
2023-08-19 13:30:28 +08:00
}