first&last
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\ServiceRequest;
|
||||
use App\Models\User;
|
||||
use App\Services\NotificationService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CheckSlaRequestsCommand extends Command
|
||||
{
|
||||
protected $signature = 'requests:check-sla';
|
||||
|
||||
protected $description = 'Проверка SLA и отправка предупреждений по заявкам';
|
||||
|
||||
public function __construct(private readonly NotificationService $notificationService)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$managers = User::query()->whereIn('role', ['admin', 'manager'])->get();
|
||||
|
||||
ServiceRequest::query()
|
||||
->with(['status', 'assignee'])
|
||||
->open()
|
||||
->whereNotNull('deadline_at')
|
||||
->whereBetween('deadline_at', [now(), now()->addHour()])
|
||||
->each(fn (ServiceRequest $request) => $this->notificationService->notifySlaWarning($request, $managers));
|
||||
|
||||
ServiceRequest::query()
|
||||
->with(['status', 'assignee'])
|
||||
->overdue()
|
||||
->each(fn (ServiceRequest $request) => $this->notificationService->notifyOverdue($request, $managers));
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user