coupons.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  5. const { ObjectId } = require('mongoose').Types;
  6. // 创新券表
  7. const coupons = {
  8. user_id: { type: ObjectId }, // 创建者id
  9. coupons_type: { type: String }, // 类型:科技创新券;研发补贴;奖励兑现
  10. name: { type: String }, // 名称
  11. discount_type: { type: String }, // 折扣类型: 全额折扣券;折扣券;定额折扣券
  12. use_type: { type: String }, // 使用服务类型
  13. classify: { type: String }, // 所属分类
  14. limit_time: { type: Number }, // 期限
  15. scale: { type: String }, // 抵扣比例-为折扣券
  16. allowance: { type: String }, // 面额
  17. total_allowance: { type: String }, // 券总额度
  18. desc: { type: String }, // 描述
  19. status: { type: String, default: '0' }, // 0:待上架;1:上架;-1:下架
  20. remark: { type: String },
  21. };
  22. const schema = new Schema(coupons, { toJSON: { virtuals: true } });
  23. schema.index({ id: 1 });
  24. schema.index({ user_id: 1 });
  25. schema.index({ type: 1 });
  26. schema.index({ name: 1 });
  27. schema.index({ coupons_type: 1 });
  28. schema.index({ discount_type: 1 });
  29. schema.index({ use_type: 1 });
  30. schema.index({ classify: 1 });
  31. schema.index({ limit_time: 1 });
  32. schema.index({ 'meta.createdAt': 1 });
  33. schema.plugin(metaPlugin);
  34. module.exports = app => {
  35. const { mongoose } = app;
  36. return mongoose.model('Coupons', schema, 'coupons');
  37. };