kqjcmdModel.php 22 KB

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