cart.js 960 B

1234567891011121314151617181920212223242526
  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. num: { type: Number, required: false, zh: '数量' }, //
  11. };
  12. const schema = new Schema(cart, { toJSON: { getters: true, virtuals: true } });
  13. schema.index({ id: 1 });
  14. schema.index({ 'meta.createdAt': 1 });
  15. schema.index({ customer: 1 });
  16. schema.index({ shop: 1 });
  17. schema.index({ goods: 1 });
  18. schema.index({ goodsSpec: 1 });
  19. schema.plugin(metaPlugin);
  20. module.exports = app => {
  21. const { mongoose } = app;
  22. return mongoose.model('Cart', schema, 'cart');
  23. };