adminModel.php 23 KB

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