diff --git a/app/Http/Controllers/Api/WorkflowController.php b/app/Http/Controllers/Api/WorkflowController.php index 13e6099..6cff76c 100644 --- a/app/Http/Controllers/Api/WorkflowController.php +++ b/app/Http/Controllers/Api/WorkflowController.php @@ -108,7 +108,19 @@ class WorkflowController extends Controller $request->validate([ 'subject_type' => 'required', ]); - $check = WorkflowCheck::where('subject_type', $request->input('subject_type'))->where('subject_id', $id)->firstOrFail(); + if ($subjectType == (new TaskHygiene)->getMorphClass()) { + $task = Task::findOrFail($id); + $taskable = $task->taskable; + if (!$taskable) { + throw new RuntimeException('任务不存在'); + } + $check = $taskable->workflow; + if (!$check) { + throw new RuntimeException('审核记录不存在'); + } + } else { + $check = WorkflowCheck::where('subject_type', $subjectType)->where('subject_id', $id)->firstOrFail(); + } $logs = $check->logs()->sort()->get(); return WorkflowLogResource::collection($logs); @@ -119,7 +131,20 @@ class WorkflowController extends Controller $request->validate([ 'subject_type' => 'required', ]); - $check = WorkflowCheck::where('subject_type', $request->input('subject_type'))->where('subject_id', $id)->firstOrFail(); + $subjectType = $request->input('subject_type'); + if ($subjectType == (new TaskHygiene)->getMorphClass()) { + $task = Task::findOrFail($id); + $taskable = $task->taskable; + if (!$taskable) { + throw new RuntimeException('任务不存在'); + } + $check = $taskable->workflow; + if (!$check) { + throw new RuntimeException('审核记录不存在'); + } + } else { + $check = WorkflowCheck::where('subject_type', $subjectType)->where('subject_id', $id)->firstOrFail(); + } try { DB::beginTransaction(); if (!$workFlowService->cancel($check)) {