cart.js 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. const act = {
  5. // 套装: 需要找到套装的商品,统一归为一个商品
  6. platform_act: { type: String, zh: '活动id' },
  7. set_id: { type: String, zh: '参加套装活动的商品组合数据id' },
  8. };
  9. // 购物车
  10. const cart = {
  11. customer: { type: String, required: false, zh: '顾客', ref: 'User.User' }, //
  12. shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, //
  13. goods: { type: String, required: false, zh: '商品', ref: 'Shop.Goods' }, //
  14. goodsSpec: { type: String, required: false, zh: '商品规格', ref: 'Shop.GoodsSpec' }, //
  15. act: { type: Array, zh: '活动相关' },
  16. num: { type: Number, required: false, zh: '数量' }, //
  17. };
  18. const schema = new Schema(cart, { toJSON: { getters: true, virtuals: true } });
  19. schema.index({ id: 1 });
  20. schema.index({ 'meta.createdAt': 1 });
  21. schema.index({ customer: 1 });
  22. schema.index({ shop: 1 });
  23. schema.index({ goods: 1 });
  24. schema.index({ goodsSpec: 1 });
  25. schema.plugin(metaPlugin);
  26. module.exports = app => {
  27. const { mongoose } = app;
  28. return mongoose.model('Cart', schema, 'cart');
  29. };