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/CarManController.php

116 lines
3.5 KiB

<?php
namespace App\Http\Controllers\Api;
use App\Http\Resources\CarMan;
use App\Http\Resources\CarManCollection;
use App\Models\CarManT;
use Illuminate\Http\Request;
/**
* @title 车辆联系人管理
* @description CarManController
* @package App\Http\Controllers\Api
* @author zcstatham
*/
class CarManController extends BaseController
{
protected $rules = [
'store' => [
'rules' => [
'car_id' => 'required|numeric',
'type' => 'numeric',
'name' => 'required|string',
'phone' => 'required|string',
'id_card_type' => 'numeric',
'id_card' => 'required|string',
],
'custom' => 'regx,id_type,id_card,id_card_type'
],
'update' => [
'rules' => [
'id' => 'bail|min:1',
'car_id' => 'required|numeric',
'type' => 'numeric',
'name' => 'required|string',
'phone' => 'required|string',
'id_card_type' => 'numeric',
'id_card' => 'required|string',
],
'custom' => [
'exists,App\Models\CarManT,id',
'regx,id_type,id_card,id_card_type'
]
],
];
public function __construct(Request $request)
{
$this->model = new CarManT();
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 CarManCollection($data));
}
/**
* @title 车辆联系人保存
* @description 车辆联系人保存
* @return \Illuminate\Http\JsonResponse
* @author zcstatham
*/
public function store()
{
$this->model->car_id = $this->params['car_id'] ?? 0;
$this->model->type = $this->params['type'] ?? 0;
$this->model->name = $this->params['name'] ?? '';
$this->model->phone = $this->params['phone'] ?? '';
$this->model->id_card_type = $this->params['id_card_type'] ?? 0;
$this->model->id_card = $this->params['id_card'] ?? '';
if($this->model->save()){
return $this->success(new CarMan($this->model));
} else {
return $this->error(500, '车辆联系人信息保存失败');
}
}
/**
* @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_id = $this->params['car_id'] ?? 0;
$this->model->type = $this->params['type'] ?? 0;
$this->model->name = $this->params['name'] ?? '';
$this->model->phone = $this->params['phone'] ?? '';
$this->model->id_card_type = $this->params['id_card_type'] ?? 0;
$this->model->id_card = $this->params['id_card'] ?? '';
if($this->model->save()){
return $this->success(new CarMan($this->model));
} else {
return $this->error(500, '车辆联系人信息保存失败');
}
}
}