'require|checkData', 'name' => 'require', 'email' => 'email', 'mobile' => 'require|mobile|unique:oa_admin', 'sex' => 'integer|in:0,1,2', 'org_id' => 'require|checkOrg', 'dept_id' => 'require|checkDept', 'job_id' => 'require|checkJob', 'type' => 'require|integer|in:0,1,2', 'age' => 'integer|gt:0', 'idcard' => 'idCard', 'entry_time' => 'require|dateFormat:Y-m-d', 'status' => 'require|integer|in:0,1,2', 'password' => 'require|length:6,32', 'role_id' => 'require|checkRole', ]; /** * 参数描述 * @var string[] */ protected $field = [ 'id' => 'id', 'name' => '员工姓名', 'email' => '电子邮箱', 'mobile' => '手机号码', 'sex' => '性别', 'org_id' => '组织', 'dept_id' => '部门', 'job_id' => '职位', 'type' => '员工类型', 'age' => '年龄', 'idcard' => '身份证', 'entry_time' => '员工入职日期', 'status' => '状态', 'password' => '登录密码', 'role_id' => '角色权限', ]; /** * @notes 添加场景 * @return OaAdminValidate * @author likeadmin * @date 2024/05/22 15:49 */ public function sceneAdd() { return $this->remove('id',true); } /** * @notes 编辑场景 * @return OaAdminValidate * @author likeadmin * @date 2024/05/22 15:49 */ public function sceneEdit() {} /** * @notes 删除场景 * @return OaAdminValidate * @author likeadmin * @date 2024/05/22 15:49 */ public function sceneDelete() { return $this->only(['id']); } /** * @notes 详情场景 * @return OaAdminValidate * @author likeadmin * @date 2024/05/22 15:49 */ public function sceneDetail() { return $this->only(['id']); } public function checkData($value): bool|string { $data = OaAdmin::field('id')->where('id',$value)->findOrEmpty(); return $data->isEmpty() ? '数据不存在' : true; } public function checkOrg($value): bool|string { $org = Orgs::where('id', $value)->findOrEmpty(); if ($org->isEmpty()) { return '组织不存在'; } return true; } public function checkDept($value, $rule, $data): bool|string { $dept = Dept::where('id', $value)->findOrEmpty(); if ($dept->isEmpty()) { return '部门不存在'; } if ($dept['org_id'] != $data['org_id']) { return '该部门不属于当前选择的组织'; } return true; } public function checkJob($value, $rule, $data): bool|string { $job = Jobs::where('id', $value)->findOrEmpty(); if ($job->isEmpty()) { return '岗位不存在'; } if ($job['dept_id'] != $data['dept_id']) { return '该岗位不属于当前选择的部门'; } return true; } public function checkRole($value): bool|string { if(empty($value) || !is_array($value)){ return '角色数据格式错误'; } foreach ($value as $item) { $res = SystemRole::where('id',$item)->findOrEmpty(); if($res->isEmpty()){ return '角色数据不存在'; } } return true; } }