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.
186 lines
7.0 KiB
186 lines
7.0 KiB
<?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'] != ''){
|
|
$query->where('name', $this->params['name']);
|
|
}
|
|
|
|
if(isset($this->params['car_sub_brand_id']) && $this->params['car_sub_brand_id'] > 0){
|
|
$query->where('car_sub_brand_id', $this->params['car_sub_brand_id']);
|
|
}
|
|
|
|
if(!isset($this->params['is_all']) || $this->params['is_all'] == 0){
|
|
$query->select(['id', 'car_sub_brand_id', 'name', 'level']);
|
|
}
|
|
|
|
if(isset($this->params['is_page']) && $this->params['is_page'] == 1){
|
|
return $this->success(new CarSeriesCollection($query->paginate()));
|
|
} else {
|
|
return $this->success($query->get());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @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, '车系信息保存失败');
|
|
}
|
|
}
|
|
}
|
|
|