goodsSpec.js 1.2 KB

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. const MoneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-plugin');
  5. // 商品规格
  6. const goodsSpec = {
  7. goods: { type: String, required: false, zh: '商品源', ref: 'Shop.Goods' }, //
  8. name: { type: String, required: false, zh: '规格名称' }, //
  9. num: { type: Number, required: false, zh: '库存' }, //
  10. status: { type: String, required: false, default: '0', zh: '状态' }, // 字典status
  11. };
  12. const schema = new Schema(goodsSpec, { toJSON: { getters: true, virtuals: true } });
  13. schema.index({ id: 1 });
  14. schema.index({ 'meta.createdAt': 1 });
  15. schema.index({ goods: 1 });
  16. schema.index({ name: 1 });
  17. schema.index({ status: 1 });
  18. schema.plugin(metaPlugin);
  19. schema.plugin(MoneyPlugin({ zh: '实际销售价格', required: false, key: 'sell_money' }));
  20. schema.plugin(MoneyPlugin({ zh: '划掉销售价格', required: false, key: 'flow_money' }));
  21. schema.plugin(MoneyPlugin({ zh: '运费', required: false, key: 'freight' }));
  22. module.exports = app => {
  23. const { mongoose } = app;
  24. return mongoose.model('GoodsSpec', schema, 'goodsSpec');
  25. };