Api.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace catchAdmin\api\controller;
  3. use catchAdmin\tag_history\model\TagHistory;
  4. use catchAdmin\worklocation\model\WorkRecord as ModelWorkRecord;
  5. use catcher\base\CatchRequest as Request;
  6. use catcher\CatchResponse;
  7. use catcher\base\CatchController;
  8. use \think\facade\Db;
  9. error_reporting(0);
  10. class Api extends CatchController
  11. {
  12. public function report()
  13. {
  14. $token = $_GET['token'];
  15. if (!$token || $token != '22723927C') {
  16. json_fail('缺少token或者token不对');
  17. }
  18. $param = json_decode(optimize_json(file_get_contents("php://input")), true);
  19. if (json_last_error() != 0) {
  20. json_fail('解析异常', json_last_error_msg());
  21. }
  22. $mac = $param['mac'];
  23. if (empty($mac)) {
  24. json_fail('mac地址不存在');
  25. }
  26. $data = [];
  27. foreach ($param['list'] as $item) {
  28. $data[] = [
  29. 'mac' => $mac,
  30. 'lable' => $item['label'],
  31. 'rssi' => $item['rssi'],
  32. 'time' => $item['time'],
  33. 'addTime' => time(),
  34. 'move' => $item['move'],
  35. 'step' => empty($item['step']) ? 0 : $item['step'],
  36. 'temperature' => empty($item['temperature']) ? 0 : $item['temperature'],
  37. ];
  38. }
  39. $tage = new TagHistory();
  40. $tage->saveAll($data);
  41. json_success('上传成功');
  42. }
  43. }