Files
ladill-queue/app/Services/Qms/VoiceAnnouncementService.php
T
isaaccladandCursor cca98eefd2
Deploy Ladill Queue / deploy (push) Successful in 56s
Initial Ladill Queue release — enterprise QMS standalone app.
Phases 1–6: tickets, counters, displays, appointments, workflows, rules, analytics, reports, feedback, admin, device API, and Gitea deploy workflow for queue.ladill.com.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 20:19:52 +00:00

70 lines
2.3 KiB
PHP

<?php
namespace App\Services\Qms;
use App\Models\Counter;
use App\Models\Ticket;
use App\Models\VoiceAnnouncement;
use Illuminate\Support\Str;
class VoiceAnnouncementService
{
public function announceCalled(Ticket $ticket, Counter $counter, ?string $locale = null): VoiceAnnouncement
{
$locale ??= data_get($ticket->serviceQueue?->settings, 'announcement_locale', 'en');
$message = $this->buildMessage($ticket, $counter, $locale);
return VoiceAnnouncement::create([
'owner_ref' => $ticket->owner_ref,
'organization_id' => $ticket->organization_id,
'branch_id' => $ticket->branch_id,
'ticket_id' => $ticket->id,
'locale' => $locale,
'message' => $message,
'voice' => data_get($ticket->serviceQueue?->settings, 'voice', 'female'),
'volume' => (int) data_get($ticket->serviceQueue?->settings, 'announcement_volume', 80),
'repeat_count' => (int) data_get($ticket->serviceQueue?->settings, 'announcement_repeat', 1),
'status' => 'pending',
]);
}
protected function buildMessage(Ticket $ticket, Counter $counter, string $locale): string
{
$templates = config('qms.announcement_templates');
$template = $templates[$locale] ?? $templates['en'];
return str_replace(
[':ticket', ':counter'],
[$ticket->ticket_number, $counter->name],
$template,
);
}
/**
* @return list<array<string, mixed>>
*/
public function pendingForBranch(int $branchId, int $limit = 10): array
{
return VoiceAnnouncement::query()
->where('branch_id', $branchId)
->where('status', 'pending')
->orderBy('id')
->limit($limit)
->get()
->map(fn (VoiceAnnouncement $a) => [
'id' => $a->id,
'message' => $a->message,
'locale' => $a->locale,
'voice' => $a->voice,
'volume' => $a->volume,
'repeat_count' => $a->repeat_count,
])
->all();
}
public function markPlayed(VoiceAnnouncement $announcement): void
{
$announcement->update(['status' => 'played', 'played_at' => now()]);
}
}