[ 'rules' => [ 'employee_id' => 'required', 'social_type' => 'required', 'base_price' => 'required', 'personal_rate' => 'required', 'unit_rate' => 'required', ] ], 'show' => [ 'rules' => [ 'id' => 'bail|min:1', ], 'custom' => 'exists,App\Models\EmployeeSocialItemsT,id' ], 'update' => [ 'rules' => [ 'id' => 'bail|min:1', 'employee_id' => 'required', 'social_type' => 'required', 'base_price' => 'required', 'personal_rate' => 'required', 'unit_rate' => 'required', ], 'custom' => [ 'exists,App\Models\EmployeeSocialItemsT,id', ] ], 'destroy' => [ 'rules' => [ 'id' => 'bail|min:1', ], 'custom' => [ 'exists,App\Models\EmployeeSocialItemsT,id', ] ] ]; public function __construct(Request $request) { $this->model = new EmployeeSocialItemsT(); 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 EmployeeSocialItemsCollection($data)); } /** * @title 社保保存 * @description 社保保存 * @return \Illuminate\Http\JsonResponse * @author zcstatham */ public function store() { $this->model->employee_id = $this->params['employee_id']; $this->model->social_type = $this->params['social_type']; $this->model->base_price = $this->params['base_price']; $this->model->personal_rate = $this->params['personal_rate']; $this->model->unit_rate = $this->params['unit_rate']; $this->model->personal_price = $this->params['personal_price'] ?: route($this->params['base_price'] * $this->params['personal_rate'] / 100); $this->model->unit_price = $this->params['unit_price'] ?: route($this->params['base_price'] * $this->params['unit_rate'] / 100); if($this->model->save()){ return $this->success(new EmployeeSocialItems($this->model)); } else { return $this->error(500, '社保信息保存失败'); } } /** * @title 社保详情 * @description 社保详情 * @param $id * @return mixed * @author zcstatham */ public function show($id) { return $this->success(new EmployeeSocialItems($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->employee_id = $this->params['employee_id']; $this->model->social_type = $this->params['social_type']; $this->model->base_price = $this->params['base_price']; $this->model->personal_rate = $this->params['personal_rate']; $this->model->unit_rate = $this->params['unit_rate']; $this->model->personal_price = $this->params['personal_price'] ?: route($this->params['base_price'] * $this->params['personal_price'] / 100); $this->model->unit_price = $this->params['unit_price'] ?: route($this->params['base_price'] * $this->params['unit_rate'] / 100); if($this->model->save()){ return $this->success(new EmployeeSocialItems($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, '社保信息保存失败'); } } }