'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: '总金额明细' }, // 优惠,活动;商品总额和运费由商品而来 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: '支付数据' }, // 有关支付时间,支付方式,支付订单号内容全都写在这里面 }; 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({ pay_id: 1 }); schema.index({ no: 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Order', schema, 'order'); };