94 lines
3.1 KiB
PHP
94 lines
3.1 KiB
PHP
<?php
|
|
namespace addon\theme_configurator\model;
|
|
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 主题配置模型
|
|
*/
|
|
class ThemeConfigModel
|
|
{
|
|
protected $table = 'addon_theme_configurator';
|
|
|
|
/**
|
|
* 获取配置
|
|
*/
|
|
public function getConfig(): array
|
|
{
|
|
$row = Db::name($this->table)->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 = Db::name($this->table)->order('id', 'asc')->find();
|
|
if ($exists) {
|
|
Db::name($this->table)->where('id', $exists['id'])->update($payload);
|
|
} else {
|
|
Db::name($this->table)->insert($payload);
|
|
}
|
|
|
|
return $config;
|
|
}
|
|
|
|
/**
|
|
* 安装时写入默认配置
|
|
*/
|
|
public function initConfig(): void
|
|
{
|
|
$exists = Db::name($this->table)->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',
|
|
'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' => [],
|
|
];
|
|
}
|
|
}
|