cityService = new CityService(); } public function index() { $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']); } } }