userModel.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. //导入数据的测试显示
  112. public function flowdaorutestdata()
  113. {
  114. return array(
  115. 'user' => 'zhangsan',
  116. 'name' => '张三',
  117. 'sex' => '男',
  118. 'mobile' => '15812345678',
  119. 'ranking' => '程序员',
  120. 'superman' => '磐石',
  121. 'deptname' => '信呼开发团队/开发部',
  122. 'tel' => '0592-1234567-005',
  123. 'email' => 'zhangsan@rockoa.com',
  124. 'workdate' => '2017-01-17',
  125. );
  126. }
  127. //导入之后
  128. public function flowdaoruafter()
  129. {
  130. //更新设置上级主管
  131. foreach($this->superarrar as $superman=>$suparr){
  132. $superid = (int)$this->getmou('id', "`name`='$superman'");
  133. $userld = "'".join("','", $suparr)."'";
  134. if($superid>0){
  135. $this->update(array(
  136. 'superman' => $superman,
  137. 'superid' => $superid,
  138. ),"`user` in($userld)");
  139. }
  140. }
  141. m('admin')->updateinfo();
  142. }
  143. //导入之前判断
  144. private $superarrar = array();
  145. public function flowdaorubefore($rows)
  146. {
  147. $inarr = array();
  148. $sort = (int)$this->getmou('max(`sort`)', '`id`>0');
  149. $dbs = m('dept');
  150. $py = c('pingyin');
  151. $dname = $dbs->getmou('name', 1);if(isempt($dname))$dname = '信呼开发团队';
  152. foreach($rows as $k=>$rs){
  153. $user = $rs['user'];
  154. $name = $rs['name'];
  155. $mobile = $rs['mobile'];
  156. $arr = $rs;
  157. $arr['pingyin'] = $py->get($name,1);
  158. if($this->rows("`name`='$name'")>0)$name = $name.'1';
  159. if(isempt($user))$user = $arr['pingyin'];
  160. if($this->rows("`user`='$user'")>0)$user = $user.'1'; //相同用户名?
  161. $arr['user'] = strtolower($user);
  162. $arr['name'] = $name;
  163. $arr['pass'] = md5('123456');
  164. $arr['sort'] = $sort+$k+1;
  165. $arr['workdate'] = arrvalue($rs,'workdate', $this->rock->date);
  166. $arr['adddt'] = $this->rock->now;
  167. $arr['companyid'] = $this->companyid; //默认单位
  168. //读取上级主管Id
  169. if(isset($arr['superman'])){
  170. //$superid = (int)$this->getmou('id', "`name`='".$arr['superman']."'");
  171. //if($superid==0)$arr['superman'] = '';
  172. //$arr['superid'] = $superid;
  173. $this->superarrar[$arr['superman']][] = $arr['user'];
  174. }
  175. $arr['superman'] = '';
  176. $arr['superid'] = '';
  177. //读取部门Id
  178. $deptarr = $this->getdeptid($rs['deptname'], $dbs);
  179. if($deptarr['deptid']==0){
  180. $arr['drerr'] = '找不到顶级部门['.$rs['deptname'].'],请写完整部门路径如:'.$dname.'/'.$rs['deptname'].'';
  181. }
  182. foreach($deptarr as $k1=>$v1)$arr[$k1]=$v1;
  183. $inarr[] = $arr;
  184. }
  185. return $inarr;
  186. }
  187. private function getdeptid($str,$dobj)
  188. {
  189. $deptid = '0';
  190. if(isempt($str))return $deptid;
  191. $stra = explode(',', $str);
  192. $depad = $this->getdeptids($stra[0],$dobj);
  193. $deptids= '';
  194. $deptnames= '';
  195. for($i=1;$i<count($stra);$i++){
  196. $depads = $this->getdeptids($stra[$i],$dobj);
  197. if($depads[0]>0){
  198. $deptids.=','.$depads[0].'';
  199. $deptnames.=','.$depads[1].'';
  200. }
  201. }
  202. if($deptids!='')$deptids = substr($deptids, 1);
  203. if($deptnames!='')$deptnames = substr($deptnames, 1);
  204. return array(
  205. 'deptid' => $depad[0],
  206. 'deptname' => $depad[1],
  207. 'deptallname' => $stra[0],
  208. 'deptids' => $deptids,
  209. 'deptnames' => $deptnames,
  210. );
  211. }
  212. private function getdeptids($str,$dobj)
  213. {
  214. $stra = explode('/', $str);
  215. $pid = 0;
  216. $id = 1;//默认顶级ID
  217. $deptname = '';
  218. for($i=0;$i<count($stra);$i++){
  219. $name = $stra[$i];
  220. $deptname = $name;
  221. $id = (int)$dobj->getmou('id',"`pid`='$pid' and `name`='$name'");
  222. //不存在就创建部门
  223. if($id==0){
  224. if($pid==0)return array(0, $deptname);
  225. $cjbm['name'] = $deptname;
  226. $cjbm['pid'] = $pid;
  227. $id = $dobj->insert($cjbm);
  228. $pid = $id;
  229. }else{
  230. $pid = $id;
  231. }
  232. }
  233. return array($id, $deptname);
  234. }
  235. }
粤ICP备19079148号