Commit 87d5f470 authored by 李尚科's avatar 李尚科

fix

parent 221f5f4d
Pipeline #13945 passed with stage
in 39 seconds
...@@ -6,6 +6,39 @@ const R = require('ramda'); ...@@ -6,6 +6,39 @@ const R = require('ramda');
const moment = require('moment'); const moment = require('moment');
class InstitutionService extends Service { class InstitutionService extends Service {
//机构列表页
async getInstitutions(input) {
const { ctx } = this;
const { cat, age, institution } = input;
let where = { status: 1, is_deleted: 0 };
if (cat) {
const cat_ret = await ctx.prometheusModel.CourseCat.one({ where: { id: cat } });
const cat_id = cat_ret.id;
const cat_level = cat_ret.level;
const next_level = cat_level + 1;
const next_next_level = cat_level + 2;
const next_cat = await ctx.prometheusModel.CourseCat.all({ where: { level: next_level, parent_id: cat_id } });
const next_next_cat = await ctx.prometheusModel.CourseCat.all({ where: { level: next_next_level, first_id: cat_id } });
let cat_ids = [cat_id,];
cat_ids = cat_ids.concat(R.pluck('id', next_cat)).concat(R.pluck('id', next_next_cat));
const institutions = await ctx.prometheusModel.CourseInstitutionToCat.all({ where: { cat_id: { $in: cat_ids } } });
where.id = { $in: R.pluck('institution_id', institutions) };
}
if (age) {
where.max_age = { $gte: age };
where.min_age = { $lte: age };
}
if (institution) {
where.corner = { $ne: '' };
}
const institutions = await ctx.prometheusModel.CourseInstitution.all({ where });
const ret = await this.formatInstitutions(institutions);
return ret;
}
/** /**
* 机构详情页 * 机构详情页
*/ */
...@@ -92,38 +125,6 @@ class InstitutionService extends Service { ...@@ -92,38 +125,6 @@ class InstitutionService extends Service {
} }
//机构列表页
async getInstitutions(input) {
const { ctx } = this;
const { cat, age, institution } = input;
let where = { status: 1, is_deleted: 0 };
if (cat) {
const cat_ret = await ctx.prometheusModel.CourseCat.one({ where: { id: cat } });
const cat_id = cat_ret.id;
const cat_level = cat_ret.level;
const next_level = cat_level + 1;
const next_next_level = cat_level + 2;
const next_cat = await ctx.prometheusModel.CourseCat.all({ where: { level: next_level, parent_id: cat_id } });
const next_next_cat = await ctx.prometheusModel.CourseCat.all({ where: { level: next_next_level, first_id: cat_id } });
let cat_ids = [cat_id,];
cat_ids = cat_ids.concat(R.pluck('id', next_cat)).concat(R.pluck('id', next_next_cat));
const institutions = await ctx.prometheusModel.CourseInstitutionToCat.all({ where: { cat_id: { $in: cat_ids } } });
where.id = { $in: R.pluck('institution_id', institutions) };
}
if (age) {
where.max_age = { $gte: age };
where.min_age = { $lte: age };
}
if (institution) {
where.corner = { $ne: '' };
}
const institutions = await ctx.prometheusModel.CourseInstitution.all({ where });
const ret = await this.formatInstitutions(institutions);
return ret;
}
async formatInstitutions(institutions) { async formatInstitutions(institutions) {
if (!Array.isArray(institutions) || institutions.length === 0) { if (!Array.isArray(institutions) || institutions.length === 0) {
......
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