浏览代码

新增帮助中心

zs 10 月之前
父节点
当前提交
e5dacf440c

+ 4 - 1
src/controller/core/course.controller.ts

@@ -34,7 +34,7 @@ export class CourseController extends BaseController {
 
   @Get('/list')
   async list() {
-    const data = await this.service.list();
+    const data = await this.service.list(this.ctx.filter);
     return data;
   }
 
@@ -42,6 +42,9 @@ export class CourseController extends BaseController {
   @ApiResponse({ type: FVO_course })
   async fetch(@Param('id') id: string) {
     const data = await this.service.fetch(id);
+    // 加浏览量
+    await this.service.fetchBrowse(data);
+
     const result = new FVO_course(data);
     return result;
   }

+ 68 - 0
src/controller/core/help.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { HelpService } from '../../service/core/help.service';
+import { CDTO_help, CVO_help, FVO_help, QDTO_help, QVO_help, UDTO_help, UVAO_help } from '../../interface/core/help.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['帮助中心'])
+@Controller('/help')
+export class HelpController extends BaseController {
+  @Inject()
+  service: HelpService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_help })
+  async create(@Body() data: CDTO_help) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_help(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_help })
+  async query(@Query() filter: QDTO_help, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_help(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_help })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_help(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_help })
+  async update(@Param('id') id: string, @Body() body: UDTO_help) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 2 - 0
src/entity/core/course.entity.ts

@@ -22,6 +22,8 @@ export class Course extends BaseModel {
   brief: string;
   @prop({ required: false, index: false, zh: '内容' })
   content: string;
+  @prop({ required: false, index: true, zh: '浏览量', default: 0 })
+  number: number;
   @prop({ required: false, index: true, zh: '是否使用', default: '0' })
   is_use: string;
   @prop({ required: false, index: true, zh: '状态', default: '0' })

+ 17 - 0
src/entity/core/help.entity.ts

@@ -0,0 +1,17 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'help' },
+})
+export class Help extends BaseModel {
+  @prop({ required: false, index: true, zh: '标题' })
+  title: string;
+  @prop({ required: false, index: true, zh: '类型' })
+  type: string;
+  @prop({ required: false, index: false, zh: '内容' })
+  content: string;
+  @prop({ required: false, index: true, zh: '是否使用', default: '0' })
+  is_use: string;
+  @prop({ required: false, index: true, zh: '状态', default: '0' })
+  status: string;
+}

+ 8 - 1
src/interface/core/course.interface.ts

@@ -32,6 +32,8 @@ export class FVO_course {
   'brief': string = undefined;
   @ApiProperty({ description: '内容' })
   'content': string = undefined;
+  @ApiProperty({ description: '浏览量' })
+  'number': number = undefined;
   @ApiProperty({ description: '是否使用' })
   'is_use': string = undefined;
   @ApiProperty({ description: '状态' })
@@ -41,7 +43,7 @@ export class FVO_course {
 export class QDTO_course extends SearchBase {
   constructor() {
     const like_prop = ['title'];
-    const props = ['year', 'type', 'brand', 'title', 'time', 'is_use', 'status'];
+    const props = ['year', 'type', 'brand', 'number', 'title', 'time', 'is_use', 'status'];
     const mapping = [];
     super({ like_prop, props, mapping });
   }
@@ -55,6 +57,8 @@ export class QDTO_course extends SearchBase {
   'time': string = undefined;
   @ApiProperty({ description: '课程类型' })
   'brand': string = undefined;
+  @ApiProperty({ description: '浏览量' })
+  'number': number = undefined;
   @ApiProperty({ description: '是否使用' })
   'is_use': string = undefined;
   @ApiProperty({ description: '状态' })
@@ -96,6 +100,9 @@ export class CDTO_course {
   @ApiProperty({ description: '内容' })
   @Rule(RuleType['string']().empty(''))
   'content': string = undefined;
+  @ApiProperty({ description: '浏览量' })
+  @Rule(RuleType['number']().empty(''))
+  'number': number = undefined;
   @ApiProperty({ description: '是否使用' })
   @Rule(RuleType['string']().empty(''))
   'is_use': string = undefined;

+ 89 - 0
src/interface/core/help.interface.ts

@@ -0,0 +1,89 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_help {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '内容' })
+  'content': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QDTO_help extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['title', 'type', 'is_use', 'status'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QVO_help extends FVO_help {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_help {
+  @ApiProperty({ description: '标题' })
+  @Rule(RuleType['string']().empty(''))
+  'title': string = undefined;
+  @ApiProperty({ description: '类型' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '内容' })
+  @Rule(RuleType['string']().empty(''))
+  'content': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+}
+
+export class CVO_help extends FVO_help {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_help extends CDTO_help {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_help extends FVO_help {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 2 - 0
src/interface/login.interface.ts

@@ -29,6 +29,7 @@ export class LoginVO {
     this._id = get(data, '_id');
     this.nick_name = get(data, 'nick_name');
     this.openid = get(data, 'openid');
+    this.gender = get(data, 'gender');
     this.role = get(data, 'role');
     this.is_super = get(data, 'is_super');
   }
@@ -36,6 +37,7 @@ export class LoginVO {
   nick_name: string;
   openid: string;
   role: string;
+  gender: string;
   is_super: number;
   @ApiProperty({ description: '登录标识' })
   'login_code': string = undefined;

+ 49 - 29
src/service/core/course.service.ts

@@ -3,40 +3,60 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
 import { ReturnModelType } from '@typegoose/typegoose';
 import { BaseService } from 'free-midway-component';
 import { Course } from '../../entity/core/course.entity';
+import { Video } from '../../entity/core/video.entity';
+import { get } from 'lodash';
 type modelType = ReturnModelType<typeof Course>;
 @Provide()
 export class CourseService extends BaseService<modelType> {
   @InjectEntityModel(Course)
   model: modelType;
+  @InjectEntityModel(Video)
+  vModel: ReturnModelType<typeof Video>;
 
-   // 首页查询
-   async list() {
-    const one = { type: '0', is_use: '0', status: '1' };
-    const two = { type: '1', is_use: '0', status: '1' };
-    const thr = { type: '2', is_use: '0', status: '1' };
-    const four = { type: '3', is_use: '0', status: '1' };
-    const five = { type: '4', is_use: '0', status: '1' };
-    let data;
-    data = await this.model.find(one).skip(0).limit(7).lean();
-    const oneInfo = data[0] || {};
-    const oneList = data.slice(1, 7) || [];
-    const oneTotal = await this.model.count(one);
-    data = await this.model.find(two).skip(0).limit(7).lean();
-    const twoInfo = data[0]|| {};
-    const twoList = data.slice(1, 7)|| [];
-    const twoTotal = await this.model.count(two);
-    data = await this.model.find(thr).skip(0).limit(7).lean();
-    const thrInfo = data[0]|| {};
-    const thrList = data.slice(1, 7)|| [];
-    const thrTotal = await this.model.count(thr);
-    data = await this.model.find(four).skip(0).limit(7).lean();
-    const fourInfo = data[0]|| {};
-    const fourList = data.slice(1, 7)|| [];
-    const fourTotal = await this.model.count(four);
-    data = await this.model.find(five).skip(0).limit(7).lean();
-    const fiveInfo = data[0]|| {};
-    const fiveList = data.slice(1, 7)|| [];
-    const fiveTotal = await this.model.count(five);
-    return { oneInfo, oneList, oneTotal, twoInfo, twoList, twoTotal, thrInfo, thrList, thrTotal, fourInfo, fourList, fourTotal, fiveInfo, fiveList, fiveTotal };
+  // 加浏览量
+  async fetchBrowse(data) {
+    const { number = 0, _id } = data;
+    await this.model.updateOne({ _id }, { number: number + 1 });
+  }
+
+  // // 首页查询
+  // async list() {
+  //   const one = { type: '0', is_use: '0', status: '1' };
+  //   const two = { type: '1', is_use: '0', status: '1' };
+  //   const thr = { type: '2', is_use: '0', status: '1' };
+  //   const four = { type: '3', is_use: '0', status: '1' };
+  //   const five = { type: '4', is_use: '0', status: '1' };
+  //   let data;
+  //   data = await this.model.find(one).skip(0).limit(7).lean();
+  //   const oneInfo = data[0] || {};
+  //   const oneList = data.slice(1, 7) || [];
+  //   const oneTotal = await this.model.count(one);
+  //   data = await this.model.find(two).skip(0).limit(7).lean();
+  //   const twoInfo = data[0] || {};
+  //   const twoList = data.slice(1, 7) || [];
+  //   const twoTotal = await this.model.count(two);
+  //   data = await this.model.find(thr).skip(0).limit(7).lean();
+  //   const thrInfo = data[0] || {};
+  //   const thrList = data.slice(1, 7) || [];
+  //   const thrTotal = await this.model.count(thr);
+  //   data = await this.model.find(four).skip(0).limit(7).lean();
+  //   const fourInfo = data[0] || {};
+  //   const fourList = data.slice(1, 7) || [];
+  //   const fourTotal = await this.model.count(four);
+  //   data = await this.model.find(five).skip(0).limit(7).lean();
+  //   const fiveInfo = data[0] || {};
+  //   const fiveList = data.slice(1, 7) || [];
+  //   const fiveTotal = await this.model.count(five);
+  //   return { oneInfo, oneList, oneTotal, twoInfo, twoList, twoTotal, thrInfo, thrList, thrTotal, fourInfo, fourList, fourTotal, fiveInfo, fiveList, fiveTotal };
+  // }
+  // 首页查询
+  async list(filter) {
+    const { skip = 0, limit = 0, ...info } = filter;
+    const data: any = await this.model.find(info).skip(skip).limit(limit).sort({ number: -1 }).lean();
+    for (const val of data) {
+      val.videoTotal = await this.vModel.count({ course: get(val, '_id') });
+    }
+    const total = await this.model.count(info);
+    return { data, total };
   }
 }

+ 11 - 0
src/service/core/help.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Help } from '../../entity/core/help.entity';
+type modelType = ReturnModelType<typeof Help>;
+@Provide()
+export class HelpService extends BaseService<modelType> {
+  @InjectEntityModel(Help)
+  model: modelType;
+}

+ 1 - 1
src/service/core/video.service.ts

@@ -10,7 +10,7 @@ export class VideoService extends BaseService<modelType> {
   model: modelType;
   // 加浏览量
   async fetchBrowse(data) {
-    const { number, _id } = data;
+    const { number = 0, _id } = data;
     await this.model.updateOne({ _id }, { number: number + 1 });
   }
   // 首页查询