order.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  5. const { ObjectId } = require('mongoose').Types;
  6. const meal = new Schema({
  7. list: { type: Array }, // 点餐内容
  8. reserve: { type: Number, default: 0 }, // 卡路里,热量
  9. is_use: { type: String, default: '0' }, // 是否使用:0-待使用;1-待评价;2-已完成;3-失效
  10. });
  11. // 订餐表
  12. const order = {
  13. user_id: { type: String }, // 用户id(预留)
  14. date: { type: String, required: true }, // 日期
  15. breakfast: { type: meal }, // 早餐
  16. lunch: { type: meal }, // 午餐
  17. dinner: { type: meal }, // 晚餐
  18. openid: { type: String }, // openid
  19. remark: { type: String },
  20. };
  21. const schema = new Schema(order, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  22. schema.index({ id: 1 });
  23. schema.index({ date: 1 });
  24. schema.index({ user_id: 1 });
  25. schema.index({ openid: 1 });
  26. schema.index({ 'meta.createdAt': 1 });
  27. schema.plugin(metaPlugin);
  28. module.exports = app => {
  29. const { mongoose } = app;
  30. return mongoose.model('Order', schema, 'order');
  31. };