Initial Ladill Queue release — enterprise QMS standalone app.
Deploy Ladill Queue / deploy (push) Successful in 56s
Deploy Ladill Queue / deploy (push) Successful in 56s
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>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Qms;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\Ticket;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DeviceService
|
||||
{
|
||||
public function findByToken(string $token): ?Device
|
||||
{
|
||||
return Device::query()
|
||||
->where('device_token', $token)
|
||||
->first();
|
||||
}
|
||||
|
||||
public function recordHeartbeat(Device $device): void
|
||||
{
|
||||
$device->update([
|
||||
'status' => 'online',
|
||||
'last_online_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function markStaleOffline(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']);
|
||||
}
|
||||
|
||||
public function generateToken(Device $device): string
|
||||
{
|
||||
$token = Str::random(48);
|
||||
$device->update(['device_token' => $token]);
|
||||
|
||||
return $token;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user