order.js 1.4 KB

123456789101112131415161718192021222324252627282930313233
  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: '总金额明细' }, // 优惠,活动;商品总额和运费由商品而来
  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. };
  19. const schema = new Schema(order, { toJSON: { getters: true, virtuals: true } });
  20. schema.index({ id: 1 });
  21. schema.index({ 'meta.createdAt': 1 });
  22. schema.index({ customer: 1 });
  23. schema.index({ buy_time: 1 });
  24. schema.index({ pay_id: 1 });
  25. schema.index({ no: 1 });
  26. schema.plugin(metaPlugin);
  27. module.exports = app => {
  28. const { mongoose } = app;
  29. return mongoose.model('Order', schema, 'order');
  30. };