s
This commit is contained in:
parent
be63b8a9e0
commit
9a809c7b8e
@ -3,6 +3,7 @@ namespace app\api\controller;
|
||||
|
||||
use app\api\logic\VehicleLogic;
|
||||
use app\common\model\vehicle\Vehicle;
|
||||
use app\common\model\vehicle\VehicleUser;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
@ -12,125 +13,7 @@ use think\response\Json;
|
||||
*/
|
||||
class VehicleController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = ['checkNum','vehicleRent','companyCarList','companyCar','addVehicle','getSelfCar','carInfo','getCarLocal','getCarHistory'];
|
||||
|
||||
|
||||
//验证租赁数量
|
||||
public function checkNum() {
|
||||
//获取参数
|
||||
$param = $this->request->post(['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 companyCar():Json {
|
||||
//获取参数
|
||||
$company_id = $this->request->post('company_id');
|
||||
//验证参数
|
||||
if(empty($company_id)){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
//获取数据
|
||||
$result = VehicleLogic::companyCar($company_id);
|
||||
//返回数据
|
||||
if($result['code'] == 1){
|
||||
return $this->success($result['msg'],$result['data']);
|
||||
}else{
|
||||
return $this->fail($result['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function addVehicle():Json {
|
||||
//获取参数
|
||||
$params = $this->request->post(['company_id','license']);
|
||||
if(empty($params['company_id']) || empty($params['license'])){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
$result = VehicleLogic::addVehicle($params);
|
||||
//返回数据
|
||||
if($result['code'] == 1){
|
||||
return $this->success($result['msg']);
|
||||
}else{
|
||||
return $this->fail($result['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function getSelfCar():Json {
|
||||
//获取参数
|
||||
$company_id = $this->request->post('company_id');
|
||||
if(empty($company_id)){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
$result = Vehicle::field('id')->where('company_id',$company_id)->where('type',2)->find();
|
||||
if($result){
|
||||
return $this->success('请求成功',['has_car'=>true]);
|
||||
}else{
|
||||
return $this->success('请求成功',['has_car'=>false]);
|
||||
}
|
||||
}
|
||||
|
||||
public function carInfo():Json {
|
||||
//获取参数
|
||||
$params = $this->request->post(['car_id','car_type']);
|
||||
if(empty($params['car_id']) || empty($params['car_type'])){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
if(!in_array($params['car_type'],[1,2])){
|
||||
return $this->fail('车辆类型错误');
|
||||
}
|
||||
//获取数据
|
||||
$result = VehicleLogic::carInfo($params);
|
||||
//返回数据
|
||||
if($result['code'] == 1){
|
||||
return $this->success($result['msg'],$result['data']);
|
||||
}else{
|
||||
return $this->fail($result['msg']);
|
||||
}
|
||||
}
|
||||
public array $notNeedLogin = ['getCarLocal','getCarHistory','createRentCarUser'];
|
||||
|
||||
//获取车辆当前位置
|
||||
public function getCarLocal():Json {
|
||||
@ -167,4 +50,19 @@ class VehicleController extends BaseApiController
|
||||
return $this->fail($result['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function createRentCarUser() {
|
||||
//获取参数
|
||||
$params = $this->request->post(['car_id','user_id','user_name','user_phone']);
|
||||
if(empty($params['car_id']) || empty($params['user_id']) || empty($params['user_name']) || empty($params['user_phone'])){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
$result = VehicleUser::create([
|
||||
'car_id' => $params['car_id'],
|
||||
'user_id' => $params['user_id'],
|
||||
'user_name' => $params['user_name'],
|
||||
'user_phone' => $params['user_phone'],
|
||||
]);
|
||||
return $result->id ? $this->success('sucess') : $this->fail('error');
|
||||
}
|
||||
}
|
||||
|
@ -25,15 +25,9 @@ Route::rule('hasCourier','Logistics/hasCourier','get');
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------------------------*/
|
||||
Route::rule('checkNum','Vehicle/checkNum','post');
|
||||
Route::rule('vehicleRent','Vehicle/vehicleRent','post');
|
||||
Route::rule('getCarLocal','Vehicle/getCarLocal','get');
|
||||
Route::rule('getCarHistory','Vehicle/getCarHistory','get');
|
||||
Route::rule('companyCarList','Vehicle/companyCarList','post');
|
||||
Route::rule('companyCar','Vehicle/companyCar','post');
|
||||
Route::rule('addVehicle','Vehicle/addVehicle','post');
|
||||
Route::rule('getSelfCar','Vehicle/getSelfCar','post');
|
||||
Route::rule('carInfo','Vehicle/carInfo','post');
|
||||
Route::rule('createRentCarUser','Contract/createRentCarUser','post');
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------------------------*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user