Deploy Ladill Frontdesk / deploy (push) Successful in 46s
Let guests check out by badge code or QR scan before leaving, with device and staff kiosk API routes. Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Frontdesk;
|
|
|
|
use App\Models\Device;
|
|
use Illuminate\Support\Str;
|
|
|
|
class DeviceService
|
|
{
|
|
public function generateToken(): string
|
|
{
|
|
return Str::random(48);
|
|
}
|
|
|
|
public function findByToken(string $token): ?Device
|
|
{
|
|
return Device::query()
|
|
->where('device_token', $token)
|
|
->first();
|
|
}
|
|
|
|
public function recordHeartbeat(Device $device): Device
|
|
{
|
|
$device->update([
|
|
'status' => 'online',
|
|
'last_online_at' => now(),
|
|
]);
|
|
|
|
return $device->fresh();
|
|
}
|
|
|
|
public function markStaleDevicesOffline(int $minutes = 10): int
|
|
{
|
|
return Device::query()
|
|
->where('status', 'online')
|
|
->where(function ($q) use ($minutes) {
|
|
$q->whereNull('last_online_at')
|
|
->orWhere('last_online_at', '<', now()->subMinutes($minutes));
|
|
})
|
|
->update(['status' => 'offline']);
|
|
}
|
|
|
|
/** @param array<string, mixed> $config */
|
|
public function defaultConfigForType(string $type): array
|
|
{
|
|
return match ($type) {
|
|
'badge_printer' => ['driver' => config('frontdesk.printers.default_driver', 'pdf')],
|
|
'kiosk' => ['mode' => 'self_service', 'allow_checkout' => true],
|
|
default => [],
|
|
};
|
|
}
|
|
}
|