coupon.js 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. const MoneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-plugin');
  5. // 优惠券
  6. const coupon = {
  7. issue: { type: String, required: false, zh: '发行方' }, // 字典:coupon_issue 平台/店铺
  8. shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, // 店铺发行的需要有店铺关联
  9. can_plus: { type: String, required: false, zh: '可叠加' }, // 字典:use
  10. use_time: { type: String, required: false, zh: '时间限制' }, // 字典:use
  11. time_start: { type: String, required: false, zh: '开始时间' }, //
  12. time_end: { type: String, required: false, zh: '结束时间' }, //
  13. num: { type: String, required: false, zh: '数量' }, // 没有就是不限制
  14. status: { type: String, required: false, default: '0', zh: '状态' }, // 字典:coupon_status
  15. is_use: { type: String, required: false, zh: '是否使用' }, // 字典:use
  16. tags: { type: Array, required: false, zh: '商品类型' }, // 优惠券适用于的商品标签.没有就是全都适用
  17. };
  18. const schema = new Schema(coupon, { toJSON: { getters: true, virtuals: true } });
  19. schema.index({ id: 1 });
  20. schema.index({ 'meta.createdAt': 1 });
  21. schema.index({ shop: 1 });
  22. schema.index({ time_start: 1 });
  23. schema.index({ time_end: 1 });
  24. schema.plugin(metaPlugin);
  25. schema.plugin(MoneyPlugin({ zh: '适用价格', required: false, key: 'money' }));
  26. module.exports = app => {
  27. const { mongoose } = app;
  28. return mongoose.model('Coupon', schema, 'coupon');
  29. };