SouhuanAnalysis.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  1. <?php
  2. namespace app\common\server;
  3. use app\common\model\FacilityModel;
  4. use app\common\model\ShalarmlistModel;
  5. use app\common\model\ShinfoModel;
  6. use app\common\model\ShreceivequeueModel;
  7. use app\common\model\ShreceiveredocdeModel;
  8. use app\common\model\ShsendlistModel;
  9. use app\common\model\ShsendqueueModel;
  10. use think\facade\Log;
  11. /**
  12. * 手环字符串解析
  13. *
  14. * @author wj
  15. * @date 2023-08-11
  16. */
  17. class SouhuanAnalysis
  18. {
  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. Log::write("长度校验失败: len:" . $len . " str:" . $str, 'shouhuan');
  31. return false;
  32. }
  33. return true;
  34. }
  35. /**
  36. * 获取信息 整个信息解析
  37. * 并验证是否可解析 无解析命令配置 不报错
  38. *
  39. * @return void
  40. * @author wj
  41. * @date 2023-08-11
  42. */
  43. public function getline($str, $field = null)
  44. {
  45. //[厂商*设备 ID*内容长度*内容]
  46. $preg = "/^\[(.*)\*(.*)\*(.*)\*(.*)\]$/";
  47. preg_match($preg, $str, $match);
  48. if (empty($match)) {
  49. Log::write("解析失败:" . $str, 'shouhuan');
  50. throw new \Exception('解析失败:' . $str);
  51. }
  52. unset($match[0]);
  53. $data = array_values($match);
  54. $sandom_string = $data[0]; //厂商 随机字符串
  55. $device_id_code = $data[1]; //设置id编码
  56. $content_len = $data[2]; //内容长度
  57. $content_str = $data[3]; //内容字符串
  58. $content_len = $this->analysislen($content_len);
  59. $result = $this->checklen($content_len, $content_str);
  60. if (empty($result)) {
  61. $errmsg = '内容位数错误';
  62. Log::write($errmsg . ":" . $str, 'shouhuan');
  63. throw new \Exception($errmsg);
  64. }
  65. $data = [
  66. 'device_id_code' => $device_id_code,
  67. 'content_len' => $content_len,
  68. 'content_str' => $content_str,
  69. ];
  70. $contentarr = $this->getcommandcontent($content_str);
  71. $command = $contentarr['command'];
  72. $data['command'] = $command;
  73. $data['content_arr'] = $contentarr['content'];
  74. $config = $this->getreceivecommandinfo($command);
  75. $data['config'] = $config;
  76. if (!$config) {
  77. $errmsg = '命令无解析配置 command:' . $command;
  78. Log::write($errmsg, 'shouhuan');
  79. return false;
  80. }
  81. if (isset($field)) {
  82. return $data[$field];
  83. }
  84. return $data;
  85. }
  86. /**
  87. * 内容解析
  88. *
  89. * @param [type] $content_str
  90. * @return void
  91. * @author wj
  92. * @date 2023-08-19
  93. */
  94. public function getcommandcontent($content_str)
  95. {
  96. $content = explode(',', $content_str);
  97. $command = $content[0];
  98. unset($content[0]);
  99. $data = [
  100. 'command' => $command,
  101. 'content' => $content,
  102. ];
  103. return $data;
  104. }
  105. /**
  106. * 解析终端发送命令长度
  107. *
  108. * @param [type] $len
  109. * @return void
  110. * @author wj
  111. * @date 2023-08-18
  112. */
  113. public function analysislen($len)
  114. {
  115. $len = base_convert($len, 16, 10);
  116. return $len;
  117. }
  118. /**
  119. * 获取平台发送命令信息
  120. *
  121. * @param [type] $command
  122. * @return void
  123. * @author wj
  124. * @date 2023-08-11
  125. */
  126. public function getsendcommandinfo($command)
  127. {
  128. $command = strtoupper($command);
  129. $data = [
  130. //平台发送
  131. 'ZONE' => [
  132. 'content' => [
  133. 'command' => 'ZONE',
  134. 'zone' => '',
  135. ],
  136. 'kind' => 'send',
  137. 'need_back' => 1,
  138. ],
  139. 'UPLOAD' => [
  140. 'content' => [
  141. 'command' => 'UPLOAD',
  142. ],
  143. 'kind' => 'send',
  144. 'need_back' => 1,
  145. ],
  146. 'CR' => [
  147. 'content' => [
  148. 'command' => 'CR',
  149. ],
  150. 'kind' => 'send',
  151. 'need_back' => 1,
  152. ],
  153. 'SLEEPTIME' => [
  154. 'content' => [
  155. 'command' => 'CR',
  156. ],
  157. 'kind' => 'send',
  158. 'content_custom' => true,
  159. 'need_back' => 1,
  160. ],
  161. 'FALLDOWN' => [
  162. 'content' => [
  163. 'command' => 'FALLDOWN',
  164. 'is_open' => '',
  165. ],
  166. 'kind' => 'send',
  167. 'need_back' => 1,
  168. ],
  169. 'FACTORY' => [
  170. 'content' => [
  171. 'command' => 'FACTORY',
  172. ],
  173. 'kind' => 'send',
  174. 'need_back' => 1,
  175. ],
  176. 'SOS' => [
  177. 'content' => [
  178. 'command' => 'SOS',
  179. ],
  180. 'kind' => 'send',
  181. 'content_custom' => true,
  182. 'need_back' => 1,
  183. ],
  184. 'VERNO' => [
  185. 'content' => [
  186. 'command' => 'VERNO',
  187. ],
  188. 'kind' => 'send',
  189. 'need_back' => 1,
  190. ],
  191. 'LOWBAT' => [
  192. 'content' => [
  193. 'command' => 'LOWBAT',
  194. 'is_open' => '',
  195. ],
  196. 'kind' => 'send',
  197. 'need_back' => 1,
  198. ],
  199. 'POWEROFF' => [
  200. 'content' => [
  201. 'command' => 'POWEROFF',
  202. ],
  203. 'kind' => 'send',
  204. 'need_back' => 1,
  205. ],
  206. 'LSSET' => [
  207. 'content' => [
  208. 'command' => 'LSSET',
  209. 'content_custom' => true,
  210. ],
  211. 'kind' => 'send',
  212. 'need_back' => 1,
  213. ],
  214. 'PEDO' => [
  215. 'content' => [
  216. 'command' => 'PEDO',
  217. 'is_open' => '',
  218. ],
  219. 'kind' => 'send',
  220. 'need_back' => 1,
  221. ],
  222. 'PHL' => [
  223. 'content' => [
  224. 'command' => 'PEDO',
  225. ],
  226. 'kind' => 'send',
  227. 'content_custom' => true,
  228. 'need_back' => 1,
  229. ],
  230. 'REMIND' => [
  231. 'content' => [
  232. 'command' => 'REMIND',
  233. ],
  234. 'kind' => 'send',
  235. 'content_custom' => true,
  236. 'need_back' => 1,
  237. ],
  238. 'SILENCETIME2' => [
  239. 'content' => [
  240. 'command' => 'SILENCETIME2',
  241. ],
  242. 'kind' => 'send',
  243. 'content_custom' => true,
  244. 'need_back' => 1,
  245. ],
  246. 'BOOTOFF' => [
  247. 'content' => [
  248. 'command' => 'BOOTOFF',
  249. 'is_open' => '',
  250. 'bootup_time' => '',
  251. 'shutdown_time' => '',
  252. ],
  253. 'kind' => 'send',
  254. 'need_back' => 1,
  255. ],
  256. 'REMOVE' => [
  257. 'content' => [
  258. 'command' => 'REMOVE',
  259. 'is_open' => '',
  260. ],
  261. 'kind' => 'send',
  262. 'need_back' => 1,
  263. ],
  264. //平台回复
  265. 'LK' => [
  266. 'content' => [
  267. 'command' => 'LK',
  268. ],
  269. 'kind' => 'back',
  270. ],
  271. 'PING' => [
  272. 'content' => [
  273. 'command' => 'PING',
  274. 'isbind' => 1,
  275. ],
  276. 'kind' => 'back',
  277. ],
  278. 'KA' => [
  279. 'content' => [
  280. 'command' => 'KA',
  281. ],
  282. 'kind' => 'back',
  283. ],
  284. 'TEMP' => [
  285. 'content' => [
  286. 'command' => 'temp',
  287. ],
  288. 'kind' => 'back',
  289. ],
  290. 'BPHRT' => [
  291. 'content' => [
  292. 'command' => 'bphrt',
  293. ],
  294. 'kind' => 'back',
  295. ],
  296. 'HEART' => [
  297. 'content' => [
  298. 'command' => 'heart',
  299. ],
  300. 'kind' => 'back',
  301. ],
  302. 'BLOOD' => [
  303. 'content' => [
  304. 'command' => 'blood',
  305. ],
  306. 'kind' => 'back',
  307. ],
  308. 'OXYGEN' => [
  309. 'content' => [
  310. 'command' => 'oxygen',
  311. ],
  312. 'kind' => 'back',
  313. ],
  314. 'AL' => [
  315. 'content' => [
  316. 'command' => 'AL',
  317. ],
  318. 'kind' => 'back',
  319. ],
  320. ];
  321. if (!isset($data[$command])) {
  322. return false;
  323. }
  324. return $data[$command];
  325. }
  326. /**
  327. * 设置可解析数据 终端发送信息解析
  328. *
  329. * @param [type] $command
  330. * @return void
  331. * @author wj
  332. * @date 2023-08-18
  333. * analysis_digit 解析位数
  334. * content 解析对应字段
  335. * kind 类型 tsend 平台发送 tback平台回复
  336. * need_back 是否需回复 1是 0否 没设置为0
  337. * command 未设置则和键值相同
  338. */
  339. public function getreceivecommandinfo($command)
  340. {
  341. $command = strtoupper($command);
  342. $data = [
  343. 'UD' => [
  344. 'analysis_digit' => [1, 2, 4, 6, 8, 9, 10, 13, 14, 15, 16],
  345. 'content' => [
  346. 'date',
  347. 'time',
  348. 'gps_long',
  349. 'gps_lat',
  350. 'speed',
  351. 'direction',
  352. 'poster',
  353. 'electric_quantity',
  354. 'step_number',
  355. 'roll_number',
  356. 'terminal_status',
  357. ],
  358. 'kind' => 'tsend',
  359. 'need_back' => 0,
  360. ],
  361. 'AL' => [
  362. 'analysis_digit' => [1, 2, 4, 6, 8, 9, 10, 13, 14, 15, 16],
  363. 'content' => [
  364. 'date',
  365. 'time',
  366. 'gps_long',
  367. 'gps_lat',
  368. 'speed',
  369. 'direction',
  370. 'poster',
  371. 'electric_quantity',
  372. 'step_number',
  373. 'roll_number',
  374. 'terminal_status',
  375. ],
  376. 'kind' => 'tsend',
  377. 'need_back' => 0,
  378. ],
  379. 'KA' => [
  380. 'analysis_digit' => [1, 2, 3, 4],
  381. 'content' => [
  382. 'date',
  383. 'step_number',
  384. 'roll_number',
  385. 'electric_quantity',
  386. ],
  387. 'kind' => 'tsend',
  388. 'need_back' => 1,
  389. ],
  390. 'LK' => [
  391. 'analysis_digit' => null,
  392. 'content' => null,
  393. 'kind' => 'tsend',
  394. 'need_back' => 1,
  395. ],
  396. 'BPHRT' => [
  397. 'analysis_digit' => [1, 2, 3],
  398. 'content' => [
  399. 'blood_height_pressure',
  400. 'blood_low_pressure',
  401. 'heart_rate',
  402. ],
  403. 'kind' => 'tsend',
  404. 'need_back' => 1,
  405. 'command' => 'bphrt',
  406. ],
  407. 'TEMP' => [
  408. 'analysis_digit' => [1],
  409. 'content' => [
  410. 'temp',
  411. ],
  412. 'kind' => 'tsend',
  413. 'need_back' => 1,
  414. 'command' => 'temp',
  415. ],
  416. 'HEART' => [
  417. 'analysis_digit' => [1],
  418. 'content' => [
  419. 'heart_rate',
  420. ],
  421. 'kind' => 'tsend',
  422. 'need_back' => 1,
  423. 'command' => 'heart',
  424. ],
  425. 'BLOOD' => [
  426. 'analysis_digit' => [1, 2],
  427. 'content' => [
  428. 'blood_height_pressure',
  429. 'blood_low_pressure',
  430. ],
  431. 'kind' => 'tsend',
  432. 'need_back' => 1,
  433. 'command' => 'blood',
  434. ],
  435. 'OXYGEN' => [
  436. 'analysis_digit' => [1],
  437. 'content' => [
  438. 'oxygen',
  439. ],
  440. 'kind' => 'tsend',
  441. 'need_back' => 1,
  442. 'command' => 'oxygen',
  443. ],
  444. //终端回复
  445. //ZONE UPLOAD CR SLEEPTIME FALLDOWN FACTORY SOS VERNO LOWBAT
  446. //POWEROFF LSSET PEDO PHL REMIND SILENCETIME2 BOOTOFF REMOVE
  447. 'ZONE' => [
  448. 'analysis_digit' => null,
  449. 'content' => null,
  450. 'kind' => 'tback',
  451. ],
  452. 'UPLOAD' => [
  453. 'analysis_digit' => null,
  454. 'content' => null,
  455. 'kind' => 'tback',
  456. ],
  457. 'CR' => [
  458. 'analysis_digit' => null,
  459. 'content' => null,
  460. 'kind' => 'tback',
  461. ],
  462. 'SLEEPTIME' => [
  463. 'analysis_digit' => null,
  464. 'content' => null,
  465. 'kind' => 'tback',
  466. ],
  467. 'FALLDOWN' => [
  468. 'analysis_digit' => null,
  469. 'content' => null,
  470. 'kind' => 'tback',
  471. ],
  472. 'SOS' => [
  473. 'analysis_digit' => null,
  474. 'content' => null,
  475. 'kind' => 'tback',
  476. ],
  477. 'VERNO' => [
  478. 'analysis_digit' => [1],
  479. 'content' => ['version'],
  480. 'kind' => 'tback',
  481. ],
  482. 'LOWBAT' => [
  483. 'analysis_digit' => null,
  484. 'content' => null,
  485. 'kind' => 'tback',
  486. ],
  487. 'POWEROFF' => [
  488. 'analysis_digit' => null,
  489. 'content' => null,
  490. 'kind' => 'tback',
  491. ],
  492. 'LSSET' => [
  493. 'analysis_digit' => null,
  494. 'content' => null,
  495. 'kind' => 'tback',
  496. ],
  497. 'PEDO' => [
  498. 'analysis_digit' => null,
  499. 'content' => null,
  500. 'kind' => 'tback',
  501. ],
  502. 'PHL' => [
  503. 'analysis_digit' => null,
  504. 'content' => null,
  505. 'kind' => 'tback',
  506. ],
  507. 'REMIND' => [
  508. 'analysis_digit' => null,
  509. 'content' => null,
  510. 'kind' => 'tback',
  511. ],
  512. 'SILENCETIME2' => [
  513. 'analysis_digit' => null,
  514. 'content' => null,
  515. 'kind' => 'tback',
  516. ],
  517. 'BOOTOFF' => [
  518. 'analysis_digit' => null,
  519. 'content' => null,
  520. 'kind' => 'tback',
  521. ],
  522. 'REMOVE' => [
  523. 'analysis_digit' => null,
  524. 'content' => null,
  525. 'kind' => 'tback',
  526. ],
  527. ];
  528. if (!isset($data[$command])) {
  529. return false;
  530. }
  531. return $data[$command];
  532. }
  533. /**
  534. * 获取回复权重
  535. *
  536. * @param [type] $command
  537. * @return void
  538. * @author wj
  539. * @date 2023-08-11
  540. */
  541. public function getsendweight($command)
  542. {
  543. $weight = -1;
  544. switch ($command) {
  545. case 'POWEROFF':
  546. //关机
  547. $weight = 99;
  548. break;
  549. case 'RESET':
  550. //重启
  551. $weight = 98; //硬件未测试
  552. break;
  553. //平台回复命令
  554. case 'AL':
  555. case 'KA':
  556. case 'LK':
  557. case 'PING':
  558. case 'BPHRT':
  559. case 'TEMP':
  560. case 'HEART':
  561. case 'BLOOD':
  562. case 'OXYGEN':
  563. $weight = 1;
  564. break;
  565. //平台发送命令
  566. case 'ZONE':
  567. case 'UPLOAD':
  568. case 'CR':
  569. case 'SLEEPTIME':
  570. case 'FALLDOWN':
  571. case 'FACTORY':
  572. case 'SOS':
  573. case 'VERNO':
  574. case 'LOWBAT':
  575. case 'POWEROFF':
  576. case 'LSSET':
  577. case 'PEDO':
  578. case 'PHL':
  579. case 'REMIND':
  580. case 'SILENCETIME2':
  581. case 'BOOTOFF':
  582. case 'REMOVE':
  583. $weight = 0;
  584. break;
  585. default:
  586. $weight = -1;
  587. break;
  588. }
  589. if ($weight < 0) {
  590. //不需设置 发送信息
  591. return false;
  592. }
  593. return $weight;
  594. }
  595. /**
  596. * 获取数据值
  597. *
  598. * @param [type] $data
  599. * @param [type] $command
  600. * @return void
  601. * @author wj
  602. * @date 2023-08-14
  603. */
  604. public function getdata($config, $content_arr)
  605. {
  606. $analysis_digit = $config['analysis_digit'];
  607. $config_content = $config['content'];
  608. $data = [];
  609. if (is_array($analysis_digit)) {
  610. foreach ($analysis_digit as $key => $value) {
  611. if (isset($content_arr[$value])) {
  612. if (isset($config_content[$key])) {
  613. $item_key = $config_content[$key];
  614. $item_value = $content_arr[$value];
  615. $data[$item_key] = $item_value;
  616. }
  617. }
  618. }
  619. }
  620. if (isset($data['time'])) {
  621. $time = $data['time'];
  622. $data['time'] = $this->gettime($time);
  623. }
  624. if (isset($data['date'])) {
  625. $date = $data['date'];
  626. $data['date'] = $this->getdate($date);
  627. }
  628. if (isset($data['terminal_status'])) {
  629. $terminalstatus = $data['terminal_status'];
  630. $terminal_status_arr = $this->getterminalstatus($terminalstatus);
  631. unset($data['terminal_status']);
  632. $data['status_type'] = $terminal_status_arr['status_type'];
  633. $data['alarm_type'] = $terminal_status_arr['alarm_type'];
  634. }
  635. return $data;
  636. }
  637. /**
  638. * 时间解析
  639. *
  640. * @param [type] $time
  641. * @return void
  642. * @author wj
  643. * @date 2023-08-19
  644. */
  645. public function gettime($time)
  646. {
  647. $hour = substr($time, 0, 2);
  648. $minute = substr($time, 2, 2);
  649. $second = substr($time, 4, 2);
  650. $time = $hour . ':' . $minute . ':' . $second;
  651. return $time;
  652. }
  653. /**
  654. * 日期解析
  655. *
  656. * @return void
  657. * @author wj
  658. * @date 2023-08-15
  659. */
  660. public function getdate($date)
  661. {
  662. $day = substr($date, 0, 2);
  663. $month = substr($date, 2, 2);
  664. $year = substr($date, 4, 2);
  665. $year1 = date('Y');
  666. $year2 = substr($year1, 0, 2);
  667. $year = $year2 . $year;
  668. if ($year != $year1) {
  669. $day = date('Y-m-d');
  670. } else {
  671. $day = $year . '-' . $month . '-' . $day;
  672. }
  673. return $day;
  674. }
  675. /**
  676. * 解析终端状态
  677. *
  678. * @param [type] $terminal_status
  679. * @return void
  680. * @author wj
  681. * @date 2023-08-19
  682. */
  683. public function getterminalstatus($terminal_status)
  684. {
  685. $terminal_status = str_split($terminal_status);
  686. foreach ($terminal_status as $key => $value) {
  687. $value = base_convert($value, 16, 2);
  688. $value = str_pad($value, 4, "0", STR_PAD_LEFT);
  689. $terminal_status[$key] = $value;
  690. }
  691. $terminal_status_str = implode("", $terminal_status);
  692. $mid = mb_strlen($terminal_status_str) / 2;
  693. $alarm = substr($terminal_status_str, 0, $mid);
  694. $first_num = strpos($alarm, '1');
  695. $end_num = strrpos($alarm, '1');
  696. if ($first_num != $end_num) {
  697. Log::write("状态解析错误:报警:" . $terminal_status . " " . $terminal_status_str, 'shouhuan');
  698. }
  699. //16:SOS报警;17:低电报警;20:手环拆除报警;21:跌倒报警;22:心率异常报警
  700. $first_num = $mid - $first_num + ($mid - 1);
  701. $alarm_type = $first_num;
  702. $status = substr($terminal_status_str, $mid);
  703. $first_num = strpos($status, '1');
  704. $end_num = strrpos($status, '1');
  705. if ($first_num != $end_num) {
  706. Log::write("状态解析错误:状态:" . $terminal_status . " " . $terminal_status_str, 'shouhuan');
  707. }
  708. $first_num = $mid - 1 - $first_num;
  709. //1:低电状态;2:出围栏状态;3:进围栏状态;4:手环戴上取下状态;5:手表运行静止状态
  710. $status_type = $first_num + 1;
  711. $data = [
  712. 'alarm_type' => $alarm_type,
  713. 'status_type' => $status_type,
  714. ];
  715. return $data;
  716. }
  717. // /**
  718. // * 解析报警
  719. // *
  720. // * @param [type] $first_num
  721. // * @return void
  722. // * @author wj
  723. // * @date 2023-08-19
  724. // */
  725. // public function getalarm($first_num)
  726. // {
  727. // $data = [
  728. // 16 => 'SOS报警',
  729. // 17 => '低电报警',
  730. // 18 => '出围栏报警',
  731. // 19 => '进围栏报警',
  732. // 20 => '手环拆除报警',
  733. // 21 => '跌倒报警',
  734. // 22 => '心率异常报警',
  735. // ];
  736. // if (isset($data[$first_num])) {
  737. // return $data[$first_num];
  738. // }
  739. // return false;
  740. // }
  741. // /**
  742. // * 解析状态
  743. // *
  744. // * @param [type] $first_num
  745. // * @return void
  746. // * @author wj
  747. // * @date 2023-08-19
  748. // */
  749. // public function getstatus($first_num)
  750. // {
  751. // $data = [
  752. // 0 => '低电状态',
  753. // 1 => '出围栏状态',
  754. // 2 => '进围栏状态',
  755. // 3 => '手环戴上取下状态',
  756. // 4 => '手表运行静止状态',
  757. // ];
  758. // if (isset($data[$first_num])) {
  759. // return $data[$first_num];
  760. // }
  761. // return false;
  762. // }
  763. // ̄へ ̄-----------内容解析结束---------------- ̄へ ̄
  764. // ̄へ ̄-----------业务处理开始---------------- ̄へ ̄
  765. /**
  766. * 获取设别表id
  767. *
  768. * @return void
  769. * @author wj
  770. * @date 2023-08-11
  771. */
  772. public function getfacilityid($device_id_code)
  773. {
  774. $m_f = new FacilityModel();
  775. $where = ['code' => $device_id_code, 'status' => 1];
  776. $finfo = $m_f->getInfo($where, ['id']);
  777. if (empty($finfo)) {
  778. throw new \Exception("设备信息错误:" . $device_id_code);
  779. return false;
  780. }
  781. $id = $finfo['id'];
  782. return $id;
  783. }
  784. /**
  785. * 保存接收信息队列
  786. *
  787. * @param [type] $data
  788. * @return void
  789. * @author wj
  790. * @date 2023-08-14
  791. */
  792. public function savereceivequeue($data)
  793. {
  794. $m_srq = new ShreceivequeueModel();
  795. $data = [
  796. 'msg' => $data,
  797. 'createtime' => date('Y-m-d H:i:s'),
  798. ];
  799. $id = $m_srq->insertData($data);
  800. if (empty($id)) {
  801. return false;
  802. }
  803. return true;
  804. }
  805. /**
  806. * 获取接收信息队列列表
  807. *
  808. * @param [type] $page
  809. * @param [type] $size
  810. * @return void
  811. * @author wj
  812. * @date 2023-08-14
  813. */
  814. public function getreceivequeuelist($page = null, $size = null)
  815. {
  816. $m_srq = new ShreceivequeueModel();
  817. $where = ['status' => 0];
  818. $size = empty($size) ? 20 : $size;
  819. if (empty($page)) {
  820. $count = $m_srq->getList($where, 'count');
  821. $totalpage = ceil($count / $size);
  822. $data = ['totalpage' => $totalpage, 'size' => $size];
  823. return $data;
  824. } else {
  825. $list = $m_srq->getList($where, '*', $page, $size, 'id asc');
  826. if (empty($list)) {
  827. //Log::write("手环接收信息队列-无数据", 'shouhuan');
  828. return false;
  829. }
  830. $list = $list->toArray();
  831. foreach ($list as $key => $value) {
  832. $id = $value['id'];
  833. if (1 != $value['status']) {
  834. $row = $m_srq->updateinfo(['id' => $id], ['status' => 1]);
  835. if (1 != $row) {
  836. $msg = "Shreceivequeue id:" . $id . " 修改失败";
  837. Log::write($msg, 'shouhuan');
  838. unset($list[$key]);
  839. }
  840. }
  841. }
  842. return $list;
  843. }
  844. }
  845. /**
  846. * 获取发送信息队列列表
  847. *
  848. * @param [type] $page
  849. * @param [type] $size
  850. * @return void
  851. * @author wj
  852. * @date 2023-08-14
  853. */
  854. public function getsendqueuelist($device_id_code, $page = null, $size = null)
  855. {
  856. $m_ssq = new ShsendqueueModel();
  857. $where = ['status' => 0, 'device_id_code' => $device_id_code];
  858. $size = empty($size) ? 20 : $size;
  859. if (empty($page)) {
  860. $count = $m_ssq->getList($where, 'count');
  861. $totalpage = ceil($count / $size);
  862. $data = ['totalpage' => $totalpage, 'size' => $size];
  863. return $data;
  864. } else {
  865. $list = $m_ssq->getList($where, '*', $page, $size, 'id asc,weight desc');
  866. if (empty($list)) {
  867. Log::write("手环发送信息队列-无数据", 'shouhuan');
  868. return false;
  869. }
  870. $list = $list->toArray();
  871. foreach ($list as $key => $value) {
  872. $id = $value['id'];
  873. if (1 != $value['status']) {
  874. $row = $m_ssq->updateinfo(['id' => $id], ['status' => 1]);
  875. if (1 != $row) {
  876. $msg = "Shsendqueue id:" . $id . " 修改失败";
  877. Log::write($msg, 'shouhuan');
  878. unset($list[$key]);
  879. }
  880. }
  881. }
  882. return $list;
  883. }
  884. }
  885. /**
  886. * 保存手环信息
  887. *
  888. * @return void
  889. * @author wj
  890. * @date 2023-08-14
  891. */
  892. public function saveshinfo($facility_id, $device_id_code, $data, $original_str)
  893. {
  894. $command = $data['command'];
  895. $content_arr = $data['content_arr'];
  896. $config = $data['config'];
  897. $data = $this->getdata($config, $content_arr);
  898. $m_sri = new ShinfoModel();
  899. $m_srir = new ShreceiveredocdeModel();
  900. $m_sa = new ShalarmlistModel();
  901. if ('AL' == $command) {
  902. //手环警报信息
  903. $data['alarm_from_type'] = 1;
  904. $said = $m_sa->insertData($data);
  905. if (empty($said)) {
  906. $msg = "报警信息添加失败:" . $original_str;
  907. Log::write($msg, 'shouhuan');
  908. throw new \Exception($msg);
  909. }
  910. } else {
  911. //手环基础信息修改
  912. $sriData = $data;
  913. $sriwhere = [
  914. 'facility_id' => $facility_id,
  915. 'device_id_code' => $device_id_code,
  916. ];
  917. $sriinfo = $m_sri->getInfo($sriwhere);
  918. if (empty($sriinfo)) {
  919. $sriData = [
  920. 'device_id_code' => $device_id_code,
  921. 'facility_id' => $facility_id,
  922. ];
  923. $sriinsertData = $sriData;
  924. $sriinsertData['createtime'] = date('Y-m-d H:i:s');
  925. $sriinsertData['updatetime'] = date('Y-m-d H:i:s');
  926. $sriinsertData = $m_sri->formatinfo($sriinsertData);
  927. $sriid = $m_sri->insertData($sriinsertData);
  928. if (empty($sriid)) {
  929. throw new \Exception("设备信息添加失败:" . $device_id_code);
  930. }
  931. } else {
  932. $sriid = $sriinfo['id'];
  933. $sriupdateData = $sriData;
  934. $sriupdateData['updatetime'] = date('Y-m-d H:i:s');
  935. $sriupdateData = $m_sri->formatinfo($sriupdateData);
  936. $row = $m_sri->updateinfo(['id' => $sriid], $sriupdateData);
  937. if (empty($row)) {
  938. throw new \Exception("设备信息修改失败:" . $device_id_code);
  939. }
  940. }
  941. //接收信息历史添加
  942. $sririnsertData['facility_id'] = $facility_id;
  943. $sririnsertData['device_id_code'] = $device_id_code;
  944. $sririnsertData['original_str'] = $original_str;
  945. $sririnsertData['content'] = json_encode($sriData);
  946. $sririnsertData['command'] = $command;
  947. $sririnsertData['createtime'] = date('Y-m-d H:i:s');
  948. if ('tback' == $config['kind']) {
  949. $is_back_msg = true;
  950. $sririnsertData['is_back_msg'] = 0;
  951. } else {
  952. $is_back_msg = false;
  953. $sririnsertData['is_back_msg'] = 1;
  954. }
  955. $sririd = $m_srir->insertData($sririnsertData);
  956. if (empty($sririd)) {
  957. throw new \Exception("设备历史信息添加失败:" . $device_id_code);
  958. }
  959. if ($is_back_msg) {
  960. //处理回复信息
  961. $m_ssl = new ShsendlistModel();
  962. $where = [
  963. 'is_success' => 0,
  964. 'is_send' => 1,
  965. 'command' => $command,
  966. ];
  967. $sslinfo = $m_ssl->getInfo($where);
  968. if ($sslinfo) {
  969. //发送成功状态回写
  970. $sslid = $sslinfo['id'];
  971. $sslupdateData = ['is_success' => 1];
  972. $m_ssl->updateinfo(['id' => $sslid], $sslupdateData);
  973. $srirupdateData = ['send_list_id' => $sslid];
  974. $m_srir->updateinfo(['id' => $sririd], $srirupdateData);
  975. }
  976. }
  977. }
  978. }
  979. /**
  980. * 创建发送信息
  981. *
  982. * @param [type] $data
  983. * @param [type] $command
  984. * @return void
  985. * @author wj
  986. * @date 2023-08-14
  987. */
  988. public function createsendmsg($facility_id, $device_id_code, $data, $command, $param = [])
  989. {
  990. $infoarr = $this->getsendcommandinfo($command);
  991. if (!$infoarr) {
  992. // Log::write("无对应命令数据1:" . $command, 'shouhuan');
  993. // Log::write($data, 'shouhuan');
  994. return false;
  995. }
  996. $command = $data['command'];
  997. $content_arr = $data['content_arr'];
  998. $config = $data['config'];
  999. $m_ssl = new ShsendlistModel();
  1000. $commandxy = "3G";
  1001. //仅创建
  1002. if ('back' == $config['kind']) {
  1003. $content = $config['content'];
  1004. $content = implode(',', $content);
  1005. $send_type = 0;
  1006. $is_success = 1;
  1007. }
  1008. if ('send' == $config['kind']) {
  1009. $content = $config['content'];
  1010. $useconmmand = $content['command'];
  1011. $content_custom = $config['content_custom'];
  1012. $need_back = $config['need_back'];
  1013. if ($content_custom) {
  1014. $functionname = 'get' . $command . "Commandinfo";
  1015. if (method_exists($this, $functionname)) {
  1016. $content = $useconmmand . "," . $this->$functionname($param);
  1017. } else {
  1018. throw new \Exception($command . "自定义方法不存在");
  1019. }
  1020. } else {
  1021. $content = implode(',', $content_arr);
  1022. }
  1023. $send_type = 1;
  1024. if ($need_back) {
  1025. $is_success = 0;
  1026. } else {
  1027. $is_success = 1;
  1028. }
  1029. }
  1030. $weight = $this->getsendweight($command);
  1031. $msgdata = [
  1032. 0 => $commandxy,
  1033. 'device_id_code' => $device_id_code,
  1034. 'len' => str_pad(dechex(mb_strlen($content)), 4, "0", STR_PAD_LEFT),
  1035. 'content' => $content,
  1036. ];
  1037. $msg = '[' . implode('*', $msgdata) . ']';
  1038. $sslInsertData = [
  1039. 'facility_id' => $facility_id,
  1040. 'device_id_code' => $device_id_code,
  1041. 'command' => $command,
  1042. 'send_msg' => $msg,
  1043. 'send_weight' => $weight,
  1044. 'send_time' => date('Y-m-d H:i:s'),
  1045. 'is_success' => $is_success,
  1046. 'send_type' => $send_type,
  1047. ];
  1048. $sslid = $m_ssl->insertData($sslInsertData);
  1049. if (empty($sslid)) {
  1050. throw new \Exception("发送数据添加失败");
  1051. }
  1052. $data = [
  1053. 'msg' => $msg,
  1054. 'weight' => $weight,
  1055. 'createtime' => date('Y-m-d H:i:s'),
  1056. 'facility_id' => $facility_id,
  1057. 'device_id_code' => $device_id_code,
  1058. 'send_list_id' => $sslid,
  1059. ];
  1060. $m_ssq = new ShsendqueueModel();
  1061. $id = $m_ssq->insertData($data);
  1062. if (empty($id)) {
  1063. throw new \Exception("发送队列数据添加失败");
  1064. }
  1065. return true;
  1066. }
  1067. /**
  1068. * 创建sos电话设置命令
  1069. * 最多三个电话
  1070. *
  1071. * @return void
  1072. * @author wj
  1073. * @date 2023-08-21
  1074. */
  1075. public function getSOSCommandinfo($param)
  1076. {
  1077. if (count($param) <= 0) {
  1078. throw new \Exception("未设置电话");
  1079. }
  1080. if (count($param) > 3) {
  1081. throw new \Exception("设置电话数量过多");
  1082. }
  1083. foreach ($param as $key => $value) {
  1084. //判断是否为手机号
  1085. //暂不处理
  1086. }
  1087. $info = implode(",", $param);
  1088. return $info;
  1089. }
  1090. /**
  1091. * 设置跌倒灵敏度命令
  1092. * [3G*358800006072996*0009*LSSET,3+6]
  1093. *
  1094. * @return void
  1095. * @author wj
  1096. * @date 2023-08-21
  1097. */
  1098. public function getLSSETCommandinfo($param)
  1099. {
  1100. if (2 != count($param)) {
  1101. throw new \Exception("LSSET参数错误");
  1102. }
  1103. foreach ($param as $key => $value) {
  1104. if (!is_numeric($value)) {
  1105. throw new \Exception("LSSET参数错误:" . $value);
  1106. }
  1107. }
  1108. $info = $param[0] . "+" . $param[1];
  1109. return $info;
  1110. }
  1111. /**
  1112. * 设置电话本
  1113. * 最多10条
  1114. *[{telno=>'',name=>''}]
  1115. * @param [type] $param
  1116. * @return void
  1117. * @author wj
  1118. * @date 2023-08-21
  1119. */
  1120. public function getPHLCommaninfo($param)
  1121. {
  1122. if (50 < count($param)) {
  1123. throw new \Exception("PHL参数错误");
  1124. }
  1125. if (0 != count($param) % 2) {
  1126. throw new \Exception("PHL参数长度错误");
  1127. }
  1128. $usedata = [];
  1129. foreach ($param as $key => $value) {
  1130. $telno = $value['telno'];
  1131. $name = $value['name'];
  1132. var_dump($name);
  1133. //电话号码
  1134. if (20 < mb_strlen($telno)) {
  1135. throw new \Exception("PHL电话号码错误:" . $telno);
  1136. }
  1137. $name = $this->srtingToUnicode($name);
  1138. $usedata[] = $telno;
  1139. $usedata[] = $name;
  1140. }
  1141. $info = implode(",", $usedata);
  1142. return $info;
  1143. }
  1144. /**
  1145. * 设置电话本
  1146. * 最多10条
  1147. *{[time=>'',isopen=>'','type'=>'','weeks'=>[]]}
  1148. * weeks 数组 每个1到7 周日到周六
  1149. * 最多设置三个
  1150. * @param [type] $param
  1151. * @return void
  1152. * @author wj
  1153. * @date 2023-08-21
  1154. */
  1155. /*
  1156. 08:10-1-1:闹钟时间 8:10,打开,响铃一次
  1157. 08:10-1-2:闹钟时间 8:10,打开,每天响铃
  1158. 08:10-1-3-0111110:闹钟时间 8:10,打开,自定义周一至周五打开
  1159. 最左边是周日,最右边是周六,即 0111110 的顺序是:周日,周一,周二,周三,周四,周五,周
  1160. 六(1 为打开,0 为关闭),其中周一至周五打开闹钟
  1161. */
  1162. public function getREMINDCommandinfo($param)
  1163. {
  1164. if (3 > count($param)) {
  1165. throw new \Exception("PHL参数错误");
  1166. }
  1167. $usedata = [];
  1168. foreach ($param as $key => $value) {
  1169. $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
  1170. $time = $this->formattime($value['time'], 'H:i');
  1171. $isopen = $value['isopen'];
  1172. $type = $value['type'];
  1173. $weeks = $value['weeks'];
  1174. if (3 == $type) {
  1175. foreach ($weeks as $wkey => $wvalue) {
  1176. if ($wvalue >= 1 && $wvalue <= 7) {
  1177. $useweeks[$wvalue - 1] = '1';
  1178. }
  1179. }
  1180. $useweeks = implode("", $useweeks);
  1181. $type = $useweeks;
  1182. }
  1183. $usedata[] = $time . "-" . $isopen . "-" . $type;
  1184. }
  1185. $usedata = implode(",", $usedata);
  1186. return $usedata;
  1187. }
  1188. /**
  1189. * 静默时间段测试
  1190. *{[starttime=>'',endtime=>'',isopen=>'',weeks=>[]]}
  1191. * weeks 数组 每个1到7 周日到周六
  1192. * 最多设置三个
  1193. *
  1194. * @return void
  1195. * @author wj
  1196. * @date 2023-08-21
  1197. */
  1198. /*
  1199. [DW*334588000000156*0038*SILENCETIME2,7:30-21:10-1-0111110,7:30-21:10-1-0111110,7:
  1200. 30-21:10-0-0111110]
  1201. 设置上课禁用时间段范围,拦截终端的任何来电。格式为“起始时间-结束时间-自定义星期几”, 比
  1202. 如上面的 7:30-21:00-0111110,则表示周一到周五 7:30 到 21:00 之间上课禁用生效,起始时间
  1203. 默认大于结束时间。
  1204. 总开关:0 为关,1 为开
  1205. 关于自定义星期几的规则:最左边是周日,最右边是周六,即 0111110 的顺序是:周日,周一,周
  1206. 二,周三,周四,周五,周六(1 为打开,0 为关闭),所以上面的意思是周一至周五打开上课禁
  1207. 用。
  1208. */
  1209. public function getSILENCETIME2Commandinfo($param)
  1210. {
  1211. if (3 <= count($param)) {
  1212. throw new \Exception("SILENCETIME2参数错误");
  1213. }
  1214. $usedata = [];
  1215. foreach ($param as $key => $value) {
  1216. $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
  1217. //未比较时间大小
  1218. $starttime = $this->formattime($value['starttime'], 'H:i');
  1219. $endtime = $this->formattime($value['endtime'], 'H:i');
  1220. $isopen = $value['isopen'];
  1221. $weeks = $value['weeks'];
  1222. foreach ($weeks as $wkey => $wvalue) {
  1223. if ($wvalue >= 1 && $wvalue <= 7) {
  1224. $useweeks[$wvalue - 1] = '1';
  1225. }
  1226. }
  1227. $useweeks = implode("", $useweeks);
  1228. $usedata[] = $starttime . "-" . $endtime . "-" . $isopen . "-" . $useweeks;
  1229. }
  1230. $usedata = implode(",", $usedata);
  1231. return $usedata;
  1232. }
  1233. /**
  1234. * 睡眠时间段设置
  1235. *{starttime=>'',endtime=>''}
  1236. *
  1237. * @return void
  1238. * @author wj
  1239. * @date 2023-08-21
  1240. */
  1241. public function getSLEEPTIMECommandinfo($param)
  1242. {
  1243. if (2 > count($param)) {
  1244. throw new \Exception("SLEEPTIME参数错误");
  1245. }
  1246. $starttime = $this->formattime($param['starttime'], 'H:i');
  1247. $endtime = $this->formattime($param['endtime'], 'H:i');
  1248. $usedata = $starttime . "-" . $endtime;
  1249. return $usedata;
  1250. }
  1251. //发送完处理
  1252. /**
  1253. * 发送成功 删除发送数据
  1254. *
  1255. * @param [type] $item
  1256. * @return void
  1257. * @author wj
  1258. * @date 2023-08-21
  1259. */
  1260. public function sendmsgsuccess($item)
  1261. {
  1262. $m_ssq = new ShsendqueueModel();
  1263. $m_ssl = new ShsendlistModel();
  1264. $ssqid = $item['id'];
  1265. if ($item['list_id']) {
  1266. $list_id = $item['list_id'];
  1267. $sslwhere = ['id' => $list_id, 'is_send' => 0];
  1268. $sslinfo = $m_ssl->getInfo($sslwhere);
  1269. if ($sslinfo) {
  1270. $row = $m_ssl->updateinfo(['id' => $sslinfo['id']], ['is_send' => 1, 'send_time' => date('Y-m-d H:i:s')]);
  1271. }
  1272. }
  1273. $ssqwhere = ['id' => $ssqid];
  1274. $ssqinfo = $m_ssq->getInfo($ssqwhere);
  1275. if ($ssqinfo) {
  1276. $m_ssq->deleteinfobyid($ssqid);
  1277. }
  1278. }
  1279. /**
  1280. * 解析成功 删除接收数据
  1281. *
  1282. * @param [type] $item
  1283. * @return void
  1284. * @author wj
  1285. * @date 2023-08-21
  1286. */
  1287. public function receivemsgsuccess($item)
  1288. {
  1289. $m_srq = new ShreceivequeueModel();
  1290. $srqid = $item['id'];
  1291. $srqwhere = ['id' => $srqid, 'status' => 1];
  1292. $srqinfo = $m_srq->getInfo($srqwhere);
  1293. if ($srqinfo) {
  1294. $m_srq->deleteinfobyid($srqid);
  1295. }
  1296. }
  1297. /**
  1298. * 初始化手环接收信息解析
  1299. *
  1300. * @return void
  1301. * @author wj
  1302. * @date 2023-08-15
  1303. */
  1304. public function initanalysisShoneReceiveMsg()
  1305. {
  1306. $m_srq = new ShreceivequeueModel();
  1307. $where = ['status' => 1];
  1308. $m_srq->updateinfo($where, ['status' => 0]);
  1309. }
  1310. /**
  1311. * 测试使用
  1312. *
  1313. * @param [type] $data
  1314. * @return void
  1315. * @author wj
  1316. * @date 2023-08-21
  1317. */
  1318. public function showfortest($data)
  1319. {
  1320. $strdata = $this->getline($data);
  1321. $content = $strdata['content_str'];
  1322. $content = $this->getcommandcontent($content);
  1323. $command = $content[0];
  1324. $showcommands = [
  1325. 'SOS', 'CR', 'UPLOAD', 'SLEEPTIME', 'ZONE', 'FALLDOWN',
  1326. 'APPLOCK', 'FACTORY', 'VERNO', 'LOWBAT', 'UD', 'POWEROFF', 'MESSAGE',
  1327. 'WALKTIME', 'PEDO', 'PHB', 'PHL', 'REMIND', 'SILENCETIME2', 'BOOTOFF',
  1328. 'REMOVE', 'INFO', 'AL', 'LSSET',
  1329. ];
  1330. if (in_array($command, $showcommands)) {
  1331. var_dump(date('Y-m-d H:i:s'));
  1332. var_dump($data);
  1333. }
  1334. }
  1335. /**
  1336. * 设置设备上线
  1337. *
  1338. * @return void
  1339. * @author wj
  1340. * @date 2023-08-21
  1341. */
  1342. public function setonlineinfo($device_id_code)
  1343. {
  1344. $m_si = new ShinfoModel();
  1345. $where = ['device_id_code' => $device_id_code, 'online_statis' => 0];
  1346. $finfo = $m_si->getInfo($where, ['id', 'online_statis']);
  1347. if ($finfo) {
  1348. $facility_id = $finfo['id'];
  1349. $m_si->setonlineinfobyid($facility_id);
  1350. }
  1351. }
  1352. /**
  1353. * 设置设备下线
  1354. *
  1355. * @return void
  1356. * @author wj
  1357. * @date 2023-08-21
  1358. */
  1359. public function setofflineinfo()
  1360. {
  1361. $m_si = new ShinfoModel();
  1362. $list = $m_si->getcheckupdatetimelist();
  1363. $list = (array) $list;
  1364. if (!empty($list)) {
  1365. $facility_ids = array_column($list, 'id');
  1366. $m_si->setofflineinfobyids($facility_ids);
  1367. }
  1368. }
  1369. //工具方法
  1370. /**
  1371. * unicode 编码
  1372. *
  1373. * @param [type] $str
  1374. * @return void
  1375. * @author wj
  1376. * @date 2023-08-21
  1377. */
  1378. public function srtingToUnicode($str)
  1379. {
  1380. $unicode = '';
  1381. $arr = mb_str_split($str); //适配中文
  1382. foreach ($arr as $key => $value) {
  1383. var_dump($value);
  1384. $char = bin2hex(iconv('UTF-8', 'UCS-2BE', $value));
  1385. $char = str_pad($char, 4, '0', STR_PAD_LEFT);
  1386. $arr[$key] = $char;
  1387. }
  1388. $unicode = implode("", $arr);
  1389. return $unicode;
  1390. }
  1391. /**
  1392. * unicode 解码
  1393. *
  1394. * @param [type] $str
  1395. * @return void
  1396. * @author wj
  1397. * @date 2023-08-21
  1398. */
  1399. public function unicodeToChn($str)
  1400. {
  1401. $arr = str_split($str);
  1402. $items = [];
  1403. $item = "";
  1404. foreach ($arr as $key => $value) {
  1405. $index = $key + 1;
  1406. if (0 != $index % 4) {
  1407. $item .= $value;
  1408. } else {
  1409. $item = "";
  1410. $items[] = $item;
  1411. }
  1412. }
  1413. foreach ($items as $key => $value) {
  1414. $char = hex2bin($value);
  1415. $char = iconv('UCS-2BE', 'UTF-8', $char);
  1416. $items[$key] = $char;
  1417. }
  1418. $info = implode("", $items);
  1419. return $info;
  1420. }
  1421. /**
  1422. * 拆包
  1423. *
  1424. * @return void
  1425. * @author wj
  1426. * @date 2023-08-15
  1427. */
  1428. public function unpack($data)
  1429. {
  1430. $arr = explode("][", $data);
  1431. foreach ($arr as $key => $value) {
  1432. if ($value[0] !== "[") {
  1433. $arr[$key] = '[' . $value;
  1434. }
  1435. if ($value[mb_strlen($value) - 1] !== "]") {
  1436. $arr[$key] .= "]";
  1437. }
  1438. }
  1439. return $arr;
  1440. }
  1441. public function formattime($time, $format)
  1442. {
  1443. $time = strtotime($time);
  1444. $time = date($format, $time);
  1445. return $time;
  1446. }
  1447. }