cart.js 1.2 KB

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. // 购物车
  5. const cart = {
  6. customer: { type: String, required: false, zh: '顾客', ref: 'User.User' }, //
  7. shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, //
  8. goods: { type: String, required: false, zh: '商品', ref: 'Shop.Goods' }, //
  9. goodsSpec: { type: String, required: false, zh: '商品规格', ref: 'Shop.GoodsSpec' }, //
  10. act: { type: Array, zh: '活动相关' },
  11. num: { type: Number, required: false, zh: '数量' }, //
  12. is_set: { type: String, required: false, default: '1', zh: '是否是套装' }, // 字典:is_use,默认不是
  13. set_id: { type: String, required: false, zh: '套装id', ref: 'Shop.GoodsSet' }, //
  14. };
  15. const schema = new Schema(cart, { toJSON: { getters: true, virtuals: true } });
  16. schema.index({ id: 1 });
  17. schema.index({ 'meta.createdAt': 1 });
  18. schema.index({ customer: 1 });
  19. schema.index({ shop: 1 });
  20. schema.index({ goods: 1 });
  21. schema.index({ goodsSpec: 1 });
  22. schema.index({ is_set: 1 });
  23. schema.index({ set_id: 1 });
  24. schema.plugin(metaPlugin);
  25. module.exports = app => {
  26. const { mongoose } = app;
  27. return mongoose.model('Cart', schema, 'cart');
  28. };