Api.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * @Descripttion:
  4. * @version: 1.0.0
  5. * @Author: likang
  6. * @Date: 2022-08-12 10:33:24
  7. * @LastEditors: likang
  8. * @LastEditTime: 2022-10-09 14:16:28
  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. if (json_last_error() != 0) {
  28. json_fail('解析异常', json_last_error_msg());
  29. }
  30. $mac = $param['mac'];
  31. if (empty($mac)) {
  32. json_fail('mac地址不存在');
  33. }
  34. $data = [];
  35. foreach ($param['list'] as $item) {
  36. $data[] = [
  37. 'mac' => $mac,
  38. 'lable' => $item['label'],
  39. 'rssi' => $item['rssi'],
  40. 'time' => $item['time'],
  41. 'addTime' => time(),
  42. 'move' => $item['move'],
  43. 'step' => empty($item['step']) ? 0 : $item['step'],
  44. 'temperature' => empty($item['temperature']) ? 0 : $item['temperature'],
  45. //告警
  46. 'temperWarn' => empty($item['temperWarn']) ? 00 : $item['temperWarn'],
  47. ];
  48. }
  49. $tage = new TagHistory();
  50. $tage->saveAll($data);
  51. json_success('上传成功');
  52. }
  53. }