dataRange() ->catchSearch() ->append(['is_online','is_online_text']) ->order($this->aliasField('online_time'), 'desc') ->paginate()->each(function($item, $key) { $wgsLoc = \algorithm\Geometry::gcj02ToWgs84((float)$item['latitude'],(float)$item['longitude']); $item['longitude']=$wgsLoc['lng']; $item['latitude']=$wgsLoc['lat']; }); return $res; } public function getMapList(){ $res = $this->dataRange() ->catchSearch() ->append(['is_online','is_online_text']) ->order($this->aliasField('online_time'), 'desc') ->paginate()->each(function($item, $key) { $wgsLoc = \algorithm\Geometry::gcj02ToWgs84((float)$item['latitude'],(float)$item['longitude']); $item['longitude']=$wgsLoc['lng']; $item['latitude']=$wgsLoc['lat']; }); return $res; } public function getExportList(){ $res = $this->dataRange() ->catchSearch() // ->field('mac,name,latitude,longitude,online_time') ->append(['is_online_text','is_online']) // ->cache(120) ->select() ->each(function($item, $key) { $wgsLoc = \algorithm\Geometry::gcj02ToWgs84((float)$item['latitude'],(float)$item['longitude']); $item['longitude']=$wgsLoc['lng']; $item['latitude']=$wgsLoc['lat']; })->toArray(); return $res; } public function getAllList($start=0,$limit=4000){ $res = $this ->catchSearch() // ->field('mac,name,latitude,longitude,online_time') ->append(['is_online_text','is_online']) ->cache(120) ->limit($start,$limit) ->select() ->each(function($item, $key) { $wgsLoc = \algorithm\Geometry::gcj02ToWgs84((float)$item['latitude'],(float)$item['longitude']); $item['longitude']=$wgsLoc['lng']; $item['latitude']=$wgsLoc['lat']; })->toArray(); return $res; } /** * 根据名称搜索 */ public function searchNameAttr($query, $value, $data) { return $query->where('name', 'like', '%'.$value.'%'); } /** * 根据编号搜索 */ public function searchShortCodeAttr($query, $value, $data) { return $query->where('shortcode|mac', 'like', '%'.$value.'%'); } /** * 关键字 */ public function searchKeywordsAttr($query, $value, $data) { return $query->where('name|mac', 'like', '%'.$value.'%'); } /** * 根据状态搜索 */ public function searchOnlineStateAttr($query, $value, $data) { $time=date('Y-m-d H:i:s',time()-600); $config=Env::get('app.station_state'); if($value=='1'){ if(!$config){ return $query->where(function ($query) use( $time) { $query->where('online_state', 1)->whereOr('online_state','null')->whereOr('online_state',''); }); } return $query->where(function ($query) use( $time) { $query->where('online_time', '>=', $time)->whereOr('online_state','=', 1); }); }elseif($value=='2'){ if(!$config){ return $query->where(function ($query) use( $time) { $query->where('online_state',2); }); } return $query->where(function ($query) use( $time) { $query->whereOr('online_time','<', $time)->whereOr('online_time','=', null); }); } } }