goodsRate.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. const reply = [{
  5. content: { type: String, zh: '内容' },
  6. time: { type: String, zh: '时间' },
  7. file: { type: Array, zh: '图片' },
  8. reply: { type: String, zh: '店家回复' },
  9. }];
  10. // 商品评价
  11. const goodsRate = {
  12. customer: { type: String, required: false, zh: '用户', ref: 'User.User' }, //
  13. orderDetail: { type: String, required: false, zh: '订单', ref: 'Trade.OrderDetail' }, //
  14. shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, //
  15. goods: { type: String, required: false, zh: '商品', ref: 'Shop.Goods' }, //
  16. goodsSpec: { type: String, required: false, zh: '规格', ref: 'Shop.GoodsSpec' }, //
  17. set_id: { type: String, required: false, zh: '套装id' },
  18. reply: { type: Array, required: false, zh: '回复' }, //
  19. goods_score: { type: Number, required: false, default: 5, zh: '商品评分' }, //
  20. shop_score: { type: Number, required: false, default: 5, zh: '服务评分' }, //
  21. transport_score: { type: Number, required: false, default: 5, zh: '快递评分' }, //
  22. };
  23. const schema = new Schema(goodsRate, { toJSON: { getters: true, virtuals: true } });
  24. schema.index({ id: 1 });
  25. schema.index({ 'meta.createdAt': 1 });
  26. schema.index({ customer: 1 });
  27. schema.index({ shop: 1 });
  28. schema.index({ goods: 1 });
  29. schema.index({ goodsSpec: 1 });
  30. schema.index({ orderDetail: 1 });
  31. schema.plugin(metaPlugin);
  32. module.exports = app => {
  33. const { mongoose } = app;
  34. return mongoose.model('GoodsRate', schema, 'goodsRate');
  35. };