添加根据经纬度获取城市
添加后台统计看板
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\server\CityService;
|
||||
use app\api\model\User;
|
||||
|
||||
class City extends ApiBase
|
||||
{
|
||||
@@ -25,4 +26,37 @@ class City extends ApiBase
|
||||
$array = $this->cityService->list();
|
||||
return $this->_success('成功',$array);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据经纬度获取所在城市
|
||||
* @return void
|
||||
*/
|
||||
public function getCity()
|
||||
{
|
||||
$lat = $this->request->param('lat', '');
|
||||
$lng = $this->request->param('lng', '');
|
||||
|
||||
if (empty($lat) || empty($lng)) {
|
||||
return $this->_error('请提供经纬度参数');
|
||||
}
|
||||
$uid = $this->user_id;
|
||||
//查询用户信息
|
||||
$userInfo = User::find($uid);
|
||||
if ($userInfo) {
|
||||
if ($userInfo->longitude == '' || $userInfo->latitude == '')
|
||||
{
|
||||
$userInfo->longitude = $lng; // 经度
|
||||
$userInfo->latitude = $lat; // 纬度
|
||||
$userInfo->save();
|
||||
}
|
||||
}
|
||||
$result = $this->cityService->getCityByLocation($lat, $lng);
|
||||
|
||||
if ($result['success']) {
|
||||
return $this->_success($result['msg'], $result['data']);
|
||||
} else {
|
||||
return $this->_error($result['msg'], $result['data']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user