修改插件数据表前缀
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
yiqiu
2025-11-20 23:46:50 +08:00
parent 8a1fa3fb8b
commit 7bc68457e9
2 changed files with 24 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
<?php
namespace addon\theme_configurator\model;
use think\facade\Config;
use think\facade\Db;
/**
@@ -8,14 +9,27 @@ use think\facade\Db;
*/
class ThemeConfigModel
{
protected $table = 'addon_theme_configurator';
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 = Db::name($this->table)->order('id', 'asc')->find();
$row = $this->query()->order('id', 'asc')->find();
if (!$row) {
return $this->defaultConfig();
}
@@ -34,11 +48,11 @@ class ThemeConfigModel
'update_time' => time(),
];
$exists = Db::name($this->table)->order('id', 'asc')->find();
$exists = $this->query()->order('id', 'asc')->find();
if ($exists) {
Db::name($this->table)->where('id', $exists['id'])->update($payload);
$this->query()->where('id', $exists['id'])->update($payload);
} else {
Db::name($this->table)->insert($payload);
$this->query()->insert($payload);
}
return $config;
@@ -49,7 +63,7 @@ class ThemeConfigModel
*/
public function initConfig(): void
{
$exists = Db::name($this->table)->order('id', 'asc')->find();
$exists = $this->query()->order('id', 'asc')->find();
if (!$exists) {
$this->saveConfig($this->defaultConfig());
}