'require|checkData', 'project_id' => 'require|checkProject', 'origin_address' => 'require', 'target_address' => 'require', 'traffic' => 'require|checkTraffic', 'start_date' => 'require|dateFormat:Y-m-d', 'end_date' => 'require|dateFormat:Y-m-d|checkEndDate', 'annex' => 'checkAnnex', 'flow_id' => 'require|checkFlow', 'path' => 'require', ]; /** * 参数描述 * @var string[] */ protected $field = [ 'id' => 'id', 'project_id' => '项目id', 'origin_address' => '出差起始地', 'target_address' => '出差目的地', 'traffic' => '交通工具', 'start_date' => '出差时间', 'end_date' => '结束时间', ]; /** * @notes 添加场景 * @return ProjectTripApplyValidate * @author likeadmin * @date 2024/01/17 09:22 */ public function sceneAdd() { return $this->remove('id', true)->remove('flow_id', true)->remove('path', true); } /** * @notes 编辑场景 * @return ProjectTripApplyValidate * @author likeadmin * @date 2024/01/17 09:22 */ public function sceneEdit() { return $this->remove('flow_id', true)->remove('path', true); } /** * @notes 删除场景 * @return ProjectTripApplyValidate * @author likeadmin * @date 2024/01/17 09:22 */ public function sceneDelete() { return $this->only(['id'])->remove('id', 'checkData'); } /** * @notes 详情场景 * @return ProjectTripApplyValidate * @author likeadmin * @date 2024/01/17 09:22 */ public function sceneDetail() { return $this->only(['id']); } public function sceneApprove() { return $this->only(['id', 'flow_id', 'path']); } public function checkData($value): bool|string { $data = ProjectTripApply::where('id', $value)->findOrEmpty(); if ($data->isEmpty()) { return '数据不存在'; } return true; } public function checkProject($value): bool|string { $data = Project::where('id', $value)->findOrEmpty(); if ($data->isEmpty()) { return '项目信息不存在'; } return true; } public function checkTraffic($value): bool|string { $dict = DictData::where('type_value', 'traffic')->column('value'); if (!in_array($value, $dict)) { return '交通工具无效'; } return true; } public function checkEndDate($value, $rule, $data): bool|string { $end_time = strtotime($value); $start_time = strtotime($data['start_date']); if ($end_time <= $start_time) { return '结束时间必须大于开始时间'; } return true; } public function checkAnnex($value): bool|string { if (!empty($value) && $value != '') { if (!is_array($value)) { return '附件格式错误'; } } return true; } }