From f5442d9729fbee0f63fc8e1f0eda758c7e68e6cc Mon Sep 17 00:00:00 2001 From: Jing Li Date: Sat, 20 Apr 2024 17:43:45 +0800 Subject: [PATCH] Fix --- app/Admin/Services/Plan/TaskService.php | 13 +++++++------ app/Models/TaskPerformance.php | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/Admin/Services/Plan/TaskService.php b/app/Admin/Services/Plan/TaskService.php index 99241cb..7aa76c9 100644 --- a/app/Admin/Services/Plan/TaskService.php +++ b/app/Admin/Services/Plan/TaskService.php @@ -135,12 +135,13 @@ class TaskService extends BaseService 'task_status' => TaskStatus::Pending, ]); - if ($taskable->isSuccess()) { - $task->task_status = TaskStatus::Success; - $task->completed_at = now(); - } - - $taskable->task()->save($task); + $taskable->task()->create([ + 'plan_id' => $plan->id, + 'name' => '清洁卫生', + 'start_at' => $startAt, + 'end_at' => $endAt, + 'task_status' => TaskStatus::Pending, + ]); break; diff --git a/app/Models/TaskPerformance.php b/app/Models/TaskPerformance.php index 18bca7c..1a7b6a9 100644 --- a/app/Models/TaskPerformance.php +++ b/app/Models/TaskPerformance.php @@ -46,7 +46,7 @@ class TaskPerformance extends Model */ public function isSuccess(): bool { - return $this->task_status === TaskPerformanceStatus::Success; + return bccomp($this->actual_performance, $this->expected_performance, 2) >= 0; } /** @@ -56,7 +56,7 @@ class TaskPerformance extends Model { return Attribute::make( get: function (mixed $value, array $attributes) { - if (bccomp($attributes['actual_performance'], $attributes['expected_performance'], 2) >= 0) { + if ($this->isSuccess()) { return TaskPerformanceStatus::Success; }