adminModel.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  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($mr=='')$mr = 'images/noface.png';
  379. if(substr($face,0,4)!='http' && !$this->isempt($face))$face = URL.''.$face.'';
  380. $face = $this->rock->repempt($face, $mr);
  381. return $face;
  382. }
  383. /**
  384. * 获取人员信息
  385. */
  386. public function getuserinfo($uids='0')
  387. {
  388. $uarr = $this->getall("`id` in(".$uids.") and `status`=1",'`id`,`name`,`face`','`sort`');
  389. foreach($uarr as $k=>$rs){
  390. $uarr[$k]['face'] = $this->getface($rs['face']);
  391. }
  392. return $uarr;
  393. }
  394. /**
  395. * 获取人员数据
  396. * $lx=0 通讯录,1选择人员
  397. */
  398. public function getuser($lx=0, $uid=0)
  399. {
  400. $fields = '`id`,`name`,`deptid`,`deptname`,`deptpath`,`groupname`,`deptallname`,`mobile`,`ranking`,`tel`,`face`,`sex`,`email`,`pingyin`,`deptids`,`isvcard`';
  401. $this->allshow = false;
  402. if($uid==0){
  403. $uid = $this->adminid;
  404. $where = m('view')->viewwhere('user', $uid, 'id');
  405. $where = str_replace('{asqom}','', $where);
  406. $range = $this->rock->get('changerange'); //指定了人
  407. $rangeno= $this->rock->get('changerangeno'); //no指定了人
  408. $where1 = '';$where2 = '';
  409. if(!isempt($range)){
  410. //本部门||下级部门
  411. if($range=='dept' || $range=='deptall'){
  412. $urs = $this->getone($uid);
  413. $deptid = $urs['deptid'];
  414. if(!isempt($urs['deptids']))$deptid.=','.$urs['deptids'].'';
  415. $deptida = explode(',', $deptid);
  416. $datsa = array();
  417. if($range=='dept'){
  418. $datsa[]= '`deptid` in('.$deptid.')';
  419. foreach($deptida as $did1)if($did1)$datsa[]=$this->rock->dbinstr('deptids', $did1);
  420. }else{
  421. foreach($deptida as $did1)if($did1)$datsa[] = 'instr(`deptpath`,\'['.$did1.']\')>0';
  422. }
  423. $where1 = join(' )or( ', $datsa);
  424. $where1 = 'and ('.$where1.')';
  425. }else if($range=='down' || $range=='downall'){
  426. $where1 = 'and '.$this->rock->dbinstr('superid', $this->adminid).'';
  427. if($range=='downall')$where1 = 'and instr(`superpath`,\'['.$this->adminid.']\')>0';
  428. }else{
  429. $where1 = $this->gjoin($range, '', 'where');
  430. $where1 = 'and ('.$where1.')';
  431. }
  432. }
  433. if(!isempt($rangeno)){
  434. $where2 = $this->gjoin($rangeno, '', 'where');
  435. $where2 = 'and not('.$where2.')';
  436. }
  437. //--start--
  438. if(ISMORECOM && $uid>1){
  439. $comid = $this->getcompanyid($uid);
  440. $str11 = $this->rock->dbinstr('`dwid`', $comid);
  441. $where2.=' and (`companyid`='.$comid.' or '.$str11.')';
  442. }
  443. //--end--
  444. //读取我可查看权限
  445. if(contain($where,'1=1')){
  446. $where = '';
  447. if($this->rock->get('gtype')=='change' && getconfig('userhoucache')=='1'){
  448. $this->allshow = true;
  449. if(!ISMORECOM && c('cache')->get('deptuserjson'))return array();
  450. }
  451. }else{
  452. $where = 'and ((1 '.$where.') or (`id`='.$uid.'))';
  453. }
  454. if($lx==0)$where2.=' and `isvcard`=1'; //通讯录显示
  455. $sql = "select $fields from `[Q]admin` where `status`=1 $where $where1 $where2 order by `sort`,`name`";
  456. $rows = $this->db->getall($sql);
  457. }else{
  458. $sql = "select $fields from `[Q]admin` where `id`='$uid'";
  459. $rows = $this->db->getall($sql);
  460. }
  461. foreach($rows as $k=>$rs){
  462. $rows[$k]['face'] = $rs['face'] = $this->getface($rs['face']);
  463. $deptidss = ','.$rs['deptid'].',';
  464. if(!isempt($rs['deptids']))$deptidss.=''.$rs['deptids'].',';
  465. $rows[$k]['deptidss'] = $deptidss;
  466. if($rs['pingyin']==null)$rows[$k]['pingyin']='';
  467. if($rs['ranking']==null)$rows[$k]['ranking']='';
  468. if($rs['deptname']==null)$rows[$k]['deptname']='';
  469. }
  470. return $rows;
  471. }
  472. public function getadmininfor($rows, $suids, $fid='checkid')
  473. {
  474. $farr = $this->db->getarr('[Q]admin', "`id` in($suids)",'`face`,`name`');
  475. foreach($rows as $k=>$rs){
  476. $face = $name = '';
  477. if(isset($farr[$rs[$fid]])){
  478. $face = $farr[$rs[$fid]]['face'];
  479. $name = $farr[$rs[$fid]]['name'];
  480. $rows[$k]['name'] = $name;
  481. }
  482. $rows[$k]['face'] = $this->getface($face);
  483. }
  484. return $rows;
  485. }
  486. public function getusinfo($uid, $fields='id')
  487. {
  488. $urs = $this->db->getone('[Q]userinfo', $uid, $fields);
  489. if(!$urs){
  490. $urs = array();
  491. $far = explode(',', str_replace('`','',$fields));
  492. foreach($far as $f)$urs[$f]='';
  493. $urs['id'] = $uid;
  494. }
  495. return $urs;
  496. }
  497. public function getidtouser($id)
  498. {
  499. return $this->getmou('user', "`id`='$id'");
  500. }
  501. /**
  502. * 更新信息
  503. */
  504. public function updateinfo($where='')
  505. {
  506. if($where)c('cache')->del('deptuserjson');
  507. $rows = $this->db->getall("select * from `[Q]admin` a where id>0 $where");
  508. $total = $this->db->count;
  509. $cl = 0;
  510. $sjo = m('sjoin');
  511. foreach($rows as $k=>$rs){
  512. $nrs = $this->getpath($rs['deptid'], $rs['superid'], $rs['deptids']);
  513. $gids = $sjo->getgroupid($rs['id']);
  514. if($gids=='0'){
  515. $gids = '';
  516. }else{
  517. $gids = substr($gids, 2);
  518. }
  519. 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']){
  520. $nrs['groupname'] = $gids;
  521. $this->record($nrs, "`id`='".$rs['id']."'");
  522. $cl++;
  523. }
  524. }
  525. $cl += $this->updateuserinfo($where);
  526. //更新单据上flow_bill上的uname,udeptname
  527. m('flowbill')->updatebill($where);
  528. m('imgroup')->updategall(); //更新会话上
  529. return array($total, $cl);
  530. }
  531. public function updateuserinfo($whe='')
  532. {
  533. $db = m('userinfo');
  534. $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.' ');
  535. $xbo = 0;
  536. foreach($rows as $k=>$rs){
  537. $uparr = array(
  538. 'id' => $rs['id'],
  539. 'name' => $rs['name'],
  540. 'deptname' => $rs['deptname'],
  541. 'deptnames' => $rs['deptnames'],
  542. 'deptallname' => $rs['deptallname'],
  543. 'ranking' => $rs['ranking'],
  544. 'rankings' => $rs['rankings'],
  545. 'sex' => $rs['sex'],
  546. 'tel' => $rs['tel'],
  547. 'mobile' => $rs['mobile'],
  548. 'email' => $rs['email'],
  549. 'workdate' => $rs['workdate'],
  550. 'quitdt' => $rs['quitdt'],
  551. 'num' => $rs['num'],
  552. 'companyid' => $rs['companyid'],
  553. 'dwid' => $rs['dwid'],
  554. );
  555. if(isempt($rs['quitdt'])){
  556. if($rs['state']=='5')$uparr['state'] = 0;
  557. }else{
  558. $uparr['state'] = 5;//离职
  559. }
  560. if(isempt($rs['ids'])){
  561. $db->insert($uparr);
  562. }else{
  563. unset($uparr['id']);
  564. $db->update($uparr, $rs['ids']);
  565. }
  566. $xbo+=$this->db->row_count();
  567. }
  568. return $xbo;
  569. }
  570. //返回这个月份人员
  571. public function monthuwhere($month, $qz='')
  572. {
  573. $month = substr($month, 0, 7);
  574. $start = ''.$month.'-01';
  575. $enddt = c('date')->getenddt($month);
  576. $s = $this->monthuwheres($start, $enddt, $qz);
  577. return $s;
  578. }
  579. public function monthuwheres($start, $enddt, $qz='')
  580. {
  581. $s = " and ($qz`quitdt` is null or $qz`quitdt`>='$start') and ($qz`workdate` is null or $qz`workdate`<='$enddt')";
  582. return $s;
  583. }
  584. public function changeface($uid, $fid)
  585. {
  586. $frs = m('file')->getone($fid);
  587. if(!$frs)return false;
  588. $path = $frs['thumbpath'];
  589. if(isempt($path))$path = $frs['filepath'];
  590. $face = $path;
  591. if(file_exists($path)){
  592. $face = ''.UPDIR.'/face/'.$uid.'_'.rand(1000,9999).'.jpg';
  593. $this->rock->createdir($face);
  594. c('image')->conver($path, $face);
  595. $oface = $this->getmou('face', $uid);
  596. if(!isempt($oface) && file_exists($oface))@unlink($oface);//删除原来头像
  597. $this->update("face='$face'", $uid);
  598. }
  599. m('file')->delfile($fid);
  600. if(!file_exists($face))$face='';
  601. return $face;
  602. }
  603. //根据邮箱获取人员姓名
  604. private $emailtoursarr = array();
  605. public function emailtours($email)
  606. {
  607. $key = 'rock'.$email.'';
  608. if(!isset($this->emailtoursarr[$key])){
  609. $urs = $this->getone("`email`='$email'",'`id`,`name`');
  610. $this->emailtoursarr[$key] = $urs;
  611. }else{
  612. $urs = $this->emailtoursarr[$key];
  613. }
  614. return $urs;
  615. }
  616. /**
  617. * 关键词搜索的
  618. */
  619. public function getkeywhere($key, $qz='', $ots='')
  620. {
  621. $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)";
  622. return $where;
  623. }
  624. /**
  625. * 根据receid获取对应字段$fid聚合得到多个,分开的
  626. */
  627. public function getjoinfields($receid, $fid)
  628. {
  629. if(!is_numeric($receid)){
  630. $receid = $this->gjoin($receid,'ud', 'where'); //读取
  631. $where = '1=1';
  632. if($receid != 'all')$where = $receid;
  633. if(isempt($receid))$where = '1=2';
  634. }else{
  635. $where = 'id='.$receid.'';
  636. }
  637. $wherew1 = $this->getcompanywhere();
  638. $rows = $this->getall("`status`=1 $wherew1 and ($where)", '`id`,`'.$fid.'`');
  639. $strs = '';
  640. foreach($rows as $k=>$rs){
  641. if(!isempt($rs[$fid]))$strs.=','.$rs[$fid].'';
  642. }
  643. if($strs!='')$strs = substr($strs, 1);
  644. return $strs;
  645. }
  646. /**
  647. * 是否已修改密码了
  648. */
  649. public function iseditpass($uid)
  650. {
  651. $editpass = (int)getconfig('editpass','0');
  652. $stype = getconfig('systype');
  653. if($editpass==0 || $stype=='dev' || $stype=='demo')return 1;
  654. $urs = $this->getone('`id`='.$uid.'');
  655. $editpass = (int)arrvalue($urs, 'editpass','0');
  656. return $editpass;
  657. }
  658. /**
  659. * 读取用户信息
  660. */
  661. private $getuserrsarr = array();
  662. public function geturs($id)
  663. {
  664. if(isempt($id))return false;
  665. if(isset($this->getuserrsarr[$id]))return $this->getuserrsarr[$id];
  666. $where = "`user`='$id'";
  667. $check = c('check');
  668. if($check->iscnmobile($id)){
  669. $where = "`mobile`='$id'";
  670. }elseif($check->isemail($id)){
  671. $where = "`email`='$id'";
  672. }elseif($check->isincn($id)){
  673. $where = "`name`='$id'";
  674. }elseif($check->isnumber($id)){
  675. $where = "`id`='$id'";
  676. }
  677. if(contain($id, ':')){
  678. $ida = explode(':', $id);
  679. $where = "`".$ida[0]."`='".$ida[1]."'";
  680. }
  681. $urs = $this->db->getall("select * from `[Q]admin` where $where");
  682. if($urs)$urs = $urs[0];
  683. $this->getuserrsarr[$id] = $urs;
  684. return $urs;
  685. }
  686. /**
  687. * 获取单位的信息
  688. */
  689. public function getcompanyinfo($uid=0, $glx=0)
  690. {
  691. if($uid==0)$uid = $this->adminid;
  692. if($uid==0)$uid = (int)arrvalue($GLOBALS,'adminid','0');
  693. if($uid==0)$uid = 1;//必须要有个值
  694. $urs = $this->getone('`id`='.$uid.'');
  695. $companyid = $urs['companyid'];
  696. $comid = (int)arrvalue($urs, 'comid', '0');
  697. if(isempt($companyid) || $companyid=='0'){
  698. $this->update('`companyid`=1', $uid);
  699. $companyid = '1';
  700. }
  701. $alldwid = $companyid;
  702. $dwid= arrvalue($urs, 'dwid');
  703. if(!isempt($dwid))$alldwid.=','.$dwid.'';
  704. $companyinfo = array('id'=>0);
  705. $companyinfd = false;
  706. $cwhere = '`id` in('.$alldwid.')';
  707. if($glx==5 && $uid==1)$cwhere = '`id`>0';
  708. $companyinfoall = m('company')->getall($cwhere,'*','`pid`,`sort`');
  709. $nid = $companyid;
  710. $allid = array(0);
  711. foreach($companyinfoall as $k=>$rs){
  712. $nlogo = 'images/logo.png';
  713. $logo = $rs['logo'];
  714. if(isempt($logo)){
  715. $logo = $nlogo;
  716. }else{
  717. if(substr($logo,0,4)!='http' && !file_exists($logo))
  718. $logo = $nlogo;
  719. }
  720. $companyinfoall[$k]['logo'] = $rs['logo'] = $this->getface($logo, $nlogo);
  721. if($rs['id']==$nid)$companyinfo = $rs;
  722. if($rs['id']==$comid)$companyinfd = $rs;
  723. $allid[] = $rs['id'];
  724. }
  725. if($companyinfd)$companyinfo = $companyinfd;
  726. $this->setcompanyid($companyinfo['id']);
  727. if($glx==1)return $companyinfo;
  728. if($glx==2)return $companyinfo['id'];
  729. return array(
  730. 'companyinfoall' => $companyinfoall,
  731. 'companyallid' => $allid,
  732. 'companyinfo' => $companyinfo,
  733. 'companyid' => $companyinfo['id']
  734. );
  735. }
  736. public function getcompanyid($uid=0)
  737. {
  738. $comid = (int)$this->rock->session('companyid','0');
  739. if($comid==0)$comid = $this->getcompanyinfo($uid,2);
  740. if(!$comid)$comid=1;
  741. return $comid;
  742. }
  743. public function setcompanyid($comid)
  744. {
  745. $this->rock->setsession('companyid', $comid);
  746. return $comid;
  747. }
  748. public function getcompanywhere($lx=0, $qz='',$comid=false)
  749. {
  750. $where = '';
  751. //--start--
  752. if(ISMORECOM){
  753. if($comid===false)$comid = ''.$this->getcompanyid().'';
  754. $comi2 = $comid;
  755. $str11 = $this->rock->dbinstr(''.$qz.'dwid', $comid);
  756. if($this->adminid==1)$comid.=',0';
  757. $where= " and (".$qz."`companyid` in (".$comid.") or $str11)";
  758. if($lx==1)$where= " and ".$qz."`comid` in (".$comid.")";
  759. if($lx==2)$where= " and ".$qz."`companyid` in (".$comid.")";
  760. if($lx==3)$where= " and ".$qz."`comid`=".$comi2."";
  761. if($lx==5)$where= " and ".$qz."`companyid`=".$comi2.""; //用在关联userinfo表只看本单位
  762. if($lx==4)$where= " and ".$qz."`uid` in(select `id` from `[Q]admin` where `companyid`=".$comi2.")";
  763. }
  764. //--end--
  765. return $where;
  766. }
  767. public function getcompanynum($uid=0)
  768. {
  769. $num ='';
  770. $carr = $this->getcompanyinfo($uid);
  771. $num = $carr['companyinfo']['num'];
  772. if(isempt($num))$num='';
  773. return $num;
  774. }
  775. }
粤ICP备19079148号