yingyongAction.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. class yingyongClassAction extends Action
  3. {
  4. public function yingyongdataAjax()
  5. {
  6. $rows = m('im_group')->getall('`type`=2','*','`sort`');
  7. $arrs = array();
  8. /*
  9. foreach($rows as $k=>$rs){
  10. $sub = m('im_group')->getall('`type`=2 and pid='.$rs['id'].'','*','`sort`');
  11. $rs['leave'] = 1;
  12. $arrs[] = $rs;
  13. foreach($sub as $k1=>$rs1){
  14. $rs1['leave'] = 2;
  15. $arrs[] = $rs1;
  16. }
  17. }*/
  18. echo json_encode(array('rows'=>$rows));
  19. }
  20. public function getdataAjax()
  21. {
  22. $rows = m('im_group')->getall('`type`=2','id,name,face,num,valid','`sort`');
  23. echo json_encode($rows);
  24. }
  25. public function loaddataAjax()
  26. {
  27. $id = (int)$this->get('id');
  28. $arr['data'] = m('im_group')->getone($id);
  29. echo json_encode($arr);
  30. }
  31. public function beforesave($table, $cans, $id)
  32. {
  33. $msg = '';
  34. $num = $cans['num'];
  35. if(m($table)->rows("`num`='$num' and `id`<>$id")>0)$msg='编号['.$num.']已存在';
  36. return array('msg'=>$msg);
  37. }
  38. public $rows;
  39. public function menudataAjax()
  40. {
  41. $this->rows = array();
  42. $mid = (int)$this->get('mid');
  43. $agentnum = m('im_group')->getmou('num',$mid);
  44. $where = "and `mid`='$mid'";
  45. $this->getmenu(0, 1, $where);
  46. $modeid = (int)m('flow_set')->getmou('id',"`num`='$agentnum'");
  47. $wherearr = m('flow_where')->getrows("setid='$modeid' and `num` is not null and `status`=1",'`name`,`num`','`pnum`,`sort`');
  48. $barr[] = array('num'=>'','name'=>'-选择-');
  49. foreach($wherearr as $k=>$rs){
  50. $wherearr[$k]['name'] = ''.$rs['num'].'.'.$rs['name'].'';
  51. $barr[] = $wherearr[$k];
  52. }
  53. echo json_encode(array(
  54. 'totalCount'=> 0,
  55. 'rows' => $this->rows,
  56. 'agentnum' => $agentnum,
  57. 'modeid' => $modeid,
  58. 'wherearr' => $barr,
  59. ));
  60. }
  61. private function getmenu($pid, $oi, $wh='')
  62. {
  63. $db = m('im_menu');
  64. $menu = $db->getall("`pid`='$pid' $wh order by `sort`",'*');
  65. foreach($menu as $k=>$rs){
  66. $sid = $rs['id'];
  67. $rs['level'] = $oi;
  68. $rs['stotal'] = $db->rows("`pid`='$sid' $wh ");
  69. $this->rows[] = $rs;
  70. $this->getmenu($sid, $oi+1, $wh);
  71. }
  72. }
  73. public function yingyongbefore($table)
  74. {
  75. return array(
  76. 'order' => '`valid` desc,`sort` asc'
  77. );
  78. }
  79. public function yingyongafter($table, $rows)
  80. {
  81. foreach($rows as $k=>$rs){
  82. if($rs['valid']=='0')$rows[$k]['status']=0;
  83. }
  84. return array(
  85. 'rows' => $rows
  86. );
  87. }
  88. public function createyingAjax()
  89. {
  90. $bh = $this->get('bh');
  91. $mrs = m('flow_set')->getone("`num`='$bh'");
  92. if(!$mrs)return returnerror('编号为“'.$bh.'”的模块不存在');
  93. $wherrows = m('flow_where')->getall('`setid`='.$mrs['id'].' and ifnull(`num`,\'\')<>\'\'','*','`sort`');
  94. if(!$wherrows)return returnerror('模块“'.$mrs['name'].'”未创建流程模块条件');
  95. $db = m('im_group');
  96. $dbs = m('im_menu');
  97. if($db->rows("`num`='$bh' and `type`=2")>0)return returnerror('编号为“'.$bh.'”的应用已经存在了');
  98. $sort = 100*$mrs['id'];
  99. $dsrs = $db->getone("`types`='".$mrs['type']."'",'*','`sort` desc');
  100. if($dsrs)$sort = (int)$dsrs['sort']+1;
  101. $udb['name'] = $mrs['name'];
  102. $udb['types'] = $mrs['type'];
  103. $udb['num'] = $mrs['num'];
  104. $udb['url'] = 'auto';
  105. $udb['type'] = 2;
  106. $udb['face'] = 'images/logo.png';
  107. $udb['sort'] = $sort;
  108. $mid = $db->insert($udb);
  109. $xdar0 = $xdar1 = array();
  110. foreach($wherrows as $k=>$rs){
  111. if(!$xdar0 && isempt($rs['pnum']))$xdar0 = $rs;
  112. if(!$xdar1 && !isempt($rs['pnum']))$xdar1 = $rs;
  113. }
  114. $iar['mid'] = $mid;
  115. if($xdar0){
  116. $iar['name'] = $xdar0['name'];
  117. $iar['url'] = $xdar0['num'];
  118. $iar['type'] = 0;
  119. $iar['sort'] = 0;
  120. $dbs->insert($iar);
  121. }
  122. if($xdar1){
  123. $iar['name'] = $xdar1['name'];
  124. $iar['url'] = $xdar1['num'];
  125. $iar['receid'] = 'u'.$this->adminid.'';
  126. $iar['recename'] = $this->adminname;
  127. $iar['type'] = 0;
  128. $iar['sort'] = 1;
  129. $dbs->insert($iar);
  130. }
  131. $iar['name'] = '+新增';
  132. $iar['url'] = 'add';
  133. $iar['receid'] = '';
  134. $iar['recename'] = '';
  135. $iar['type'] = 1;
  136. $iar['sort'] = 2;
  137. $dbs->insert($iar);
  138. return returnsuccess();
  139. }
  140. }
粤ICP备19079148号