kqjcmdModel.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. <?php
  2. //考勤机管理命令
  3. class kqjcmdClassModel extends Model
  4. {
  5. private $snrs;
  6. private $pinpai = 0;
  7. public $snobj,$kquobj;
  8. public function initModel()
  9. {
  10. $this->snobj = m('kqjsn');
  11. $this->kquobj = m('kqjuser');
  12. }
  13. /**
  14. * 命令类型
  15. */
  16. public function cmdtype($type)
  17. {
  18. $atrr = array(
  19. 'config' => '设置配置',
  20. 'reboot' => '重启',
  21. 'dept' => '上传部门',
  22. 'user' => '上传人员',
  23. 'deluser' => '删除人员',
  24. 'delsuser' => '删除不存在人员',
  25. 'getfingerprint' => '获取指纹',
  26. 'getheadpic' => '获取头像',
  27. 'headpic' => '上传头像',
  28. 'advert1' => '设置广告图1',
  29. 'advert2' => '设置广告图2',
  30. 'advert3' => '设置广告图3',
  31. 'deladvert' => '删除广告图',
  32. 'getuser' => '获取人员',
  33. 'getinfo' => '获取设备信息',
  34. 'getclockin' => '获取打卡记录',
  35. 'delclockin' => '删除打卡记录',
  36. 'getpic' => '获取现场照片',
  37. 'delpic' => '删除现场照片',
  38. 'fingerprint' => '上传指纹',
  39. );
  40. return arrvalue($atrr, $type, $type);
  41. }
  42. /**
  43. * 发送命令
  44. */
  45. public function send($snid, $type, $ohter='')
  46. {
  47. $snrs = $this->getsninfo($snid);
  48. if(!$snrs)return returnerror('设备不存在,请添加');
  49. $pinpai = (int)arrvalue($snrs,'pinpai', 0);
  50. $this->pinpai = $pinpai;
  51. if(isempt($snrs['name']))return returnerror('请设置设备名称');
  52. if(isempt($snrs['company']))return returnerror('请设置设备显示公司名称');
  53. $id = 0;
  54. //中控支持命令类型
  55. $zkarr = array('reboot','config','user','dept','getuser','getinfo','deluser','delsuser','getclockin','delclockin');
  56. if($pinpai==1 && !in_array($type, $zkarr))return returnerror('中控考勤机不支持['.$type.'.'.$this->cmdtype($type).']命令发送');
  57. //判断是不是有重复
  58. $arrpda = array('reboot','config','getuser','getinfo','advert');
  59. if(in_array($type, $arrpda)){
  60. $tod = $this->rows("`snid`='$snid' and `atype`='$type' and `status`=0");
  61. if($tod>0)return returnerror('还有['.$this->cmdtype($type).']命令待运行,不能重复发送');
  62. }
  63. //重启
  64. if($type=='reboot'){
  65. $id = $this->savedata($snid, $type, array(
  66. 'do' => 'cmd',
  67. 'cmd' => 'reboot',
  68. ));
  69. }
  70. //获取设备信息
  71. if($type=='getinfo'){
  72. $id = $this->savedata($snid, $type, array(
  73. 'do' => 'upload',
  74. 'data' => 'info',
  75. ));
  76. }
  77. //发送配置信息
  78. if($type=='config'){
  79. $id = $this->savedata($snid, $type, $this->getconfigs($snrs));
  80. }
  81. //部门推送更新
  82. if($type=='dept'){
  83. $id = $this->savedata($snid, $type, $this->depttosn($ohter));
  84. }
  85. //人员推送
  86. if($type=='user'){
  87. $id = $this->savedata($snid, $type, $this->usertosn($ohter));
  88. }
  89. //获取指纹和头像
  90. if($type=='getfingerprint' || $type=='getheadpic'){
  91. $id = $this->savedata($snid, $type, $this->sntofingerhead($ohter, $type));
  92. }
  93. //获取所有人员
  94. if($type=='getuser'){
  95. $data = array('user');
  96. if($pinpai==1)$data = 'user';
  97. $id = $this->savedata($snid, $type, array(
  98. 'do' => 'upload',
  99. 'data' => $data,
  100. ));
  101. }
  102. //设置广告图
  103. if(substr($type,0,6)=='advert'){
  104. $index = substr($type,6);
  105. $path = 'images/kqbanner'.$index.'.jpg';
  106. if(!file_exists($path)){
  107. $id = '广告图片'.$index.'不存在,请在系统目录下添加图片:'.$path.'';
  108. }else{
  109. $id = $this->savedata($snid, $type, array(
  110. 'do' => 'update',
  111. 'data' => 'advert',
  112. 'index' => $index,
  113. 'advert'=> base64_encode(file_get_contents($path))
  114. ));
  115. }
  116. }
  117. //上传头像
  118. if($type=='headpic'){
  119. $id = $this->uoloadface($snid,$ohter);
  120. }
  121. //删除选中人员
  122. if($type=='deluser'){
  123. $id = $this->savedata($snid, $type, $this->userdeltosn($snid, $ohter));
  124. }
  125. //删除不存在人员
  126. if($type=='delsuser'){
  127. $id = $this->savedata($snid, 'deluser', $this->userdeltosns($snid));
  128. }
  129. //获取打卡记录
  130. if($type=='getclockin' || $type=='getpic' || $type=='delclockin' || $type=='delpic'){
  131. $id = $this->savedata($snid, $type, $this->getsntosyspic($snid, $type,$ohter));
  132. }
  133. //上次指纹,采集就不上传了
  134. if($type=='fingerprint'){
  135. $id = $this->fingerprinttosn($snid, $ohter);
  136. }
  137. if($id==0 || is_string($id))return returnerror('发送失败:'.$id.'');
  138. return returnsuccess(array(
  139. 'id' => $id
  140. ));
  141. }
  142. //保存命令到数据库
  143. private function savedata($snid, $type, $data)
  144. {
  145. if(is_string($data))return $data;
  146. if(!$data)return 0;
  147. if(!isset($data[0]))$data = array($data);
  148. $id = $this->getrandid();
  149. $others = '';
  150. foreach($data as $k=>$rs){
  151. $data[$k]['id'] = $id+$k;
  152. if($k==0)$others = arrvalue($rs,'others');
  153. unset($data[$k]['others']);
  154. }
  155. $cmd = json_encode($data,256);
  156. $this->insert(array(
  157. 'id' => $id,
  158. 'snid' => $snid,
  159. 'others' => $others, //其他主键ID
  160. 'status'=> '0',
  161. 'atype' => $type,
  162. 'cmd' => $cmd,
  163. 'optdt' => $this->rock->now,
  164. ));
  165. return $id;
  166. }
  167. private function getrandid()
  168. {
  169. $id = rand(10000,99999999);
  170. if($this->rows($id)>0)$id = $this->getrandid();
  171. return $id;
  172. }
  173. /**
  174. * 获取命令,一次可获取条数
  175. */
  176. public function getcmd($snid)
  177. {
  178. //60分钟内的
  179. $optdt= date('Y-m-d H:i:s', time()-60*60);
  180. $rows = $this->getall("`snid`='$snid' and `status`=0 and `optdt`>'$optdt'",'*','optdt asc');
  181. $snrs = $this->getsninfo($snid);
  182. if($rows){
  183. $data = $rows[0];
  184. $this->update(array(
  185. 'status' => 2,
  186. 'qjtime' => $this->rock->now,
  187. ), $data['id']);
  188. $cmd = $data['cmd'];
  189. $cmd = str_replace("\n",'', $cmd);
  190. $barr = json_decode($cmd, true);
  191. }else{
  192. //$barr[] = $this->getconfigs($snrs);
  193. $barr = '';
  194. }
  195. $this->snobj->update(array(
  196. 'lastdt' => $this->rock->now
  197. ), $snid);
  198. return $barr;
  199. }
  200. //配置信息
  201. private function getconfigs($snrs)
  202. {
  203. $name = arrvalue($snrs,'name','信呼云考勤');
  204. $company = arrvalue($snrs,'company','信呼云考勤');
  205. $snid = arrvalue($snrs,'id','0');
  206. if($this->pinpai==1){
  207. $dtarr = explode('.', date('Y.m.d.H.i.s'));
  208. return array(
  209. 'id' => 0,
  210. 'do' => 'update',
  211. 'data' => 'config',
  212. 'name' => $name,
  213. 'y0' => (int)$dtarr[0],
  214. 'm0' => (int)$dtarr[1],
  215. 'd0' => (int)$dtarr[2],
  216. 'h0' => (int)$dtarr[3],
  217. 'i0' => (int)$dtarr[4],
  218. 's0' => (int)$dtarr[5],
  219. 'systime' => $this->rock->now
  220. );
  221. }
  222. return array(
  223. 'id' => 0,
  224. 'do' => 'update',
  225. 'data' => 'config',
  226. 'name' => $name,
  227. 'company' => $company,
  228. 'companyid' => $snid, //公司ID/设备ID
  229. 'max' => 3000, //目前设计最大值
  230. 'function' => 65535, //全部功能
  231. 'delay' => 20,
  232. 'errdelay' => 50,
  233. 'interval' => 5,
  234. 'timezone' => 'GMT+08:00',
  235. 'encrypt' => 0,
  236. 'expired' => 0
  237. );
  238. }
  239. /**
  240. * 推送过来的数据
  241. */
  242. public function postdata($snid, $dstr)
  243. {
  244. $this->rock->debugs($dstr,'postkqj_'.$snid.'_');
  245. $barr = json_decode($dstr, true);
  246. $carr = array();
  247. $uids = $dids = '';
  248. $snrs = $this->getsninfo($snid);
  249. if($barr)foreach($barr as $k=>$rs){
  250. $dtype = arrvalue($rs, 'data'); //数据类型
  251. $carr[]= $rs['id']; //设备上来的ID
  252. //发送的命令返回
  253. if($dtype == 'return'){
  254. $mids = '';
  255. foreach($rs['return'] as $k1=>$rs1){
  256. $mid = arrvalue($rs1,'id'); //我发送时ID
  257. if(isempt($mid))continue;
  258. $result = $rs1['result']; //处理结果
  259. $status = ($result=='0') ? 1 : 3;//
  260. $this->update(array(
  261. 'status' => $status,
  262. 'cjtime' => $this->rock->now,
  263. ),'`id`='.$mid.'');
  264. $mids.=','.$mid.'';
  265. }
  266. if($mids!=''){
  267. $mids = substr($mids, 1);
  268. $this->returnchuli($mids, $snid); //返回处理
  269. }
  270. }
  271. //推送过来的人员信息
  272. if($dtype=='user' && isset($rs['deptid'])){
  273. $uids .= ','.$rs['ccid'].'';
  274. $dids .= ','.$rs['deptid'].'';
  275. }
  276. //推送来的指纹
  277. if($dtype=='fingerprint'){
  278. $this->savefingerprint($snid, $rs['ccid'], $rs['fingerprint']);
  279. }
  280. //推送来的头像
  281. if($dtype=='headpic'){
  282. $this->saveheadpic($snid, $rs['ccid'], $rs['headpic']);
  283. }
  284. //解除绑定(解除绑定会清空设备上所有数据,包括设备上待发送的命令)
  285. if($dtype=='unbound'){
  286. $this->cleardatasn($snid);
  287. }
  288. //打卡记录
  289. if($dtype=='clockin'){
  290. $this->adddkjl($snid, $rs);
  291. }
  292. //推送来的设备信息
  293. if($dtype=='info'){
  294. $this->setsnconfig($snid, $rs);
  295. }
  296. }
  297. //保存用户
  298. if($uids!='')$this->saveuseriddids(substr($uids, 1), substr($dids, 1), $snid);
  299. return $carr;
  300. }
  301. //上传完成回调处理
  302. public function returnchuli($mids, $snid)
  303. {
  304. $clarr = $this->getall("`id` in($mids) and `status`=1");//处理成功的
  305. $detpids= $userids= $useridsdel = '';
  306. foreach($clarr as $k=>$rs){
  307. $others = $rs['others'];
  308. if(isempt($others))continue;//不需要处理
  309. $atype = $rs['atype'];
  310. //部门说明设备已
  311. if($atype=='dept'){
  312. $detpids.=','.$others.'';
  313. }
  314. //人员
  315. if($atype=='user'){
  316. $userids.=','.$others.'';
  317. }
  318. //上传头像成功
  319. if($atype=='headpic'){
  320. $uid = (int)$others;
  321. $face= $this->db->getmou('[Q]admin','face','`id`='.$uid.'');
  322. $this->saveheadpic($snid, $uid, '', $face); //设置设备头像
  323. }
  324. //删除人员成功
  325. if($atype=='deluser'){
  326. $useridsdel.=','.$others.'';
  327. }
  328. //指纹上传成功
  329. if($atype=='fingerprint'){
  330. $cmdarr = json_decode($rs['cmd'], true);
  331. $cnsrs = $cmdarr[0];
  332. $this->savefingerprint($snid, $cnsrs['ccid'], $cnsrs['fingerprint']); //保存指纹
  333. }
  334. }
  335. //部门
  336. if(!isempt($detpids)){
  337. $this->addupstr($snid, substr($detpids, 1), 'deptids');
  338. }
  339. //人员的,说明设备上有哪些人员
  340. if(!isempt($userids)){
  341. $this->addupstr($snid, substr($userids, 1), 'userids');
  342. }
  343. //删除人员
  344. if(!isempt($useridsdel)){
  345. $this->delupstr($snid, substr($useridsdel, 1), 'userids');
  346. }
  347. }
  348. //清除设备上所有信息
  349. private function cleardatasn($snid)
  350. {
  351. m('kqjuser')->delete('`snid`='.$snid.'');//删除数据
  352. m('kqjcmd')->delete('`snid`='.$snid.''); //删除命令
  353. $this->snobj->update(array(
  354. 'userids' => '',
  355. 'deptids' => '',
  356. ), $snid);
  357. }
  358. //添加打卡记录$rs = {time,ccid,pic,verify}
  359. private $uinfoarr = array();
  360. public function adddkjl($snid, $rs, $type=1, $ddbs=null, $iszk=0)
  361. {
  362. $dkdt = $rs['time'];
  363. $uid = $rs['ccid']; //用户ID
  364. if(isset($rs['uid'])){
  365. $uid = $rs['uid'];
  366. $this->uinfoarr[$uid] = $uid;
  367. }
  368. //是中控考勤机来的
  369. if($iszk==1){
  370. if(isset($this->uinfoarr[$uid])){
  371. $uid = $this->uinfoarr[$uid];
  372. }else{
  373. $unfo = $this->db->getone('[Q]userinfo',"`finger`='$uid'");
  374. if($unfo){
  375. $this->uinfoarr[$uid] = $unfo['id'];
  376. $uid = $unfo['id'];
  377. }else{
  378. $this->uinfoarr[$uid] = $uid;
  379. }
  380. }
  381. }
  382. $pic = arrvalue($rs,'pic'); //现成照片
  383. $sntype = $rs['verify'];//打卡方式
  384. $where = "`uid`='$uid' and `dkdt`='$dkdt' and `type`='$type'";
  385. if($ddbs==null)$ddbs = m('kqdkjl');
  386. $to = $ddbs->rows($where);
  387. $datype = array('密码','指纹','刷卡');
  388. $uarr['sntype'] = $sntype;
  389. $uarr['snid'] = $snid;
  390. $uarr['optdt'] = $this->rock->now;
  391. $uarr['explain'] = '在['.$this->snrs['name'].']使用('.arrvalue($datype, $sntype).')打卡';
  392. if($to==0){
  393. $uarr['type'] = $type;
  394. $uarr['uid'] = $uid;
  395. $uarr['dkdt'] = $dkdt;
  396. $where = '';
  397. }
  398. if(!isempt($pic)){
  399. $imgpath = ''.UPDIR.'/'.date('Y-m').'/'.$uid.'_'.strtotime($dkdt).'.jpg';
  400. $this->rock->createtxt($imgpath, base64_decode($pic));
  401. $uarr['imgpath'] = $imgpath;
  402. }
  403. $ddbs->record($uarr, $where);
  404. $dkdta = explode(' ', $dkdt);
  405. $fenxiarr[''.$dkdta[0].'|'.$uid] = $uid;
  406. return $fenxiarr;
  407. }
  408. //保存设备用户
  409. private function saveuseriddids($userids, $dids, $snid)
  410. {
  411. $darrs = $this->depttosn($dids);
  412. $deptids = $darrs['others'];
  413. $this->snobj->update(array(
  414. 'userids' => $userids,
  415. 'deptids' => $deptids,
  416. ), $snid);
  417. }
  418. //保存指纹
  419. public function savefingerprint($snid, $uid, $finge)
  420. {
  421. $snid = (int)$snid;
  422. $uid = (int)$uid;
  423. $where = "`snid`='$snid' and `uid`='$uid'";
  424. $arr['fingerprint1'] = str_replace("\n",'', arrvalue($finge, 0));
  425. $arr['fingerprint2'] = str_replace("\n",'', arrvalue($finge, 1));
  426. //if(isempt($arr['fingerprint1']) && isempt($arr['fingerprint2']))return;
  427. if($this->kquobj->rows($where)==0){
  428. $where = '';
  429. $arr['snid'] = $snid;
  430. $arr['uid'] = $uid;
  431. }
  432. $this->kquobj->record($arr, $where);
  433. }
  434. //保存设备头像
  435. private function saveheadpic($snid, $uid, $headpic, $face='')
  436. {
  437. $snid = (int)$snid;
  438. $uid = (int)$uid;
  439. $where = "`snid`='$snid' and `uid`='$uid'";
  440. if(isempt($face)){
  441. if(isempt($headpic))return;
  442. $face = ''.UPDIR.'/face/kqj'.$snid.'_u'.$uid.'.jpg'; //头像保存为图片
  443. $this->rock->createtxt($face, base64_decode($headpic));
  444. }
  445. $arr['headpic'] = $face;
  446. if($this->kquobj->rows($where)==0){
  447. $where = '';
  448. $arr['snid'] = $snid;
  449. $arr['uid'] = $uid;
  450. }
  451. $this->kquobj->record($arr, $where);
  452. }
  453. //获取设备信息
  454. public function getsninfo($id)
  455. {
  456. $snrs = $this->db->getone('`[Q]kqjsn`','`id`='.$id.'');
  457. $this->snrs = $snrs;//当前设备信息
  458. return $snrs;
  459. }
  460. //设置设备信息
  461. private function setsnconfig($snid, $rs)
  462. {
  463. $uarr['model'] = arrvalue($rs,'model');
  464. $uarr['appver'] = $rs['app'];
  465. $uarr['romver'] = $rs['rom'];
  466. $uarr['space'] = $rs['space'];
  467. $uarr['memory'] = $rs['memory'];
  468. $uarr['usershu'] = $rs['user'];
  469. $uarr['fingerprintshu'] = $rs['fingerprint'];
  470. $uarr['headpicshu'] = $rs['headpic'];
  471. $uarr['clockinshu'] = $rs['clockin'];
  472. $uarr['picshu'] = $rs['pic'];
  473. $this->snobj->update($uarr, $snid);
  474. }
  475. private function delupstr($snid, $dstr, $fields)
  476. {
  477. $this->kquobj->delete('`snid`='.$snid.' and `uid` in('.$dstr.')');
  478. $snrs = $this->getsninfo($snid);
  479. $odeptid = $snrs[$fields];
  480. if(isempt($odeptid))return;
  481. $dstr = ','.$dstr.','; //要删除的
  482. $depta = explode(',', $odeptid);
  483. $dids = array(); //最后Id
  484. foreach($depta as $dis1){
  485. if(!contain($dstr,','.$dis1.','))$dids[] = $dis1;
  486. }
  487. $ids = join(',', $dids);
  488. $this->snobj->update("`$fields`='$ids'", $snid);
  489. }
  490. //更新添加记录
  491. private function addupstr($snid, $strss, $fields)
  492. {
  493. $snrs = $this->getsninfo($snid);
  494. $odeptid = $snrs[$fields];
  495. if(isempt($odeptid))$odeptid = '';
  496. if(!isempt($odeptid))$odeptid.=',';
  497. $odeptid.=''.$strss.''; //最新的
  498. $depta = explode(',', $odeptid);
  499. $dids = array(); //最后Id
  500. foreach($depta as $dis1){
  501. if(!in_array($dis1, $dids))$dids[] = $dis1;
  502. }
  503. $ids = join(',', $dids);
  504. $this->snobj->update("`$fields`='$ids'", $snid);
  505. }
  506. /**
  507. * 部门推送更新
  508. */
  509. private function depttosn($deptids)
  510. {
  511. if(isempt($deptids))return 0;
  512. $dids = '';
  513. $deptida = explode(',', $deptids);
  514. foreach($deptida as $did){
  515. $didsss = $this->db->getpval('[Q]dept', 'pid', 'id', $did,','); //获取路径
  516. if(!isempt($didsss))$dids.=','.$didsss.'';
  517. }
  518. if($dids=='')return 0;
  519. $dids = substr($dids, 1);
  520. $drows= $this->db->getall('select * from `[Q]dept` where `id` in('.$dids.')');
  521. $deptarr = array();
  522. $ids = '';
  523. foreach($drows as $k=>$rs){
  524. $deptarr[] = array(
  525. 'id' => $rs['id'],
  526. 'name' => $rs['name'],
  527. 'pid' => $rs['pid'],
  528. );
  529. $ids.=','.$rs['id'].'';
  530. }
  531. $data['do'] = 'update';
  532. $data['data'] = 'dept';
  533. $data['dept'] = $deptarr;
  534. $data['others'] = substr($ids, 1); //部门id
  535. return $data;
  536. }
  537. //人员上传
  538. private function usertosn($uids)
  539. {
  540. //$uarr = m('admin')->getall('id in('.$uids.') and `status`=1');
  541. $uarr = $this->db->getall('select a.*,b.`finger` from `[Q]admin` a left join `[Q]userinfo` b on a.`id`=b.`id` where a.`id` in('.$uids.') and a.`status`=1');
  542. if(!$uarr)return 0;
  543. $data = array();
  544. $ids = '';
  545. $dids = '';
  546. $deptids= ','.arrvalue($this->snrs,'deptids').',';
  547. foreach($uarr as $k=>$rs){
  548. $data[] = array(
  549. 'do' => 'update',
  550. 'data' => 'user',
  551. 'ccid' => $rs['id'],
  552. 'finger' => $this->rock->repempt($rs['finger']),
  553. 'name' => $rs['name'],
  554. 'passwd'=> $rs['pass'], // 密码
  555. 'card' => $rs['user'],
  556. 'deptid' => $rs['deptid'],
  557. 'auth' => 0, //刷卡卡号
  558. 'faceexist' => 0, //是否有人脸,0 没有,1 有(暂无用,预留字段)
  559. );
  560. $ids.=','.$rs['id'].'';
  561. if(!contain($deptids,','.$rs['deptid'].',')){
  562. $dids.=','.$rs['deptid'].'';
  563. }
  564. }
  565. $data[0]['others'] = substr($ids, 1); //人员ID
  566. //同时也要上传部门ID
  567. if($dids!=''){
  568. $dids = substr($dids, 1);
  569. $this->savedata($this->snrs['id'], 'dept', $this->depttosn($dids));
  570. }
  571. return $data;
  572. }
  573. //设备上获取指纹和头像
  574. private function sntofingerhead($uids, $type)
  575. {
  576. $uarr = $this->userinsn($uids);
  577. if(is_string($uarr))return $uarr;
  578. $ccid = array();
  579. foreach($uarr as $k=>$rs){
  580. $ccid[] = $rs['id'];
  581. }
  582. $data = array(
  583. 'do' => 'upload',
  584. 'data' => array(substr($type,3)),
  585. 'ccid' => $ccid,
  586. 'others' => join(',', $ccid)
  587. );
  588. if($this->pinpai==1){
  589. $data['data'] = $data['data'][0];
  590. $data['ccid'] = $data['others'];
  591. }
  592. return $data;
  593. }
  594. //判断人员是否在设备上
  595. private function userinsn($uids)
  596. {
  597. $userids = arrvalue($this->snrs,'userids');
  598. if(isempt($userids))return '设备上没有人员';
  599. $uarr = m('admin')->getall('id in('.$uids.') and `id` in('.$userids.')');
  600. if(!$uarr)return '没有选中人员没在此设备上';
  601. return $uarr;
  602. }
  603. //上传头像
  604. private function uoloadface($snid, $uids)
  605. {
  606. $uarr = $this->userinsn($uids);
  607. if(is_string($uarr))return $uarr;
  608. foreach($uarr as $k=>$rs){
  609. $face = $rs['face'];
  610. if(!isempt($face) && file_exists($face)){
  611. $data['do'] = 'update';
  612. $data['data'] = 'headpic';
  613. $data['ccid'] = $rs['id'];
  614. $data['others'] = $rs['id'];
  615. $data['headpic']= base64_encode(file_get_contents($face));
  616. $this->savedata($snid, 'headpic', $data);
  617. }
  618. }
  619. return 1;
  620. }
  621. //删除选中的人员
  622. private function userdeltosn($snid, $uids)
  623. {
  624. $uarr = $this->userinsn($uids);
  625. if(is_string($uarr))return $uarr;
  626. $ccid = array();
  627. foreach($uarr as $k=>$rs){
  628. $ccid[] = $rs['id'];
  629. }
  630. $data = array(
  631. 'do' => 'delete',
  632. 'data' => array("user","fingerprint","face","headpic","clockin","pic"), //删除全部
  633. 'ccid' => $ccid,
  634. 'others' => join(',', $ccid)
  635. );
  636. //中控
  637. if($this->pinpai==1){
  638. $data['data'] = 'deluser';
  639. $data['ccid'] = join(',', $ccid);
  640. }
  641. return $data;
  642. }
  643. //删除不存在的
  644. private function userdeltosns($snid)
  645. {
  646. $ccid = $this->getnosys($snid);
  647. if(!$ccid)return '没有可删除的人员';
  648. $data = array(
  649. 'do' => 'delete',
  650. 'data' => array("user","fingerprint","face","headpic","clockin","pic"), //删除全部
  651. 'ccid' => $ccid,
  652. 'others' => join(',', $ccid)
  653. );
  654. //中控
  655. if($this->pinpai==1){
  656. $data['data'] = 'deluser';
  657. $data['ccid'] = join(',', $ccid);
  658. }
  659. return $data;
  660. }
  661. //对应设备显示显示离职人员等信息
  662. public function getnosys($snid)
  663. {
  664. $snrs = $this->getsninfo($snid);
  665. $userids = $snrs['userids'];
  666. if(isempt($userids))return array();
  667. $uarr = m('admin')->getall('`status`=1');
  668. $ccid = array();
  669. foreach($uarr as $k=>$rs){
  670. $ccid[] = $rs['id'];
  671. }
  672. $useridsa = explode(',', $userids);
  673. $nuco = array();//不存在
  674. foreach($useridsa as $adis){
  675. if(!in_array($adis, $ccid))$nuco[] = $adis;
  676. }
  677. return $nuco;
  678. }
  679. //获取打卡记录
  680. private function getsntosyspic($snid, $type, $uids)
  681. {
  682. $startdt = $this->rock->post('startdt', $this->rock->date);
  683. $endddt = $this->rock->post('endddt', $this->rock->date);
  684. if($endddt<$startdt)return '获取开始日期不能大于截止日期';
  685. $userids = arrvalue($this->snrs,'userids');
  686. if(isempt($userids))return '设备上没有人员';
  687. $ccid = array();
  688. if($uids!='0'){
  689. $uarr = m('admin')->getall('`id` in('.$userids.') and `id` in('.$uids.')');
  690. if(!$uarr)return '没有选中人员没在此设备上';
  691. $ccid = array();
  692. foreach($uarr as $k=>$rs){
  693. $ccid[] = $rs['id'];
  694. }
  695. }
  696. //删除
  697. if($type=='delclockin' || $type=='delpic'){
  698. $data['do'] = 'delete';
  699. $data['data'] = array(substr($type, 3));
  700. }else{
  701. $data['do'] = 'upload';
  702. $data['data'] = array('clockin');
  703. if($type=='getpic')$data['data'][]= 'pic';//要照片
  704. }
  705. if($ccid){
  706. $data['ccid'] = $ccid;
  707. $data['others'] = join(',', $ccid);
  708. }
  709. $data['from'] = ''.$startdt.' 00:00:00';
  710. $data['to'] = ''.$endddt.' 23:59:59';
  711. if($this->pinpai==1){
  712. $data['data'] = $data['data'][0];
  713. $data['ccid'] = join(',', $ccid);
  714. }
  715. return $data;
  716. }
  717. //上传指纹
  718. public function fingerprinttosn($snid, $uids)
  719. {
  720. $uarr = $this->userinsn($uids);
  721. if(is_string($uarr))return $uarr;
  722. $ccid = array();
  723. $ubo = 0;
  724. foreach($uarr as $k=>$rs){
  725. $uid = $rs['id'];
  726. $zwra = $this->kquobj->getone('snid='.$snid.' and `uid`='.$uid.'');
  727. $fingerprint1 = arrvalue($zwra,'fingerprint1');
  728. $fingerprint2 = arrvalue($zwra,'fingerprint2');
  729. $uobo = false;
  730. //找找别的设备有没有指纹
  731. if(isempt($fingerprint1)){
  732. $fingerprint1s = $this->kquobj->getmou('fingerprint1',"`uid`='$uid' and ifnull(`fingerprint1`,'')<>''");
  733. if(!isempt($fingerprint1s)){
  734. $fingerprint1 = $fingerprint1s;
  735. $uobo = true;
  736. }
  737. }
  738. if(isempt($fingerprint2)){
  739. $fingerprint2s = $this->kquobj->getmou('fingerprint2',"`uid`='$uid' and ifnull(`fingerprint2`,'')<>''");
  740. if(!isempt($fingerprint2s)){
  741. $fingerprint2 = $fingerprint2s;
  742. $uobo = true;
  743. }
  744. }
  745. if($uobo){
  746. $ubo++;
  747. $data['do'] = 'update';
  748. $data['data'] = 'fingerprint';
  749. $data['ccid'] = $uid;
  750. $data['others'] = $uid;
  751. $data['fingerprint'] = array($fingerprint1, $fingerprint2);
  752. $this->savedata($snid, 'fingerprint', $data);
  753. }
  754. }
  755. if($ubo==0)$ubo = '没有可上传的指纹';
  756. return $ubo;
  757. }
  758. }
粤ICP备19079148号