adminModel.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. <?php
  2. class adminClassModel extends Model
  3. {
  4. private $_getjoinstr = array();
  5. public $nowurs,$allshow,$getsuperarrba;
  6. public function gjoin($joinid, $glx='', $blx='bxl')
  7. {
  8. $uid = $did = $gid = '0';
  9. if($glx=='')$glx = 'ud';
  10. if(isempt($joinid))return '';
  11. $joinid = strtolower($joinid);
  12. if(contain($joinid, 'all'))return 'all';
  13. if($blx!='where' && $glx!='d' && !contain($joinid,'u')
  14. && !contain($joinid,'d') && !contain($joinid,'g'))return $joinid;
  15. $narr = explode(',', $joinid);
  16. $dwhe = array();
  17. foreach($narr as $sid){
  18. if(isempt($sid))continue;
  19. $lx = substr($sid, 0, 1);
  20. $ssid = str_replace(array('u','d','g'), array('','',''), $sid);
  21. if($lx == 'd' || $glx=='d'){
  22. $did.=','.$ssid.'';
  23. $dwhe[] = "instr(`deptpath`, '[$ssid]')>0";
  24. }else if($lx=='g'){
  25. $gid.=','.$ssid.'';
  26. }else{
  27. $uid.=','.$ssid.'';
  28. }
  29. }
  30. $where = '';
  31. if($gid!='0'){
  32. $uids = $this->getgrouptouid($gid);
  33. if($uids!='')$uid.=','.$uids.'';
  34. }
  35. if($did != '0'){
  36. $where = join(' or ', $dwhe);
  37. if($uid!='0')$where.=" or `id` in($uid)";
  38. }else{
  39. if($uid!='0')$where ="`id` in($uid)";
  40. }
  41. if($blx == 'where')return $where;
  42. $guid = '';
  43. if($where!=''){
  44. $swhe = '`status`=1';
  45. if($blx=='all')$swhe = '1=1';
  46. $swhe.= $this->getcompanywhere();
  47. $rows = $this->getall("$swhe and ($where)", '`id`');
  48. foreach($rows as $k=>$rs)$guid.=','.$rs['id'].'';
  49. if($guid !='')$guid = substr($guid, 1);
  50. }
  51. return $guid;
  52. }
  53. /**
  54. * 根据组部门id获取底下人员ID
  55. */
  56. public function gjoins($receid)
  57. {
  58. if(contain($receid,'u') || contain($receid, 'd') || contain($receid, 'g'))$receid = $this->gjoin($receid);
  59. return $receid;
  60. }
  61. /**
  62. * 根据组获取底下人员Id
  63. */
  64. public function getgrouptouid($gid)
  65. {
  66. if(isempt($gid))return '';
  67. $where = "1=1 and ((`type`='gu' and `mid` in($gid)) or (`type`='ug' and `sid` in($gid)))";
  68. $rows = $this->db->getall("select `type`,`mid`,`sid` from `[Q]sjoin` where $where");
  69. $uids = array();
  70. foreach($rows as $k=>$rs){
  71. $uid = '';
  72. if($rs['type']=='gu')$uid =$rs['sid'];
  73. if($rs['type']=='ug')$uid =$rs['mid'];
  74. if($uid!='' && !in_array($uid, $uids)){
  75. $uids[]= $uid;
  76. }
  77. }
  78. return join(',', $uids);
  79. }
  80. /**
  81. * 判断某个id是不是在里面,权限
  82. */
  83. public function containjoin($joinid, $myid=0, $glx='ud')
  84. {
  85. $bo = false;
  86. $wh = $this->gjoin($joinid, $glx, 'where');
  87. if($wh == 'all')$bo = true;
  88. if(!$bo && $wh != ''){
  89. if($this->rows("`id`='$myid' and ($wh)")>0)$bo = true;
  90. }
  91. return $bo;
  92. }
  93. public function getjoinstr($fids, $us, $lx=0, $slx=0)
  94. {
  95. $s = '';
  96. if(is_numeric($us)){
  97. $key= 'a'.$fids.''.$us.'_'.$lx.'_'.$slx.'';
  98. if(isset($this->_getjoinstr[$key]))return $this->_getjoinstr[$key];
  99. $us = $this->getone($us,'id,`name`,`deptid`,`deptpath`,`type`');
  100. }
  101. if(!$us)return '';
  102. $this->nowurs = $us;
  103. $uid = $us['id'];
  104. $key = 'a'.$fids.''.$uid.'_'.$lx.'_'.$slx.'';
  105. if(isset($this->_getjoinstr[$key]))return $this->_getjoinstr[$key];
  106. if($slx==0)$tj[] = "ifnull($fids,'')=''";
  107. $tj[] = $this->rock->dbinstr($fids, 'all');
  108. $tj[] = $this->rock->dbinstr($fids, 'u'.$uid);
  109. if($us){
  110. $dep = explode(',', $us['deptpath']);
  111. foreach($dep as $deps){
  112. $_deps = str_replace(array('[',']'), array('',''), $deps);
  113. $tj[] = $this->rock->dbinstr($fids, 'd'.$_deps);
  114. }
  115. //所在组Id
  116. $gids = m('sjoin')->getgroupid($uid);
  117. if($gids!='0'){
  118. $gidsa = explode(',', $gids);
  119. foreach($gidsa as $k1=>$gid1)if($k1>0)$tj[] = $this->rock->dbinstr($fids, 'g'.$gid1);
  120. }
  121. }
  122. $s = join(' or ', $tj);
  123. if($s != '' && $lx==0)$s = ' and ('.$s.')';
  124. $this->_getjoinstr[$key] = $s;
  125. return $s;
  126. }
  127. /**
  128. * 获取对应部门负责人
  129. */
  130. public function getdeptheadman($id, $lx=0)
  131. {
  132. $drs = $this->db->getone('[Q]dept','id='.$id.'');
  133. if(!$drs)return false;
  134. $cuid = $drs['headid'];
  135. $name = $drs['headman'];
  136. if(isempt($cuid)){
  137. if($lx==0){
  138. $lbar = $this->getdeptheadman($drs['pid'], 1);
  139. if($lbar){
  140. $cuid = $lbar[0];
  141. $name = $lbar[1];
  142. }
  143. }
  144. }
  145. if(isempt($cuid))return false;
  146. return array($cuid, $name);
  147. }
  148. /**
  149. * 获取某个人的上级主管或者领导
  150. * 返回 array(id,$name)
  151. */
  152. public function getsuperman($uid)
  153. {
  154. $b = array(0,'');
  155. $urs = $this->getone($uid,'`superid`,`superman`,`deptid`');
  156. if(!$urs)return $b;
  157. $cuid = $urs['superid'];
  158. $name = $urs['superman'];
  159. if(isempt($cuid)){
  160. $deptid = (int)$urs['deptid'];
  161. if($deptid > 0){
  162. $drs = $this->getdeptheadman($deptid);
  163. if($drs){
  164. $cuid = $drs[0];
  165. $name = $drs[1];
  166. }
  167. }
  168. }
  169. if(!isempt($cuid)){
  170. $b = array($cuid, $name);
  171. }
  172. return $b;
  173. }
  174. public function getjoinstrs($fids, $us, $slx=0, $lx=0)
  175. {
  176. return $this->getjoinstr($fids, $us, $lx, $slx);
  177. }
  178. /**
  179. 获取人员上级主管id
  180. */
  181. public function getup($uid)
  182. {
  183. $one = $this->getone($uid, 'superid,deptid');
  184. $rows = $this->getpath($one['deptid'], $one['superid']);
  185. $s = $rows['superpath'];
  186. $s = str_replace('[', '', $s);
  187. $s = str_replace(']', '', $s);
  188. return $s;
  189. }
  190. /**
  191. * 递归获取人员全部上级
  192. */
  193. public function getsuperarr($uid, $lx=0)
  194. {
  195. if($lx==0)$this->getsuperarrba = array();
  196. $sql = "select a.id,a.name,b.`headid`,a.`superid` from `[Q]admin` a left join `[Q]dept` b on a.`deptid`=b.`id` where a.`id`='$uid'";
  197. $rows = $this->db->getall($sql);
  198. $superid = '';
  199. if($rows){
  200. $urs = $rows[0];
  201. $superid = $urs['superid'];
  202. if(isempt($superid))$superid = $urs['headid'];
  203. }
  204. if(!isempt($superid) && $lx<20){
  205. $superida = explode(',', $superid);
  206. foreach($superida as $sid){
  207. if($sid != $uid){
  208. $sna = $this->getmou('name', $sid);
  209. $this->getsuperarrba[] = array('id'=>$sid,'name'=>$sna);
  210. $this->getsuperarr($sid, $lx+1);
  211. }
  212. }
  213. }
  214. return $this->getsuperarrba;
  215. }
  216. private $deptarr = array();
  217. public function getpath($did, $sup,$dids='')
  218. {
  219. $deptpath = $this->db->getpval('[Q]dept', 'pid', 'id', $did, '],[');
  220. $deptallname= $this->db->getpval('[Q]dept', 'pid', 'name', $did, '/');
  221. if(!$this->deptarr)$this->deptarr = $this->db->getkeyall('[Q]dept','id,name');
  222. $deptname = arrvalue($this->deptarr, $did);
  223. $supername = '';
  224. $deptnames = '';
  225. $superpath = '';
  226. if(!isempt($sup)){
  227. $sua = explode(',', $sup);
  228. foreach($sua as $suas){
  229. $sss1 = $this->db->getpval('[Q]admin', 'superid', 'id' ,$suas, '],[');
  230. if($sss1 != '')$superpath.=',['.$sss1.']';
  231. $sss2 = $this->db->getmou('[Q]admin', 'name', "`id`='$suas'");
  232. if(!isempt($sss2))$supername.=','.$sss2;
  233. }
  234. if($superpath!='')$superpath=substr($superpath,1);
  235. if($supername!='')$supername=substr($supername,1);
  236. }
  237. //部门路径
  238. if(!isempt($deptpath))$deptpath = $this->rock->strformat('[?0]', $deptpath);
  239. //有多部门
  240. if(!isempt($dids)){
  241. $didsa = explode(',', $dids);
  242. foreach($didsa as $dids1){
  243. $desss = $this->db->getpval('[Q]dept', 'pid', 'id', $dids1, '],[');
  244. if(isempt($desss))continue;
  245. $desssa = explode(',', $this->rock->strformat('[?0]', $desss));
  246. foreach($desssa as $desssa1){
  247. if(!contain($deptpath, $desssa1))$deptpath.=','.$desssa1.'';
  248. }
  249. $names1 = arrvalue($this->deptarr, $dids1);
  250. if(!isempt($names1))$deptnames.=','.$names1.'';
  251. }
  252. if($deptnames!='')$deptnames=substr($deptnames, 1);
  253. }
  254. if(!isempt($deptpath) && substr($deptpath,0,1)==',')$deptpath = substr($deptpath,1);
  255. $rows['deptpath'] = $deptpath;
  256. $rows['superpath'] = $superpath;
  257. $rows['deptname'] = $deptname;
  258. $rows['deptnames'] = $deptnames;
  259. $rows['superman'] = $supername;
  260. $rows['deptallname']= $deptallname;
  261. return $rows;
  262. }
  263. /**
  264. * 获取下级人员id
  265. * $lx 0 全部下级,1直属下级
  266. * return 所有人员ID
  267. */
  268. public function getdown($uid, $lx=0)
  269. {
  270. $where = $this->getdowns($uid, $lx);
  271. $rows = $this->getall($where, 'id');
  272. $s = '';
  273. foreach($rows as $k=>$rs)$s.=','.$rs['id'];
  274. if($s != '')$s = substr($s, 1);
  275. return $s;
  276. }
  277. /**
  278. * 获取下级人员id
  279. * $lx 0 全部下级,1直属下级
  280. * return 字符串条件
  281. */
  282. public function getdowns($uid, $lx=0)
  283. {
  284. $where = "instr(superpath,'[$uid]')>0";
  285. if($lx==1)$where=$this->rock->dbinstr('superid', $uid);
  286. return $where;
  287. }
  288. /**
  289. * 获取下属人员Id条件记录,如我下属任务
  290. * 返回如( distid in(1) or uid in(2) )
  291. */
  292. public function getdownwhere($fid, $uid, $lx=0)
  293. {
  294. $bstr = $this->getdown($uid, $lx);
  295. $where= '1=2';
  296. if($bstr=='')return $where;
  297. $bas = explode(',', $bstr);
  298. $barr = array();
  299. foreach($bas as $bid){
  300. $barr[] = ''.$fid.' in('.$bid.')';
  301. }
  302. $where = join(' or ', $barr);
  303. $where = '('.$where.')';
  304. return $where;
  305. }
  306. //返回我下属字符串条件如: instr(',1,2,3,', 字段)>0;
  307. public function getdownwheres($fid, $uid, $lx=0)
  308. {
  309. $bstr = $this->getdown($uid, $lx);
  310. $where= '1=2';
  311. if($bstr=='')return $where;
  312. $bstr = ','.$bstr.',';
  313. $where= "instr('$bstr', concat(',',$fid,','))>0";
  314. return $where;
  315. }
  316. /**
  317. * 获取用户信息(部门,单位,职位等)
  318. */
  319. public function getinfor($uid)
  320. {
  321. $unitname = $deptname = $ranking = '';
  322. $name = '';
  323. $face = '';
  324. $deptid = '';
  325. $rs = $this->getone($uid, 'name,deptname,deptid,ranking,face');
  326. if($rs){
  327. $deptname = $rs['deptname'];
  328. $ranking = $rs['ranking'];
  329. $name = $rs['name'];
  330. $deptid = $rs['deptid'];
  331. $face = $this->getface($rs['face']);
  332. if(!$this->isempt($deptid))$unitname = $this->db->getpval('[Q]dept','pid','name', $deptid);
  333. }
  334. return array(
  335. 'id' => $uid,
  336. 'unitname' => $unitname,
  337. 'deptname' => $deptname,
  338. 'name' => $name,
  339. 'ranking' => $ranking,
  340. 'face' => $face,
  341. 'deptid' => $deptid
  342. );
  343. }
  344. /*
  345. 获取在线的人员Id
  346. */
  347. public function getonline($receid, $lx=10)
  348. {
  349. $uarr = $this->getonlines('reim,pc', $receid, $lx);
  350. $jonus = join(',', $uarr);
  351. return $jonus;
  352. }
  353. //获取对应类型在线人员
  354. public function getonlines($type, $teuid='all', $lx=11, $where='')
  355. {
  356. $arrs = array();
  357. $dts = c('date')->adddate($this->rock->now, 'i', 0-$lx);
  358. $wheres = '';
  359. if($teuid != 'all' && $teuid!=''){
  360. if($this->contain($teuid,'u') || $this->contain($teuid,'d')){
  361. $teuid = $this->gjoin($teuid);
  362. if($teuid=='')return $arrs;
  363. }
  364. $wheres=" and `uid` in($teuid)";
  365. }
  366. if($lx>0){
  367. $wheres .= " and `moddt`>'$dts'";
  368. }
  369. $sql = "select `uid` from `[Q]logintoken` where instr(',".$type.",', concat(',',`cfrom`, ','))>0 and `online`=1 $wheres $where group by `uid`";
  370. $rows = $this->db->getall($sql);
  371. foreach($rows as $k=>$rs){
  372. $arrs[] = $rs['uid'];
  373. }
  374. return $arrs;
  375. }
  376. public function getface($face, $mr='')
  377. {
  378. if($face==null)$face='';
  379. if($mr=='')$mr = 'images/noface.png';
  380. if(substr($face,0,4)!='http' && !$this->isempt($face))$face = URL.''.$face.'';
  381. $face = $this->rock->repempt($face, $mr);
  382. return $face;
  383. }
  384. /**
  385. * 获取人员信息
  386. */
  387. public function getuserinfo($uids='0')
  388. {
  389. $uarr = $this->getall("`id` in(".$uids.") and `status`=1",'`id`,`name`,`face`','`sort`');
  390. foreach($uarr as $k=>$rs){
  391. $uarr[$k]['face'] = $this->getface($rs['face']);
  392. }
  393. return $uarr;
  394. }
  395. /**
  396. * 获取人员数据
  397. * $lx=0 通讯录,1选择人员
  398. */
  399. public function getuser($lx=0, $uid=0)
  400. {
  401. $fields = '`id`,`name`,`deptid`,`deptname`,`deptpath`,`groupname`,`deptallname`,`mobile`,`ranking`,`tel`,`face`,`sex`,`email`,`pingyin`,`deptids`,`isvcard`';
  402. $this->allshow = false;
  403. if($uid==0){
  404. $uid = $this->adminid;
  405. $where = m('view')->viewwhere('user', $uid, 'id');
  406. $where = str_replace('{asqom}','', $where);
  407. $range = $this->rock->get('changerange'); //指定了人
  408. $rangeno= $this->rock->get('changerangeno'); //no指定了人
  409. $where1 = '';$where2 = '';
  410. if(!isempt($range)){
  411. //本部门||下级部门
  412. if($range=='dept' || $range=='deptall'){
  413. $urs = $this->getone($uid);
  414. $deptid = $urs['deptid'];
  415. if(!isempt($urs['deptids']))$deptid.=','.$urs['deptids'].'';
  416. $deptida = explode(',', $deptid);
  417. $datsa = array();
  418. if($range=='dept'){
  419. $datsa[]= '`deptid` in('.$deptid.')';
  420. foreach($deptida as $did1)if($did1)$datsa[]=$this->rock->dbinstr('deptids', $did1);
  421. }else{
  422. foreach($deptida as $did1)if($did1)$datsa[] = 'instr(`deptpath`,\'['.$did1.']\')>0';
  423. }
  424. $where1 = join(' )or( ', $datsa);
  425. $where1 = 'and ('.$where1.')';
  426. }else if($range=='down' || $range=='downall'){
  427. $where1 = 'and '.$this->rock->dbinstr('superid', $this->adminid).'';
  428. if($range=='downall')$where1 = 'and instr(`superpath`,\'['.$this->adminid.']\')>0';
  429. }else{
  430. $where1 = $this->gjoin($range, '', 'where');
  431. $where1 = 'and ('.$where1.')';
  432. }
  433. }
  434. if(!isempt($rangeno)){
  435. $where2 = $this->gjoin($rangeno, '', 'where');
  436. $where2 = 'and not('.$where2.')';
  437. }
  438. //--start--
  439. if(ISMORECOM && $uid>1){
  440. $comid = $this->getcompanyid($uid);
  441. $str11 = $this->rock->dbinstr('`dwid`', $comid);
  442. $where2.=' and (`companyid`='.$comid.' or '.$str11.')';
  443. }
  444. //--end--
  445. //读取我可查看权限
  446. if(contain($where,'1=1')){
  447. $where = '';
  448. if($this->rock->get('gtype')=='change' && getconfig('userhoucache')=='1'){
  449. $this->allshow = true;
  450. if(!ISMORECOM && c('cache')->get('deptuserjson'))return array();
  451. }
  452. }else{
  453. $where = 'and ((1 '.$where.') or (`id`='.$uid.'))';
  454. }
  455. if($lx==0)$where2.=' and `isvcard`=1'; //通讯录显示
  456. $sql = "select $fields from `[Q]admin` where `status`=1 $where $where1 $where2 order by `sort`,`name`";
  457. $rows = $this->db->getall($sql);
  458. }else{
  459. $sql = "select $fields from `[Q]admin` where `id`='$uid'";
  460. $rows = $this->db->getall($sql);
  461. }
  462. foreach($rows as $k=>$rs){
  463. $rows[$k]['face'] = $rs['face'] = $this->getface($rs['face']);
  464. $deptidss = ','.$rs['deptid'].',';
  465. if(!isempt($rs['deptids']))$deptidss.=''.$rs['deptids'].',';
  466. $rows[$k]['deptidss'] = $deptidss;
  467. if($rs['pingyin']==null)$rows[$k]['pingyin']='';
  468. if($rs['ranking']==null)$rows[$k]['ranking']='';
  469. if($rs['deptname']==null)$rows[$k]['deptname']='';
  470. }
  471. return $rows;
  472. }
  473. public function getadmininfor($rows, $suids, $fid='checkid')
  474. {
  475. $farr = $this->db->getarr('[Q]admin', "`id` in($suids)",'`face`,`name`');
  476. foreach($rows as $k=>$rs){
  477. $face = $name = '';
  478. if(isset($farr[$rs[$fid]])){
  479. $face = $farr[$rs[$fid]]['face'];
  480. $name = $farr[$rs[$fid]]['name'];
  481. $rows[$k]['name'] = $name;
  482. }
  483. $rows[$k]['face'] = $this->getface($face);
  484. }
  485. return $rows;
  486. }
  487. public function getusinfo($uid, $fields='id')
  488. {
  489. $urs = $this->db->getone('[Q]userinfo', $uid, $fields);
  490. if(!$urs){
  491. $urs = array();
  492. $far = explode(',', str_replace('`','',$fields));
  493. foreach($far as $f)$urs[$f]='';
  494. $urs['id'] = $uid;
  495. }
  496. return $urs;
  497. }
  498. public function getidtouser($id)
  499. {
  500. return $this->getmou('user', "`id`='$id'");
  501. }
  502. /**
  503. * 更新信息
  504. */
  505. public function updateinfo($where='')
  506. {
  507. if($where)c('cache')->del('deptuserjson');
  508. $rows = $this->db->getall("select * from `[Q]admin` a where id>0 $where");
  509. $total = $this->db->count;
  510. $cl = 0;
  511. $sjo = m('sjoin');
  512. foreach($rows as $k=>$rs){
  513. $nrs = $this->getpath($rs['deptid'], $rs['superid'], $rs['deptids']);
  514. $gids = $sjo->getgroupid($rs['id']);
  515. if($gids=='0'){
  516. $gids = '';
  517. }else{
  518. $gids = substr($gids, 2);
  519. }
  520. if($nrs['deptpath'] != $rs['deptpath'] || $nrs['deptname'] != $rs['deptname'] || $nrs['superpath'] != $rs['superpath'] || $nrs['superman'] != $rs['superman'] || $nrs['deptnames'] != $rs['deptnames'] || $nrs['deptallname'] != $rs['deptallname'] || $gids != $rs['groupname']){
  521. $nrs['groupname'] = $gids;
  522. $this->record($nrs, "`id`='".$rs['id']."'");
  523. $cl++;
  524. }
  525. }
  526. $cl += $this->updateuserinfo($where);
  527. //更新单据上flow_bill上的uname,udeptname
  528. m('flowbill')->updatebill($where);
  529. m('imgroup')->updategall(); //更新会话上
  530. return array($total, $cl);
  531. }
  532. public function updateuserinfo($whe='')
  533. {
  534. $db = m('userinfo');
  535. $rows = $this->db->getall('select a.name,a.deptname,a.id,a.status,a.ranking,b.id as ids,a.sex,a.tel,a.mobile,a.email,a.workdate,a.quitdt,b.state,a.num,a.companyid,a.dwid,a.deptnames,a.rankings,a.deptallname from `[Q]admin` a left join `[Q]userinfo` b on a.id=b.id where a.id>0 '.$whe.' ');
  536. $xbo = 0;
  537. foreach($rows as $k=>$rs){
  538. $uparr = array(
  539. 'id' => $rs['id'],
  540. 'name' => $rs['name'],
  541. 'deptname' => $rs['deptname'],
  542. 'deptnames' => $rs['deptnames'],
  543. 'deptallname' => $rs['deptallname'],
  544. 'ranking' => $rs['ranking'],
  545. 'rankings' => $rs['rankings'],
  546. 'sex' => $rs['sex'],
  547. 'tel' => $rs['tel'],
  548. 'mobile' => $rs['mobile'],
  549. 'email' => $rs['email'],
  550. 'workdate' => $rs['workdate'],
  551. 'quitdt' => $rs['quitdt'],
  552. 'num' => $rs['num'],
  553. 'companyid' => $rs['companyid'],
  554. 'dwid' => $rs['dwid'],
  555. );
  556. if(isempt($rs['quitdt'])){
  557. if($rs['state']=='5')$uparr['state'] = 0;
  558. }else{
  559. $uparr['state'] = 5;//离职
  560. }
  561. if(isempt($rs['ids'])){
  562. $db->insert($uparr);
  563. }else{
  564. unset($uparr['id']);
  565. $db->update($uparr, $rs['ids']);
  566. }
  567. $xbo+=$this->db->row_count();
  568. }
  569. return $xbo;
  570. }
  571. //返回这个月份人员
  572. public function monthuwhere($month, $qz='')
  573. {
  574. $month = substr($month, 0, 7);
  575. $start = ''.$month.'-01';
  576. $enddt = c('date')->getenddt($month);
  577. $s = $this->monthuwheres($start, $enddt, $qz);
  578. return $s;
  579. }
  580. public function monthuwheres($start, $enddt, $qz='')
  581. {
  582. $s = " and ($qz`quitdt` is null or $qz`quitdt`>='$start') and ($qz`workdate` is null or $qz`workdate`<='$enddt')";
  583. return $s;
  584. }
  585. public function changeface($uid, $fid)
  586. {
  587. $frs = m('file')->getone($fid);
  588. if(!$frs)return false;
  589. $path = $frs['thumbpath'];
  590. if(isempt($path))$path = $frs['filepath'];
  591. $face = $path;
  592. if(file_exists($path)){
  593. $face = ''.UPDIR.'/face/'.$uid.'_'.rand(1000,9999).'.jpg';
  594. $this->rock->createdir($face);
  595. c('image')->conver($path, $face);
  596. $oface = $this->getmou('face', $uid);
  597. if(!isempt($oface) && file_exists($oface))@unlink($oface);//删除原来头像
  598. $this->update("face='$face'", $uid);
  599. }
  600. m('file')->delfile($fid);
  601. if(!file_exists($face))$face='';
  602. return $face;
  603. }
  604. //根据邮箱获取人员姓名
  605. private $emailtoursarr = array();
  606. public function emailtours($email)
  607. {
  608. $key = 'rock'.$email.'';
  609. if(!isset($this->emailtoursarr[$key])){
  610. $urs = $this->getone("`email`='$email'",'`id`,`name`');
  611. $this->emailtoursarr[$key] = $urs;
  612. }else{
  613. $urs = $this->emailtoursarr[$key];
  614. }
  615. return $urs;
  616. }
  617. /**
  618. * 关键词搜索的
  619. */
  620. public function getkeywhere($key, $qz='', $ots='')
  621. {
  622. $where = " and ($qz`name` like '%$key%' or $qz`user` like '%$key%' or $qz`deptallname` like '%$key%' or $qz`ranking` like '%$key%' or $qz`pingyin` like '$key%' $ots)";
  623. return $where;
  624. }
  625. /**
  626. * 根据receid获取对应字段$fid聚合得到多个,分开的
  627. */
  628. public function getjoinfields($receid, $fid)
  629. {
  630. if(!is_numeric($receid)){
  631. $receid = $this->gjoin($receid,'ud', 'where'); //读取
  632. $where = '1=1';
  633. if($receid != 'all')$where = $receid;
  634. if(isempt($receid))$where = '1=2';
  635. }else{
  636. $where = 'id='.$receid.'';
  637. }
  638. $wherew1 = $this->getcompanywhere();
  639. $rows = $this->getall("`status`=1 $wherew1 and ($where)", '`id`,`'.$fid.'`');
  640. $strs = '';
  641. foreach($rows as $k=>$rs){
  642. if(!isempt($rs[$fid]))$strs.=','.$rs[$fid].'';
  643. }
  644. if($strs!='')$strs = substr($strs, 1);
  645. return $strs;
  646. }
  647. /**
  648. * 是否已修改密码了
  649. */
  650. public function iseditpass($uid)
  651. {
  652. $editpass = (int)getconfig('editpass','0');
  653. $stype = getconfig('systype');
  654. if($editpass==0 || $stype=='dev' || $stype=='demo')return 1;
  655. $urs = $this->getone('`id`='.$uid.'');
  656. $editpass = (int)arrvalue($urs, 'editpass','0');
  657. return $editpass;
  658. }
  659. /**
  660. * 读取用户信息
  661. */
  662. private $getuserrsarr = array();
  663. public function geturs($id)
  664. {
  665. if(isempt($id))return false;
  666. if(isset($this->getuserrsarr[$id]))return $this->getuserrsarr[$id];
  667. $where = "`user`='$id'";
  668. $check = c('check');
  669. if($check->iscnmobile($id)){
  670. $where = "`mobile`='$id'";
  671. }elseif($check->isemail($id)){
  672. $where = "`email`='$id'";
  673. }elseif($check->isincn($id)){
  674. $where = "`name`='$id'";
  675. }elseif($check->isnumber($id)){
  676. $where = "`id`='$id'";
  677. }
  678. if(contain($id, ':')){
  679. $ida = explode(':', $id);
  680. $where = "`".$ida[0]."`='".$ida[1]."'";
  681. }
  682. $urs = $this->db->getall("select * from `[Q]admin` where $where");
  683. if($urs)$urs = $urs[0];
  684. $this->getuserrsarr[$id] = $urs;
  685. return $urs;
  686. }
  687. /**
  688. * 获取单位的信息
  689. */
  690. public function getcompanyinfo($uid=0, $glx=0)
  691. {
  692. if($uid==0)$uid = $this->adminid;
  693. if($uid==0)$uid = (int)arrvalue($GLOBALS,'adminid','0');
  694. if($uid==0)$uid = 1;//必须要有个值
  695. $urs = $this->getone('`id`='.$uid.'');
  696. $companyid = $urs['companyid'];
  697. $comid = (int)arrvalue($urs, 'comid', '0');
  698. if(isempt($companyid) || $companyid=='0'){
  699. $this->update('`companyid`=1', $uid);
  700. $companyid = '1';
  701. }
  702. $alldwid = $companyid;
  703. $dwid= arrvalue($urs, 'dwid');
  704. if(!isempt($dwid))$alldwid.=','.$dwid.'';
  705. $companyinfo = array('id'=>0);
  706. $companyinfd = false;
  707. $cwhere = '`id` in('.$alldwid.')';
  708. if($glx==5 && $uid==1)$cwhere = '`id`>0';
  709. $companyinfoall = m('company')->getall($cwhere,'*','`pid`,`sort`');
  710. $nid = $companyid;
  711. $allid = array(0);
  712. foreach($companyinfoall as $k=>$rs){
  713. $nlogo = 'images/logo.png';
  714. $logo = $rs['logo'];
  715. if(isempt($logo)){
  716. $logo = $nlogo;
  717. }else{
  718. if(substr($logo,0,4)!='http' && !file_exists($logo))
  719. $logo = $nlogo;
  720. }
  721. $companyinfoall[$k]['logo'] = $rs['logo'] = $this->getface($logo, $nlogo);
  722. if($rs['id']==$nid)$companyinfo = $rs;
  723. if($rs['id']==$comid)$companyinfd = $rs;
  724. $allid[] = $rs['id'];
  725. }
  726. if($companyinfd)$companyinfo = $companyinfd;
  727. $this->setcompanyid($companyinfo['id']);
  728. if($glx==1)return $companyinfo;
  729. if($glx==2)return $companyinfo['id'];
  730. return array(
  731. 'companyinfoall' => $companyinfoall,
  732. 'companyallid' => $allid,
  733. 'companyinfo' => $companyinfo,
  734. 'companyid' => $companyinfo['id']
  735. );
  736. }
  737. public function getcompanyid($uid=0)
  738. {
  739. $comid = (int)$this->rock->session('companyid','0');
  740. if($comid==0)$comid = $this->getcompanyinfo($uid,2);
  741. if(!$comid)$comid=1;
  742. return $comid;
  743. }
  744. public function setcompanyid($comid)
  745. {
  746. $this->rock->setsession('companyid', $comid);
  747. return $comid;
  748. }
  749. public function getcompanywhere($lx=0, $qz='',$comid=false)
  750. {
  751. $where = '';
  752. //--start--
  753. if(ISMORECOM){
  754. if($comid===false)$comid = ''.$this->getcompanyid().'';
  755. $comi2 = $comid;
  756. $str11 = $this->rock->dbinstr(''.$qz.'dwid', $comid);
  757. if($this->adminid==1)$comid.=',0';
  758. $where= " and (".$qz."`companyid` in (".$comid.") or $str11)";
  759. if($lx==1)$where= " and ".$qz."`comid` in (".$comid.")";
  760. if($lx==2)$where= " and ".$qz."`companyid` in (".$comid.")";
  761. if($lx==3)$where= " and ".$qz."`comid`=".$comi2."";
  762. if($lx==5)$where= " and ".$qz."`companyid`=".$comi2.""; //用在关联userinfo表只看本单位
  763. if($lx==4)$where= " and ".$qz."`uid` in(select `id` from `[Q]admin` where `companyid`=".$comi2.")";
  764. }
  765. //--end--
  766. return $where;
  767. }
  768. public function getcompanynum($uid=0)
  769. {
  770. $num ='';
  771. $carr = $this->getcompanyinfo($uid);
  772. $num = $carr['companyinfo']['num'];
  773. if(isempt($num))$num='';
  774. return $num;
  775. }
  776. }
粤ICP备19079148号