market.js 1.1 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 { ObjectId } = require('mongoose').Types;
  5. // 商品表
  6. const market = {
  7. mech_id: { type: ObjectId }, // 商户id
  8. mech_name: { type: String }, // 商户名称
  9. type: { type: String }, // 分类
  10. type_id: { type: ObjectId }, // 分类id
  11. name: { type: String }, // 商品名称
  12. brief: { type: String }, // 简介
  13. money: { type: Number }, // 单价
  14. img_url: { type: Array }, // 图片
  15. status: { type: String }, // 状态 【0:待上架,1:上架,2:下架,3:删除】
  16. remark: { type: String },
  17. };
  18. const schema = new Schema(market, { toJSON: { virtuals: true } });
  19. schema.index({ id: 1 });
  20. schema.index({ mech_id: 1 });
  21. schema.index({ mech_name: 1 });
  22. schema.index({ type: 1 });
  23. schema.index({ type_id: 1 });
  24. schema.index({ name: 1 });
  25. schema.index({ money: 1 });
  26. schema.index({ status: 1 });
  27. schema.index({ 'meta.createdAt': 1 });
  28. schema.plugin(metaPlugin);
  29. module.exports = app => {
  30. const { mongoose } = app;
  31. return mongoose.model('Market', schema, 'market');
  32. };