12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- // +----------------------------------------------------------------------
- // | framework
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://framework.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | github开源项目:https://github.com/zoujingli/framework
- // +----------------------------------------------------------------------
- namespace app\admin\controller;
- use library\Controller;
- use library\tools\Data;
- use think\Db;
- /**
- * 系统节点管理
- * Class Node
- * @package app\admin\controller
- */
- class Node extends Controller
- {
- /**
- * 指定当前数据表
- * @var string
- */
- protected $table = 'SystemNode';
- /**
- * 系统节点管理
- * @throws \ReflectionException
- */
- public function index()
- {
- $this->title = '系统节点管理';
- list($nodes, $groups) = [\app\admin\service\AuthService::get(), []];
- $this->nodes = Data::arr2table($nodes, 'node', 'pnode');
- foreach ($this->nodes as $node) {
- $pnode = explode('/', $node['node'])[0];
- if ($node['node'] === $pnode) $groups[$pnode]['node'] = $node;
- $groups[$pnode]['list'][] = $node;
- }
- $this->groups = $groups;
- $this->fetch();
- }
- /**
- * 清理无效的节点
- * @throws \ReflectionException
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function clear()
- {
- $nodes = array_unique(array_column(\app\admin\service\AuthService::get(), 'node'));
- if (false !== Db::name($this->table)->whereNotIn('node', $nodes)->delete()) {
- $this->success('清理无效的节点配置成功!', '');
- } else {
- $this->error('清理无效的节点配置,请稍候再试!');
- }
- }
- /**
- * 更新节点数据
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function save()
- {
- if ($this->request->isPost()) {
- list($post, $data) = [$this->request->post(), []];
- foreach ($post['list'] as $vo) if (!empty($vo['node'])) {
- $data['node'] = $vo['node'];
- $data[$vo['name']] = $vo['value'];
- }
- empty($data) || data_save($this->table, $data, 'node');
- $this->success('节点配置保存成功!', '');
- } else {
- $this->error('访问异常,请重新进入...');
- }
- }
- }
|