You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
5.4 KiB
158 lines
5.4 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Resources\CarModel;
|
|
use App\Http\Resources\CarModelCollection;
|
|
use App\Models\CarModelT;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* @title CarModelController
|
|
* @description CarModelController
|
|
* @package App\Http\Controllers\Api
|
|
* @author zcstatham
|
|
*/
|
|
class CarModelController extends BaseController
|
|
{
|
|
|
|
protected $rules = [
|
|
'store' => [
|
|
'rules' => [
|
|
'car_series_id' => 'required',
|
|
'name' => 'required',
|
|
'year' => 'required',
|
|
]
|
|
],
|
|
'show' => [
|
|
'rules' => [
|
|
'id' => 'bail|min:1',
|
|
],
|
|
'custom' => 'exists,App\Models\CarModelT,id'
|
|
],
|
|
'update' => [
|
|
'rules' => [
|
|
'id' => 'bail|min:1',
|
|
'car_series_id' => 'required',
|
|
'name' => 'required',
|
|
'year' => 'required',
|
|
],
|
|
'custom' => [
|
|
'exists,App\Models\CarModelT,id',
|
|
]
|
|
],
|
|
];
|
|
|
|
public function __construct(Request $request)
|
|
{
|
|
$this->model = new CarModelT();
|
|
parent::__construct($request);
|
|
}
|
|
|
|
/**
|
|
* @title 基础列表
|
|
* @description 基础列表
|
|
* @return \Illuminate\Http\JsonResponse
|
|
* @author zcstatham
|
|
*/
|
|
public function index()
|
|
{
|
|
$query = $this->model->query();
|
|
|
|
if(isset($this->params['name']) && $this->params['name'] != ''){
|
|
$query->where('name', $this->params['name']);
|
|
}
|
|
|
|
if(isset($this->params['is_page']) && $this->params['is_page'] == 1){
|
|
$data = $query->paginate();
|
|
} else {
|
|
$data = $query->get();
|
|
}
|
|
|
|
return $this->success(new CarModelCollection($data));
|
|
}
|
|
|
|
/**
|
|
* @title 基础保存
|
|
* @description 基础保存
|
|
* @return \Illuminate\Http\JsonResponse
|
|
* @author zcstatham
|
|
*/
|
|
public function store()
|
|
{
|
|
$this->model->car_series_id = $this->params['car_series_id'];
|
|
$this->model->name = $this->params['name'];
|
|
$this->model->year = $this->params['year'];
|
|
$this->model->modelYears = $this->params['modelYears'];
|
|
$this->model->vehicle_type = $this->params['vehicle_type'];
|
|
$this->model->vehicle_size = $this->params['vehicle_size'];
|
|
$this->model->engine_model = $this->params['engine_model'];
|
|
$this->model->emission_standard = $this->params['emission_standard'];
|
|
$this->model->displacement = $this->params['displacement'];
|
|
$this->model->induction = $this->params['induction'];
|
|
$this->model->fuel_type = $this->params['fuel_type'];
|
|
$this->model->transmission_type = $this->params['transmission_type'];
|
|
$this->model->transmission_description = $this->params['transmission_description'];
|
|
$this->model->gear_number = $this->params['gear_number'];
|
|
$this->model->front_tyre = $this->params['front_tyre'];
|
|
$this->model->rear_tyre = $this->params['rear_tyre'];
|
|
$this->model->doors = $this->params['doors'];
|
|
$this->model->seats = $this->params['seats'];
|
|
$this->model->tuhu_code = $this->params['tuhu_code'];
|
|
$this->model->guidance_price = $this->params['guidance_price'];
|
|
if($this->model->save()){
|
|
return $this->success(new CarModel($this->model));
|
|
} else {
|
|
return $this->error(500, '基础信息保存失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @title 基础详情
|
|
* @description 基础详情
|
|
* @param $id
|
|
* @return mixed
|
|
* @author zcstatham
|
|
*/
|
|
public function show($id)
|
|
{
|
|
return $this->success(new CarModel($this->model->where('id', $id)->first()));
|
|
}
|
|
|
|
/**
|
|
* @title 基础更新
|
|
* @description 基础更新
|
|
* @param $id
|
|
* @return \Illuminate\Http\JsonResponse
|
|
* @author zcstatham
|
|
*/
|
|
public function update($id)
|
|
{
|
|
$this->model = $this->model->where('id', $id)->first();
|
|
$this->model->car_series_id = $this->params['car_series_id'];
|
|
$this->model->name = $this->params['name'];
|
|
$this->model->year = $this->params['year'];
|
|
$this->model->modelYears = $this->params['modelYears'];
|
|
$this->model->vehicle_type = $this->params['vehicle_type'];
|
|
$this->model->vehicle_size = $this->params['vehicle_size'];
|
|
$this->model->engine_model = $this->params['engine_model'];
|
|
$this->model->emission_standard = $this->params['emission_standard'];
|
|
$this->model->displacement = $this->params['displacement'];
|
|
$this->model->induction = $this->params['induction'];
|
|
$this->model->fuel_type = $this->params['fuel_type'];
|
|
$this->model->transmission_type = $this->params['transmission_type'];
|
|
$this->model->transmission_description = $this->params['transmission_description'];
|
|
$this->model->gear_number = $this->params['gear_number'];
|
|
$this->model->front_tyre = $this->params['front_tyre'];
|
|
$this->model->rear_tyre = $this->params['rear_tyre'];
|
|
$this->model->doors = $this->params['doors'];
|
|
$this->model->seats = $this->params['seats'];
|
|
$this->model->tuhu_code = $this->params['tuhu_code'];
|
|
$this->model->guidance_price = $this->params['guidance_price'];
|
|
if($this->model->save()){
|
|
return $this->success(new CarModel($this->model));
|
|
} else {
|
|
return $this->error(500, '基础信息保存失败');
|
|
}
|
|
}
|
|
}
|
|
|