[ 'rules' => [ 'employee_id' => 'required', 'type' => 'required', 'date' => 'required|date', 'price' => 'required', ], 'custom' => [ 'unique,App\Models\EmployeeRewardPunishmentT,date,type' ] ], 'show' => [ 'rules' => [ 'id' => 'bail|min:1', ], 'custom' => 'exists,App\Models\EmployeeRewardPunishmentT,id' ], 'update' => [ 'rules' => [ 'id' => 'bail|min:1', 'employee_id' => 'required', 'type' => 'required', 'date' => 'required|date', 'price' => 'required', ], 'custom' => [ 'exists,App\Models\EmployeeRewardPunishmentT,id', 'unique,App\Models\EmployeeRewardPunishmentT,date,type,id' ] ], 'destroy' => [ 'rules' => [ 'id' => 'bail|min:1', ], 'custom' => [ 'exists,App\Models\EmployeeRewardPunishmentT,id', ] ] ]; public function __construct(Request $request) { $this->model = new EmployeeRewardPunishmentT(); 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 EmployeeRewardPunishmentCollection($data)); } /** * @title 奖惩保存 * @description 奖惩保存 * @return \Illuminate\Http\JsonResponse * @author zcstatham */ public function store() { $this->model->employee_id = $this->params['employee_id']; $this->model->type = $this->params['type']; $this->model->price = $this->params['type'] > 600 ? abs($this->params['price']) : -abs($this->params['price']); $this->model->remark = $this->params['remark'] ?? ''; $this->model->date = $this->params['date'] ?? ''; $this->model->status = $this->params['status'] ?? 1; if($this->model->save()){ return $this->success(new EmployeeRewardPunishment($this->model)); } else { return $this->error(500, '奖惩信息保存失败'); } } /** * @title 奖惩详情 * @description 奖惩详情 * @param $id * @return mixed * @author zcstatham */ public function show($id) { return $this->success(new EmployeeRewardPunishment($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->type = $this->params['type']; $this->model->price = $this->params['type'] > 600 ? abs($this->params['price']) : -abs($this->params['price']); $this->model->remark = $this->params['remark'] ?? $this->model->remark; if($this->model->save()){ return $this->success(new EmployeeRewardPunishment($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::find($id); $this->model->status = 0; if($this->model->save()){ return $this->success(); } else { return $this->error(500, '奖惩信息保存失败'); } } }