Api.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. <?php
  2. namespace catchAdmin\api\controller;
  3. use catchAdmin\api\service\dispose;
  4. use catchAdmin\tag_history\model\Access;
  5. use catchAdmin\tag_history\model\Dormitory;
  6. use catchAdmin\tag_history\model\TagHistory;
  7. use catchAdmin\worklocation\model\WorkRecord as ModelWorkRecord;
  8. use catcher\base\CatchRequest as Request;
  9. use catcher\CatchResponse;
  10. use catcher\base\CatchController;
  11. use Exception;
  12. use think\facade\Cache;
  13. use \think\facade\Db;
  14. error_reporting(0);
  15. class Api extends CatchController
  16. {
  17. public function report()
  18. {
  19. $token = $_GET['token'];
  20. if (!$token || $token != '22723927C') {
  21. json_fail('缺少token或者token不对');
  22. }
  23. $param = json_decode(optimize_json(file_get_contents("php://input")), true);
  24. debug_log("上报数据",json_encode($param));
  25. if (json_last_error() != 0) {
  26. json_fail('解析异常', json_last_error_msg());
  27. }
  28. $mac = $param['mac'];
  29. if (empty($mac)) {
  30. json_fail('mac地址不存在');
  31. }
  32. $data = [];
  33. foreach ($param['list'] as $item) {
  34. // $onetime= TagHistory::where("mac",$mac)->where('lable',$item['label'])->order("id","desc")->value("time");
  35. $data[] = [
  36. 'mac' => $mac,
  37. 'lable' => $item['label'],
  38. 'rssi' => $item['rssi'],
  39. 'time' => $item['time'],
  40. 'addTime' => time(),
  41. 'move' => $item['move'],
  42. 'step' => empty($item['step']) ? 0 : $item['step'],
  43. 'temperature' => empty($item['temperature']) ? 0 : $item['temperature'],
  44. //告警
  45. 'temperWarn' => empty($item['temperWarn']) ? 00 : $item['temperWarn'],
  46. // "interval_time"=>empty($onetime) ?0:($item['time']-$onetime)
  47. ];
  48. }
  49. $tage = new TagHistory();
  50. $tage->saveAll($data);
  51. json_success('上传成功');
  52. }
  53. //储存数据到redis
  54. public function redis_to_mysql(){
  55. $ues_redis=Cache::store('redis')->handler();
  56. $dispose = new dispose($ues_redis);
  57. $text=null;
  58. while(1){
  59. $jsonData= $ues_redis->rpop("mqtt_data");
  60. if(empty($jsonData)){
  61. sleep(1);
  62. continue;
  63. }
  64. debug_log("InAndOUT",'数据redis'.$jsonData);
  65. $data=json_decode($jsonData,true);
  66. $time=$data['time'];
  67. $mac=$data['devId'];
  68. //存入基站的最新时间
  69. $dispose->setStations($mac,$time);
  70. $list=[];
  71. $text=$text.$data['cnt'];
  72. if(strlen($text)<24){
  73. continue;
  74. }
  75. while(strlen($text)>=24){
  76. $da=substr($text,0,24);
  77. $t1 = substr($da,8,2)=='00'||substr($da,8,2)=='10'||substr($da,8,2)=='01' ? true:false;
  78. $t2 =substr($da,10,6)=="FFFFFF"||substr($da,10,6)=="000000" ?true:false;
  79. if($t1&&$t2){
  80. $label= substr($da,0,8);
  81. $rssi1= substr($da,16,2);
  82. $rssi2= substr($da,18,2);
  83. $rssi3= substr($da,20,2);
  84. $rssi4= substr($da,22,2);
  85. $DA=[
  86. 'mac' => $mac,
  87. 'label' =>$label,
  88. 'rssi1' => hexdec($rssi1),
  89. 'rssi2' => hexdec($rssi2),
  90. 'rssi3' => hexdec($rssi3),
  91. 'rssi4' => hexdec($rssi4),
  92. 'report_time'=>$time
  93. ];
  94. $vs=false;
  95. $history_status=false;
  96. $DA['other_time']=date("Y-m-d H:i:s",$time);
  97. debug_log("label_log","cssh: ".json_encode($DA));
  98. if($DA['rssi1']<=85||$DA['rssi2']<=85||$DA['rssi3']<=85||$DA['rssi4']<=85){
  99. $history_status=true;
  100. }
  101. if($DA['rssi1']<=72||$DA['rssi2']<=72||$DA['rssi3']<=72||$DA['rssi4']<=72){
  102. $vs=true;
  103. }
  104. $DA['rssi1']=$DA['rssi1']==255?100:$DA['rssi1'];
  105. $DA['rssi2']=$DA['rssi2']==255?100:$DA['rssi2'];
  106. $DA['rssi3']=$DA['rssi3']==255?100:$DA['rssi3'];
  107. $DA['rssi4']=$DA['rssi4']==255?100:$DA['rssi4'];
  108. $DA["rssi1"]=$DA["rssi1"]<=$DA["rssi3"]?$DA["rssi1"]:$DA["rssi3"];
  109. $DA["rssi2"]=$DA["rssi2"]<=$DA["rssi4"]?$DA["rssi2"]:$DA["rssi4"];
  110. /**
  111. * 缓存到redis历史数据
  112. */
  113. if(substr($da,8,2)=='01'&&$history_status&&$DA["rssi1"]!=$DA["rssi2"]){
  114. debug_log("label_log","cache: ".json_encode($DA));
  115. $diff= $DA["rssi1"]-$DA["rssi2"];
  116. if(abs($diff)>2){
  117. $dispose->set_label_history($DA);
  118. }
  119. debug_log("label_log","cache_diff: ".$diff);
  120. }
  121. if($vs&&(substr($da,8,2)=='01')){
  122. try{
  123. $DA= $dispose->check_data($DA);
  124. debug_log("label_log","xsj:".json_encode($DA));
  125. $dispose->computeResout($DA);
  126. }catch(Exception $e){
  127. debug_log("InAndOUT","抛出异常:".$e->getMessage());
  128. }
  129. }
  130. $text=substr($text,24);
  131. }else{
  132. $text=substr($text,1);
  133. }
  134. }
  135. }
  136. }
  137. /**
  138. * 清除数据
  139. *
  140. * @return void
  141. */
  142. public function clear_redis(){
  143. while(1){
  144. sleep(1);
  145. $redis=Cache::store('redis')->handler();
  146. $dispose = new dispose($redis);
  147. $keylist= $dispose->getStations();
  148. debug_log("clear_label","查询数据".json_encode($keylist));
  149. if(empty($keylist)){
  150. continue;
  151. }
  152. foreach($keylist as $station){
  153. //结果key值
  154. $key="res".$station;
  155. //存取旧的数据的reids数据
  156. $catchkey=$station."station";
  157. //获取该基站的所有key
  158. $keys= $redis->hKeys($key);
  159. if(empty($keys)){
  160. continue;
  161. }
  162. foreach($keys as $item){
  163. if( $json_data=$redis->hget($key,$item)){
  164. debug_log("clear_label",'基站'.$station.'获取的数据'.'标签'.$item.$json_data);
  165. $json_data=json_decode($json_data,true);
  166. //列表
  167. $a=$json_data['a'];
  168. //状态
  169. $status=$json_data['status'];
  170. //进出
  171. $in_and_out=$json_data["in_and_out"];
  172. //总数
  173. $count= count($a);
  174. $time= $dispose->getNowStationTime($station);
  175. debug_log("clear_label","标签最新最新时间". date('Y-m-d H:i:s', $time));
  176. if(($time-$json_data["time"])<=7){
  177. debug_log("clear_label", $item.':'. "标签上报间隔没有超过7秒进行跳过");
  178. continue;
  179. }
  180. if($count<5){
  181. if($count>2){
  182. debug_log("clear_label", $item.':'. "标签信号个数等于超过2个,参与计算");
  183. $frist=$a[0]['dirt'];
  184. $end=$a[$count-1]['dirt'];
  185. if($frist!=$end){
  186. $data_array=[];
  187. $data_array[]=[
  188. "label"=>$item,
  189. 'time'=>$a[$count-1]['time'],
  190. 'dirt'=> $frist==1?1:2 //1是进 2是出
  191. ];
  192. $url_data=[
  193. "mac"=>$station,
  194. "data"=>$data_array
  195. ];
  196. debug_log("clear_label", $item.':'. "标签信号个数等于超过2个,参与计算,得出结果:".$frist);
  197. $dispose->set_time_results($station,$item,$a[$count-1]['time'],$frist==1?1:2);
  198. $dispose->getRemoteData($url_data);
  199. debug_log("clear_label","发送给远程".json_encode($url_data));
  200. }else{
  201. debug_log("clear_label", $item.':'. "标签信号个数没有超过4个,全部去清除");
  202. }
  203. }
  204. }else{
  205. $front=0;
  206. $back=0;
  207. $res=0;
  208. if($a[$count-3]['dirt']==1){
  209. $front+=1;
  210. }else{
  211. $back+=1;
  212. }
  213. if($a[$count-2]['dirt']==1){
  214. $front+=1;
  215. }else{
  216. $back+=1;
  217. }
  218. if($a[$count-1]['dirt']==1){
  219. $front+=1;
  220. }else{
  221. $back+=1;
  222. }
  223. if($front>$back){
  224. $res=1;
  225. }else{
  226. $res=2;
  227. }
  228. if($status['dirt']!=$res){
  229. debug_log("clear_label", $item.':'. "最后一个信号,方向相反,得出结果,清除缓存数据");
  230. $redis->hdel($key,$item);
  231. $data_array=[];
  232. $data_array[]=[
  233. "label"=>$item,
  234. 'time'=>$a[$count-1]['time'],
  235. 'dirt'=> $status['dirt']==1?1:2 //1是进 2是出
  236. ];
  237. $url_data=[
  238. "mac"=>$station,
  239. "data"=>$data_array
  240. ];
  241. //设置key
  242. $dispose->set_time_results($station,$item,$a[$count-1]['time'],$status['dirt']==1?1:2);
  243. // debug_log("InAndOUT","得出计算结果:".json_encode($arr));
  244. debug_log("clear_label","发送给远程".json_encode($url_data));
  245. //远程推送
  246. $dispose->getRemoteData($url_data);
  247. }else{
  248. //上午不做二次计算
  249. if(empty($in_and_out)){
  250. //二次生成结果
  251. $res=$dispose->second_create_direction($station,$item);
  252. if(!empty($res)){
  253. $res_time= $dispose->get_time_results($station,$item);
  254. $res_time= empty($res_time)?0:$res_time;
  255. $diff_time=$res['time']-$res_time;
  256. debug_log("clear_label", $item.':'. "间隔时间".$diff_time);
  257. //判断如果结果超过时间
  258. if($diff_time>10){
  259. debug_log("clear_label", $item.':'. "二次生成进出");
  260. $data_array=[];
  261. $data_array[]=[
  262. "label"=>$item,
  263. 'time'=>$res['time'],
  264. 'dirt'=>$res['dirt'],
  265. ];
  266. $url_data=[
  267. "mac"=>$station,
  268. "data"=>$data_array
  269. ];
  270. debug_log("clear_label","二次生成发送给远程".json_encode($url_data));
  271. //远程推送时间
  272. $dispose->set_time_results($station,$item,$res['time'],$res['dirt']);
  273. //远程推送
  274. $dispose->getRemoteData($url_data);
  275. }
  276. }
  277. }
  278. //二次进出
  279. debug_log("clear_label", $item.':'. "最后一个信号,方向没有变化,清除缓存数据");
  280. }
  281. }
  282. //清除对应的键值对
  283. //清空头部尾部历史
  284. $dispose->get_label_history(3,$station,$item);
  285. $redis->hdel($key,$item);
  286. $redis->hdel($catchkey,$item);
  287. }
  288. }
  289. }
  290. }
  291. }
  292. /**
  293. * 远程推送数据
  294. *
  295. * @return void
  296. */
  297. public function remotePush(){
  298. while(true){
  299. $redis=Cache::store('redis')->handler();
  300. $key="push_data";
  301. $url="http://localhost:8115/api/accessReport";
  302. sleep(2);
  303. while($data=$redis->lPop($key)){
  304. if(!empty($data)){
  305. debug_log($key,"远程推送的数据".$data);
  306. $url_res= curl_http_post($data,$url,false);
  307. $num=1;
  308. while($url_res==false){
  309. $num++;
  310. $url_res= curl_http_post($data,$url,false);
  311. if($num>=3){
  312. debug_log($key,"远程推送的地址".$url);
  313. debug_log($key,"连续推送三次失败,远程推送的数据".$data);
  314. break;
  315. }
  316. }
  317. debug_log($key,"远程返回结果".$url_res);
  318. }
  319. }
  320. }
  321. }
  322. public function redis_to_mysql_parea(){
  323. $ues_redis=Cache::store('redis')->handler();
  324. $text="";
  325. $dispose = new dispose($ues_redis);
  326. while(1){
  327. $jsonData= $ues_redis->rpop("mqtt_data_parea4rssi");
  328. debug_log("pare_InAndOUT",'数据redis'.$jsonData);
  329. if(empty($jsonData)){
  330. debug_log("pare_InAndOUT",'没有数据');
  331. sleep(1);
  332. continue;
  333. }
  334. // debug_log("InAndOUT",$jsonData);
  335. $data=json_decode($jsonData,true);
  336. // debug_log("InAndOUT",$data['cnt']);
  337. $time=$data['time'];
  338. $mac=$data['devId'];
  339. $text=$text.$data['cnt'];
  340. if(strlen($text)<24){
  341. continue;
  342. }
  343. $text = $this->handleMessage($text, $mac, $time, $ues_redis);
  344. // foreach ($jsonData as $k => $v) {
  345. // $data = json_decode($v, true);
  346. // $config = $this->selectHash("anbang_four_wire",$data['mac']);
  347. // if(!$config){
  348. // $config = [
  349. // "front" => 70,
  350. // "behind" => 70,
  351. // "left" => 70,
  352. // "right" => 70
  353. // ];
  354. // }else{
  355. // $config = json_decode($config);
  356. // }
  357. // $field = "";
  358. // $infos = $ues_redis->hget("parea_rfidinfos",$field);
  359. // if(!$infos){
  360. // }
  361. // //判断进出段
  362. // //1。当前时间 - 上次时间 > 设定时间
  363. // if( (time() - $v["time"]) > $setInt ){
  364. // //推送离开
  365. // }
  366. // }
  367. // sleep(2);
  368. }
  369. }
  370. // //http://47.114.185.186:8115/api/areaReport
  371. // //{“mac”:”013560”,”data”:[{“label”:”258962f”,”time”:1682317268,”dirt”:2},{“label”:”258962f”,”time”:1682317268,”dirt”:1}]
  372. // }
  373. //打印日志
  374. public function temporary_label_log(){
  375. $redis=Cache::store('redis')->handler();
  376. // $key="temporary_label";
  377. // $list= $redis->HgetAll($key);
  378. // debug_log($key,json_encode($list));
  379. // debug_log($key,"所有的标签");
  380. // foreach($list as $k=>$value){
  381. // debug_log($key,json_encode([$k=>$value]));
  382. // }
  383. // debug_log($key,"所有总数".count($list));
  384. // debug_log($key,"上报的标签");
  385. // $i=0;
  386. // foreach($list as $k=>$value){
  387. // if($value==2){
  388. // debug_log($key,json_encode([$k=>$value]));
  389. // $i++;
  390. // }
  391. // }
  392. // debug_log($key,"正常上报的标签总数".$i);
  393. // debug_log($key,"补出的标签");
  394. // $t=0;
  395. // foreach($list as $k=>$value){
  396. // if($value==3){
  397. // $t++;
  398. // debug_log($key,json_encode([$k=>$value]));
  399. // }
  400. // }
  401. // debug_log($key,"补出的标签总数".$t);
  402. // debug_log($key,"没有上报的的标签");
  403. // $f=0;
  404. // foreach($list as $k=>$value){
  405. // if($value==1){
  406. // debug_log($key,json_encode([$k=>$value]));
  407. // $f++;
  408. // }
  409. // }
  410. // debug_log($key,"没有上报的的标签总数".$f);
  411. // // $redis->del($key);
  412. $dis= new dispose($redis);
  413. $dis->analysisLog();
  414. }
  415. // public function temporary_label($redis,$label,$type){
  416. // $key="temporary_label";
  417. // if($type==1){
  418. // $res= $redis->hGet($key,$label);
  419. // if($res==false){
  420. // $redis->hSet($key,$label,1);
  421. // }
  422. // }else{
  423. // $redis->hSet($key,$label,3);
  424. // }
  425. // }
  426. //消息处理
  427. public function handleMessage($text, $mac, $time, $ues_redis){
  428. while(strlen($text)>=24){
  429. $da=substr($text,0,24);
  430. $t1 = substr($da,8,2)=='00'||substr($da,8,2)=='10'||substr($da,8,2)=='01' ? true:false;
  431. $t2 =substr($da,10,6)=="FFFFFF"||substr($da,10,6)=="000000" ?true:false;
  432. if($t1&&$t2){
  433. // var_dump($text);
  434. $rfid= substr($da,0,8);
  435. $rssi1= hexdec(substr($da,16,2));
  436. $rssi2= hexdec(substr($da,18,2));
  437. $rssi3= hexdec(substr($da,20,2));
  438. $rssi4= hexdec(substr($da,22,2));
  439. // $rc1 = ($rssi1 == 255 ? 0 : 1);
  440. // $rc2 = ($rssi2 == 255 ? 0 : 1);
  441. // $rc3 = ($rssi3 == 255 ? 0 : 1);
  442. // $rc4 = ($rssi4 == 255 ? 0 : 1);
  443. $DA=[
  444. 'mac' => $mac,
  445. 'label' =>$rfid,
  446. 'rssi1' => $rssi1,
  447. 'rssi2' => $rssi2,
  448. 'rssi3' => $rssi3,
  449. 'rssi4' => $rssi4,
  450. 'report_time'=>$time
  451. ];
  452. $field = $mac."_".$rfid;
  453. $info = $ues_redis->hget("parea_rfidinfos",$field);
  454. debug_log("pare_InAndOUT","数据:".json_encode($DA,true));
  455. if($rssi1 ==255 && $rssi2 == 255 && $rssi3 == 255 && $rssi4 == 255){
  456. debug_log("pare_InAndOUT","无效数据:".json_encode($DA,true));
  457. }else{
  458. if(!$info){
  459. $info = [
  460. "mac" => $mac,
  461. "id" => $rfid,
  462. "firs_time" => $time,
  463. "time" => $time,
  464. "status" => 2,//2出状态,1进状态
  465. "rssi" => [
  466. [
  467. "front" => $rssi1,
  468. "behind" => $rssi2,
  469. "left" => $rssi3,
  470. "right" => $rssi4,
  471. "time" => $time
  472. ]
  473. ]
  474. ];
  475. $ues_redis->hset("parea_rfidinfos",$field, json_encode($info,true));
  476. debug_log("parea_rfidinfos_redis_set_record","redis更新记录".json_encode($info,true));
  477. }else{
  478. $info = json_decode($info,true);
  479. $config = $ues_redis->hget("anbang_four_wire", $info["mac"]);
  480. if (!$config) {
  481. # code...
  482. $config = [
  483. "front_in" => 80,
  484. "behind_in" => 80,
  485. "left_in" => 80,
  486. "right_in" => 80,
  487. "front_out" => 255,
  488. "behind_out" => 255,
  489. "left_out" => 255,
  490. "right_out" => 255,
  491. "expInt" => 12,
  492. "effSigNum" => 6
  493. ];
  494. }else{
  495. $config = json_decode($config,true);
  496. }
  497. // var_dump("+++++++++++++++++",$config);
  498. $info["time"] = $time;
  499. $newRssi = [
  500. "front" => $rssi1,
  501. "behind" => $rssi2,
  502. "left" => $rssi3,
  503. "right" => $rssi4,
  504. "time" => $time
  505. ];
  506. $rssisArr = $info["rssi"];
  507. // var_dump("+++++++++++++++++", $time, $newRssi["time"]);
  508. foreach ($rssisArr as $k => $v) {
  509. # code...
  510. if( ($time - $v["time"] ) > $config['expInt'] ){
  511. unset($rssisArr[$k]);
  512. }
  513. }
  514. // var_dump("+++++++++++++++++",$rssisArr);
  515. if(count($rssisArr) == $config['effSigNum']){
  516. array_shift($rssisArr);
  517. array_push($rssisArr, $newRssi);
  518. }else{
  519. array_push($rssisArr, $newRssi);
  520. }
  521. $rssisArr =array_values($rssisArr);
  522. // var_dump("+++++++++++++++++",$rssisArr);
  523. $info["rssi"] = $rssisArr;
  524. // var_dump("------------",$info["rssi"]);
  525. $cacCount = count($rssisArr);
  526. // if($cacCount > $EFF_SIG_NUM){
  527. $sum1 = 0;
  528. $sum2 = 0;
  529. $sum3 = 0;
  530. $sum4 = 0;
  531. foreach ($rssisArr as $k => $v) {
  532. # code...
  533. $sum1 += ($v["front"] == 255 ? 90 : $v["front"]);
  534. $sum2 += ($v["behind"] == 255 ? 90 : $v["behind"]);
  535. $sum3 += ($v["left"] == 255 ? 90 : $v["left"]);
  536. $sum4 += ($v["right"] == 255 ? 90 : $v["right"]);
  537. }
  538. $info["avg"] = [
  539. "front" => number_format( $sum1/$cacCount, 2 ),
  540. "behind" => number_format( $sum2/$cacCount, 2 ),
  541. "left" => number_format( $sum3/$cacCount, 2 ),
  542. "right" => number_format( $sum4/$cacCount, 2 ),
  543. ];
  544. // var_dump($cacCount, $EFF_SIG_NUM, "dddddddd");
  545. if ($cacCount == $config['effSigNum']) {
  546. # code...
  547. $info = $this->compAndPush($info ,$config);
  548. }
  549. $ues_redis->hset("parea_rfidinfos",$field, json_encode($info,true));
  550. debug_log("parea_rfidinfos_redis_set_record","redis更新记录".json_encode($info,true));
  551. }
  552. }
  553. $text=substr($text,24);
  554. }else{
  555. $text=substr($text,1);
  556. }
  557. }
  558. return $text ?$text : "";
  559. }
  560. //判断进出和推送
  561. public function compAndPush($info, $config ){
  562. //标签多,数据多时候,判断完成后放入redis,异步推送,当前暂时直接推
  563. // $config = $ues_redis->hget("anbang_four_wire", $info["mac"]);
  564. //{"front_in":44,"front_out":44,"behind_in":50,"behind_out":50,"left_in":55,"left_out":55,"right_out":44,"right_out":44}
  565. $avg = $info['avg'];
  566. $status = $info['status'];
  567. $flagIn = $avg["front"] < $config["front_in"] || $avg["behind"] < $config["behind_in"] || $avg["left"] < $config["left_in"] || $avg["right"] < $config["right_in"];
  568. $flagOut = $avg["front"] > $config["front_out"] && $avg["behind"] > $config["behind_out"] && $avg["left"] > $config["left_out"] && $avg["right"] > $config["right_out"];
  569. $url="http://localhost:8115/api/areaReport";
  570. if($flagIn && $status == 2){
  571. if ($info["pushTime"] && (time()-$info['pushTime']) < 5 ) {
  572. # code...
  573. return $info;
  574. }
  575. //推送进
  576. $info['status'] = 1;
  577. $url_data = [
  578. "mac" => $info["mac"],
  579. "data" => [
  580. [
  581. "label" => $info["id"],
  582. "time" => $info["time"],
  583. "dirt" => 1,
  584. "rssi" => $info["rssi"],//数组 [{"front":72,"behind":255,"left":255,"right":255,"time":1685067709},{"front":76,"behind":255,"left":255,"right":255,"time":1685067710}]
  585. "avg" => $info["avg"] //{"front":"77.17","behind":"90.00","left":"90.00","right":"90.00"}
  586. ]
  587. ]
  588. ];
  589. debug_log("pushPareaRes","进推送依赖:".json_encode($info));
  590. $url_res= curl_http_post(json_encode($url_data),$url,false);
  591. $info['pushTime'] = time();
  592. debug_log("pushPareaRes","远程返回结果".$url_res);
  593. }
  594. // if($info['id'] == "E2B15AD5"){
  595. // var_dump($flagIn, $flagOut, $status, $avg["front"],$avg["behind"],$avg["left"], $avg["right"]);
  596. // }
  597. if($flagOut && $status == 1){
  598. if ($info["pushTime"] && (time()-$info['pushTime']) < 5 ) {
  599. # code...
  600. return $info;
  601. }
  602. //推送出
  603. $info['status'] = 2;
  604. $url_data = [
  605. "mac" => $info["mac"],
  606. "data" => [
  607. [
  608. "label" => $info["id"],
  609. "time" => $info["time"],
  610. "dirt" => 2,
  611. "rssi" => $info["rssi"],//数组 [{"front":72,"behind":255,"left":255,"right":255,"time":1685067709},{"front":76,"behind":255,"left":255,"right":255,"time":1685067710}]
  612. "avg" => $info["avg"] //{"front":"77.17","behind":"90.00","left":"90.00","right":"90.00"}
  613. ]
  614. ]
  615. ];
  616. debug_log("pushPareaRes","出推送依赖:".json_encode($info));
  617. $url_res= curl_http_post(json_encode($url_data),$url,false);
  618. $info['pushTime'] = time();
  619. debug_log("pushPareaRes","远程返回结果".$url_res);
  620. }
  621. return $info;
  622. }
  623. // $url="http://47.114.185.186:8115/api/accessReport";
  624. // $url_res= curl_http_post(json_encode($url_data),$url,false);
  625. // debug_log("InAndOUT","远程返回结果".$url_res);
  626. public function test(){
  627. try{
  628. $ues_redis=Cache::store('redis')->handler();
  629. $jsonData= $ues_redis->rpop("mqtt_data");
  630. debug_log("InAndOUT","1212");
  631. }catch(Exception $e){
  632. var_dump($e->getMessage());
  633. }
  634. }
  635. /**
  636. * 删除前1天的数据
  637. *
  638. * @return void
  639. */
  640. public function deleteHistory()
  641. {
  642. while(true)
  643. {
  644. $where[] = ['addTime','<',strtotime("-1 day")];
  645. Db::name('tag_history')->where($where)->delete();
  646. sleep(60*60*24);
  647. }
  648. }
  649. /**
  650. * 检测小程序版本版本 function
  651. *
  652. * @return void
  653. */
  654. public function detectionVersion(){
  655. $token = $_GET['token'];
  656. if (!$token || $token != '444333d3') {
  657. json_fail('缺少token或者token不对');
  658. }
  659. $data["url"]="http://116.62.220.88:8112/static/app/蓝牙小程序/1.1.1/rl-release.apk";
  660. $data["version"]="1.1.1";
  661. json_success("查询版本成功",$data);
  662. }
  663. }