ShOneanalysis.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. <?php
  2. namespace app\common\server;
  3. use app\common\model\FacilityModel;
  4. use app\common\model\ShoneReceiveInfoModel;
  5. use app\common\model\ShoneReceiveInfoRecode;
  6. use app\common\model\ShoneReceiveQueueModel;
  7. use app\common\model\ShoneSendListModel;
  8. use app\common\model\ShoneSendQueueModel;
  9. use think\facade\Log;
  10. /**
  11. * 手环字符串解析
  12. *
  13. * @author wj
  14. * @date 2023-08-11
  15. */
  16. class ShOneanalysis
  17. {
  18. private $num_scale = 16; //16进制
  19. /**
  20. * 校验长度
  21. *
  22. * @return void
  23. * @author wj
  24. * @date 2023-08-11
  25. */
  26. public function checklen($len, $str)
  27. {
  28. $strlen = mb_strlen($str);
  29. if ($len != $strlen) {
  30. return false;
  31. }
  32. return true;
  33. }
  34. /**
  35. * 获取信息
  36. *
  37. * @return void
  38. * @author wj
  39. * @date 2023-08-11
  40. */
  41. public function getline($str)
  42. {
  43. //[厂商*设备 ID*内容长度*内容]
  44. $preg = "/^\[(.*)\*(.*)\*(.*)\*(.*)\]$/";
  45. preg_match($preg, $str, $match);
  46. if (empty($match)) {
  47. throw new \Exception('解析失败:' . $str);
  48. }
  49. unset($match[0]);
  50. $data = array_values($match);
  51. $sandom_string = $data[0]; //厂商 随机字符串
  52. $device_id_code = $data[1]; //设置id编码
  53. $content_len = $data[2]; //内容长度
  54. $content_str = $data[3]; //内容字符串
  55. $content_len = $this->analysislen($content_len);
  56. $result = $this->checklen($content_len, $content_str);
  57. if (empty($result)) {
  58. throw new \Exception('内容位数错误');
  59. }
  60. $data = [
  61. 'device_id_code' => $device_id_code,
  62. 'content_len' => $content_len,
  63. 'content_str' => $content_str,
  64. ];
  65. return $data;
  66. }
  67. //KA,230814,0,0,96
  68. //WT,130823,160054,V,22.601242,N,113.8302765,E,0.00,0.0,29.2,0,70,96,0,0,00000000,1,1,460,0,8593,265807240,136,0,9999.0
  69. //ICCID,02203002080045057806
  70. public function getcommandcontent($content_str)
  71. {
  72. $content = explode(',', $content_str);
  73. return $content;
  74. }
  75. /**
  76. * 保存手环设备one信息
  77. *
  78. * @return void
  79. * @author wj
  80. * @date 2023-08-11
  81. */
  82. public function saveshouhuanoneinfo()
  83. {
  84. //保存时时
  85. //保存历史
  86. }
  87. //内容解析
  88. //解析长度
  89. public function analysislen($len)
  90. {
  91. //低位数在前
  92. $len = base_convert($len, 16, 10);
  93. return $len;
  94. }
  95. /**
  96. * 获取命令信息
  97. *
  98. * @param [type] $command
  99. * @return void
  100. * @author wj
  101. * @date 2023-08-11
  102. */
  103. public function getcommandinfo($command)
  104. {
  105. $command = strtoupper($command);
  106. $data = [
  107. 'LK' => [
  108. 'content' => [
  109. 'command' => 'LK',
  110. ],
  111. 'kind' => 'back',
  112. ],
  113. 'PING' => [
  114. 'content' => [
  115. 'command' => 'PING',
  116. 'isbind' => 1,
  117. ],
  118. 'kind' => 'back',
  119. ],
  120. 'KA' => [
  121. 'content' => [
  122. 'command' => 'KA',
  123. ],
  124. 'kind' => 'back',
  125. ],
  126. 'MONITOR' => [
  127. 'content' => [
  128. 'command' => 'MONITOR',
  129. 'telno' => '',
  130. ],
  131. 'kind' => 'send',
  132. ],
  133. 'SOS' => [
  134. 'content' => [
  135. 'command' => 'SOS',
  136. 'telno1' => '',
  137. 'telno2' => '',
  138. 'telno3' => '',
  139. ],
  140. 'kind' => 'send',
  141. ],
  142. 'VERNO' => [
  143. 'content' => [
  144. 'command' => 'VERNO',
  145. ],
  146. 'kind' => 'send',
  147. ],
  148. 'ZONE' => [
  149. 'content' => [
  150. 'command' => 'ZONE',
  151. 'zone' => '',
  152. ],
  153. 'kind' => 'send',
  154. ],
  155. 'POWEROFF' => [
  156. 'content' => [
  157. 'command' => 'POWEROFF',
  158. ],
  159. 'kind' => 'send',
  160. ],
  161. 'TEMP' => [
  162. 'content' => [
  163. 'command' => 'temp',
  164. ],
  165. 'kind' => 'back',
  166. ],
  167. 'BPHRT' => [
  168. 'content' => [
  169. 'command' => 'bphrt',
  170. ],
  171. 'kind' => 'back',
  172. ],
  173. 'HEART' => [
  174. 'content' => [
  175. 'command' => 'heart',
  176. ],
  177. 'kind' => 'back',
  178. ],
  179. 'BLOOD' => [
  180. 'content' => [
  181. 'command' => 'blood',
  182. ],
  183. 'kind' => 'back',
  184. ],
  185. 'OXYGEN' => [
  186. 'content' => [
  187. 'command' => 'oxygen',
  188. ],
  189. 'kind' => 'back',
  190. ],
  191. ];
  192. if (!isset($data[$command])) {
  193. return false;
  194. }
  195. return $data[$command];
  196. }
  197. public function gettsendcommandinfo($command)
  198. {
  199. $command = strtoupper($command);
  200. $data = [
  201. 'WT' => [
  202. 'content' => [
  203. 'command' => 'WT',
  204. 'date' => '',
  205. 'time' => '',
  206. 'is_location' => '',
  207. 'gps_long' => '',
  208. 'gps_long_tag' => '',
  209. 'gps_lat' => '',
  210. 'gps_lat_tag' => '',
  211. 'speed' => '',
  212. 'direction' => '',
  213. 'poster' => '',
  214. 'direction' => '',
  215. 'gps_satellite_num' => '',
  216. 'gsm_signal_strength' => '',
  217. 'electric_quantity' => '',
  218. 'step_number' => '',
  219. 'roll_number' => '',
  220. 'terminal_status' => '',
  221. ],
  222. 'kind' => 'tsend',
  223. 'need_bacl' => 0,
  224. ],
  225. 'WG' => [
  226. 'content' => [
  227. 'command' => 'WT',
  228. 'date' => '',
  229. 'time' => '',
  230. 'is_location' => '',
  231. 'gps_long' => '',
  232. 'gps_long_tag' => '',
  233. 'gps_lat' => '',
  234. 'gps_lat_tag' => '',
  235. 'speed' => '',
  236. 'direction' => '',
  237. 'poster' => '',
  238. 'direction' => '',
  239. 'gps_satellite_num' => '',
  240. 'gsm_signal_strength' => '',
  241. 'electric_quantity' => '',
  242. 'step_number' => '',
  243. 'roll_number' => '',
  244. 'terminal_status' => '',
  245. ],
  246. 'kind' => 'tsend',
  247. 'need_bacl' => 0,
  248. ],
  249. 'KA' => [
  250. 'content' => [
  251. 'command' => 'KA',
  252. 'date' => '',
  253. 'step_number' => '',
  254. 'roll_number' => '',
  255. 'electric_quantity' => '',
  256. ],
  257. 'kind' => 'tsend',
  258. 'need_back' => 1,
  259. ],
  260. 'LK' => [
  261. 'content' => [
  262. 'command' => 'LK',
  263. ],
  264. 'kind' => 'tsend',
  265. 'need_back' => 1,
  266. ],
  267. 'MONITOR' => [
  268. 'content' => [
  269. 'command' => 'MONITOR',
  270. ],
  271. 'kind' => 'tback',
  272. ],
  273. 'SOS3' => [
  274. 'content' => [
  275. 'command' => 'SOS',
  276. ],
  277. 'kind' => 'tback',
  278. ],
  279. 'VERNO' => [
  280. 'content' => [
  281. 'command' => 'VERNO',
  282. 'version' => '',
  283. ],
  284. 'kind' => 'tback',
  285. ],
  286. 'TEMP' => [
  287. 'content' => [
  288. 'command' => 'temp',
  289. 'temp' => '',
  290. ],
  291. 'kind' => 'tsend',
  292. 'need_back' => 1,
  293. ],
  294. 'BPHRT' => [
  295. 'content' => [
  296. 'command' => 'bphrt',
  297. 'blood_height_pressure' => '',
  298. 'blood_low_pressure' => '',
  299. 'heart_rate' => '',
  300. 'height' => '',
  301. 'gender' => '',
  302. 'age' => '',
  303. 'weight' => '',
  304. ],
  305. 'kind' => 'tsend',
  306. 'need_back' => 1,
  307. ],
  308. 'HEART' => [
  309. 'content' => [
  310. 'command' => 'heart',
  311. 'heart_rate' => '',
  312. ],
  313. 'kind' => 'tsend',
  314. 'need_back' => 1,
  315. ],
  316. 'BLOOD' => [
  317. 'content' => [
  318. 'command' => 'blood',
  319. 'blood_height_pressure' => '',
  320. 'blood_low_pressure' => '',
  321. ],
  322. 'kind' => 'tsend',
  323. 'need_back' => 1,
  324. ],
  325. 'OXYGEN' => [
  326. 'content' => [
  327. 'command' => 'oxygen',
  328. 'oxygen' => '',
  329. ],
  330. 'kind' => 'tsend',
  331. 'need_back' => 1,
  332. ],
  333. ];
  334. if (!isset($data[$command])) {
  335. return false;
  336. }
  337. return $data[$command];
  338. }
  339. /**
  340. * 获取回复权重
  341. *
  342. * @param [type] $command
  343. * @return void
  344. * @author wj
  345. * @date 2023-08-11
  346. */
  347. public function getsendweight($command)
  348. {
  349. $weight = -1;
  350. switch ($command) {
  351. case 'POWEROFF':
  352. //关机
  353. $weight = 99;
  354. break;
  355. case 'RESET':
  356. //重启
  357. $weight = 98;
  358. break;
  359. case 'LK':
  360. case 'PING':
  361. case 'KA':
  362. case 'AL':
  363. case 'UD2';
  364. $weight = 1;
  365. break;
  366. case 'UPLOAD':
  367. case 'MONITOR':
  368. case 'SOS':
  369. case 'LANG':
  370. case 'ZONE':
  371. case 'CENTER':
  372. case 'SOSSMS':
  373. case 'REMOVE':
  374. case 'REMOVESMS':
  375. case 'VERNO':
  376. case 'CR':
  377. case 'SILENCETIME2':
  378. case 'WALKTIME':
  379. case 'SLEEPTIME':
  380. case 'FIND':
  381. case 'REMIND':
  382. case 'SCHEDULE':
  383. case 'PHB':
  384. case 'PHBX':
  385. case 'DPHBX':
  386. case 'MESSAGE':
  387. case 'FACTORY':
  388. case 'PROFILE':
  389. case 'BTEMP2':
  390. case 'BODYTEMP':
  391. case 'BTWARNSET':
  392. case 'APPLOCK':
  393. case 'HRTSTART':
  394. case 'BPHRT':
  395. case 'LSSET':
  396. $weight = 0;
  397. break;
  398. default:
  399. $weight = -1;
  400. break;
  401. }
  402. if ($weight < 0) {
  403. //不需设置 发送信息
  404. return false;
  405. }
  406. return $weight;
  407. }
  408. /**
  409. * 获取设别表id
  410. *
  411. * @return void
  412. * @author wj
  413. * @date 2023-08-11
  414. */
  415. public function getfacilityid($device_id_code)
  416. {
  417. $m_f = new FacilityModel();
  418. $where = ['code' => $device_id_code, 'status' => 1];
  419. $finfo = $m_f->getInfo($where, ['id']);
  420. if (empty($finfo)) {
  421. throw new \Exception("设备信息错误:" . $device_id_code);
  422. return false;
  423. }
  424. $id = $finfo['id'];
  425. return $id;
  426. }
  427. /**
  428. * 创建发送信息
  429. *
  430. * @param [type] $data
  431. * @param [type] $command
  432. * @return void
  433. * @author wj
  434. * @date 2023-08-14
  435. */
  436. public function createbacksendmsg($facility_id, $device_id_code, $data, $command)
  437. {
  438. $infoarr = $this->gettsendcommandinfo($command);
  439. if (!$infoarr) {
  440. Log::write("无对应命令数据1:" . $command, 'shouhuan');
  441. Log::write($data, 'shouhuan');
  442. return false;
  443. }
  444. $data = $this->getdata($data, $command, $infoarr);
  445. $info_content = $data['info_content'];
  446. $need_back = isset($data['need_back']) && $data['need_back'] ? true : false;
  447. if ($need_back) {
  448. $infoarr = $this->getcommandinfo($command);
  449. $data = $this->getdata($data, $command, $infoarr);
  450. $info_content = $data['info_content'];
  451. $weight = $this->getsendweight($command);
  452. $content = implode(',', $info_content);
  453. $msgdata = [
  454. 0 => '3G',
  455. 'device_id_code' => $device_id_code,
  456. 'len' => str_pad(dechex(mb_strlen($content)), 4, "0", STR_PAD_LEFT),
  457. 'content' => $content,
  458. ];
  459. $msg = '[' . implode('*', $msgdata) . ']';
  460. $sslInsertData = [
  461. 'facility_id' => $facility_id,
  462. 'device_id_code' => $device_id_code,
  463. 'send_msg' => $msg,
  464. 'send_time' => date('Y-m-d H:i:s'),
  465. 'send_weight' => $weight,
  466. ];
  467. $m_ssl = new ShoneSendListModel();
  468. $sslid = $m_ssl->insertData($sslInsertData);
  469. if (empty($sslid)) {
  470. throw new \Exception("发送数据添加失败");
  471. }
  472. $data = [
  473. 'msg' => $msg,
  474. 'weight' => $weight,
  475. 'createtime' => date('Y-m-d H:i:s'),
  476. 'device_id_code' => $device_id_code,
  477. 'list_id' => $sslid,
  478. ];
  479. $m_ssq = new ShoneSendQueueModel();
  480. $id = $m_ssq->insertData($data);
  481. if (empty($id)) {
  482. throw new \Exception("发送队列数据添加失败");
  483. }
  484. return $data;
  485. }
  486. return false;
  487. }
  488. /**
  489. * 获取数据值
  490. *
  491. * @param [type] $data
  492. * @param [type] $command
  493. * @return void
  494. * @author wj
  495. * @date 2023-08-14
  496. */
  497. public function getdata($data, $command, $infoarr)
  498. {
  499. $info_content = $infoarr['content'];
  500. foreach (array_keys($info_content) as $key => $value) {
  501. if (empty($info_content[$value])) {
  502. if (isset($data[$key])) {
  503. $info_content[$value] = $data[$key];
  504. }
  505. }
  506. }
  507. if (isset($info_content['time'])) {
  508. $time = $info_content['time'];
  509. $info_content['time'] = $this->gettime($time);
  510. }
  511. if (isset($info_content['date'])) {
  512. $date = $info_content['date'];
  513. $info_content['date'] = $this->getdate($date);
  514. }
  515. $infoarr['info_content'] = $info_content;
  516. return $infoarr;
  517. }
  518. /**
  519. * 保存接收信息队列
  520. *
  521. * @param [type] $data
  522. * @return void
  523. * @author wj
  524. * @date 2023-08-14
  525. */
  526. public function savereceivequeue($data)
  527. {
  528. $m_srq = new ShoneReceiveQueueModel();
  529. $data = [
  530. 'msg' => $data,
  531. 'createtime' => date('Y-m-d H:i:s'),
  532. ];
  533. $id = $m_srq->insertData($data);
  534. Log::write('id:' . $id, 'shouhuan');
  535. if (empty($id)) {
  536. return false;
  537. }
  538. return true;
  539. }
  540. /**
  541. * 保存手环信息
  542. *
  543. * @return void
  544. * @author wj
  545. * @date 2023-08-14
  546. */
  547. public function saveshinfo($facility_id, $device_id_code, $data, $original_str)
  548. {
  549. $command = $data[0];
  550. $infoarr = $this->gettsendcommandinfo($command);
  551. if (!$infoarr) {
  552. Log::write("无对应命令数据2:" . $command, 'shouhuan');
  553. Log::write($data, 'shouhuan');
  554. return false;
  555. }
  556. $data = $this->getdata($data, $data[0], $infoarr);
  557. $m_sri = new ShoneReceiveInfoModel();
  558. $m_srir = new ShoneReceiveInfoRecode();
  559. $data = $data['info_content'];
  560. $data['facility_id'] = $facility_id;
  561. $data['device_id_code'] = $device_id_code;
  562. //$m_sri处理
  563. $sriwhere = [
  564. 'facility_id' => $facility_id,
  565. 'device_id_code' => $device_id_code,
  566. ];
  567. $sriinfo = $m_sri->getInfo($sriwhere);
  568. unset($data['command']);
  569. if (empty($sriinfo)) {
  570. $sriinsertData = $data;
  571. $sriinsertData['createtime'] = date('Y-m-d H:i:s');
  572. $sriinsertData = $m_sri->formatinfo($sriinsertData);
  573. $sriid = $m_sri->insertData($sriinsertData);
  574. if (empty($sriid)) {
  575. throw new \Exception("设备信息添加失败:" . $device_id_code);
  576. }
  577. } else {
  578. unset($data['device_id_code']);
  579. unset($data['facility_id']);
  580. $sriid = $sriinfo['id'];
  581. $sriupdateData = $data;
  582. $sriupdateData['updatetime'] = date('Y-m-d H:i:s');
  583. $sriupdateData = $m_sri->formatinfo($sriupdateData);
  584. $row = $m_sri->updateinfo(['id' => $sriid], $sriupdateData);
  585. if (empty($row)) {
  586. throw new \Exception("设备信息修改失败:" . $device_id_code);
  587. }
  588. }
  589. //m_srir处理
  590. $data['original_str'] = $original_str;
  591. $sririnsertData = $data;
  592. $sririnsertData['facility_id'] = $facility_id;
  593. $sririnsertData['device_id_code'] = $device_id_code;
  594. $sririnsertData['createtime'] = date('Y-m-d H:i:s');
  595. $sririd = $m_srir->insertData($sririnsertData);
  596. if (empty($sririd)) {
  597. throw new \Exception("设备历史信息添加失败:" . $device_id_code);
  598. }
  599. }
  600. /**
  601. * 获取接收信息队列列表
  602. *
  603. * @param [type] $page
  604. * @param [type] $size
  605. * @return void
  606. * @author wj
  607. * @date 2023-08-14
  608. */
  609. public function getreceivequeuelist($page = null, $size = null)
  610. {
  611. $m_srq = new ShoneReceiveQueueModel();
  612. $where = ['status' => 0];
  613. $size = empty($size) ? 20 : $size;
  614. if (empty($page)) {
  615. $count = $m_srq->getList($where, 'count');
  616. $totalpage = ceil($count / $size);
  617. $data = ['totalpage' => $totalpage, 'size' => $size];
  618. return $data;
  619. } else {
  620. $list = $m_srq->getList($where, '*', $page, $size, 'id asc');
  621. if (empty($list)) {
  622. Log::write("手环接收信息队列-无数据", 'shouhuan');
  623. return false;
  624. }
  625. $list = $list->toArray();
  626. $ids = array_column($list, 'id');
  627. $updatecount = $m_srq->updateinfo(['id' => ['in', $ids], 'status' => 0], ['status' => 1]);
  628. if ($updatecount != count($ids)) {
  629. Log::write("手环接收信息队列-部分未修改", 'shouhuan');
  630. Log::write("count:" . count($ids) . " update count:" . $updatecount, 'shouhuan');
  631. }
  632. if (empty($updatecount)) {
  633. Log::write("手环接收信息队列-无修改数据", 'shouhuan');
  634. return false;
  635. }
  636. return $list;
  637. }
  638. }
  639. /**
  640. * 获取发送信息队列列表
  641. *
  642. * @param [type] $page
  643. * @param [type] $size
  644. * @return void
  645. * @author wj
  646. * @date 2023-08-14
  647. */
  648. public function getsendqueuelist($device_id_code, $page = null, $size = null)
  649. {
  650. $m_ssq = new ShoneSendQueueModel();
  651. $where = ['status' => 0, 'device_id_code' => $device_id_code];
  652. $size = empty($size) ? 20 : $size;
  653. if (empty($page)) {
  654. $count = $m_ssq->getList($where, 'count');
  655. $totalpage = ceil($count / $size);
  656. $data = ['totalpage' => $totalpage, 'size' => $size];
  657. return $data;
  658. } else {
  659. $list = $m_ssq->getList($where, '*', $page, $size, 'id asc,weight desc');
  660. if (empty($list)) {
  661. Log::write("手环发送信息队列-无数据", 'shouhuan');
  662. return false;
  663. }
  664. $list = $list->toArray();
  665. $ids = array_column($list, 'id');
  666. $updatecount = $m_ssq->updateinfo(['id' => ['in', $ids], 'status' => 0], ['status' => 1]);
  667. if ($updatecount != count($ids)) {
  668. Log::write("手环发送信息队列-部分未修改", 'shouhuan');
  669. Log::write("count:" . count($ids) . " update count:" . $updatecount, 'shouhuan');
  670. }
  671. if (empty($updatecount)) {
  672. Log::write("手环发送信息队列-无修改数据", 'shouhuan');
  673. return false;
  674. }
  675. return $list;
  676. }
  677. }
  678. public function sendmsgsuccess($item)
  679. {
  680. $m_ssq = new ShoneSendQueueModel();
  681. $m_ssl = new ShoneSendListModel();
  682. $ssqid = $item['id'];
  683. $list_id = $item['list_id'];
  684. $sslwhere = ['id' => $list_id, 'is_send' => 0];
  685. $sslinfo = $m_ssl->getInfo($sslwhere);
  686. if ($sslinfo) {
  687. $row = $m_ssl->updateinfo(['id' => $sslinfo['id']], ['is_send' => 1, 'send_time' => date('Y-m-d H:i:s')]);
  688. }
  689. $ssqwhere = ['id' => $ssqid];
  690. $ssqinfo = $m_ssq->getInfo($ssqwhere);
  691. if ($ssqinfo) {
  692. $m_ssq->deleteinfobyid($ssqid);
  693. }
  694. }
  695. public function receivemsgsuccess($item)
  696. {
  697. $m_srq = new ShoneReceiveQueueModel();
  698. $srqid = $item['id'];
  699. $srqwhere = ['id' => $srqid, 'status' => 1];
  700. $srqinfo = $m_srq->getInfo($srqwhere);
  701. if ($srqinfo) {
  702. $m_srq->deleteinfobyid($srqid);
  703. }
  704. }
  705. /**
  706. * 日期解析
  707. *
  708. * @return void
  709. * @author wj
  710. * @date 2023-08-15
  711. */
  712. public function getdate($date)
  713. {
  714. $day = substr($date, 0, 2);
  715. $month = substr($date, 2, 2);
  716. $year = substr($date, 4, 2);
  717. $year1 = date('Y');
  718. $year2 = substr($year1, 0, 2);
  719. $year = $year2 . $year;
  720. if ($year != $year1) {
  721. $day = date('Y-m-d');
  722. } else {
  723. $day = $year . '-' . $month . '-' . $day;
  724. }
  725. return $day;
  726. }
  727. public function gettime($time)
  728. {
  729. $hour = substr($time, 0, 2);
  730. $minute = substr($time, 2, 2);
  731. $second = substr($time, 4, 2);
  732. $time = $hour . ':' . $minute . ':' . $second;
  733. return $time;
  734. }
  735. /**
  736. * 初始化手环接收信息解析
  737. *
  738. * @return void
  739. * @author wj
  740. * @date 2023-08-15
  741. */
  742. public function initanalysisShoneReceiveMsg()
  743. {
  744. $m_srq = new ShoneReceiveQueueModel();
  745. $where = ['status' => 1];
  746. $m_srq->updateinfo($where, ['status' => 0]);
  747. }
  748. /**
  749. * 拆包
  750. *
  751. * @return void
  752. * @author wj
  753. * @date 2023-08-15
  754. */
  755. public function unpack($data)
  756. {
  757. $arr = explode("][", $data);
  758. foreach ($arr as $key => $value) {
  759. if ($value[0] !== "[") {
  760. $arr[$key] = '[' . $value;
  761. }
  762. if ($value[mb_strlen($value) - 1] !== "]") {
  763. $arr[$key] .= "]";
  764. }
  765. }
  766. return $arr;
  767. }
  768. }