adminModel.php 24 KB

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