userModel.php 7.5 KB

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