Przeglądaj źródła

修改课程表

zs 1 rok temu
rodzic
commit
ddba9f5e0d

+ 15 - 0
src/controller/core/course.controller.ts

@@ -19,6 +19,7 @@ export class CourseController extends BaseController {
     const result = new CVO_course(dbData);
     return result;
   }
+
   @Get('/')
   @ApiQuery({ name: 'query' })
   @ApiResponse({ type: QVO_course })
@@ -41,6 +42,14 @@ export class CourseController extends BaseController {
     return { data, total };
   }
 
+  @Get('/appHome')
+  async appHome() {
+    const list = await this.service.appHome(this.ctx.filter);
+    const data = list.data;
+    const total = list.total;
+    return { data, total };
+  }
+
   @Get('/:id')
   @ApiResponse({ type: FVO_course })
   async fetch(@Param('id') id: string) {
@@ -49,6 +58,12 @@ export class CourseController extends BaseController {
     return result;
   }
 
+  @Get('/appHomeDetail/:id')
+  async appHomeDetail(@Param('id') id: string) {
+    const result = await this.service.appHomeDetail(id);
+    return result;
+  }
+
   @Post('/:id')
   @Validate()
   @ApiResponse({ type: UVAO_course })

+ 26 - 0
src/service/core/course.service.ts

@@ -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;
+  }
 }