|
@@ -42,4 +42,30 @@ export class CourseService extends BaseService<modelType> {
|
|
|
const total = await this.model.count(info);
|
|
|
return { data, total };
|
|
|
}
|
|
|
+ // 小程序首页显示课程
|
|
|
+ async appHome(query) {
|
|
|
+ const { skip = 0, limit = 0, ...info } = query;
|
|
|
+ const data = [];
|
|
|
+ const list = await this.model.find(info, { meta: 0, __v: 0 }).skip(skip).limit(limit).sort({ start_time: -1 }).lean();
|
|
|
+ for (const val of list) {
|
|
|
+ const info = { _id: val._id, name: val.name, status: val.status, money: val.money, start_time: val.start_time, teacher: val.teacher };
|
|
|
+ if (get(val, 'teacher')) {
|
|
|
+ const userData = await this.tModel.findById(val.teacher).lean();
|
|
|
+ if (userData) Object.assign(info, { teacher_name: userData.nick_name, icon: userData.icon });
|
|
|
+ }
|
|
|
+ data.push(info);
|
|
|
+ }
|
|
|
+ const total = await this.model.count(info);
|
|
|
+ return { data, total };
|
|
|
+ }
|
|
|
+ // 小程序首页显示详情
|
|
|
+ async appHomeDetail(id) {
|
|
|
+ const result = await this.model.findById(id).lean();
|
|
|
+ const info = { courseInfo: result };
|
|
|
+ if (get(result, 'teacher')) {
|
|
|
+ const userData = await this.tModel.findById(result.teacher).lean();
|
|
|
+ if (userData) Object.assign(info, { teacherInfo: userData });
|
|
|
+ }
|
|
|
+ return info;
|
|
|
+ }
|
|
|
}
|