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->deviceBloodPressureData($id,$p); if(!$list['success']){ $this->error($list['error_desc']); } $data = []; foreach ($list['objs'] as $k=>$v){ $a = [ 'id'=>$k+1, 'dbp'=>$v['dbp'], 'sbp'=>$v['sbp'], '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(); } } }