'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 goodsConfig = { shop: { type: String, required: false, zh: '店铺id', ref: 'Shop' }, // goods: { type: String, required: false, zh: '商品id', ref: 'Goods' }, // spec: { type: String, required: false, zh: '规格id', ref: 'GoodsSpec' }, // }; const schema = new Schema(goodsConfig, { toJSON: { getters: true, virtuals: true } }); schema.index({ id: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.index({ shop: 1 }); schema.index({ goods: 1 }); schema.index({ spec: 1 }); schema.plugin(metaPlugin); schema.plugin(MoneyPlugin({ zh: '团长价', required: false, key: 'leader_price' })); schema.plugin(MoneyPlugin({ zh: '团购价', required: false, key: 'price' })); schema.plugin(MoneyPlugin({ zh: '团长提成金额', required: false, key: 'leader_get' })); schema.plugin(MoneyPlugin({ zh: '运费', required: false, key: 'freight' })); module.exports = app => { const { mongoose } = app; return mongoose.model('GoodsConfig', schema, 'goodsConfig'); };