1234567891011121314151617181920212223242526272829 |
- '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 goodsSpec = {
- goods: { type: String, required: false, zh: '商品源', ref: 'Shop.Goods' }, //
- name: { type: String, required: false, zh: '规格名称' }, //
- num: { type: Number, required: false, zh: '库存' }, //
- status: { type: String, required: false, default: '0', zh: '状态' }, // 字典status
- };
- const schema = new Schema(goodsSpec, { toJSON: { getters: true, virtuals: true } });
- schema.index({ id: 1 });
- schema.index({ 'meta.createdAt': 1 });
- schema.index({ goods: 1 });
- schema.index({ name: 1 });
- schema.index({ status: 1 });
- schema.plugin(metaPlugin);
- schema.plugin(MoneyPlugin({ zh: '实际销售价格', required: false, key: 'sell_money' }));
- schema.plugin(MoneyPlugin({ zh: '划掉销售价格', required: false, key: 'flow_money' }));
- schema.plugin(MoneyPlugin({ zh: '运费', required: false, key: 'freight' }));
- module.exports = app => {
- const { mongoose } = app;
- return mongoose.model('GoodsSpec', schema, 'goodsSpec');
- };
|