api = new Api($this->app); } public function index(){ if(request()->post()){ $length = input('rows',10,'intval'); //每页条数 $page = input('page',1,'intval'); //第几页 $start = ($page - 1) * $length; //分页开始位置 $map[] =['del','=',0]; $map[] =['org_id','=',cur_org_id()]; $map= empty($map) ? true: $map; $lists = Db::name('bracelet_device') ->where($map)->limit($start,$length) ->select(); $deviceInfo = []; foreach ($lists as $k=>$v){ $a = $this->api->getDevice($v['imei']); if(!$a['success']) $this->error($v['imei'].$a['error_desc']); $deviceInfo[] = $a['obj']; } $totalCount = Db::name('bracelet_device') ->where($map) ->count(); $totalPage = ceil($totalCount/$length); $data = []; $ydw = []; $wdw = []; $onlineNumber = 0; foreach ($deviceInfo as $k=>$v){ if(!empty($v['last_address'])){ $a = [ 'lonLat'=>[$v['last_location']['coordinates'][0],$v['last_location']['coordinates'][1]], 'imeI'=>$v['_id'], 'name'=>$v['name'], 'lon'=>$v['last_location']['coordinates'][0], 'lat'=>$v['last_location']['coordinates'][1], 'address'=>$v['last_address'], 'updated_at'=>nDate($v['location_updated_at']['$date']), 'icon'=>$v['online']?$this->zx:$this->lx ]; $ydw[] = [ 'imeI'=>$v['_id'], 'name'=>$v['name'], 'online'=>$v['online']?'在线':'离线', ]; if($v['online']){ $onlineNumber++; } }else{ $wdw[] = [ 'imeI'=>$v['_id'], 'name'=>$v['name'], ]; } } $data['data'][] = $a; $data['online_numbers'] =$onlineNumber; $lpage['page_count'] = $totalPage; $lpage['total'] = $totalCount; $lastPage = $page+1; $proPage = $page-1; $a1 = ' 当前第'.$page.'页 '; $a3 = ' 共'.$lpage['total'].'条'; if($page==1 && $lpage['page_count'] <=1){ $a0 = '上一页 |'; $a2 = '| 下一页 |'; }else if ($page==1 && $lpage['page_count'] >1){ $a0 = '上一页 |'; $a2 = '| 下一页 |'; }else if ($page > 1 && $lpage['page_count'] <=1){ $a0 = '上一页 |'; $a2 = '| 下一页 |'; }else if ($page > 1 && $lpage['page_count'] >1){ $a0 = '上一页 |'; $a2 = '| 下一页 |'; } $data['page'] = $a0.$a1.$a2.$a3; $ydwTxt =''; $wdwTxt =''; if(!empty($ydw)){ foreach ($ydw as $v){ $ydwTxt.='