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.='
  • '.$v['imeI'].'['.$v['name'].']['.$v['online'].']
  • '; } } if(!empty($wdw)){ foreach ($wdw as $v){ $wdwTxt.='
  • '.$v['imeI'].'['.$v['name'].']
  • '; } } $data['ydw'] = $ydwTxt; $data['wdw'] = $wdwTxt; $this->success('获取成功','',$data); }else{ $this->assign('gdKey',config('app.gdmap')); return $this->fetch(); } } public function getSosNum(){ $count = Db::name('sos_data') ->where('org_id',cur_org_id()) ->count(); $this->success('操作成功','',$count); } public function getSosList(){ if(request()->isAjax()){ //分页参数 $length = input('rows',10,'intval'); //每页条数 $page = 1; //第几页 $start = ($page - 1) * $length; //分页开始位置 $map[] = ['org_id','=',cur_org_id()]; $list = Db::name('sos_data')->where($map) ->limit($start,$length)->order('id','desc') ->select(); foreach ($list as $k=>&$v){ $v['created_at'] = $v['time_begin']; } $totalCount = Db::name('sos_data')->where($map)->count(); $totalPage = ceil($totalCount/$length); $result['page'] = $page; $result['total'] = $totalPage; $result['records'] = $totalCount; $result['rows'] = $list; Db::name('sos_data') ->whereIn('id',array_column($list,'id')) ->delete(); return json($result); }else{ return $this->fetch(); } } }