public static function nearby($lat, $lng, $type)
{
$model = new ShopModel();
$fields = 'id, type, name, logo, start_time, end_time, tags, address, desc, lng,lat,status,phone';
if ($lat && $lng) {
$model = $model->fieldRaw("$fields, ACOS(SIN(( $lat * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS(( $lat * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS(( $lng * 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380 as distance")->order('distance');
}
if ($type) {
$model = $model->where('type', $type);
}
$shop = $model->find();
$shop->distance = $shop->distance > 1 ? round($shop->distance, 2).'km' : round($shop->distance * 1000) .'m';
$shop->status_name = ShopModel::$status[$shop->status];
return $shop;
}
网友评论