更新网站架构

This commit is contained in:
2026-03-09 16:35:17 +08:00
parent 4cbc52c51b
commit bf0daf987b
180 changed files with 60682 additions and 491 deletions
+36 -15
View File
@@ -67,7 +67,8 @@ class ThemeService
}
$fullPath = $this->themesPath . DIRECTORY_SEPARATOR . $item;
if (is_dir($fullPath) && is_file($fullPath . DIRECTORY_SEPARATOR . 'index.html')) {
// 检查是否有 index.html 或 index.php
if (is_dir($fullPath) && (is_file($fullPath . DIRECTORY_SEPARATOR . 'index.html') || is_file($fullPath . DIRECTORY_SEPARATOR . 'index.php'))) {
$dirs[] = $item;
}
}
@@ -114,14 +115,18 @@ class ThemeService
/**
* 获取当前激活的模板Key
* @param int $tid 租户ID
* @return string
*/
public function getCurrentTheme(): string
public function getCurrentTheme(int $tid = 0): string
{
try {
$where = [['key', '=', 'current_theme'], ['delete_time', '=', null]];
if ($tid > 0) {
$where[] = ['tid', '=', $tid];
}
$config = Db::name('mete_template_site_config')
->where('key', 'current_theme')
->where('delete_time', null)
->where($where)
->find();
return $config['value'] ?? 'default';
} catch (\Exception $e) {
@@ -131,10 +136,11 @@ class ThemeService
/**
* 切换当前模板
* @param int $tid 租户ID
* @param string $themeKey
* @return bool
*/
public function switchTheme(string $themeKey): bool
public function switchTheme(int $tid, string $themeKey): bool
{
// 验证模板是否存在
$themes = $this->getThemeList();
@@ -152,9 +158,12 @@ class ThemeService
try {
// 查找或创建配置记录
$where = [['key', '=', 'current_theme'], ['delete_time', '=', null]];
if ($tid > 0) {
$where[] = ['tid', '=', $tid];
}
$config = Db::name('mete_template_site_config')
->where('key', 'current_theme')
->where('delete_time', null)
->where($where)
->find();
$now = date('Y-m-d H:i:s');
@@ -181,17 +190,21 @@ class ThemeService
/**
* 获取模板数据(用于前端渲染)
* @param int $tid 租户ID
* @param string|null $themeKey
* @return array
*/
public function getThemeData(?string $themeKey = null): array
public function getThemeData(int $tid = 0, ?string $themeKey = null): array
{
$themeKey = $themeKey ?? $this->getCurrentTheme();
$themeKey = $themeKey ?? $this->getCurrentTheme($tid);
try {
$where = [['theme_key', '=', $themeKey], ['delete_time', '=', null]];
if ($tid > 0) {
$where[] = ['tid', '=', $tid];
}
$themeData = Db::name('mete_template_theme_data')
->where('theme_key', $themeKey)
->where('delete_time', null)
->where($where)
->select()
->toArray();
@@ -216,18 +229,25 @@ class ThemeService
/**
* 保存模板字段数据
* @param int $tid 租户ID
* @param string $themeKey
* @param string $fieldKey
* @param mixed $fieldValue
* @return bool
*/
public function saveThemeField(string $themeKey, string $fieldKey, $fieldValue): bool
public function saveThemeField(int $tid, string $themeKey, string $fieldKey, $fieldValue): bool
{
try {
$where = [
['theme_key', '=', $themeKey],
['field_key', '=', $fieldKey],
['delete_time', '=', null]
];
if ($tid > 0) {
$where[] = ['tid', '=', $tid];
}
$existing = Db::name('mete_template_theme_data')
->where('theme_key', $themeKey)
->where('field_key', $fieldKey)
->where('delete_time', null)
->where($where)
->find();
$value = is_array($fieldValue) ? json_encode($fieldValue, JSON_UNESCAPED_UNICODE) : $fieldValue;
@@ -242,6 +262,7 @@ class ThemeService
]);
} else {
Db::name('mete_template_theme_data')->insert([
'tid' => $tid,
'theme_key' => $themeKey,
'field_key' => $fieldKey,
'field_value' => $value,