'require', 'org_id' => 'require|checkOrg', 'dept_id' => 'require|checkDept', 'name' => 'require', 'file' => 'checkFile' ]; protected $message = [ 'id.require' => '缺少必要参数', 'org_id.require' => '请选择组织', 'dept_id.require' => '请选择部门', 'name.require' => '请填写规范名称', ]; /** * 参数描述 * @var string[] */ protected $field = [ 'id' => 'id', 'org_id' => '组织id', 'dept_id' => '部门id', 'type' => '规范类别', 'name' => '规范名称', 'publish_dep' => '发布部门', 'content' => '规范内容', 'file' => '附件', ]; /** * @notes 添加场景 * @return SafetyStandardValidate * @author likeadmin * @date 2023/12/19 10:21 */ public function sceneAdd() { return $this->only(['org_id', 'dept_id', 'type', 'name', 'publish_dep', 'content', 'file']); } /** * @notes 编辑场景 * @return SafetyStandardValidate * @author likeadmin * @date 2023/12/19 10:21 */ public function sceneEdit() { return $this->only(['id', 'org_id', 'dept_id', 'type', 'name', 'publish_dep', 'content', 'file']); } /** * @notes 删除场景 * @return SafetyStandardValidate * @author likeadmin * @date 2023/12/19 10:21 */ public function sceneDelete() { return $this->only(['id'])->remove('id', 'checkData'); } /** * @notes 详情场景 * @return SafetyStandardValidate * @author likeadmin * @date 2023/12/19 10:21 */ public function sceneDetail() { return $this->only(['id']); } public function checkOrg($value): bool|string { $data = Orgs::where('id', $value)->findOrEmpty(); if ($data->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 checkFile($value): bool|string { if (!empty($value) && $value != '') { if (!is_array($value)) { return '附件必须是json数组'; } } return true; } }