Jing Li 2024-04-20 17:43:45 +08:00
parent 0a4aec1690
commit f5442d9729
2 changed files with 9 additions and 8 deletions

View File

@ -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;

View File

@ -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;
}