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

266 lines
10 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 车辆管理
* @description CarInfoController
* @package App\Http\Controllers\Api
* @author zcstatham
*/
class CarInfoController extends BaseController
{
protected $rules = [
'store' => [
'rules' => [
'model_id' => 'numeric',
'car_no' => 'required|string',
'frame_no' => 'required|string',
'engine_no' => 'string',
'factory_model' => 'string',
'car_used_type' => 'string',
'car_man' => 'string',
'purchase_price' => 'string',
'register_date' => 'string',
'seat_count' => 'string',
'insurance_times' => 'numeric',
'insurance_serial_times' => 'numeric',
'repair_times' => 'numeric',
'insurance_repair_times' => 'numeric',
'last_insurance_company' => 'string',
'last_insurance_type' => 'string',
'last_insurance_rate' => 'numeric',
'last_insurance_salesman' => 'string',
'last_insurance_date' => 'string',
'force_expire_date' => 'string',
'business_expire_date' => 'string',
'status' => 'numeric',
]
],
'show' => [
'rules' => [
'id' => 'bail|min:1',
],
'custom' => 'exists,App\Models\CarInfoT,id'
],
'update' => [
'rules' => [
'id' => 'bail|min:1',
'model_id' => 'numeric',
'car_no' => 'required|string',
'frame_no' => 'required|string',
'engine_no' => 'string',
'factory_model' => 'string',
'car_used_type' => 'string',
'car_man' => 'string',
'purchase_price' => 'string',
'register_date' => 'string',
'seat_count' => 'string',
'insurance_times' => 'numeric',
'insurance_serial_times' => 'numeric',
'repair_times' => 'numeric',
'insurance_repair_times' => 'numeric',
'last_insurance_company' => 'string',
'last_insurance_type' => 'string',
'last_insurance_rate' => 'numeric',
'last_insurance_salesman' => 'string',
'last_insurance_date' => 'string',
'force_expire_date' => 'string',
'business_expire_date' => 'string',
'status' => 'numeric',
],
'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['model_id']) && $this->params['model_id'] != ''){
$query->where('model_id', $this->params['model_id']);
}
if(isset($this->params['car_no']) && $this->params['car_no'] != ''){
$query->where('car_no', $this->params['car_no']);
}
if(isset($this->params['frame_no']) && $this->params['frame_no'] != ''){
$query->where('frame_no', $this->params['frame_no']);
}
if(isset($this->params['engine_no']) && $this->params['engine_no'] != ''){
$query->where('engine_no', $this->params['engine_no']);
}
if(isset($this->params['factory_model']) && $this->params['factory_model'] != ''){
$query->where('factory_model', $this->params['factory_model']);
}
if(isset($this->params['car_used_type']) && $this->params['car_used_type'] != ''){
$query->where('car_used_type', $this->params['car_used_type']);
}
if(isset($this->params['car_man']) && $this->params['car_man'] != ''){
$query->where('car_man', $this->params['car_man']);
}
if(isset($this->params['purchase_price']) && $this->params['purchase_price'] != ''){
$query->where('purchase_price', $this->params['purchase_price']);
}
if(isset($this->params['register_date']) && $this->params['register_date'] != ''){
$query->where('register_date', $this->params['register_date']);
}
if(isset($this->params['last_insurance_date']) && $this->params['name'] != ''){
$query->where('name', $this->params['name']);
}
if(isset($this->params['business_expire_date']) && $this->params['name'] != ''){
$query->where('name', $this->params['name']);
}
if(isset($this->params['force_expire_date']) && $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->model_id = $this->params['model_id'] ?? 0;
$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'] ?? 0;
$this->model->insurance_serial_times = $this->params['insurance_serial_times'] ?? 0;
$this->model->repair_times = $this->params['repair_times'] ?? 0;
$this->model->insurance_repair_times = $this->params['insurance_repair_times'] ?? 0;
$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'] ?? 0;
$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'] ?? 0;
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->model_id = $this->params['model_id'] ?? 0;
$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'] ?? 0;
$this->model->insurance_serial_times = $this->params['insurance_serial_times'] ?? 0;
$this->model->repair_times = $this->params['repair_times'] ?? 0;
$this->model->insurance_repair_times = $this->params['insurance_repair_times'] ?? 0;
$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'] ?? 0;
$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'] ?? 0;
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)
{
$this->model = $this->model->where('id', $id)->first();
$this->model->status = 0;
if($this->model->save()){
return $this->success();
} else {
return $this->error(500, '车辆信息保存失败');
}
}
}