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