query()->order('id', 'asc')->find(); if (!$row) { $config = $this->defaultConfig(); } else { $config = json_decode($row['config'], true); $config = is_array($config) ? $config : $this->defaultConfig(); } // 临时禁用缓存写入用于调试 /* // 写入缓存 (忽略缓存写入失败) try { Cache::set(self::CACHE_KEY, $config, self::CACHE_TTL); } catch (\Throwable $e) { // 忽略缓存写入失败 } */ return $config; } /** * 保存配置 */ public function saveConfig(array $config): array { $payload = [ 'config' => json_encode($config, JSON_UNESCAPED_UNICODE), 'update_time' => time(), ]; $exists = $this->query()->find(); if ($exists) { $this->query()->where('id', $exists['id'])->update($payload); } else { $this->query()->insert($payload); } // 清除缓存,确保下次读取最新数据 try { Cache::delete(self::CACHE_KEY); } catch (\Throwable $e) { // 忽略缓存删除失败 } return $config; } /** * 安装时写入默认配置 */ public function initConfig(): void { $exists = $this->query()->order('id', 'asc')->find(); if (!$exists) { $this->saveConfig($this->defaultConfig()); } } /** * 默认结构 */ protected function defaultConfig(): array { return [ 'seo' => [ 'title' => 'BlackFruit-UI', 'keywords' => '云服务器,主题云,BlackFruit', 'description' => 'BlackFruit-UI 默认站点说明', ], // 顶部/底部导航 'header_nav' => [], 'footer_nav' => [], // 站点基础信息 'site_config' => [ 'enterprise_name' => '主题云', 'enterprise_telephone' => '400-000-0000', 'enterprise_mailbox' => 'support@example.com', 'enterprise_qrcode' => '/upload/qrcode.png', 'official_website_logo' => '/upload/logo.png', // 在线客服链接,对应原主题中的 online_customer_service_link 'online_customer_service_link' => 'http://www.test.com', 'icp_info' => '京ICP备示例号', 'icp_info_link' => 'https://beian.miit.gov.cn/#/Integrated/index', 'public_security_network_preparation' => '京公网安备示例号', 'public_security_network_preparation_link' => 'https://beian.mps.gov.cn/#/query/webSearch', 'telecom_appreciation' => '增值电信业务经营许可证', 'copyright_info' => '© ' . date('Y') . ' 主题云', 'terms_service_url' => '/agreement/service.html', 'terms_privacy_url' => '/agreement/privacy.html', 'cloud_product_link' => '/cart/goods.htm?id=1', 'dcim_product_link' => '/cart/goods.htm?id=2', ], // 友情链接、轮播、侧边浮窗等 'friendly_link' => [], 'banner' => [], 'side' => [], // 用于 /console/v1/common 的扩展字段 'feedback_type' => [], 'honor' => [], ]; } }