menuAction.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. class menuClassAction extends Action
  3. {
  4. public $rows,$alldata;
  5. public function dataAjax()
  6. {
  7. $this->rows = array();
  8. $type = $this->get('type');
  9. $loadci = (int)$this->get('loadci');
  10. $pid = (int)$this->get('pid','0');
  11. $where = '';
  12. //权限那来的
  13. if($type != ''){
  14. $where = 'and `status`=1 and `ispir`=1 and `type`=0';
  15. if($type=='view')$where = 'and `status`=1 and `type`=0';
  16. }else{
  17. $this->updatepirss();
  18. }
  19. if($pid>0){
  20. $where.=' and (`id`='.$pid.' or `pid`='.$pid.' or `pid` in(select `id` from `[Q]menu` where `pid`='.$pid.'))';
  21. }
  22. $this->alldata = $this->db->getall('select *,(select count(1)from `[Q]menu` where `pid`=a.id '.$where.')stotal from `[Q]menu` a where 1=1 '.$where.' order by `sort`');
  23. $this->getmenu(0, 1, 1);
  24. $pdata = array();
  25. if($loadci==1){
  26. foreach($this->alldata as $k=>$rs){
  27. if($rs['pid']=='0')$pdata[] = array('name'=>$rs['name'],'id'=>$rs['id']);
  28. }
  29. }
  30. echo json_encode(array(
  31. 'totalCount'=> 0,
  32. 'pdata' => $pdata,
  33. 'rows' => $this->rows
  34. ));
  35. }
  36. private function getmenu($pid, $oi, $zt)
  37. {
  38. $downid = '';
  39. foreach($this->alldata as $k=>$rs){
  40. if($pid==$rs['pid']){
  41. $downid.=','.$rs['id'].'';
  42. $rs['level'] = $oi;
  43. $zthui = $rs['status'];
  44. if($zt==0){
  45. $rs['ishui']=1;
  46. $zthui = 0;
  47. }
  48. //if($oi>1)$rs['trstyle']='display:none;';
  49. $this->rows[] = $rs;
  50. $len = count($this->rows)-1;
  51. $sidss = $this->getmenu($rs['id'], $oi+1, $zthui);
  52. //if($sidss)$this->rows[$len]['downallid'] = substr($sidss,1);
  53. }
  54. }
  55. return $downid;
  56. }
  57. //下级需要验证,那上级也必须验证的
  58. private function updatepirss()
  59. {
  60. $rows = $this->db->getall('select `pid` from `[Q]menu` where `pid`>0 and `ispir`=1 group by `pid`');
  61. $sid = '0';
  62. foreach($rows as $k=>$rs)$sid.=','.$rs['pid'].'';
  63. if($sid!='')m('menu')->update('`ispir`=1', "`id` in($sid)");
  64. }
  65. /**
  66. * 菜单管理获取菜单
  67. */
  68. public function getdataAjax()
  69. {
  70. $pvalue = (int)$this->get('pvalue','0');
  71. $level = (int)$this->get('level','1');
  72. $rows = $this->db->getall('select *,(select count(1)from `[Q]menu` where `pid`=a.id )stotal from `[Q]menu` a where `pid`='.$pvalue.' order by `sort`');
  73. foreach($rows as $k=>$rs)$rows[$k]['level'] = $level;
  74. echo json_encode(array(
  75. 'totalCount'=> 0,
  76. 'rows' => $rows
  77. ));
  78. }
  79. public function delmenuAjax()
  80. {
  81. $id = (int)$this->post('id');
  82. if(m('menu')->rows('pid='.$id.'')>0)return returnerror('有下级菜单不能删除');
  83. m('menu')->delete($id);
  84. return returnsuccess();
  85. }
  86. public function createmenuAjax()
  87. {
  88. $pid = (int)$this->get('menuid','0');
  89. $where =' and (`id`='.$pid.' or `pid`='.$pid.' or `pid` in(select `id` from `[Q]menu` where `pid`='.$pid.'))';
  90. $rows = $this->db->getall('select *,(select count(1)from `[Q]menu` where `pid`=a.id '.$where.')stotal from `[Q]menu` a where 1=1 '.$where.' order by pid,`sort`');
  91. $str = '';
  92. $ors = m('menu')->getone($pid);
  93. foreach($rows as $k=>$rs){
  94. if($k>0)$str.=''.chr(10).'ROCKSPLIT'.chr(10).'';
  95. $str.="INSERT INTO `[Q]menu` (`id`,`name`,`pid`,`sort`,`url`,`num`,`icons`,`type`,`ispir`) select '".$rs['id']."','".$rs['name']."','".$rs['pid']."','".$rs['sort']."',".$this->seveslst($rs['url']).",".$this->seveslst($rs['num']).",".$this->seveslst($rs['icons']).",'".$rs['type']."','".$rs['ispir']."' from `[Q]menu` WHERE `id`=1 and NOT EXISTS(SELECT 1 FROM `[Q]menu` where `id`='".$rs['id']."');";
  96. //$str.=''.chr(10).'ROCKSPLIT'.chr(10).'';
  97. //$str.="update `[Q]menu` set `name`='".$rs['name']."',`status`=1,`url`=".$this->seveslst($rs['url']).",`pid`='".$rs['pid']."',`sort`='".$rs['sort']."' where `id`='".$rs['id']."';";
  98. }
  99. $bh = $ors['num'];
  100. if(isempt($bh))$bh=$ors['id'];
  101. $num = 'menu'.$bh.'';
  102. $this->rock->createtxt('upload/data/'.$num.'.txt', $str);
  103. }
  104. public function seveslst($v)
  105. {
  106. if($v===null)return 'null';
  107. return "'".$v."'";
  108. }
  109. }
粤ICP备19079148号