Navi.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace app\admin\controller;
  3. /**
  4. * 导航管理
  5. */
  6. class Navi extends Admin{
  7. protected $Navi = null;
  8. protected function _initialize(){
  9. parent::_initialize();
  10. $this->Navi = model('Navi');
  11. }
  12. //导航列表
  13. public function index(){
  14. $pid = input('get.pid',0);
  15. $pnavi = $this->Navi->where(['id'=>$pid])->find();
  16. if ($pnavi) {
  17. $position = $pnavi['position'];
  18. }else{
  19. $position = input('param.position','admin');
  20. }
  21. $this->assign('pnavi',$pnavi);
  22. $this->assign('position',$position);
  23. $this->assign('meta_title','导航列表');
  24. return $this->fetch();
  25. }
  26. public function load(){
  27. $role = $this->user['role'];
  28. $Navi = model('Navi');
  29. $level = input('get.level',3);
  30. $pid = input('get.pid',0);
  31. $pnavi = $this->Navi->get($pid);
  32. if ($pnavi) {
  33. $position = $pnavi['position'];
  34. }else{
  35. $position = input('get.position');
  36. }
  37. $list = $Navi->navis($pid,$position,[],$level);
  38. return json(['data'=>$list,'code'=>0,'msg'=>'加载成功']);
  39. }
  40. //排序
  41. public function sort(){
  42. $id = input('post.id');
  43. $navi = $this->Navi->get($id);
  44. if ($navi) {
  45. $sort = input('post.sort');
  46. $navi->sort = $sort;
  47. $result = $navi->save();
  48. if ($result) {
  49. return json(['data'=>null,'code'=>0,'msg'=>'排序成功']);
  50. }
  51. }
  52. return json(['data'=>$_POST,'code'=>1,'msg'=>'参数错误']);
  53. }
  54. public function add(){
  55. if ($this->request->isPost()) {
  56. $this->Navi->pid = input('post.pid');
  57. $this->Navi->position = input('post.position');
  58. $this->Navi->name = input('post.name');
  59. $this->Navi->cname = input('post.cname');
  60. $this->Navi->icon = input('post.icon');
  61. $this->Navi->image = input('post.image');
  62. $this->Navi->action = input('post.action');
  63. $this->Navi->target = input('post.target');
  64. $this->Navi->type = input('post.type');
  65. $result = $this->Navi->save();
  66. if ($result) {
  67. return json(['data'=>$this->Navi->id,'code'=>0,'msg'=>'添加导航成功']);
  68. }
  69. return json(['data'=>$_POST,'code'=>1,'msg'=>'添加导航失败']);
  70. }else{
  71. $pid = input('param.pid');
  72. $pnavi = $this->Navi->get($pid);
  73. $this->assign('pnavi',$pnavi);
  74. $position = input('param.position');
  75. $this->assign('position',$position);
  76. $this->assign('meta_title','添加菜单');
  77. return $this->fetch();
  78. }
  79. }
  80. public function edit(){
  81. if ($this->request->isPost()) {
  82. $id = input('post.id');
  83. $navi = $this->Navi->where(['id'=>$id])->find();
  84. if ($navi) {
  85. $navi->name = input('post.name');
  86. $navi->cname = input('post.cname');
  87. $navi->icon = input('post.icon');
  88. $navi->image = input('post.image');
  89. $navi->action = input('post.action');
  90. $navi->target = input('post.target');
  91. $navi->type = input('post.type');
  92. $result = $navi->save();
  93. if ($result) {
  94. return json(['data'=>null,'code'=>0,'msg'=>'编辑导航成功']);
  95. }
  96. return json(['data'=>$_POST,'code'=>1,'msg'=>'编辑导航失败']);
  97. }
  98. return json(['data'=>$_POST,'code'=>1,'msg'=>'参数错误']);
  99. }else{
  100. $id = input('param.id');
  101. $navi = $this->Navi->where(['id'=>$id])->find();
  102. if (!$navi) {
  103. $this->error('参数错误');
  104. }
  105. $this->assign('navi',$navi);
  106. $this->assign('meta_title','删除菜单');
  107. return $this->fetch();
  108. }
  109. }
  110. public function delete(){
  111. if ($this->request->isPost()) {
  112. $id = input('post.id');
  113. $navi = $this->Navi->where(['id'=>$id])->find();
  114. if (!$navi) {
  115. return json(['data'=>null,'code'=>1,'msg'=>'参数错误']);
  116. }
  117. $result = $navi->delete();
  118. if ($result) {
  119. return json(['data'=>null,'code'=>0,'msg'=>'删除成功']);
  120. }
  121. return json(['data'=>null,'code'=>1,'msg'=>'删除失败']);
  122. }
  123. }
  124. }