Commit 00211cb0 authored by 李尚科's avatar 李尚科

course fix

parent 414ea6f4
Pipeline #14098 passed with stage
in 16 seconds
'use strict';
const Controller = require('egg').Controller;
class LocationController extends Controller {
/**
* 筛选项
*/
async getAddress() {
const { ctx } = this;
const { lat, lng } = ctx.request.body;
if (!lat || !lng) {
ctx.failed('error lat lng');
}
const location_ret = await ctx.service.course.lbs.getLBSLocation({ lat, lng });
let address = '获取位置信息失败';
if (location_ret.result.formatted_addresses && location_ret.result.formatted_addresses.recommend) {
address = location_ret.result.formatted_addresses.recommend;
}
ctx.success({ result: address });
}
}
module.exports = LocationController;
...@@ -6,6 +6,7 @@ module.exports = app => { ...@@ -6,6 +6,7 @@ module.exports = app => {
const miniAuth = app.middleware.miniAuth();//登录中间件 const miniAuth = app.middleware.miniAuth();//登录中间件
router.get('third', '/options', 'course.option.getOptions');//筛选项 router.get('third', '/options', 'course.option.getOptions');//筛选项
router.post('third', '/address', 'course.location.getAddress');//根据经纬度或ip获取地理位置信息
router.post('third', '/institutions', 'course.institution.institutionList');//机构列表 router.post('third', '/institutions', 'course.institution.institutionList');//机构列表
router.get('third', '/institutions', 'course.institution.institutionList');//机构列表 router.get('third', '/institutions', 'course.institution.institutionList');//机构列表
router.get('third', '/institution/:institution_id/:area_id', 'course.institution.institutionInfo');//机构详情 router.get('third', '/institution/:institution_id/:area_id', 'course.institution.institutionInfo');//机构详情
......
...@@ -95,28 +95,28 @@ class LbsService extends Service { ...@@ -95,28 +95,28 @@ class LbsService extends Service {
return { result }; return { result };
} }
// 地址解析 // 逆地址解析
async getLBSAddress(address) { async getLBSLocation(location) {
const { ctx } = this; const { ctx } = this;
let result = {}; let result = {};
const params = { const params = {
address, location: location.lat + ',' + location.lng,
key: ctx.app.config.TX_LBS_KEY, key: ctx.app.config.TX_LBS_KEY,
}; };
const resp = await ctx.helper.send_request(ctx.app.config.TX_LBS_ADDRESS_URL, params, { method: 'GET' }); const resp = await ctx.helper.send_request(ctx.app.config.TX_LBS_ADDRESS_URL, params, { method: 'GET' });
// resp.data.status 状态码,0:正常,310:请求参数信息有误,311:Key格式错误,306:请求有护持信息请检查字符串,110:请求来源未被授权 // resp.data.status 状态码,0:正常,310:请求参数信息有误,311:Key格式错误,306:请求有护持信息请检查字符串,110:请求来源未被授权
ctx.logger.info('tx_lbs_address_resp: ' + JSON.stringify(resp)); ctx.logger.info('tx_lbs_address_resp: ' + JSON.stringify(resp));
if (resp.status === 200) { if (resp.status === 200) {
// 判断响应是否正确 // 判断响应是否正确
if (resp.data.status === 0) { if (resp.data.status === 0) {
result = resp.data.result; result = resp.data.result;
}
} }
return { result };
} }
return { result };
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment