文件还在测试中

This commit is contained in:
2026-08-08 15:53:53 +08:00
parent 5f1e7adb64
commit 8101177cb5
241 changed files with 18074 additions and 22 deletions
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace App\Models;
use Core\Model;
class Setting extends Model
{
protected $table = 'settings';
protected $orderBy = 'id';
/** 读取单个设置 */
public function get(string $key, $default = '')
{
$row = $this->where('skey', $key);
return $row ? $row['sval'] : $default;
}
/** 批量读取为 [skey => sval] */
public function allKV(): array
{
$out = [];
foreach ($this->all() as $r) $out[$r['skey']] = $r['sval'];
return $out;
}
/** 设置(不存在则新增) */
public function set(string $key, $val, string $group = 'site'): void
{
$row = $this->where('skey', $key);
if ($row) {
$this->update($row['id'], ['sval' => $val, 'sgroup' => $group]);
} else {
$this->insert(['skey' => $key, 'sval' => $val, 'sgroup' => $group]);
}
}
/** 批量保存 */
public function saveMany(array $pairs, string $group = 'site'): void
{
foreach ($pairs as $k => $v) $this->set($k, $v, $group);
}
}