增加 修改状态

This commit is contained in:
iVampireSP.com 2023-02-13 15:50:19 +08:00
parent bafc660c11
commit ef91809691
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -110,11 +110,6 @@ public function isStopped(): bool
return $this->status === 'stopped';
}
public function isPending(): bool
{
return $this->status === 'pending';
}
public function isUnavailable(): bool
{
return $this->status === 'unavailable';
@ -260,11 +255,6 @@ public function run(): bool
return true;
}
public function isOverdue(): bool
{
return now()->gt($this->next_due_at);
}
public function safeDelete(): bool
{
// 如果创建时间大于大于 1 小时
@ -378,11 +368,35 @@ public function cost(string $amount = null, $auto = true, $description = null):
return true;
}
public function updateOrDelete(): bool
public function changeStatus(string $status): bool
{
dispatch(new UpdateOrDeleteHostJob($this));
$is_user = auth()->guard('api')->check() || auth()->guard('web')->check();
return true;
if ($is_user) {
if ($this->isPending() || $this->isOverdue() || $this->status === 'locked' || $this->status === 'unavailable') {
return false;
}
}
if ($status === 'running') {
return $this->run();
} elseif ($status === 'suspended') {
return $this->suspend();
} elseif ($status === 'stopped') {
return $this->stop();
}
return false;
}
public function isPending(): bool
{
return $this->status === 'pending';
}
public function isOverdue(): bool
{
return now()->gt($this->next_due_at);
}
public function suspend(): bool
@ -393,4 +407,20 @@ public function suspend(): bool
return true;
}
public function stop(): bool
{
$this->update([
'status' => 'stopped',
]);
return true;
}
public function updateOrDelete(): bool
{
dispatch(new UpdateOrDeleteHostJob($this));
return true;
}
}