order.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. /**
  5. * 订单表:
  6. * 地址(address), 商品规格(goods) 都是快照 使用id重新查出来赋值回去
  7. * 之后的优惠都放在total_detail中进行计算
  8. */
  9. const order = {
  10. customer: { type: String, required: false, zh: '顾客', ref: 'User.User' }, //
  11. address: { type: Object, required: false, zh: '邮寄地址' }, // 快照
  12. goods: { type: Array, required: false, zh: '商品' }, // 按店铺分组,快照过来,带上备注[{店铺信息,商品列表:[{商品规格:{商品信息}}]}]
  13. total_detail: { type: Object, required: false, zh: '总金额明细' }, // 优惠,活动;商品总额和运费由商品而来:{货物总价,运费总价,优惠详情:{优惠券id:{规格id:优惠金额}}}
  14. buy_time: { type: String, required: false, zh: '下单时间' }, //
  15. no: { type: String, required: false, zh: '订单号' }, //
  16. status: { type: String, required: false, zh: '订单状态' }, // 字典:order_process
  17. pay: { type: Object, required: false, zh: '支付数据' }, // 有关支付时间,支付方式,支付订单号内容全都写在这里面
  18. type: { type: String, required: false, default: '0', zh: '订单类型' }, // 字典:order_type
  19. inviter: { type: String, required: false, zh: '推荐商品人', ref: 'User.User' }, // 返现部分
  20. };
  21. const schema = new Schema(order, { toJSON: { getters: true, virtuals: true } });
  22. schema.index({ id: 1 });
  23. schema.index({ 'meta.createdAt': 1 });
  24. schema.index({ customer: 1 });
  25. schema.index({ buy_time: 1 });
  26. schema.index({ no: 1 });
  27. schema.index({ type: 1 });
  28. schema.index({ inviter: 1 });
  29. schema.plugin(metaPlugin);
  30. module.exports = app => {
  31. const { mongoose } = app;
  32. return mongoose.model('Order', schema, 'order');
  33. };