mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
92 lines
2.5 KiB
PHP
92 lines
2.5 KiB
PHP
<?php
|
||
|
||
// +----------------------------------------------------------------------
|
||
// | EasyAdmin
|
||
// +----------------------------------------------------------------------
|
||
// | PHP交流群: 763822524
|
||
// +----------------------------------------------------------------------
|
||
// | 开源协议 https://mit-license.org
|
||
// +----------------------------------------------------------------------
|
||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\admin\controller\system;
|
||
|
||
|
||
use app\admin\model\SystemConfig;
|
||
use app\admin\service\TriggerService;
|
||
use app\common\controller\AdminController;
|
||
use EasyAdmin\annotation\ControllerAnnotation;
|
||
use EasyAdmin\annotation\NodeAnotation;
|
||
use think\App;
|
||
|
||
/**
|
||
* Class Config
|
||
* @package app\admin\controller\system
|
||
* @ControllerAnnotation(title="系统配置管理")
|
||
*/
|
||
class Config extends AdminController
|
||
{
|
||
|
||
public function __construct(App $app)
|
||
{
|
||
parent::__construct($app);
|
||
$this->model = new SystemConfig();
|
||
}
|
||
|
||
/**
|
||
* @NodeAnotation(title="列表")
|
||
*/
|
||
public function index()
|
||
{
|
||
return $this->fetch();
|
||
}
|
||
|
||
/**
|
||
* @NodeAnotation(title="保存")
|
||
*/
|
||
public function save()
|
||
{
|
||
$this->checkPostRequest();
|
||
|
||
$post = $this->request->except(['group_name'], 'post');
|
||
|
||
$group_name = $this->request->post('group_name');
|
||
|
||
try {
|
||
foreach ($post as $key => $val) {
|
||
|
||
if (empty($group_name)) {
|
||
|
||
$this->model
|
||
->where('name', $key)
|
||
->update([
|
||
'value' => $val,
|
||
]);
|
||
} else {
|
||
$model_config = SystemConfig::where('group', $group_name)
|
||
->where('name', $key)
|
||
->find();
|
||
|
||
if (empty($model_config)) {
|
||
$model_config = SystemConfig::create([
|
||
'group' => $group_name,
|
||
'name' => $key,
|
||
'value' => $val
|
||
]);
|
||
}
|
||
|
||
$model_config->save([
|
||
'value' => $val
|
||
]);
|
||
}
|
||
}
|
||
TriggerService::updateMenu();
|
||
TriggerService::updateSysconfig();
|
||
} catch (\Exception $e) {
|
||
$this->error('保存失败');
|
||
}
|
||
$this->success('保存成功');
|
||
}
|
||
}
|