userCoupon.js 905 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. // 领劵记录
  5. const userCoupon = {
  6. customer: { type: String, required: false, zh: '顾客', ref: 'User.User' }, //
  7. shop: { type: String, required: false, zh: '发行店铺', ref: 'Shop.Shop' }, //
  8. coupon: { type: Object, required: false, zh: '优惠券' }, //
  9. status: { type: String, required: false, default: '0', zh: '是否使用' }, //
  10. };
  11. const schema = new Schema(userCoupon, { toJSON: { getters: true, virtuals: true } });
  12. schema.index({ id: 1 });
  13. schema.index({ 'meta.createdAt': 1 });
  14. schema.index({ customer: 1 });
  15. schema.index({ shop: 1 });
  16. schema.index({ coupon: 1 });
  17. schema.index({ status: 1 });
  18. schema.plugin(metaPlugin);
  19. module.exports = app => {
  20. const { mongoose } = app;
  21. return mongoose.model('UserCoupon', schema, 'userCoupon');
  22. };