'require|checkDept', 'org_id' => 'require|checkOrg', 'name' => 'require|length:1,30', 'leader' => 'checkLeader', 'mobile' => 'mobile', 'status' => 'require|in:0,1', 'sort' => 'egt:0', ]; protected $message = [ 'id.require' => '参数缺失', 'org_id.require' => '请选择所属组织', 'name.require' => '请填写部门名称', 'name.length' => '部门名称长度须在1-30位字符', 'name.unique' => '部门名称已存在', 'leader.require' => '请选择部门负责人', 'mobile.require' => '请填写部门负责人联系电话', 'mobile.mobile' => '部门负责人联系电话格式错误', 'status.require' => '请选择部门状态', 'sort.egt' => '排序值不正确', ]; /** * @notes 添加场景 * @return DeptValidate * @author 段誉 * @date 2022/5/25 18:16 */ public function sceneAdd() { return $this->remove('id', true)->append('name','checkUniqueByAdd'); } /** * @notes 详情场景 * @return DeptValidate * @author 段誉 * @date 2022/5/25 18:16 */ public function sceneDetail() { return $this->only(['id']); } /** * @notes 编辑场景 * @return DeptValidate * @author 段誉 * @date 2022/5/26 18:42 */ public function sceneEdit() { return $this->only(['id','org_id','name','leader','mobile','status'])->append('name','checkUniqueByEdit');; } /** * @notes 删除场景 * @return DeptValidate * @author 段誉 * @date 2022/5/25 18:16 */ public function sceneDelete() { return $this->only(['id'])->append('id','checkDept'); } //验证唯一 public function checkUniqueByAdd($value,$rule,$data): bool|string { $dep = Dept::where('org_id',$data['org_id'])->where('name',$data['name'])->findOrEmpty(); if(!$dep->isEmpty()){ return '部门已存在'; } return true; } public function checkUniqueByEdit($value,$rule,$data): bool|string { $dep = Dept::where('org_id',$data['org_id'])->where('name',$data['name'])->where('id','<>',$data['id'])->findOrEmpty(); if(!$dep->isEmpty()){ return '部门已存在'; } return true; } //校验组织 public function checkOrg($value): bool|string { $org = Orgs::findOrEmpty($value); if ($org->isEmpty()) { return '组织不存在'; } return true; } //校验部门 public function checkDept($value): bool|string { $dept = Dept::findOrEmpty($value); if ($dept->isEmpty()) { return '部门不存在'; } return true; } public function checkLeader($value){ $data = Admin::where('id',$value)->findOrEmpty(); if($data->isEmpty()){ return '负责人信息不存在'; } return true; } }