Commit 4d3c8226 authored by 任国军's avatar 任国军

add backClassList && fix classInfo

parent 2c4bb343
Pipeline #24778 passed with stage
in 4 seconds
...@@ -66,6 +66,15 @@ class BackController extends Controller { ...@@ -66,6 +66,15 @@ class BackController extends Controller {
const ret = await service.course.back.addRedeemCode(params); const ret = await service.course.back.addRedeemCode(params);
ctx.success(ret); ctx.success(ret);
} }
// 获取课程列表
async getClassList() {
const { ctx, service } = this;
const ret = await service.course.back.getClassList();
ctx.success(ret);
}
} }
module.exports = BackController; module.exports = BackController;
...@@ -16,6 +16,7 @@ module.exports = app => { ...@@ -16,6 +16,7 @@ module.exports = app => {
name: STRING, name: STRING,
logo: STRING, logo: STRING,
description: TEXT, description: TEXT,
title: STRING,
status: INTEGER, status: INTEGER,
is_deleted: INTEGER, is_deleted: INTEGER,
created_time: { created_time: {
......
...@@ -9,4 +9,5 @@ module.exports = app => { ...@@ -9,4 +9,5 @@ module.exports = app => {
router.get('third', '/order', auth, 'course.back.getOrderList'); router.get('third', '/order', auth, 'course.back.getOrderList');
router.get('third', '/redeem', auth, 'course.back.getRedeemCodeList'); router.get('third', '/redeem', auth, 'course.back.getRedeemCodeList');
router.post('third', '/redeem', auth, 'course.back.addRedeemCode'); router.post('third', '/redeem', auth, 'course.back.addRedeemCode');
router.get('third', '/class', auth, 'course.back.getClassList');
}; };
...@@ -234,6 +234,42 @@ class BackService extends Service { ...@@ -234,6 +234,42 @@ class BackService extends Service {
} }
return ret; return ret;
} }
// 获取机构和课程
async getClassList() {
const { ctx } = this;
const userUuid = ctx.userUuid;
const userInfo = await ctx.classModel.CourseBackUser.findOne({ where: { id: userUuid, is_deleted: 0 } });
if (ctx.isEmpty(userInfo)) {
ctx.failed('用户异常');
}
const filter = userInfo.is_admin === 0 ? { where: { id: userInfo.institution_id, status: 1, is_deleted: 0 }, attributes: [ 'id', 'name' ], raw: true } : { where: { status: 1, is_deleted: 0 }, attributes: [ 'id', 'name' ] };
const institutionList = await ctx.classModel.V5.CourseV5Institution.findAll(filter);
if (ctx.isEmpty(institutionList)) {
return {
list: [],
};
}
let classList = await ctx.classModel.V5.CourseV5Class.findAll({ where: { institution_id: { $in: R.pluck('id', institutionList) }, status: 1, is_deleted: 0 }, attributes: [ 'id', 'institution_id', 'name' ] });
classList = _.groupBy(classList, 'institution_id');
const results = [];
for (const v of institutionList) {
results.push({
id: v.id,
name: v.name,
class: ctx.isEmpty(classList[v.id]) ? [] : classList[v.id],
});
}
return {
list: results,
};
}
} }
module.exports = BackService; module.exports = BackService;
...@@ -143,6 +143,10 @@ class InstitutionSubService extends Service { ...@@ -143,6 +143,10 @@ class InstitutionSubService extends Service {
const typeList = await ctx.classModel.V5.CourseV5ClassToType.findAll({ where: { class_id: id, status: 1, is_deleted: 0 }, attributes: [ 'type_id' ] }); const typeList = await ctx.classModel.V5.CourseV5ClassToType.findAll({ where: { class_id: id, status: 1, is_deleted: 0 }, attributes: [ 'type_id' ] });
const type = await ctx.classModel.V5.CourseV5Type.findAll({ where: { id: { $in: R.pluck('type_id', typeList) } }, attributes: [ 'id', 'name' ] }); const type = await ctx.classModel.V5.CourseV5Type.findAll({ where: { id: { $in: R.pluck('type_id', typeList) } }, attributes: [ 'id', 'name' ] });
// 授课频次
const frequencyList = await ctx.classModel.V5.CourseV5ClassToFrequency.findAll({ where: { class_id: id, status: 1, is_deleted: 0 }, attributes: [ 'frequency_id' ] });
const frequency = await ctx.classModel.V5.CourseV5Frequency.findAll({ where: { id: { $in: R.pluck('frequency_id', frequencyList) } }, attributes: [ 'id', 'name' ] });
const columns = []; const columns = [];
for (const v of classColumns) { for (const v of classColumns) {
if (!ctx.isEmpty(columnList[v.column_id])) { if (!ctx.isEmpty(columnList[v.column_id])) {
...@@ -178,8 +182,10 @@ class InstitutionSubService extends Service { ...@@ -178,8 +182,10 @@ class InstitutionSubService extends Service {
classInfo.institution_name = ctx.isEmpty(institution) ? '' : institution.name; classInfo.institution_name = ctx.isEmpty(institution) ? '' : institution.name;
classInfo.institution_logo = ctx.isEmpty(institution) ? '' : institution.logo; classInfo.institution_logo = ctx.isEmpty(institution) ? '' : institution.logo;
classInfo.institution_description = ctx.isEmpty(institution) ? '' : institution.description; classInfo.institution_description = ctx.isEmpty(institution) ? '' : institution.description;
classInfo.institution_title = ctx.isEmpty(institution) ? '' : institution.title;
classInfo.pay_count += orderCount; classInfo.pay_count += orderCount;
classInfo.video_count = videoCount; classInfo.video_count = videoCount;
classInfo.frequency = frequency;
return classInfo; return classInfo;
} }
......
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