|
@@ -0,0 +1,26 @@
|
|
|
+'use strict';
|
|
|
+const Schema = require('mongoose').Schema;
|
|
|
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
|
|
|
+
|
|
|
+// 购物车
|
|
|
+const cart = {
|
|
|
+ customer: { type: String, required: false, zh: '顾客', ref: 'User.User' }, //
|
|
|
+ shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, //
|
|
|
+ goods: { type: String, required: false, zh: '商品', ref: 'Shop.Goods' }, //
|
|
|
+ goodsSpec: { type: String, required: false, zh: '商品规格', ref: 'Shop.GoodsSpec' }, //
|
|
|
+ num: { type: Number, required: false, zh: '数量' }, //
|
|
|
+};
|
|
|
+const schema = new Schema(cart, { toJSON: { getters: true, virtuals: true } });
|
|
|
+schema.index({ id: 1 });
|
|
|
+schema.index({ 'meta.createdAt': 1 });
|
|
|
+schema.index({ customer: 1 });
|
|
|
+schema.index({ shop: 1 });
|
|
|
+schema.index({ goods: 1 });
|
|
|
+schema.index({ goodsSpec: 1 });
|
|
|
+
|
|
|
+schema.plugin(metaPlugin);
|
|
|
+
|
|
|
+module.exports = app => {
|
|
|
+ const { mongoose } = app;
|
|
|
+ return mongoose.model('Cart', schema, 'cart');
|
|
|
+};
|