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