0
0

Shui.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\admin\controller;
  3. use app\watch\controller\Api;
  4. use think\App;
  5. use think\facade\Db;
  6. class Shui 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 = isset($d['objs'][0]['_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->deviceSleepData($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. 'interval'=>$v['interval'],
  41. 'total'=>$v['total'],
  42. 'deep_sleep'=>$v['deep_sleep'],
  43. 'light_sleep'=>$v['light_sleep'],
  44. 'awake_time'=>$v['awake_time'],
  45. 'total_sleep'=>$v['total_sleep'],
  46. 'created_at'=>nDate($v['created_at']['$date']),
  47. ];
  48. $data[$k] = $a;
  49. }
  50. $result['page'] = $page;
  51. $result['total'] = $list['page']['page_count'];
  52. $result['records'] = $list['page']['total'];
  53. $result['rows'] = $data;
  54. return json($result);
  55. }else{
  56. $this->assign('id',$id);
  57. return $this->fetch();
  58. }
  59. }
  60. }