goodsSpec.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  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. buy_limit: { type: String, required: false, default: '0', zh: '购买限制' }, // 字典表:buy_limit
  11. limit_num: { type: Number, required: false, zh: '限制数量界限' }, //
  12. status: { type: String, required: false, default: '0', zh: '状态' }, // 字典:use
  13. file: { type: Array, required: false, zh: '图片' }, //
  14. sort: { type: Number, required: false, default: '0', zh: '排序' }, //
  15. };
  16. const schema = new Schema(goodsSpec, { toJSON: { getters: true, virtuals: true } });
  17. schema.index({ id: 1 });
  18. schema.index({ 'meta.createdAt': 1 });
  19. schema.index({ goods: 1 });
  20. schema.index({ name: 1 });
  21. schema.index({ buy_limit: 1 });
  22. schema.index({ status: 1 });
  23. schema.index({ sort: 1 });
  24. schema.plugin(metaPlugin);
  25. schema.plugin(MoneyPlugin({ zh: '实际销售价格', required: false, key: 'sell_money' }));
  26. schema.plugin(MoneyPlugin({ zh: '划掉销售价格', required: false, key: 'flow_money' }));
  27. schema.plugin(MoneyPlugin({ zh: '运费', required: false, key: 'freight' }));
  28. schema.plugin(MoneyPlugin({ zh: '团长价格', required: false, key: 'leader_price' }));
  29. module.exports = app => {
  30. const { mongoose } = app;
  31. return mongoose.model('GoodsSpec', schema, 'goodsSpec');
  32. };