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.
 
 
user_center/app/Http/Controllers/Api/CarInfoController.php

178 lines
6.2 KiB

<?php
namespace App\Http\Controllers\Api;
use App\Http\Resources\CarInfo;
use App\Http\Resources\CarInfoCollection;
use App\Models\CarInfoT;
use Illuminate\Http\Request;
/**
* @title CarInfoController
* @description CarInfoController
* @package App\Http\Controllers\Api
* @author zcstatham
*/
class CarInfoController extends BaseController
{
protected $rules = [
'store' => [
'rules' => [
'car_no' => 'required',
'frame_no' => 'required',
]
],
'show' => [
'rules' => [
'id' => 'bail|min:1',
],
'custom' => 'exists,App\Models\CarInfoT,id'
],
'update' => [
'rules' => [
'id' => 'bail|min:1',
'car_no' => 'required',
'frame_no' => 'required',
],
'custom' => [
'exists,App\Models\CarInfoT,id',
]
],
'destroy' => [
'rules' => [
'id' => 'bail|min:1',
],
'custom' => [
'exists,App\Models\CarInfoT,id',
]
]
];
public function __construct(Request $request)
{
$this->model = new CarInfoT();
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']);
}
$data = $query->paginate();
return $this->success(new CarInfoCollection($data));
}
/**
* @title 基础保存
* @description 基础保存
* @return \Illuminate\Http\JsonResponse
* @author zcstatham
*/
public function store()
{
$this->model->car_no = $this->params['car_no'];
$this->model->frame_no = $this->params['frame_no'];
$this->model->engine_no = $this->params['engine_no'];
$this->model->factory_model = $this->params['factory_model'];
$this->model->car_used_type = $this->params['car_used_type'];
$this->model->car_man = $this->params['car_man'];
$this->model->purchase_price = $this->params['purchase_price'];
$this->model->register_date = $this->params['register_date'];
$this->model->seat_count = $this->params['seat_count'];
$this->model->insurance_times = $this->params['insurance_times'];
$this->model->insurance_serial_times = $this->params['insurance_serial_times'];
$this->model->repair_times = $this->params['repair_times'];
$this->model->insurance_repair_times = $this->params['insurance_repair_times'];
$this->model->last_insurance_company = $this->params['last_insurance_company'];
$this->model->last_insurance_type = $this->params['last_insurance_type'];
$this->model->last_insurance_rate = $this->params['last_insurance_rate'];
$this->model->last_insurance_salesman = $this->params['last_insurance_salesman'];
$this->model->last_insurance_date = $this->params['last_insurance_date'];
$this->model->force_expire_date = $this->params['force_expire_date'];
$this->model->business_expire_date = $this->params['business_expire_date'];
$this->model->status = $this->params['status'];
if($this->model->save()){
return $this->success(new CarInfo($this->model));
} else {
return $this->error(500, '基础信息保存失败');
}
}
/**
* @title 基础详情
* @description 基础详情
* @param $id
* @return mixed
* @author zcstatham
*/
public function show($id)
{
return $this->success(new CarInfo($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_no = $this->params['car_no'];
$this->model->frame_no = $this->params['frame_no'];
$this->model->engine_no = $this->params['engine_no'];
$this->model->factory_model = $this->params['factory_model'];
$this->model->car_used_type = $this->params['car_used_type'];
$this->model->car_man = $this->params['car_man'];
$this->model->purchase_price = $this->params['purchase_price'];
$this->model->register_date = $this->params['register_date'];
$this->model->seat_count = $this->params['seat_count'];
$this->model->insurance_times = $this->params['insurance_times'];
$this->model->insurance_serial_times = $this->params['insurance_serial_times'];
$this->model->repair_times = $this->params['repair_times'];
$this->model->insurance_repair_times = $this->params['insurance_repair_times'];
$this->model->last_insurance_company = $this->params['last_insurance_company'];
$this->model->last_insurance_type = $this->params['last_insurance_type'];
$this->model->last_insurance_rate = $this->params['last_insurance_rate'];
$this->model->last_insurance_salesman = $this->params['last_insurance_salesman'];
$this->model->last_insurance_date = $this->params['last_insurance_date'];
$this->model->force_expire_date = $this->params['force_expire_date'];
$this->model->business_expire_date = $this->params['business_expire_date'];
$this->model->status = $this->params['status'];
if($this->model->save()){
return $this->success(new CarInfo($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, '基础信息保存失败');
}
}
}