Deploy Ladill Queue / deploy (push) Successful in 33s
Add corporate layout, live preview, URL copy, queue details, and a polished TV display with clock, stats sidebar, and branded now-serving cards. Co-authored-by: Cursor <cursoragent@cursor.com>
85 lines
2.7 KiB
PHP
85 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Qms;
|
|
|
|
use App\Models\DisplayScreen;
|
|
use App\Models\ServiceQueue;
|
|
use App\Models\Ticket;
|
|
|
|
class DisplayService
|
|
{
|
|
public function findByToken(string $token): ?DisplayScreen
|
|
{
|
|
return DisplayScreen::query()
|
|
->where('access_token', $token)
|
|
->where('is_active', true)
|
|
->first();
|
|
}
|
|
|
|
public function touch(DisplayScreen $screen): void
|
|
{
|
|
$screen->update(['last_seen_at' => now()]);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function payload(DisplayScreen $screen): array
|
|
{
|
|
$screen->loadMissing(['branch', 'organization']);
|
|
$queueIds = $screen->service_queue_ids ?? [];
|
|
$queues = ServiceQueue::query()
|
|
->whereIn('id', $queueIds)
|
|
->where('is_active', true)
|
|
->get();
|
|
|
|
$nowServing = Ticket::query()
|
|
->whereIn('service_queue_id', $queueIds)
|
|
->whereIn('status', ['called', 'serving'])
|
|
->with(['counter', 'serviceQueue'])
|
|
->orderByDesc('called_at')
|
|
->limit(5)
|
|
->get()
|
|
->map(fn (Ticket $t) => [
|
|
'ticket_number' => $t->ticket_number,
|
|
'queue_name' => $t->serviceQueue?->name,
|
|
'counter' => $t->counter?->name,
|
|
]);
|
|
|
|
$waiting = Ticket::query()
|
|
->whereIn('service_queue_id', $queueIds)
|
|
->where('status', 'waiting')
|
|
->count();
|
|
|
|
$avgWait = (int) Ticket::query()
|
|
->whereIn('service_queue_id', $queueIds)
|
|
->where('status', 'completed')
|
|
->whereDate('issued_at', today())
|
|
->whereNotNull('called_at')
|
|
->get(['issued_at', 'called_at'])
|
|
->avg(fn (Ticket $t) => $t->called_at->diffInSeconds($t->issued_at));
|
|
|
|
return [
|
|
'screen' => [
|
|
'name' => $screen->name,
|
|
'layout' => $screen->layout,
|
|
'branch_name' => $screen->branch?->name,
|
|
'organization_name' => $screen->organization?->name,
|
|
],
|
|
'now_serving' => $nowServing,
|
|
'waiting_count' => $waiting,
|
|
'estimated_wait_minutes' => $avgWait > 0 ? (int) ceil($avgWait / 60) : null,
|
|
'queues' => $queues->map(fn (ServiceQueue $q) => [
|
|
'name' => $q->name,
|
|
'prefix' => $q->prefix,
|
|
'is_paused' => $q->is_paused,
|
|
]),
|
|
'announcements' => app(VoiceAnnouncementService::class)->pendingForBranch(
|
|
(int) $screen->branch_id,
|
|
array_map('intval', $screen->service_queue_ids ?? []),
|
|
),
|
|
'updated_at' => now()->toIso8601String(),
|
|
];
|
|
}
|
|
}
|