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