'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin'); // content同下 const act_time = { value: { type: String, zh: '对应的值' }, is_use: { type: String, zh: '是否使用' }, // 字典:is_use title: { type: String, zh: '活动标题' }, }; // 满折 const manZhe = { limit: { type: Number, zh: '消费金额下限----x' }, number: { type: Number, zh: '减免折扣----y' }, max: { type: Number, zh: '优惠上限' }, }; // 满减设置 const manJian = { limit: { type: Number, zh: '消费金额下限----x' }, number: { type: Number, zh: '减免金额----y' }, }; const config = { time_start: { type: String, zh: '开始时间' }, // 死信机制,用来限时关闭活动 time_end: { type: String, zh: '结束时间' }, // 死信机制,用来限时关闭活动 // 满减部分, 只有满减和满折在平台活动设置,剩下的都是和商品有关的 discount: { type: [ manJian ] || [ manZhe ], zh: '满减档位' }, // 加价购部分 plus_money: { type: Number, zh: '加价购下限金额' }, }; // 平台活动 const platformAct = { // title: { type: String, required: false, zh: '活动标题' }, // 转移到活动时间下 share: { type: Array, required: false, zh: '分享图片' }, // cover: { type: Array, required: false, zh: '封面图片' }, // act_time: { type: Object, required: false, zh: '活动时间' }, // value:值;is_use:字典(is_use)是否启用 content: { type: Object, required: false, zh: '活动说明' }, // 富文本;value:值;is_use:字典(is_use)是否启用,title:活动标题 is_use: { type: String, required: false, default: '1', zh: '是否开启' }, // 字典:is_use,默认不开启 show_index: { type: String, required: false, default: '0', zh: '是否在首页显示' }, // 字典:is_use sort: { type: Number, required: false, default: 0, zh: '排序' }, // type: { type: String, required: false, zh: '活动类型' }, // 字典:act_type config: { type: Object, required: false, zh: '设置' }, // }; const schema = new Schema(platformAct, { toJSON: { getters: true, virtuals: true } }); schema.index({ id: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.index({ sort: 1 }); schema.index({ is_use: 1 }); schema.index({ show_index: 1 }); schema.index({ type: 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('PlatformAct', schema, 'platformAct'); };