'use strict'; const Schema = require('mongoose').Schema; const moment = require('moment'); const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin'); const { Secret } = require('naf-framework-mongoose-free/lib/model/schema'); const { ObjectId } = require('mongoose').Types; // 出售信息 const sells = new Schema({ sell_id: { type: ObjectId }, // 出售id selluser_id: { type: ObjectId }, // 出售者id contacts: { type: String }, // 出售者联系人 phone: { type: String }, // 出售者手机号 email: { type: String }, // 出售者电子邮箱 patent_id: { type: String }, // 出售者专利id patent_type: { type: String }, // 出售者专利类型 selle_type: { type: String }, // 出售者交易类型 money: { type: String }, // 出售者钱(元/年) }); // 求购信息 const purchases = new Schema({ purchases_id: { type: ObjectId }, // 求购id purchasesuser_id: { type: ObjectId }, // 求购者id contacts: { type: String }, // 求购者联系人 phone: { type: String }, // 求购者手机号 email: { type: String }, // 求购者电子邮箱 demand: { type: String }, // 求购者需求 patent_type: { type: String }, // 求购者专利类型 purchases_type: { type: String }, // 求购者交易类型 money: { type: String }, // 出售者钱(万元) }); // 订单表 const tradeorder = { order_num: { type: String }, // 订单id buyer_id: { type: ObjectId }, // 买家id buyer_contacts: { type: String }, // 买家联系人 buyer_phone: { type: String }, // 买家手机号 buyer_email: { type: String }, // 买家邮箱 type: { type: String }, // 订单类型 sell: { type: sells }, // 出售信息 purchase: { type: purchases }, // 求购信息 status: { type: String }, // 状态 remark: { type: String }, }; const schema = new Schema(tradeorder, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ order_id: 1 }); schema.index({ buyer_id: 1 }); schema.index({ sell_id: 1 }); schema.index({ selluser_id: 1 }); schema.index({ purchases_id: 1 }); schema.index({ purchasesuser_id: 1 }); schema.index({ status: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Tradeorder', schema, 'trade_order'); };