tradeorder.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  5. const { Secret } = require('naf-framework-mongoose/lib/model/schema');
  6. const { ObjectId } = require('mongoose').Types;
  7. // 出售信息
  8. const sells = new Schema({
  9. sell_id: { type: ObjectId }, // 出售id
  10. selluser_id: { type: ObjectId }, // 出售者id
  11. contacts: { type: String }, // 出售者联系人
  12. phone: { type: String }, // 出售者手机号
  13. email: { type: String }, // 出售者电子邮箱
  14. patent_id: { type: String }, // 出售者专利id
  15. patent_type: { type: String }, // 出售者专利类型
  16. selle_type: { type: String }, // 出售者交易类型
  17. money: { type: String }, // 出售者钱(元/年)
  18. });
  19. // 求购信息
  20. const purchases = new Schema({
  21. purchases_id: { type: ObjectId }, // 求购id
  22. purchasesuser_id: { type: ObjectId }, // 求购者id
  23. contacts: { type: String }, // 求购者联系人
  24. phone: { type: String }, // 求购者手机号
  25. email: { type: String }, // 求购者电子邮箱
  26. demand: { type: String }, // 求购者需求
  27. patent_type: { type: String }, // 求购者专利类型
  28. purchases_type: { type: String }, // 求购者交易类型
  29. money: { type: String }, // 出售者钱(万元)
  30. });
  31. // 订单表
  32. const tradeorder = {
  33. order_num: { type: String }, // 订单id
  34. buyer_id: { type: ObjectId }, // 买家id
  35. buyer_contacts: { type: String }, // 买家联系人
  36. buyer_phone: { type: String }, // 买家手机号
  37. buyer_email: { type: String }, // 买家邮箱
  38. type: { type: String }, // 订单类型
  39. sell: { type: sells }, // 出售信息
  40. purchase: { type: purchases }, // 求购信息
  41. status: { type: String }, // 状态
  42. remark: { type: String },
  43. };
  44. const schema = new Schema(tradeorder, { toJSON: { virtuals: true } });
  45. schema.index({ id: 1 });
  46. schema.index({ order_id: 1 });
  47. schema.index({ buyer_id: 1 });
  48. schema.index({ sell_id: 1 });
  49. schema.index({ selluser_id: 1 });
  50. schema.index({ purchases_id: 1 });
  51. schema.index({ purchasesuser_id: 1 });
  52. schema.index({ status: 1 });
  53. schema.index({ 'meta.createdAt': 1 });
  54. schema.plugin(metaPlugin);
  55. module.exports = app => {
  56. const { mongoose } = app;
  57. return mongoose.model('Tradeorder', schema, 'trade_order');
  58. };