dataRange() ->catchSearch() ->append(['is_online','is_online_text']) ->order($this->aliasField('online_time'), 'desc') ->paginate()->each(function($item, $key) { $wgsLoc = \algorithm\Geometry::convertGcj02ToBd09((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 getAllList(){ $res = $this ->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 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()-300); if($value=='1'){ return $query->where('online_time', '>=', $time); }elseif($value=='2'){ return $query->where(function ($query) use( $time) { $query->whereOr('online_time','<', $time)->whereOr('online_time','=', null); }); } } }