Files
BlackFruit-UI/plugins/addon/theme_configurator/model/ThemeConfigModel.php
yiqiu 74a008fe98
All checks were successful
continuous-integration/drone/push Build is passing
移植所有功能
2025-11-21 15:47:29 +08:00

117 lines
4.0 KiB
PHP

<?php
namespace addon\theme_configurator\model;
use think\facade\Config;
use think\facade\Db;
/**
* 主题配置模型
*/
class ThemeConfigModel
{
public const TABLE = 'addon_theme_configurator';
public static function tableName(): string
{
$connections = Config::get('database.connections', []);
$defaultConnection = Config::get('database.default', 'mysql');
$prefix = $connections[$defaultConnection]['prefix'] ?? Config::get('database.prefix', '');
return $prefix . self::TABLE;
}
protected function query()
{
return Db::name(self::TABLE);
}
/**
* 获取配置
*/
public function getConfig(): array
{
$row = $this->query()->order('id', 'asc')->find();
if (!$row) {
return $this->defaultConfig();
}
$config = json_decode($row['config'], true);
return is_array($config) ? $config : $this->defaultConfig();
}
/**
* 保存配置
*/
public function saveConfig(array $config): array
{
$payload = [
'config' => json_encode($config, JSON_UNESCAPED_UNICODE),
'update_time' => time(),
];
$exists = $this->query()->order('id', 'asc')->find();
if ($exists) {
$this->query()->where('id', $exists['id'])->update($payload);
} else {
$this->query()->insert($payload);
}
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' => [],
'partner' => [],
];
}
}