home.js 1.6 KB

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