deptAction.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. class deptClassAction extends Action
  3. {
  4. public function defaultAction()
  5. {
  6. }
  7. public function dataAjax()
  8. {
  9. $carr = m('admin')->getcompanyinfo(0,5);
  10. $this->allid= $carr['companyallid'];
  11. $this->rows = array();
  12. $this->getdept(0, 1);
  13. $errmsg = '';
  14. if(ISMORECOM){
  15. foreach($this->rows as $k1=>$rs1){
  16. if($rs1['companyname']=='' && $rs1['level']==2){
  17. $this->rows[$k1]['trbgcolor']='red';
  18. $errmsg = '1';
  19. }
  20. }
  21. if($errmsg=='1')$errmsg='红色行必须选择所属单位,请编辑';
  22. }
  23. echo json_encode(array(
  24. 'totalCount'=> 0,
  25. 'rows' => $this->rows,
  26. 'carr' => $carr,
  27. 'errmsg' => $errmsg
  28. ));
  29. }
  30. private function getdept($pid, $oi)
  31. {
  32. $db = m('dept');
  33. $menu = $db->getall("`pid`='$pid' order by `sort`",'*');
  34. foreach($menu as $k=>$rs){
  35. $comid = $rs['companyid'];
  36. //开启单位模式只能看到自己单位下的组织结构
  37. if(!in_array($comid, $this->allid) && $this->adminid>1 && getconfig('companymode'))continue;
  38. $companyname = '';
  39. if($comid>0 && getconfig('companymode'))$companyname = m('company')->getmou('name', $comid);
  40. $rs['companyname'] = $companyname;
  41. $sid = $rs['id'];
  42. $rs['level'] = $oi;
  43. $rs['stotal'] = $db->rows("`pid`='$sid'");
  44. $this->rows[] = $rs;
  45. $this->getdept($sid, $oi+1);
  46. }
  47. }
  48. public function publicbeforesave($table, $cans, $id)
  49. {
  50. $pid = (int)$cans['pid'];
  51. if($pid<=0 && $id != 1)return '上级ID必须大于0';
  52. if($pid!=0 && $id == 1)return '顶级禁止修改上级ID';
  53. if($pid!=0 && m($table)->rows('id='.$pid.'')==0)return '上级ID不存在';
  54. return '';
  55. }
  56. public function publicaftersave($table, $cans, $id)
  57. {
  58. $name = $cans['name'];
  59. $db = m('admin');
  60. $db->update("deptname='$name'", "`deptid`=$id");
  61. $db->updateinfo("and instr(a.`deptpath`,'[$id]')>0");
  62. }
  63. public function deptuserdataAjax()
  64. {
  65. $type = $this->request('changetype');
  66. $val = $this->request('value');
  67. $pid = 0;
  68. $rows = $this->getdeptmain($pid, $type, ','.$val.',');
  69. echo json_encode($rows);
  70. }
  71. private function getdeptmain($pid, $type, $val)
  72. {
  73. $sql = $this->stringformat('select `id`,`name` from `?0` where `pid`=?1 order by `sort`', array($this->T('dept'), $pid));
  74. $arr = $this->db->getall($sql);
  75. $rows = array();
  76. foreach($arr as $k=>$rs){
  77. $children = $this->getdeptmain($rs['id'], $type, $val);
  78. $uchek = $this->contain($type, 'check');
  79. $expanded = false;
  80. if($this->contain($type, 'user')){
  81. $sql = $this->stringformat('select `id`,`name`,`sex`,`ranking`,`deptname` from `?0` where `deptid`=?1 and `status`=1 order by `sort`', array($this->T('admin'), $rs['id']));
  82. $usarr = $this->db->getall($sql);
  83. foreach($usarr as $k1=>$urs){
  84. $usarr[$k1]['leaf'] = true;
  85. $usarr[$k1]['uid'] = $urs['id'];
  86. $usarr[$k1]['id'] = 'u'.$urs['id'];
  87. $usarr[$k1]['type'] = 'u';
  88. $usarr[$k1]['icons'] = 'user';
  89. if($uchek){
  90. $bo = false;
  91. if($this->contain($type, 'dept')){
  92. $bo = $this->contain($val, $usarr[$k1]['id']);
  93. }else{
  94. $bo = $this->contain($val, $usarr[$k1]['uid']);
  95. }
  96. $usarr[$k1]['checked']=$bo;
  97. if(!$expanded)$expanded = $bo;
  98. }
  99. }
  100. $children= array_merge($children, $usarr);
  101. }
  102. if($pid==0)$expanded = true;
  103. $ars['children']= $children;
  104. $ars['name'] = $rs['name'];
  105. $ars['id'] = 'd'.$rs['id'];
  106. $ars['did'] = $rs['id'];
  107. $ars['type'] = 'd';
  108. $ars['expanded'] = $expanded;
  109. if($this->contain($type, 'dept')){
  110. if($uchek){
  111. $bo = false;
  112. if($this->contain($type, 'user')){
  113. $bo = $this->contain($val, $ars['id']);
  114. }else{
  115. $bo = $this->contain($val, $ars['did']);
  116. }
  117. $ars['checked']=$bo;
  118. }
  119. }
  120. $rows[] = $ars;
  121. }
  122. return $rows;
  123. }
  124. public function deptuserjsonAjax()
  125. {
  126. $udarr = m('dept')->getdeptuserdata(1);
  127. $bool = false;
  128. if(!ISMORECOM && !$udarr['uarr'] && $udarr['isall']){
  129. $udarrs = c('cache')->get('deptuserjson');
  130. if($udarrs)$udarr = $udarrs;
  131. $bool = true;
  132. }
  133. $userarr = $udarr['uarr'];
  134. $deptarr = $udarr['darr'];
  135. $grouparr = $udarr['garr'];
  136. $arr['deptjson'] = json_encode($deptarr);
  137. $arr['userjson'] = json_encode($userarr);
  138. $arr['groupjson'] = json_encode($grouparr);
  139. $arr['iscache'] = getconfig('usercache');
  140. if(!ISMORECOM && $udarr['isall'] && !$bool)c('cache')->set('deptuserjson', $udarr);
  141. $this->showreturn($arr);
  142. }
  143. }
粤ICP备19079148号