Files

117 lines
2.9 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace addon\blog\controller\backend;
use think\facade\Request;
use think\facade\View;
use think\facade\Config;
use think\facade\Cache;
use ywxapp\controller\BackendBase;
/**
* Setting 类
*
* @author ywxapp <admin@ywxapp.cn>
*/
class Setting extends BackendBase
{
/**
* Summary of needLogin
* @var array
*/
/**
* Summary of needRight
* @var array
*/
protected $noNeedVerify = ['*'];
/**
* 控制器初始化 _initialize
* @return void
*/
protected function initialize()
{}
/**
* 系统设置首页
*/
public function index()
{
$settings = [
'site' => Config::get('site'),
'seo' => Config::get('seo'),
'email' => Config::get('email'),
'upload' => Config::get('upload')
];
return View::fetch('setting/index', ['settings' => $settings]);
}
/**
* 基本设置
*/
public function site()
{
if (Request::isPost()) {
$data = Request::post();
$this->saveConfig('site', $data);
return json(['code' => 1, 'msg' => '基本设置已保存']);
}
$settings = Config::get('site');
return View::fetch('setting/site', ['settings' => $settings]);
}
/**
* SEO设置
*/
public function seo()
{
if (Request::isPost()) {
$data = Request::post();
$this->saveConfig('seo', $data);
return json(['code' => 1, 'msg' => 'SEO设置已保存']);
}
$settings = Config::get('seo');
return View::fetch('setting/seo', ['settings' => $settings]);
}
/**
* 邮件设置
*/
public function email()
{
if (Request::isPost()) {
$data = Request::post();
$this->saveConfig('email', $data);
return json(['code' => 1, 'msg' => '邮件设置已保存']);
}
$settings = Config::get('email');
return View::fetch('setting/email', ['settings' => $settings]);
}
/**
* 保存配置
*/
private function saveConfig($key, $data)
{
$configFile = app_path() . 'config/' . $key . '.php';
$content = "<?php\nreturn " . var_export($data, true) . ";\n";
file_put_contents($configFile, $content);
// 清除配置缓存
Config::set([], $key);
Cache::delete('config_' . $key);
}
}