123456789101112131415161718192021222324252627282930 |
- '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' }, //
- act: { type: Array, zh: '活动相关' },
- num: { type: Number, required: false, zh: '数量' }, //
- is_set: { type: String, required: false, default: '1', zh: '是否是套装' }, // 字典:is_use,默认不是
- set_id: { type: String, required: false, zh: '套装id', ref: 'Shop.GoodsSet' }, //
- };
- 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.index({ is_set: 1 });
- schema.index({ set_id: 1 });
- schema.plugin(metaPlugin);
- module.exports = app => {
- const { mongoose } = app;
- return mongoose.model('Cart', schema, 'cart');
- };
|