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