Node.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | framework
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://framework.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/framework
  12. // +----------------------------------------------------------------------
  13. namespace app\admin\controller;
  14. use library\Controller;
  15. use library\tools\Data;
  16. use think\Db;
  17. /**
  18. * 系统节点管理
  19. * Class Node
  20. * @package app\admin\controller
  21. */
  22. class Node extends Controller
  23. {
  24. /**
  25. * 指定当前数据表
  26. * @var string
  27. */
  28. protected $table = 'SystemNode';
  29. /**
  30. * 系统节点管理
  31. * @throws \ReflectionException
  32. */
  33. public function index()
  34. {
  35. $this->title = '系统节点管理';
  36. list($nodes, $groups) = [\app\admin\service\AuthService::get(), []];
  37. $this->nodes = Data::arr2table($nodes, 'node', 'pnode');
  38. foreach ($this->nodes as $node) {
  39. $pnode = explode('/', $node['node'])[0];
  40. if ($node['node'] === $pnode) $groups[$pnode]['node'] = $node;
  41. $groups[$pnode]['list'][] = $node;
  42. }
  43. $this->groups = $groups;
  44. $this->fetch();
  45. }
  46. /**
  47. * 清理无效的节点
  48. * @throws \ReflectionException
  49. * @throws \think\Exception
  50. * @throws \think\exception\PDOException
  51. */
  52. public function clear()
  53. {
  54. $nodes = array_unique(array_column(\app\admin\service\AuthService::get(), 'node'));
  55. if (false !== Db::name($this->table)->whereNotIn('node', $nodes)->delete()) {
  56. $this->success('清理无效的节点配置成功!', '');
  57. } else {
  58. $this->error('清理无效的节点配置,请稍候再试!');
  59. }
  60. }
  61. /**
  62. * 更新节点数据
  63. * @throws \think\Exception
  64. * @throws \think\exception\PDOException
  65. */
  66. public function save()
  67. {
  68. if ($this->request->isPost()) {
  69. list($post, $data) = [$this->request->post(), []];
  70. foreach ($post['list'] as $vo) if (!empty($vo['node'])) {
  71. $data['node'] = $vo['node'];
  72. $data[$vo['name']] = $vo['value'];
  73. }
  74. empty($data) || data_save($this->table, $data, 'node');
  75. $this->success('节点配置保存成功!', '');
  76. } else {
  77. $this->error('访问异常,请重新进入...');
  78. }
  79. }
  80. }