- SystemSetting: 系统设置模型,支持配置管理 - Terminal: 终端模型,支持终端管理 - TerminalKnowledgeBase: 终端知识库关联模型 - TerminalPrompt: 终端提示词模型 - TerminalSyncLog: 终端同步日志模型 - SopTemplate: SOP模板模型 - SopStep: SOP步骤模型 - SopInteractiveTask: SOP交互任务模型 - SopTemplateVersion: SOP模板版本模型 所有模型集成 LogsActivity trait 用于操作日志记录
81 lines
1.8 KiB
PHP
81 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
use Spatie\Activitylog\LogOptions;
|
|
|
|
class SystemSetting extends Model
|
|
{
|
|
use HasFactory, LogsActivity;
|
|
/**
|
|
* 可批量赋值的属性
|
|
*
|
|
* @var array<string>
|
|
*/
|
|
protected $fillable = [
|
|
'key',
|
|
'value',
|
|
'group',
|
|
'description',
|
|
'is_public',
|
|
];
|
|
|
|
/**
|
|
* 属性类型转换
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'value' => 'array',
|
|
'is_public' => 'boolean',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取配置值
|
|
*
|
|
* @param string $key 配置键
|
|
* @param mixed $default 默认值
|
|
* @return mixed
|
|
*/
|
|
public static function get(string $key, $default = null)
|
|
{
|
|
$setting = static::where('key', $key)->first();
|
|
return $setting ? $setting->value : $default;
|
|
}
|
|
|
|
/**
|
|
* 设置配置值
|
|
*
|
|
* @param string $key 配置键
|
|
* @param mixed $value 配置值
|
|
* @param string $group 配置分组
|
|
* @return \App\Models\SystemSetting
|
|
*/
|
|
public static function set(string $key, $value, string $group = 'general')
|
|
{
|
|
return static::updateOrCreate(
|
|
['key' => $key],
|
|
['value' => $value, 'group' => $group]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 配置活动日志选项
|
|
*
|
|
* @return \Spatie\Activitylog\LogOptions
|
|
*/
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly(['key', 'value', 'group', 'description'])
|
|
->logOnlyDirty()
|
|
->setDescriptionForEvent(fn(string $eventName) => "系统设置已{$eventName}");
|
|
}
|
|
}
|