transaction.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 pact = new Schema({
  9. file_path: { type: String }, // 合同图片
  10. desc: { type: String }, // 描述
  11. status: { type: String, default: '0' }, // 状态(0:待审核 1:通过审核)
  12. });
  13. // 交易表
  14. const transaction = {
  15. dock_id: { type: ObjectId }, // 展会id
  16. supplier: { type: ObjectId }, // 供给者
  17. s_name: { type: String }, // 供给者姓名
  18. s_phone: { type: String }, // 供给者联系电话
  19. demander: { type: ObjectId }, // 需求者
  20. d_name: { type: String }, // 需求者姓名
  21. d_phone: { type: String }, // 需求者联系电话
  22. product_id: { type: ObjectId }, // 产品id
  23. product: { type: String }, // 产品名称
  24. pact: { type: pact }, // 合同备案
  25. status: { type: String, default: '0' }, // 状态(0-正在洽谈;1-达成意向;2-交易备案(待确定);3-交易完成;4-交易失败)
  26. remark: { type: String, maxLength: 200 },
  27. create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
  28. };
  29. const schema = new Schema(transaction, { toJSON: { virtuals: true } });
  30. schema.index({ id: 1 });
  31. schema.index({ dock_id: 1 });
  32. schema.index({ supplier: 1 });
  33. schema.index({ demander: 1 });
  34. schema.index({ product: 1 });
  35. schema.index({ 'meta.createdAt': 1 });
  36. schema.plugin(metaPlugin);
  37. module.exports = app => {
  38. const { mongoose } = app;
  39. return mongoose.model('Transaction', schema, 'transaction');
  40. };