deptModel.php 4.6 KB

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