Commit 202b066b authored by 任国军's avatar 任国军

add distance filter

parent 4a808024
......@@ -14,6 +14,7 @@ class InstitutionService extends Service {
const { ctx } = this;
const user_uuid = ctx.userUuid;
const { cats, ages, lat, lng, address, page } = input;
const distance = !ctx.isEmpty(input.distance) ? Number(input.distance) : 0;
const where_institutions = input.institutions;
// 保存定位记录
if (address && lat && lng) {
......@@ -51,7 +52,7 @@ class InstitutionService extends Service {
const institution_area_list = await this.getInstitutionAreaList(institutions);// 将校区表处理成数组
// const from = { lat, lng };
// const area_lbs = await this.computeDistance(institution_area_list, { lat, lng });// 计算距离信息
const area_distance_list = await this.calcDistance(institution_area_list, { lat, lng }, page);
const area_distance_list = await this.calcDistance(institution_area_list, { lat, lng }, page, distance);
const area_distance = area_distance_list.rows;
const institution_areas = await this.computeDistance(area_distance, { lat, lng });
for (const i in institution_areas) {
......@@ -402,7 +403,7 @@ class InstitutionService extends Service {
}
// 先本地用公式计算距离,然后分页,取对应的再去调腾讯接口
async calcDistance(lbs_array, from_gps, page = 1) {
async calcDistance(lbs_array, from_gps, page = 1, distance = 0) {
const { ctx } = this;
if (!Array.isArray(lbs_array) || lbs_array.length === 0) {
......@@ -419,11 +420,13 @@ class InstitutionService extends Service {
ctx.failed(error);
});
let ret = [];
const ret = [];
for (const i in result) {
const tmp = lbs_array[i];
tmp.distance = result[i];
ret.push(tmp);
if (distance > 0 && tmp.distance < distance) {
ret.push(tmp);
}
}
const sort = function(a, b) {
......@@ -438,17 +441,9 @@ class InstitutionService extends Service {
}
let results = [];
let debugs = [];
for (const v of institutions) {
if (!ctx.isEmpty(v)) {
results.push(v);
debugs.push(
{
id: v.id,
name: v.name,
distance: v.distance,
}
)
}
}
......
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