'integer', 'is_enabled' => 'boolean', 'options' => 'array' ]; /** * 获取配置值(自动转换类型) */ public function getTypedValueAttribute() { switch ($this->type) { case 'boolean': return (bool) $this->value; case 'number': return (float) $this->value; case 'select': $options = $this->options ?? []; return $options[$this->value] ?? $this->value; default: return $this->value; } } /** * 按分组获取所有启用的配置 */ public static function getGroupSettings($group) { return self::where('group', $group) ->where('is_enabled', true) ->orderBy('sort_order') ->get() ->pluck('value', 'code') ->toArray(); } /** * 获取单个配置值 */ public static function getValue($code, $default = null) { $setting = self::where('code', $code)->first(); if (!$setting) { return $default; } return $setting->typed_value; } /** * 设置配置值 */ public static function setValue($code, $value) { return self::updateOrCreate( ['code' => $code], ['value' => $value] ); } }