deptModel.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. class deptClassModel extends Model
  3. {
  4. public $firstpid,$groupids,$temparaa;
  5. /**
  6. * $uarr 相应人员才能查看对应部门数据
  7. */
  8. public function getdata($uarr=array())
  9. {
  10. $darr = $dtotal =array();
  11. $gids = '0';
  12. $dbs = m('admin');
  13. //要权限判断
  14. if(is_array($uarr)){
  15. $did = '0';
  16. if($uarr)foreach($uarr as $k=>$rs){
  17. $dpath = str_replace(array('[',']'), array('',''), $rs['deptpath']);
  18. if(!isempt($dpath)){
  19. $dpatha = explode(',', $dpath);
  20. foreach($dpatha as $dpatha1){
  21. if(isempt($dpatha1))continue;
  22. $darr[$dpatha1]=$dpatha1;
  23. if(!isset($dtotal[$dpatha1]))$dtotal[$dpatha1]=0;
  24. $dtotal[$dpatha1]++;
  25. }
  26. }
  27. if(!isempt(arrvalue($rs,'groupname')))$gids.=','.$rs['groupname'].'';
  28. }
  29. foreach($darr as $k1=>$v1)$did.=','.$k1.'';
  30. $where= 'id in('.$did.')';
  31. if(isempt($this->rock->get('changerange'))){
  32. if((int)$dbs->getmou('type', $this->adminid)==1){
  33. $where = '1=1'; //管理员可看全部
  34. }else{
  35. $where1= m('view')->viewwhere('dept', $this->adminid, 'id');
  36. if(contain($where1,'1=1')){
  37. $where = '1=1'; //全部
  38. }else{
  39. $where = '`id`>0 and ((1 '.$where1.') or (id in('.$did.')))';
  40. }
  41. }
  42. }
  43. }else{
  44. $where = '1=1';
  45. }
  46. $this->firstpid = 0;
  47. //多单位
  48. if(ISMORECOM){
  49. $sysalluview = ','.m('option')->getval('sysalluview','0').',1,';
  50. if(!contain($sysalluview,','.$this->adminid.',')){
  51. $comid = $dbs->getcompanyid();
  52. $where.=' and `companyid` in(0,'.$comid.') and `id`>1';
  53. $this->firstpid = 1;
  54. }
  55. }
  56. $rows = $this->getall($where,'`id`,`name`,`pid`,`sort`','`pid`,`sort`');
  57. if(is_array($uarr))foreach($rows as $k=>$rs){
  58. //$stotal = $dbs->rows("`status`=1 and instr(`deptpath`,'[".$rs['id']."]')>0");
  59. $stotal = 0;
  60. $rows[$k]['stotal'] = $stotal; //对应部门下有多少人
  61. $rows[$k]['ntotal'] = $this->rock->arrvalue($dtotal, $rs['id'], '0');
  62. }
  63. $this->groupids = $gids;
  64. $this->temparaa = array();
  65. $this->getshowdeptarr($rows, $this->firstpid, 1);
  66. return $this->temparaa;
  67. }
  68. private function getshowdeptarr($rows, $pid, $level)
  69. {
  70. foreach($rows as $k=>$rs){
  71. if($pid>=0){
  72. if($rs['pid']==$pid){
  73. $rs['level'] = $level;
  74. $this->temparaa[] = $rs;
  75. $this->getshowdeptarr($rows, $rs['id'],$level+1);
  76. }
  77. }
  78. }
  79. }
  80. public function getdeptrows($ids)
  81. {
  82. if(isempt($ids))return array();
  83. $rows = $this->getall("`id` in($ids)",'`id`,`name`,`pid`,`sort`','`pid`,`sort`');
  84. return $rows;
  85. }
  86. /**
  87. * 获取部门和人员数据
  88. * $lx=0 通讯录,1选择人员
  89. */
  90. public function getdeptuserdata($lx=0)
  91. {
  92. $changerange= $this->rock->get('changerange');
  93. $admindb = m('admin');
  94. $userarr = $admindb->getuser($lx);
  95. //根据禁看权限
  96. $flow = m('flow')->initflow('user');
  97. $userarr = $flow->viewjinfields($userarr);
  98. $deptarr = $this->getdata($userarr);
  99. $where1 = '';
  100. if(ISMORECOM && $this->adminid>1)$where1=' and `companyid` in('.$admindb->getcompanyid().')';
  101. $grouparr = m('group')->getall('id >0'.$where1.'','id,name','`sort`');
  102. $garr = array();
  103. foreach($grouparr as $k=>$rs){
  104. if(!isempt($changerange)){
  105. if(!contain(','.$changerange.',',',g'.$rs['id'].','))continue;
  106. }
  107. $uids = $admindb->getgrouptouid($rs['id']);
  108. $usershu = 0;
  109. if($uids!='')$usershu = count(explode(',', $uids));
  110. $rs['usershu'] = $usershu;
  111. $garr[] = $rs;
  112. }
  113. return array(
  114. 'uarr' => $userarr,
  115. 'darr' => $deptarr,
  116. 'garr' => $garr,
  117. 'isall'=> $admindb->allshow
  118. );
  119. }
  120. //获取某个人对应部门Id
  121. public function getudept($uid)
  122. {
  123. $urs = $this->db->getone('[Q]admin', "`id`='$uid'",'deptid,deptpath');
  124. $deptid = arrvalue($urs,'deptid','0');
  125. $drs = $this->getone('`id`='.$deptid.'');
  126. if(!$drs)$drs = array('name'=>'','id'=>0,'num'=>'');
  127. $nums = $drs['num'];
  128. if(isempt($nums))$nums = $drs['id'];
  129. $drs['nums'] = $nums;
  130. return $drs;
  131. }
  132. //人员在线离线更新
  133. public function online($lx)
  134. {
  135. $ustr = "online=".$lx.",`lastonline`='".$this->rock->now."'";
  136. $this->db->update('[Q]admin', $ustr,'`id`='.$this->adminid.'');
  137. if($lx==1)m('login')->uplastdt('pc', $this->rock->session('admintoken'));
  138. }
  139. public function getheadman($did)
  140. {
  141. $rs = $this->getone($did);
  142. $headid = '';
  143. $headids = '';
  144. if($rs){
  145. $headid = $rs['headid'];
  146. $headids = $rs['headman'];
  147. if(isempt($headid) && $rs['pid']>0){
  148. $sars= $this->getheadman($rs['pid']);
  149. $headid = $sars[0];
  150. $headids = $sars[1];
  151. }
  152. }
  153. return array($headid, $headids);
  154. }
  155. }
粤ICP备19079148号