home.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. class HomeController extends Controller {
  4. async index() {
  5. const { ctx } = this;
  6. ctx.body = 'hi, egg';
  7. }
  8. async makeCoupons() {
  9. const dictDataModel = this.ctx.model.Dev.DictData;
  10. const couponModel = this.ctx.model.Trade.Coupon;
  11. // 过期字典
  12. const expList = await dictDataModel.find({ code: 'coupon_expire_type' });
  13. // 减免字典
  14. const disList = await dictDataModel.find({ code: 'coupon_discount_type' });
  15. // 使用字典
  16. const useList = await dictDataModel.find({ code: 'coupon_use_limit' });
  17. // 领取字典
  18. const getList = await dictDataModel.find({ code: 'coupon_get_limit' });
  19. const arr = [];
  20. for (const e of expList) {
  21. const { value: expire_type, label: el } = e;
  22. for (const d of disList) {
  23. const { value: discount_type, label: dl } = d;
  24. for (const u of useList) {
  25. const { value: use_limit, label: ul } = u;
  26. for (const g of getList) {
  27. const { value: get_limit, label: gl } = g;
  28. const obj = { issue: '0', expire_type, discount_type, use_limit, get_limit, num: 100, status: '0' };
  29. obj.name = `平台测试优惠券-${el}-${dl}-${ul}-${gl}`;
  30. arr.push(obj);
  31. }
  32. }
  33. }
  34. }
  35. await couponModel.insertMany(arr);
  36. return arr;
  37. }
  38. }
  39. module.exports = HomeController;