NodeModel.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\index\model;
  3. use think\Model;
  4. class NodeModel extends Model{
  5. // 确定链接表名
  6. protected $name = 'node';
  7. /**
  8. * 根据条件获取访问权限节点数据
  9. * @param $where
  10. */
  11. public function getActions($where)
  12. {
  13. return $this->field('control_name,action_name')->where($where)->select();
  14. }
  15. /**
  16. * 根据节点数据获取对应的菜单
  17. * @param $nodeStr
  18. */
  19. public function getMenu($nodeStr = '')
  20. {
  21. if(empty($nodeStr)){
  22. return [];
  23. }
  24. // 超级管理员没有节点数组 * 号表示
  25. $where = '*' == $nodeStr ? 'is_menu = 2' : 'is_menu = 2 and id in(' . $nodeStr . ')';
  26. $result = $this->field('id,node_name,type_id,control_name,action_name,style')
  27. ->where($where)->select();
  28. return prepareMenu($result);
  29. }
  30. /**
  31. * 获取节点数据
  32. * @return mixed
  33. */
  34. public function getNodeList()
  35. {
  36. return $this->field('id,node_name name,type_id pid,is_menu,style,control_name,action_name')->select();
  37. }
  38. /**
  39. * 插入节点信息
  40. * @param $param
  41. */
  42. public function insertNode($param)
  43. {
  44. try{
  45. $this->save($param);
  46. return msg(1, '', '添加节点成功');
  47. }catch(PDOException $e){
  48. return msg(-2, '', $e->getMessage());
  49. }
  50. }
  51. /**
  52. * 删除节点
  53. * @param $id
  54. */
  55. public function delNode($id)
  56. {
  57. try{
  58. $this->where('id', $id)->delete();
  59. return msg(1, '', '删除节点成功');
  60. }catch(PDOException $e){
  61. return msg(-1, '', $e->getMessage());
  62. }
  63. }
  64. }