userModel.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <?php
  2. class flow_userClassModel extends flowModel
  3. {
  4. protected $flowviewufieds = 'id';
  5. protected $flowcompanyidfieds = 'companyid';
  6. public function getstatusarr()
  7. {
  8. $barr[1] = array('启用','green');
  9. $barr[0] = array('停用','#888888');
  10. return $barr;
  11. }
  12. public function flowsearchfields()
  13. {
  14. $arr[] = array('name'=>'部门/用户...','fields'=>'id');
  15. return $arr;
  16. }
  17. /**
  18. * 用户显示展示
  19. */
  20. protected function flowbillwhere($uid, $lx)
  21. {
  22. $where = '';
  23. $pnum = $this->rock->get('pnum');
  24. //其他地方来的,需要权限
  25. if($pnum != 'all' ){
  26. $where = 'and `status`=1 '.$this->viewmodel->viewwhere($this->moders, $uid, 'id');//权限控制
  27. }
  28. $detpid = (int)$this->rock->post('deptid','0');
  29. if($detpid>0){
  30. $where.= " and instr(`deptpath`,'[$detpid]')>0";
  31. }
  32. return array(
  33. 'fields'=> '`name`,`id`,`id` as uid,`face`,`sort`,`deptallname`,deptpath,`ranking`,`tel`,`mobile`,`email`,`user`,num,workdate,sex,deptname,deptnames,superman,status,type,online,lastonline,isvcard,`companyid`',
  34. 'order' => '`status` desc,`sort`',
  35. 'where' => $where
  36. );
  37. }
  38. //替换
  39. private $companyarr = array();
  40. public function flowrsreplace($rs, $lx=0)
  41. {
  42. if(!$this->companyarr){
  43. $this->companyarr = $this->db->getkeyall('[Q]company','id,name');
  44. }
  45. if(isset($rs['mobile'])){
  46. $sjhao = $rs['mobile'];
  47. }
  48. if(getconfig('systype')=='demo')$rs['mobile']='';
  49. if($this->rock->ismobile()){
  50. if(isset($rs['mobile']) && !isempt($rs['mobile']))$rs['mobile']='<a onclick="return callPhone(\''.$sjhao.'\')" href="tel:'.$sjhao.'">'.$rs['mobile'].'</a>';
  51. if(isset($rs['tel']) && !isempt($rs['tel']))$rs['tel']='<a onclick="return callPhone(this)" href="tel:'.$rs['tel'].'">'.$rs['tel'].'</a>';
  52. }
  53. $type = arrvalue($rs,'type');
  54. if($type=='0')$rs['type']='';
  55. if($type=='1')$rs['type']='<font color=green>是</font>';
  56. if(isset($rs['companyid']))$rs['companyid'] = arrvalue($this->companyarr, $rs['companyid']);
  57. //判断当前用户状态
  58. $online = arrvalue($rs,'online','0');
  59. $lastonline = arrvalue($rs,'lastonline');
  60. if($online=='1'){
  61. $jgtime = time()- strtotime($lastonline);
  62. if($jgtime>210){
  63. $online = '0'; //超过200
  64. $this->adminmodel->update('online=0', $rs['id']);
  65. }
  66. }
  67. $rs['online'] = $online;
  68. if($lx==1){
  69. $rs['temp_dwid'] = $this->getdwname($rs);
  70. }
  71. return $rs;
  72. }
  73. //编辑时候替换
  74. protected function flowrsreplaceedit($rs)
  75. {
  76. $rs['groupname'] = m('sjoin')->getgroupid($rs['id']);
  77. $rs['pass'] = '';
  78. unset($rs['deptallname']);
  79. $rs['temp_dwid'] = $this->getdwname($rs);
  80. if(getconfig('systype')=='demo')$rs['mobile'] = '';
  81. return $rs;
  82. }
  83. private function getdwname($rs)
  84. {
  85. $dwid = arrvalue($rs,'dwid');
  86. $temp_dwid = '';
  87. if(!isempt($dwid)){
  88. $dwarr = m('company')->getall('`id` in('.$dwid.')');
  89. foreach($dwarr as $k1=>$rs1)$temp_dwid.=','.$rs1['name'].'';
  90. if($temp_dwid!='')$temp_dwid = substr($temp_dwid, 1);
  91. }
  92. return $temp_dwid;
  93. }
  94. //删除用户时
  95. protected function flowdeletebill($sm)
  96. {
  97. $id = $this->id;
  98. $name = $this->rs['name'];
  99. m('im_messzt')->delete('`uid`='.$id.'');
  100. m('im_history')->delete('`uid`='.$id.'');
  101. $dbs = m('userinfo');
  102. $urs = $dbs->getone($id);
  103. if(!$urs)return;
  104. $quitdt = $urs['quitdt'];
  105. $state = $urs['state'];
  106. $uarr = array();
  107. if(isempt($quitdt))$uarr['quitdt'] = date('Y-m-d'); //设置离职日期
  108. if($state != '5')$uarr['state'] = 5;//离职状态为5
  109. if($uarr)$dbs->update($uarr, $id);
  110. // 第三方会议——同步删除用户
  111. // $uinfo = m('meet_sys_login')->getone("oa_uid=$id", 'id, username');
  112. // m('log')->addlog('删除用户-删', json_encode($uinfo));
  113. // m('meet_sys_login')->dropUser($uinfo['username'] ?? null);
  114. }
  115. //导入数据的测试显示
  116. public function flowdaorutestdata()
  117. {
  118. return array(
  119. 'user' => 'zhangsan',
  120. 'name' => '张三',
  121. 'sex' => '男',
  122. 'mobile' => '15812345678',
  123. 'ranking' => '程序员',
  124. 'superman' => '磐石',
  125. 'deptname' => 'XX煤矿/信息化',
  126. 'tel' => '0592-1234567-005',
  127. 'email' => 'zhangsan@rockoa.com',
  128. 'workdate' => '2017-01-17',
  129. );
  130. }
  131. //导入之后
  132. public function flowdaoruafter()
  133. {
  134. //更新设置上级主管
  135. foreach($this->superarrar as $superman=>$suparr){
  136. $superid = (int)$this->getmou('id', "`name`='$superman'");
  137. $userld = "'".join("','", $suparr)."'";
  138. if($superid>0){
  139. $this->update(array(
  140. 'superman' => $superman,
  141. 'superid' => $superid,
  142. ),"`user` in($userld)");
  143. }
  144. }
  145. m('admin')->updateinfo();
  146. }
  147. //导入之前判断
  148. private $superarrar = array();
  149. public function flowdaorubefore($rows)
  150. {
  151. $inarr = array();
  152. $sort = (int)$this->getmou('max(`sort`)', '`id`>0');
  153. $dbs = m('dept');
  154. $py = c('pingyin');
  155. $dname = $dbs->getmou('name', 1);
  156. if(isempt($dname))$dname = getconfig('title');
  157. foreach($rows as $k=>$rs){
  158. $user = $rs['user'];
  159. $name = $rs['name'];
  160. $mobile = $rs['mobile'];
  161. $arr = $rs;
  162. $arr['pingyin'] = $py->get($name,1);
  163. if($this->rows("`name`='$name'")>0)$name = $name.'1';
  164. if(isempt($user))$user = $arr['pingyin'];
  165. if($this->rows("`user`='$user'")>0)$user = $user.'1'; //相同用户名?
  166. $arr['user'] = strtolower($user);
  167. $arr['name'] = $name;
  168. // 初始化密码
  169. $passStr = 'Zhks'.$rs['user'].'@jw';
  170. $arr['pass'] = md5($passStr);
  171. $arr['sort'] = $sort+$k+1;
  172. $arr['workdate'] = arrvalue($rs,'workdate', $this->rock->date);
  173. $arr['adddt'] = $this->rock->now;
  174. $arr['companyid'] = $this->companyid; //默认单位
  175. //读取上级主管Id
  176. if(isset($arr['superman'])){
  177. //$superid = (int)$this->getmou('id', "`name`='".$arr['superman']."'");
  178. //if($superid==0)$arr['superman'] = '';
  179. //$arr['superid'] = $superid;
  180. $this->superarrar[$arr['superman']][] = $arr['user'];
  181. }
  182. $arr['superman'] = '';
  183. $arr['superid'] = '';
  184. //读取部门Id
  185. $deptarr = $this->getdeptid($rs['deptname'], $dbs);
  186. if($deptarr['deptid']==0)return '行'.($k+1).'找不到顶级部门['.$rs['deptname'].'],请写完整部门路径如:'.$dname.'/'.$rs['deptname'].'';
  187. foreach($deptarr as $k1=>$v1)$arr[$k1]=$v1;
  188. $inarr[] = $arr;
  189. }
  190. return $inarr;
  191. }
  192. private function getdeptid($str,$dobj)
  193. {
  194. $deptid = '0';
  195. if(isempt($str))return $deptid;
  196. $stra = explode(',', $str);
  197. $depad = $this->getdeptids($stra[0],$dobj);
  198. $deptids= '';
  199. $deptnames= '';
  200. for($i=1;$i<count($stra);$i++){
  201. $depads = $this->getdeptids($stra[$i],$dobj);
  202. if($depads[0]>0){
  203. $deptids.=','.$depads[0].'';
  204. $deptnames.=','.$depads[1].'';
  205. }
  206. }
  207. if($deptids!='')$deptids = substr($deptids, 1);
  208. if($deptnames!='')$deptnames = substr($deptnames, 1);
  209. return array(
  210. 'deptid' => $depad[0],
  211. 'deptname' => $depad[1],
  212. 'deptallname' => $stra[0],
  213. 'deptids' => $deptids,
  214. 'deptnames' => $deptnames,
  215. );
  216. }
  217. private function getdeptids($str,$dobj)
  218. {
  219. $stra = explode('/', $str);
  220. $pid = 0;
  221. $id = 1;//默认顶级ID
  222. $deptname = '';
  223. for($i=0;$i<count($stra);$i++){
  224. $name = $stra[$i];
  225. $deptname = $name;
  226. $id = (int)$dobj->getmou('id',"`pid`='$pid' and `name`='$name'");
  227. //不存在就创建部门
  228. if($id==0){
  229. if($pid==0)return array(0, $deptname);
  230. $cjbm['name'] = $deptname;
  231. $cjbm['pid'] = $pid;
  232. $id = $dobj->insert($cjbm);
  233. $pid = $id;
  234. }else{
  235. $pid = $id;
  236. }
  237. }
  238. return array($id, $deptname);
  239. }
  240. }