menuAction.php 4.0 KB

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