tp/app/admin/controller/SiteSettingsController.php
2026-02-26 11:47:46 +08:00

175 lines
4.9 KiB
PHP

<?php
declare(strict_types=1);
namespace app\admin\controller;
use app\admin\BaseController;
use think\exception\ValidateException;
use think\facade\Db;
use think\response\Json;
use app\model\System\SystemSiteSettings;
class SiteSettingsController extends BaseController
{
/**
* 获取指定站点设置列表
* @return Json
*/
public function getNormalInfos()
{
// 定义你需要的 label 列表
$targetLabels = [
'sitename',
'logo',
'logow',
'description',
'copyright',
'companyname',
'icp'
];
$siteSettings = SystemSiteSettings::where('delete_time', null)
->whereIn('label', $targetLabels) // 仅筛选指定的 label
->field('label, value')
->select();
$this->logSuccess('站点设置管理', '查看基本信息配置', [], $this->getAdminUserInfo());
return json([
'code' => 200,
'msg' => '获取成功',
'data' => $siteSettings->toArray()
]);
}
/**
* 保存基本信息
* @return Json
*/
public function saveNormalInfos()
{
$params = $this->request->param();
$rawData = isset($params['data']) ? json_decode($params['data'], true) : $params;
$allowedLabels = ['sitename', 'logo', 'logow', 'description', 'copyright', 'companyname', 'icp'];
foreach ($allowedLabels as $label) {
if (isset($rawData[$label])) {
SystemSiteSettings::update(
['value' => (string)$rawData[$label]],
['label' => $label]
);
}
}
$this->logSuccess('站点设置管理', '保存基本信息', ['labels' => $allowedLabels], $this->getAdminUserInfo());
return json(['code' => 200, 'msg' => '基本信息保存成功']);
}
/**
* 获取登录验证数据
* @return Json
*/
public function getVerifyInfos()
{
// 定义你需要的 label 列表
$targetLabels = [
'openVerify',
'verifyModel',
'geetestID',
'geetestKEY'
];
$legalInfos = SystemSiteSettings::where('delete_time', null)
->whereIn('label', $targetLabels) // 仅筛选指定的 label
->field('label, value')
->select();
$this->logSuccess('站点设置管理', '查看登录验证数据', [], $this->getAdminUserInfo());
return json([
'code' => 200,
'msg' => '获取成功',
'data' => $legalInfos->toArray()
]);
}
/**
* 保存登录验证数据
* @return Json
*/
public function saveVerifyInfos()
{
$params = $this->request->param();
$allowedLabels = ['openVerify', 'verifyModel', 'geetestID', 'geetestKEY'];
foreach ($allowedLabels as $label) {
if (isset($params[$label])) {
$val = $params[$label];
if (is_bool($val)) {
$val = $val ? '1' : '0';
}
SystemSiteSettings::where('label', $label)->update([
'value' => (string)$val
]);
}
}
$this->logSuccess('站点设置管理', '保存登录验证配置', $params, $this->getAdminUserInfo());
return json(['code' => 200, 'msg' => '保存成功']);
}
/**
* 获取法律声明和隐私条款
* @return Json
*/
public function getLegalInfos()
{
// 定义你需要的 label 列表
$targetLabels = [
'legalNotice',
'privacyTerms'
];
$legalInfos = SystemSiteSettings::where('delete_time', null)
->whereIn('label', $targetLabels) // 仅筛选指定的 label
->field('label, value')
->select();
$this->logSuccess('站点设置管理', '查看法律声明和隐私条款', [], $this->getAdminUserInfo());
return json([
'code' => 200,
'msg' => '获取成功',
'data' => $legalInfos->toArray()
]);
}
/**
* 保存法律声明和隐私条款
* @return Json
*/
public function saveLegalInfos()
{
$params = $this->request->param();
$rawData = isset($params['data']) ? json_decode($params['data'], true) : $params;
$allowedLabels = ['legalNotice', 'privacyTerms'];
foreach ($allowedLabels as $label) {
if (isset($rawData[$label])) {
SystemSiteSettings::update(
['value' => (string)$rawData[$label]],
['label' => $label]
);
}
}
$this->logSuccess('站点设置管理', '保存法律声明和隐私条款', ['labels' => $allowedLabels], $this->getAdminUserInfo());
return json(['code' => 200, 'msg' => '法律声明和隐私条款保存成功']);
}
}