12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
- // 失效配置: expire_type nolimit 不需要设置
- const expire_config = {
- fixed: [{ start: '生效开始日期', end: '生效结束日期' }], // 存数组
- days: '生效${days}天后过期', // Number
- };
- // 减免配置: 在limit中, 都有一个选项,是无限制(nolimit)
- // min(减免)/dicount(折扣)
- const discount_config = {
- limit: '使用券的金额下限',
- min: '满减:减多少 / 折扣:9折 = 90%;8.5折=85%; 输入前面 x折的 x',
- max: '上限,折扣有上限,满减不取上限',
- };
- // 使用配置: use_limit为all时,不需要这个设置
- const use_limit_config = {
- tags: '指定商品类型',
- };
- // 领取配置: get_limit为nolimit时,不需要这个设置
- const get_limit_config = {
- max: '限制每人做多领取多少张该优惠券',
- };
- // 优惠券
- const coupon = {
- issue: { type: String, required: false, zh: '发行方' }, // 字典:coupon_issue 平台/店铺
- shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, // 店铺发行的需要有店铺关联
- name: { type: String, required: false, zh: '优惠券名称' }, //
- expire_type: { type: String, required: false, zh: '失效方式' }, // 字典:coupon_expire_type
- expire_config: { type: Object, required: false, zh: '失效配置' }, //
- discount_type: { type: String, required: false, zh: '减免方式' }, // 字典:coupon_discount_type
- discount_config: { type: Object, required: false, zh: '减免配置' }, //
- use_limit: { type: String, required: false, zh: '使用限制' }, // 字典:coupon_use_limit
- use_limit_config: { type: Object, required: false, zh: '使用配置' }, //
- get_limit: { type: String, required: false, zh: '领取限制' }, // 字典:coupon_get_limit
- get_limit_config: { type: Object, required: false, zh: '领取配置' }, //
- num: { type: Number, required: false, zh: '数量' }, //
- status: { type: String, required: false, zh: '使用状态' }, // 字典:use
- };
- 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({ name: 1 });
- schema.index({ expire_type: 1 });
- schema.index({ discount_type: 1 });
- schema.index({ use_limit: 1 });
- schema.index({ get_limit: 1 });
- schema.index({ status: 1 });
- schema.plugin(metaPlugin);
- module.exports = app => {
- const { mongoose } = app;
- return mongoose.model('Coupon', schema, 'coupon');
- };
|