1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 'use strict';
- const Service = require('../service/baseService');
- class ValueService extends Service {
- tag() {
- return this.ctx.model.ValueModel;
- }
- async userValueDetails(query) {
- const { ctx } = this;
- const { model } = ctx;
- const { id } = query;
- if (id) {
- const valueInfoList = await model.ValueModel.aggregate([
- { $match: { userid: this.app.mongoose.Types.ObjectId(id), type: '0' } },
- { $lookup: { from: 'info', localField: 'infoId', foreignField: '_id', as: 'infos' } },
- { $unwind: { path: '$infos', preserveNullAndEmptyArrays: true } },
- { $project: {
- _id: 0,
- oldName: '$infos.name',
- time: '$infos.time',
- } },
- { $sort: { time: -1 } },
- ]).allowDiskUse(true);// 允许使用磁盘缓存
- const valueVisitList = await model.ValueModel.aggregate([
- { $match: { userid: this.app.mongoose.Types.ObjectId(id), type: '1' } },
- { $lookup: { from: 'info', localField: 'infoId', foreignField: '_id', as: 'infos' } },
- { $unwind: { path: '$infos', preserveNullAndEmptyArrays: true } },
- { $project: {
- _id: 0,
- oldName: '$infos.name',
- time: '$time',
- } },
- { $sort: { time: -1 } },
- ]).allowDiskUse(true);// 允许使用磁盘缓存
- const valueInfoCount = await model.ValueModel.find({ userid: id, type: '0' }).countDocuments();
- const valueVisitCount = await model.ValueModel.find({ userid: id, type: '1' }).countDocuments();
- const userTotalValue = 5 * valueInfoCount + valueVisitCount;
- return {
- valueInfoCount, valueVisitCount, userTotalValue, valueInfoList, valueVisitList,
- };
- }
- return null;
- }
- }
- module.exports = ValueService;
|