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.
193 lines
6.9 KiB
193 lines
6.9 KiB
4 years ago
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\Api;
|
||
|
|
||
|
use App\Http\Resources\CarSeries;
|
||
|
use App\Http\Resources\CarSeriesCollection;
|
||
|
use App\Models\CarSeriesT;
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
/**
|
||
|
* @title 基础管理
|
||
|
* @description CarSeriesController
|
||
|
* @package App\Http\Controllers\Api
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
class CarSeriesController extends BaseController
|
||
|
{
|
||
|
|
||
|
protected $rules = [
|
||
|
'store' => [
|
||
|
'rules' => [
|
||
|
'car_sub_brand_id' => 'required|numeric',
|
||
|
'name' => 'required|string',
|
||
|
'series' => 'string',
|
||
|
'level' => 'string',
|
||
|
'externalPanelPrice' => 'numeric',
|
||
|
'internalPanelPrice' => 'numeric',
|
||
|
'externalPaintPrice' => 'numeric',
|
||
|
'internalPaintPrice' => 'numeric',
|
||
|
'externalUnderPrice' => 'numeric',
|
||
|
'internalUnderPrice' => 'numeric',
|
||
|
'externalPolishPrice' => 'numeric',
|
||
|
'internalPolishPrice' => 'numeric',
|
||
|
'externalRepairPrice' => 'numeric',
|
||
|
'internalRepairPrice' => 'numeric',
|
||
|
'externalOutreachPrice' => 'numeric',
|
||
|
]
|
||
|
],
|
||
|
'show' => [
|
||
|
'rules' => [
|
||
|
'id' => 'bail|min:1',
|
||
|
],
|
||
|
'custom' => 'exists,App\Models\CarSeriesT,id'
|
||
|
],
|
||
|
'update' => [
|
||
|
'rules' => [
|
||
|
'id' => 'bail|min:1',
|
||
|
'car_sub_brand_id' => 'required|numeric',
|
||
|
'name' => 'required|string',
|
||
|
'series' => 'string',
|
||
|
'level' => 'string',
|
||
|
'externalPanelPrice' => 'numeric',
|
||
|
'internalPanelPrice' => 'numeric',
|
||
|
'externalPaintPrice' => 'numeric',
|
||
|
'internalPaintPrice' => 'numeric',
|
||
|
'externalUnderPrice' => 'numeric',
|
||
|
'internalUnderPrice' => 'numeric',
|
||
|
'externalPolishPrice' => 'numeric',
|
||
|
'internalPolishPrice' => 'numeric',
|
||
|
'externalRepairPrice' => 'numeric',
|
||
|
'internalRepairPrice' => 'numeric',
|
||
|
'externalOutreachPrice' => 'numeric',
|
||
|
],
|
||
|
'custom' => [
|
||
|
'exists,App\Models\CarSeriesT,id',
|
||
|
]
|
||
|
],
|
||
|
'destroy' => [
|
||
|
'rules' => [
|
||
|
'id' => 'bail|min:1',
|
||
|
],
|
||
|
'custom' => [
|
||
|
'exists,App\Models\CarSeriesT,id',
|
||
|
]
|
||
|
]
|
||
|
];
|
||
|
|
||
|
public function __construct(Request $request)
|
||
|
{
|
||
|
$this->model = new CarSeriesT();
|
||
|
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'] > 0){
|
||
|
$query->where('name', $this->params['name']);
|
||
|
}
|
||
|
|
||
|
$data = $query->paginate();
|
||
|
|
||
|
return $this->success(new CarSeriesCollection($data));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 基础保存
|
||
|
* @description 基础保存
|
||
|
* @return \Illuminate\Http\JsonResponse
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function store()
|
||
|
{
|
||
|
$this->model->car_sub_brand_id = $this->params['car_sub_brand_id'] ?? 0;
|
||
|
$this->model->name = $this->params['name'] ?? '';
|
||
|
$this->model->series = $this->params['series'] ?? '';
|
||
|
$this->model->level = $this->params['level'] ?? '';
|
||
|
$this->model->externalPanelPrice = $this->params['externalPanelPrice'] ?? 0;
|
||
|
$this->model->internalPanelPrice = $this->params['internalPanelPrice'] ?? 0;
|
||
|
$this->model->externalPaintPrice = $this->params['externalPaintPrice'] ?? 0;
|
||
|
$this->model->internalPaintPrice = $this->params['internalPaintPrice'] ?? 0;
|
||
|
$this->model->externalUnderPrice = $this->params['externalUnderPrice'] ?? 0;
|
||
|
$this->model->internalUnderPrice = $this->params['internalUnderPrice'] ?? 0;
|
||
|
$this->model->externalPolishPrice = $this->params['externalPolishPrice'] ?? 0;
|
||
|
$this->model->internalPolishPrice = $this->params['internalPolishPrice'] ?? 0;
|
||
|
$this->model->externalRepairPrice = $this->params['externalRepairPrice'] ?? 0;
|
||
|
$this->model->internalRepairPrice = $this->params['internalRepairPrice'] ?? 0;
|
||
|
$this->model->externalOutreachPrice = $this->params['externalOutreachPrice'] ?? 0;
|
||
|
if($this->model->save()){
|
||
|
return $this->success(new CarSeries($this->model));
|
||
|
} else {
|
||
|
return $this->error(500, '基础信息保存失败');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 基础详情
|
||
|
* @description 基础详情
|
||
|
* @param $id
|
||
|
* @return mixed
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function show($id)
|
||
|
{
|
||
|
return $this->success(new CarSeries($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_sub_brand_id = $this->params['car_sub_brand_id'] ?? 0;
|
||
|
$this->model->name = $this->params['name'] ?? '';
|
||
|
$this->model->series = $this->params['series'] ?? '';
|
||
|
$this->model->level = $this->params['level'] ?? '';
|
||
|
$this->model->externalPanelPrice = $this->params['externalPanelPrice'] ?? 0;
|
||
|
$this->model->internalPanelPrice = $this->params['internalPanelPrice'] ?? 0;
|
||
|
$this->model->externalPaintPrice = $this->params['externalPaintPrice'] ?? 0;
|
||
|
$this->model->internalPaintPrice = $this->params['internalPaintPrice'] ?? 0;
|
||
|
$this->model->externalUnderPrice = $this->params['externalUnderPrice'] ?? 0;
|
||
|
$this->model->internalUnderPrice = $this->params['internalUnderPrice'] ?? 0;
|
||
|
$this->model->externalPolishPrice = $this->params['externalPolishPrice'] ?? 0;
|
||
|
$this->model->internalPolishPrice = $this->params['internalPolishPrice'] ?? 0;
|
||
|
$this->model->externalRepairPrice = $this->params['externalRepairPrice'] ?? 0;
|
||
|
$this->model->internalRepairPrice = $this->params['internalRepairPrice'] ?? 0;
|
||
|
$this->model->externalOutreachPrice = $this->params['externalOutreachPrice'] ?? 0;
|
||
|
if($this->model->save()){
|
||
|
return $this->success(new CarSeries($this->model));
|
||
|
} else {
|
||
|
return $this->error(500, '基础信息保存失败');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 基础删除
|
||
|
* @description 基础删除
|
||
|
* @param $id
|
||
|
* @return \Illuminate\Http\JsonResponse
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function destroy($id)
|
||
|
{
|
||
|
if($this->model->destroy($id)){
|
||
|
return $this->success();
|
||
|
} else {
|
||
|
return $this->error(500, '基础信息保存失败');
|
||
|
}
|
||
|
}
|
||
|
}
|