初始版本
This commit is contained in:
40
server/app/common/logic/CityLogic.php
Executable file
40
server/app/common/logic/CityLogic.php
Executable file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace app\common\logic;
|
||||
use app\common\model\city\City;
|
||||
|
||||
/**
|
||||
* 城市逻辑类
|
||||
* Class CityLogic
|
||||
* @package app\common\logic
|
||||
*/
|
||||
class CityLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取经纬度附近的城市
|
||||
* @param $longitude
|
||||
* @param $latitude
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/9/3 23:41
|
||||
*/
|
||||
public static function getNearbyCity($longitude,$latitude)
|
||||
{
|
||||
//用st_distance_sphere函数计算两点记录,单位米,这里换成千米
|
||||
$field = 'id,city_id,name,0 as distance,gcj02_lng as longitude,gcj02_lat as latitude';
|
||||
if($longitude && $latitude){
|
||||
//用st_distance_sphere函数计算两点记录,单位米,这里换成千米
|
||||
$field = 'id,city_id,name,round(st_distance_sphere(point('.$longitude.','.$latitude.'),
|
||||
point(gcj02_lng, gcj02_lat))/1000,2) as distance,'.$longitude.' as longitude,'.$latitude.' as latitude';
|
||||
}
|
||||
|
||||
$cityLists = City::field($field)
|
||||
->append(['distance_desc'])
|
||||
->order('distance asc')
|
||||
->hidden(['distance'])
|
||||
->select()
|
||||
->toArray();
|
||||
return $cityLists;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user