home.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. await this.ctx.service.util.rabbitMq.initTestQueue();
  8. await this.ctx.service.util.rabbitMq.toDead();
  9. }
  10. async m1() {
  11. const { taskMqConfig } = this.app.config;
  12. const body = this.ctx.request.body;
  13. await this.ctx.service.util.rabbitMq.makeTask(taskMqConfig.queue, body);
  14. this.ctx.ok();
  15. }
  16. async makeCoupons() {
  17. const dictDataModel = this.ctx.model.Dev.DictData;
  18. const couponModel = this.ctx.model.Trade.Coupon;
  19. // 过期字典
  20. const expList = await dictDataModel.find({ code: 'coupon_expire_type' });
  21. // 减免字典
  22. const disList = await dictDataModel.find({ code: 'coupon_discount_type' });
  23. // 使用字典
  24. const useList = await dictDataModel.find({ code: 'coupon_use_limit' });
  25. // 领取字典
  26. const getList = await dictDataModel.find({ code: 'coupon_get_limit' });
  27. const arr = [];
  28. for (const e of expList) {
  29. const { value: expire_type, label: el } = e;
  30. for (const d of disList) {
  31. const { value: discount_type, label: dl } = d;
  32. for (const u of useList) {
  33. const { value: use_limit, label: ul } = u;
  34. for (const g of getList) {
  35. const { value: get_limit, label: gl } = g;
  36. const obj = { issue: '0', expire_type, discount_type, use_limit, get_limit, num: 100, status: '0' };
  37. obj.name = `平台测试优惠券-${el}-${dl}-${ul}-${gl}`;
  38. arr.push(obj);
  39. }
  40. }
  41. }
  42. }
  43. await couponModel.insertMany(arr);
  44. return arr;
  45. }
  46. }
  47. module.exports = HomeController;