'use strict'; const Service = require('egg').Service; class ExportsService extends Service { // 用户导出 async exportsuser({ filter, skip, ids, _this }) { const key = Object.keys(filter); if (key.length > 0) return await _this.ctx.model.User.find({ ...filter }).skip(skip * 10).limit(10); if (ids) { let list = await Promise.all( ids.map(async e => { const res = await _this.ctx.model.User.findOne({ _id: e }); if (res) return res; }) ); list = list.filter(e => e !== undefined); return list; } return await _this.ctx.model.User.find().skip(skip * 10).limit(10); } // vip导出 async exportsvip({ filter, skip, ids, _this }) { const key = Object.keys(filter); if (key.length > 0) return await _this.ctx.model.Vip.find({ ...filter }).skip(skip * 10).limit(10); if (ids) { let list = await Promise.all( ids.map(async e => { const res = await _this.ctx.model.User.findOne({ _id: e }); if (res) return res; }) ); list = list.filter(e => e !== undefined); return list; } return await _this.ctx.model.User.find().skip(skip * 10).limit(10); } // 数据转换函数 async convert({ data }) { console.log(data); // startTime endTime status return data; } } module.exports = ExportsService;