12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace app\admin\controller;
- use app\watch\controller\Api;
- use think\App;
- use think\facade\Db;
- class Shui extends Auth
- {
- public function __construct(App $app) {
- parent::__construct($app);
- $this->api = new Api($this->app);
- }
- public function index(){
- $id = request()->get('id');
- if(empty($id)){
- $d = $this->api->community(1,10);
- if(!isset($d['objs'][0])) $this->error('没有添加设备');
- $id = isset($d['objs'][0]['_id'])?$d['objs'][0]['_id']:'';
- }
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $date = input('riqi','');
- $imei = input('imei','');
- $p = ['rows_per_page'=>$length,'page'=>$page];
- if($date){
- $p['time_begin'] = date('Ymd',strtotime($date));
- }
- if(!empty($imei)){
- $id = $imei;
- }
- $list = $this->api->deviceSleepData($id,$p);
- if(!$list['success']){
- $this->error($list['error_desc']);
- }
- $data = [];
- foreach ($list['objs'] as $k=>$v){
- $a = [
- 'id'=>$k+1,
- 'interval'=>$v['interval'],
- 'total'=>$v['total'],
- 'deep_sleep'=>$v['deep_sleep'],
- 'light_sleep'=>$v['light_sleep'],
- 'awake_time'=>$v['awake_time'],
- 'total_sleep'=>$v['total_sleep'],
- 'created_at'=>nDate($v['created_at']['$date']),
- ];
- $data[$k] = $a;
- }
- $result['page'] = $page;
- $result['total'] = $list['page']['page_count'];
- $result['records'] = $list['page']['total'];
- $result['rows'] = $data;
- return json($result);
- }else{
- $this->assign('id',$id);
- return $this->fetch();
- }
- }
- }
|