Commit 822c141b authored by 任国军's avatar 任国军

classList add institution_name & category

parent 4df4e4e4
Pipeline #21835 passed with stage
in 12 seconds
......@@ -15,7 +15,7 @@ class InstitutionSubService extends Service {
const page_size = Number(input.page_size) || 10;
const offset = (page - 1) * page_size;
const attributes = [ 'id', 'institution_id', 'name', 'logo', 'age', 'price', 'price_type', 'mode', 'time', 'class_amount', 'multi_classes', 'cycle', 'description', 'sort' ];
const filter = { where: { status: 1, is_deleted: 0 }, order: [[ 'sort', 'asc' ], [ 'id', 'desc' ]], page_size, offset, attributes };
const filter = { where: { status: 1, is_deleted: 0 }, order: [[ 'sort', 'asc' ], [ 'id', 'desc' ]], page_size, offset, attributes, raw: true };
let filterIds = [];
let flag = false;
// 年龄筛选
......@@ -43,6 +43,9 @@ class InstitutionSubService extends Service {
}
const classList = await ctx.classModel.V5.CourseV5Class.findAndCountAll(filter);
if (classList.count === 0) {
return { list: [], total_count: 0, page, page_size };
}
// 用户收藏的课程
const userCollection = await ctx.classModel.V5.CourseUserCollection.findAll({ where: { user_uuid: ctx.userUuid, is_deleted: 0, type: 3 }, raw: true });
......@@ -51,6 +54,32 @@ class InstitutionSubService extends Service {
classList.rows[i].is_collected = collectedIds.includes(classList.rows[i].id) ? 1 : 0;
}
// 获取课程类型
let classToCategory = await ctx.classModel.V5.CourseV5ClassToCat.findAll({ where: { class_id: { $in: R.pluck('id', classList.rows) } }, attributes: [ 'cat_id', 'class_id' ] });
let categoryList = await ctx.classModel.V5.CourseV5Category.findAll({ where: { id: { $in: R.pluck('cat_id', classToCategory) } }, attributes: [ 'id', 'name' ] });
classToCategory = _.groupBy(classToCategory, 'class_id');
categoryList = _.groupBy(categoryList, 'id');
// 获取机构
let institutionList = await ctx.classModel.V5.CourseV5Institution.findAll({ where: { id: { $in: R.pluck('institution_id', classList.rows) } }, attributes: [ 'id', 'name' ] });
institutionList = _.groupBy(institutionList, 'id');
for (const i in classList.rows) {
const classCategoryList = [];
if (!ctx.isEmpty(classToCategory[classList.rows[i].id])) {
for (const j of classToCategory[classList.rows[i].id]) {
if (!ctx.isEmpty(categoryList[j.cat_id])) {
classCategoryList.push({
id: j.cat_id,
name: categoryList[j.cat_id][0].name,
});
}
}
}
classList.rows[i].category = classCategoryList;
classList.rows[i].institution_name = ctx.isEmpty(institutionList[classList.rows[i].institution_id]) ? '' : institutionList[classList.rows[i].institution_id][0].name;
}
const ret = {
list: classList.rows,
total_count: classList.count,
......
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