12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 'use strict';
- const Controller = require('egg').Controller;
- class HomeController extends Controller {
- async index() {
- const { ctx } = this;
- ctx.body = 'hi, egg';
- // 模拟优惠券发行
- // const data = await this.makeCoupons();
- // this.ctx.ok({ data, total: data.length });
- }
- async makeCoupons() {
- const dictDataModel = this.ctx.model.Dev.DictData;
- const couponModel = this.ctx.model.Trade.Coupon;
- // 过期字典
- const expList = await dictDataModel.find({ code: 'coupon_expire_type' });
- // 减免字典
- const disList = await dictDataModel.find({ code: 'coupon_discount_type' });
- // 使用字典
- const useList = await dictDataModel.find({ code: 'coupon_use_limit' });
- // 领取字典
- const getList = await dictDataModel.find({ code: 'coupon_get_limit' });
- const arr = [];
- for (const e of expList) {
- const { value: expire_type, label: el } = e;
- for (const d of disList) {
- const { value: discount_type, label: dl } = d;
- for (const u of useList) {
- const { value: use_limit, label: ul } = u;
- for (const g of getList) {
- const { value: get_limit, label: gl } = g;
- const obj = { issue: '0', expire_type, discount_type, use_limit, get_limit, num: 100, status: '0' };
- obj.name = `平台测试优惠券-${el}-${dl}-${ul}-${gl}`;
- arr.push(obj);
- }
- }
- }
- }
- await couponModel.insertMany(arr);
- return arr;
- }
- }
- module.exports = HomeController;
|