erp-backend/app/Models/PrintPluginInstallation.php
2026-04-01 17:07:04 +08:00

60 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PrintPluginInstallation extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'plugin_id',
'installed_version',
'device_id',
'device_name',
'os_version',
'install_status',
'error_message',
'last_heartbeat',
'installed_at',
];
protected $casts = [
'last_heartbeat' => 'datetime',
'installed_at' => 'datetime',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function plugin(): BelongsTo
{
return $this->belongsTo(PrintPlugin::class, 'plugin_id');
}
/**
* 检查心跳是否超时超过5分钟视为离线
*/
public function isOnline(): bool
{
if (!$this->last_heartbeat) {
return false;
}
return $this->last_heartbeat->diffInMinutes(now()) < 5;
}
/**
* 记录心跳
*/
public function recordHeartbeat(): void
{
$this->update(['last_heartbeat' => now()]);
}
}