批量更新租户规则

This commit is contained in:
2026-03-09 23:00:20 +08:00
parent e09b4c639c
commit e27cc8f457
45 changed files with 579 additions and 314 deletions
+11 -14
View File
@@ -6,6 +6,8 @@ namespace app\service;
use think\facade\Db;
use think\facade\Config;
use app\model\Cms\TemplateSiteConfig;
use app\model\Cms\TemplateThemeData;
/**
* 模板服务类
@@ -36,7 +38,7 @@ class ThemeService
$themes[] = [
'key' => $dir,
'name' => $config['name'] ?? $dir,
'description'=> $config['description'] ?? '',
'description' => $config['description'] ?? '',
'version' => $config['version'] ?? '1.0.0',
'author' => $config['author'] ?? '',
'preview' => $preview,
@@ -125,8 +127,7 @@ class ThemeService
if ($tid > 0) {
$where[] = ['tid', '=', $tid];
}
$config = Db::name('mete_template_site_config')
->where($where)
$config = TemplateSiteConfig::where($where)
->find();
return $config['value'] ?? 'default';
} catch (\Exception $e) {
@@ -162,19 +163,18 @@ class ThemeService
if ($tid > 0) {
$where[] = ['tid', '=', $tid];
}
$config = Db::name('mete_template_site_config')
->where($where)
$config = TemplateSiteConfig::where($where)
->find();
$now = date('Y-m-d H:i:s');
if ($config) {
Db::name('mete_template_site_config')->where('id', $config['id'])->update([
TemplateSiteConfig::where('id', $config['id'])->update([
'value' => $themeKey,
'update_time' => $now
]);
} else {
Db::name('mete_template_site_config')->insert([
TemplateSiteConfig::insert([
'key' => 'current_theme',
'value' => $themeKey,
'create_time' => $now,
@@ -203,8 +203,7 @@ class ThemeService
if ($tid > 0) {
$where[] = ['tid', '=', $tid];
}
$themeData = Db::name('mete_template_theme_data')
->where($where)
$themeData = TemplateThemeData::where($where)
->select()
->toArray();
@@ -246,22 +245,20 @@ class ThemeService
if ($tid > 0) {
$where[] = ['tid', '=', $tid];
}
$existing = Db::name('mete_template_theme_data')
->where($where)
$existing = TemplateThemeData::where($where)
->find();
$value = is_array($fieldValue) ? json_encode($fieldValue, JSON_UNESCAPED_UNICODE) : $fieldValue;
$now = date('Y-m-d H:i:s');
if ($existing) {
Db::name('mete_template_theme_data')
->where('id', $existing['id'])
TemplateThemeData::where('id', $existing['id'])
->update([
'field_value' => $value,
'update_time' => $now
]);
} else {
Db::name('mete_template_theme_data')->insert([
TemplateThemeData::insert([
'tid' => $tid,
'theme_key' => $themeKey,
'field_key' => $fieldKey,