Files
AirService_potyk/app/Console/Commands/CheckSlaRequestsCommand.php
T
2026-03-20 15:47:17 +05:00

40 lines
1.2 KiB
PHP

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