1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace app\admin\controller;
- use app\watch\controller\Api;
- use think\App;
- use think\facade\Db;
- class Bushu 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->devicePedometerData($id,$p);
- if(!$list['success']){
- $this->error($list['error_desc']);
- }
- $data = [];
- foreach ($list['objs'] as $k=>$v){
- $a = [
- 'id'=>$k+1,
- 'heartrate'=>$v['heartrate'],
- '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();
- }
- }
- }
|