NodesController.class.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Admin\Controller;
  3. /**
  4. * NodesController
  5. * 节点信息
  6. */
  7. class NodesController extends CommonController {
  8. /**
  9. * 节点列表
  10. * @return
  11. */
  12. protected function _initialize(){
  13. parent::_initialize();
  14. $this->breadcrumb1='权限管理';
  15. $this->breadcrumb2='节点管理';
  16. }
  17. public function index() {
  18. $nodeService = D('Node', 'Service');
  19. $nodes = $nodeService->getNodes();
  20. foreach ($nodes as $key => $node) {
  21. $nodes[$key]['type'] = $nodeService->getNodeType($node['level']);
  22. }
  23. $this->assign('nodes', $nodes);
  24. $this->assign('rows_count', count($nodes));
  25. $this->display();
  26. }
  27. /**
  28. * 添加节点
  29. * @return
  30. */
  31. public function add() {
  32. $this->assign('nodes', D('Node', 'Service')->getNodes());
  33. $this->display();
  34. }
  35. /**
  36. * 创建节点
  37. * @return
  38. */
  39. public function create() {
  40. if (!isset($_POST['node'])) {
  41. return $this->errorReturn('无效的操作!');
  42. }
  43. $result = D('Node', 'Service')->addNode($_POST['node']);
  44. if (!$result['status']) {
  45. $status = array('status'=>'back','message'=>$result['data']['error']);
  46. $this->osc_alert($status);
  47. }
  48. $status = array('status'=>'success','message'=>'添加节点成功!','jump'=>U('Nodes/add'));
  49. $this->osc_alert($status);
  50. }
  51. /**
  52. * 切换节点状态
  53. * @return
  54. */
  55. public function toggleStatus() {
  56. $data = array('state' => 0);
  57. $nodeService = D('Node', 'Service');
  58. if (!isset($_GET['id'])
  59. || !$nodeService->existNode($_GET['id'])) {
  60. $data['msg'] = '无效的操作!';
  61. $this->ajaxReturn($data);
  62. }
  63. if (!$_GET['status']) {
  64. $nodeService->setStatus($_GET['id'], 1);
  65. } else {
  66. $nodeService->setStatus($_GET['id'], 0);
  67. }
  68. $info = $_GET['status'] ? '禁用成功!' : '启用成功!';
  69. $data['state'] = 1;
  70. $data['msg'] = $info;
  71. $this->ajaxReturn($data);
  72. }
  73. }