Api.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /*
  3. * @Descripttion:
  4. * @version: 1.0.0
  5. * @Author: likang
  6. * @Date: 2022-08-12 10:33:24
  7. * @LastEditors: likang 1186820806@qq.com
  8. * @LastEditTime: 2023-04-11 15:01:54
  9. */
  10. namespace catchAdmin\api\controller;
  11. use catchAdmin\tag_history\model\TagHistory;
  12. use catchAdmin\worklocation\model\WorkRecord as ModelWorkRecord;
  13. use catcher\base\CatchRequest as Request;
  14. use catcher\CatchResponse;
  15. use catcher\base\CatchController;
  16. use \think\facade\Db;
  17. error_reporting(0);
  18. class Api extends CatchController
  19. {
  20. public function report()
  21. {
  22. $token = $_GET['token'];
  23. if (!$token || $token != '22723927C') {
  24. json_fail('缺少token或者token不对');
  25. }
  26. $param = json_decode(optimize_json(file_get_contents("php://input")), true);
  27. debug_log("上报数据",json_encode($param));
  28. if (json_last_error() != 0) {
  29. json_fail('解析异常', json_last_error_msg());
  30. }
  31. $mac = $param['mac'];
  32. if (empty($mac)) {
  33. json_fail('mac地址不存在');
  34. }
  35. $data = [];
  36. foreach ($param['list'] as $item) {
  37. $data[] = [
  38. 'mac' => $mac,
  39. 'lable' => $item['label'],
  40. 'rssi' => $item['rssi'],
  41. 'time' => $item['time'],
  42. 'addTime' => time(),
  43. 'move' => $item['move'],
  44. 'step' => empty($item['step']) ? 0 : $item['step'],
  45. 'temperature' => empty($item['temperature']) ? 0 : $item['temperature'],
  46. //告警
  47. 'temperWarn' => empty($item['temperWarn']) ? 00 : $item['temperWarn'],
  48. ];
  49. }
  50. $tage = new TagHistory();
  51. $tage->saveAll($data);
  52. json_success('上传成功');
  53. }
  54. /**
  55. * 删除前1天的数据
  56. *
  57. * @return void
  58. */
  59. public function deleteHistory()
  60. {
  61. while(true)
  62. {
  63. $where[] = ['addTime','<',strtotime("-1 day")];
  64. Db::name('tag_history')->where($where)->delete();
  65. sleep(60*60*24);
  66. }
  67. }
  68. /**
  69. * 检测小程序版本版本 function
  70. *
  71. * @return void
  72. */
  73. public function detectionVersion(){
  74. $token = $_GET['token'];
  75. if (!$token || $token != '444333d3') {
  76. json_fail('缺少token或者token不对');
  77. }
  78. $data["url"]="http://116.62.220.88:8112/static/app/蓝牙小程序/1.1.1/rl-release.apk";
  79. $data["version"]="1.1.1";
  80. json_success("查询版本成功",$data);
  81. }
  82. }