<?php

namespace app\index\controller;

use app\index\controller\Base;
use app\index\model\NodeModel;

class Node extends Base{

    // 节点列表
    public function nodeList()
    {
        $node = new NodeModel();
        $nodes = $node->getNodeList();

        $nodes = getTree(objToArray($nodes), false);
        json_return(200 , $nodes , 'success');
    }

    // 添加节点
    public function nodeAdd()
    {
        $param = input('post.');

        $node = new NodeModel();
        $flag = $node->insertNode($param);
        if($flag['code'] != 1){
            return json(json_error_exception('1006',$flag['msg']));
        }
        $this->removRoleCache();
        json_return(200,[],'success');
    }

    // 删除节点
    public function nodeDel()
    {
        $id = input('param.id');

        $role = new NodeModel();
        $flag = $role->delNode($id);
        if($flag['code'] != 1){
            return json(json_error_exception('1006',$flag['msg']));
        }
        $this->removRoleCache();
        json_return(200,[],'success');
    }

}