Commit 6042ffc4 authored by Hsinli's avatar Hsinli

Merge branch 'master' of t-git.51gjj.com:fangbin/51business

parents 309bec2a 00211cb0
Pipeline #14099 passed with stage
in 37 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 => {
const miniAuth = app.middleware.miniAuth();//登录中间件
router.get('third', '/options', 'course.option.getOptions');//筛选项
router.post('third', '/address', 'course.location.getAddress');//根据经纬度或ip获取地理位置信息
router.post('third', '/institutions', 'course.institution.institutionList');//机构列表
router.get('third', '/institutions', 'course.institution.institutionList');//机构列表
router.get('third', '/institution/:institution_id/:area_id', 'course.institution.institutionInfo');//机构详情
......
......@@ -95,28 +95,28 @@ class LbsService extends Service {
return { result };
}
// 地址解析
async getLBSAddress(address) {
const { ctx } = this;
let result = {};
const params = {
address,
key: ctx.app.config.TX_LBS_KEY,
};
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:请求来源未被授权
ctx.logger.info('tx_lbs_address_resp: ' + JSON.stringify(resp));
if (resp.status === 200) {
// 判断响应是否正确
if (resp.data.status === 0) {
result = resp.data.result;
}
// 逆地址解析
async getLBSLocation(location) {
const { ctx } = this;
let result = {};
const params = {
location: location.lat + ',' + location.lng,
key: ctx.app.config.TX_LBS_KEY,
};
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:请求来源未被授权
ctx.logger.info('tx_lbs_address_resp: ' + JSON.stringify(resp));
if (resp.status === 200) {
// 判断响应是否正确
if (resp.data.status === 0) {
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