Jiu.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\admin\controller;
  3. use app\watch\controller\Api;
  4. use think\App;
  5. use think\facade\Db;
  6. class Jiu extends Auth
  7. {
  8. public function __construct(App $app) {
  9. parent::__construct($app);
  10. $this->api = new Api($this->app);
  11. }
  12. public function index(){
  13. $id = request()->get('id');
  14. if(empty($id)){
  15. $d = $this->api->community(1,10);
  16. if(!isset($d['objs'][0])) $this->error('没有添加设备');
  17. $id = $d['objs'][0]['_id'];
  18. }
  19. if(request()->isAjax()){
  20. //分页参数
  21. $length = input('rows',10,'intval'); //每页条数
  22. $page = input('page',1,'intval'); //第几页
  23. $date = input('riqi','');
  24. $imei = input('imei','');
  25. $p = ['rows_per_page'=>$length,'page'=>$page];
  26. if($date){
  27. $p['time_begin'] = date('Ymd',strtotime($date));
  28. }
  29. if(!empty($imei)){
  30. $id = $imei;
  31. }
  32. $list = $this->api->deviceSosData($id,$p);
  33. if(!$list['success']){
  34. $this->error($list['error_desc']);
  35. }
  36. $data = [];
  37. foreach ($list['objs'] as $k=>$v){
  38. $a = [
  39. 'id'=>$k+1,
  40. 'address'=>$v['address'],
  41. 'created_at'=>nDate($v['created_at']['$date']),
  42. ];
  43. $data[$k] = $a;
  44. }
  45. $result['page'] = $page;
  46. $result['total'] = $list['page']['page_count'];
  47. $result['records'] = $list['page']['total'];
  48. $result['rows'] = $data;
  49. return json($result);
  50. }else{
  51. $this->assign('id',$id);
  52. return $this->fetch();
  53. }
  54. }
  55. }