llmbackend/app/Models/Client.php
2024-12-04 13:32:14 +08:00

69 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Client extends Model
{
/**
* 客户状态常量
*/
public const STATUS_ACTIVE = 'active';
public const STATUS_INACTIVE = 'inactive';
/**
* 有效的状态列表
*/
public const VALID_STATUSES = [
self::STATUS_ACTIVE,
self::STATUS_INACTIVE,
];
protected $table = 'clients';
protected $fillable = [
'name',
'llm_provider_id',
'rate_limit',
'timeout',
'status',
];
protected $casts = [
'rate_limit' => 'integer',
'timeout' => 'integer',
'status' => 'string',
];
public function llmProvider(): BelongsTo
{
return $this->belongsTo(LlmProvider::class);
}
public function admins(): BelongsToMany
{
return $this->belongsToMany(Admin::class, 'admin_client')
->withTimestamps();
}
/**
* 检查客户是否处于活跃状态
*/
public function isActive(): bool
{
return $this->status === self::STATUS_ACTIVE;
}
/**
* 检查是否可以发送LLM请求
*/
public function canSendLlmRequest(): bool
{
return $this->isActive() && $this->llmProvider->isActive();
}
}