exports.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. const Service = require('egg').Service;
  3. class ExportsService extends Service {
  4. // 用户导出
  5. async exportsuser({ filter, skip, ids, _this }) {
  6. const key = Object.keys(filter);
  7. if (key.length > 0) return await _this.ctx.model.User.find({ ...filter }).skip(skip * 10).limit(10);
  8. if (ids) {
  9. let list = await Promise.all(
  10. ids.map(async e => {
  11. const res = await _this.ctx.model.User.findOne({ _id: e });
  12. if (res) return res;
  13. })
  14. );
  15. list = list.filter(e => e !== undefined);
  16. return list;
  17. }
  18. return await _this.ctx.model.User.find().skip(skip * 10).limit(10);
  19. }
  20. // vip导出
  21. async exportsvip({ filter, skip, ids, _this }) {
  22. const key = Object.keys(filter);
  23. if (key.length > 0) return await _this.ctx.model.Vip.find({ ...filter }).skip(skip * 10).limit(10);
  24. if (ids) {
  25. let list = await Promise.all(
  26. ids.map(async e => {
  27. const res = await _this.ctx.model.User.findOne({ _id: e });
  28. if (res) return res;
  29. })
  30. );
  31. list = list.filter(e => e !== undefined);
  32. return list;
  33. }
  34. return await _this.ctx.model.User.find().skip(skip * 10).limit(10);
  35. }
  36. // 数据转换函数
  37. async convert({ data }) {
  38. console.log(data);
  39. // startTime endTime status
  40. return data;
  41. }
  42. }
  43. module.exports = ExportsService;