matchSign.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. // 赛事报名
  5. const match_sign = {
  6. match_id: { type: String, required: true, zh: '赛事id', ref: 'Race.Match', getProp: [ 'name', 'status', 'contact' ] }, // 比赛信息中的名称
  7. group_id: { type: String, required: true, zh: '组别id', ref: 'Race.MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称
  8. project_id: { type: String, required: true, zh: '项目id', ref: 'Race.MatchProject', getProp: [ 'name' ] }, // 组别项目中的名称
  9. user_id: { type: String, required: true, zh: '用户id', ref: 'Race.User' }, //
  10. is_share: { type: Boolean, required: false, zh: '是否转发' }, //
  11. pay_id: { type: String, required: false, zh: '账单id', ref: 'Race.PayOrder' }, //
  12. pay_status: { type: String, required: false, zh: '账单状态', default: '0' }, // 0:未支付;1支付成功;-1:支付失败;-2:申请退款(退赛);-3:已退款(退赛)
  13. };
  14. const schema = new Schema(match_sign, { toJSON: { getters: true, virtuals: true } });
  15. schema.index({ id: 1 });
  16. schema.index({ 'meta.createdAt': 1 });
  17. schema.index({ match_id: 1 });
  18. schema.index({ group_id: 1 });
  19. schema.index({ project_id: 1 });
  20. schema.index({ user_id: 1 });
  21. schema.index({ is_share: 1 });
  22. schema.index({ pay_id: 1 });
  23. schema.index({ pay_status: 1 });
  24. schema.plugin(metaPlugin);
  25. const source = 'race';
  26. module.exports = app => {
  27. const is_multiple = app.mongooseDB.clients;
  28. let model;
  29. if (is_multiple) {
  30. const conn = app.mongooseDB.get(source);
  31. model = conn.model('MatchSign', schema, 'matchSign');
  32. } else {
  33. const { mongoose } = app;
  34. model = mongoose.model('MatchSign', schema, 'matchSign');
  35. }
  36. return model;
  37. };