'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin'); // 赛事报名 const match_sign = { match_id: { type: String, required: true, zh: '赛事id', ref: 'Match', getProp: [ 'name', 'status' ] }, // 比赛信息中的名称 group_id: { type: String, required: true, zh: '组别id', ref: 'MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称 project_id: { type: String, required: true, zh: '项目id', ref: 'MatchProject', getProp: [ 'name' ] }, // 组别项目中的名称 user_id: { type: String, required: true, zh: '用户id' }, // is_share: { type: Boolean, required: false, zh: '是否转发' }, // pay_id: { type: String, required: false, zh: '账单id', ref: 'PayOrder' }, // pay_status: { type: String, required: false, zh: '账单状态', default: '0' }, // 0:未支付;1支付成功;-1:支付失败;-2:申请退款(退赛);-3:已退款(退赛) }; const schema = new Schema(match_sign, { toJSON: { getters: true, virtuals: true } }); schema.index({ id: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.index({ match_id: 1 }); schema.index({ group_id: 1 }); schema.index({ project_id: 1 }); schema.index({ user_id: 1 }); schema.index({ is_share: 1 }); schema.index({ pay_id: 1 }); schema.index({ pay_status: 1 }); schema.plugin(metaPlugin); const source = 'race'; module.exports = app => { const is_multiple = app.mongooseDB.clients; let model; if (is_multiple) { const conn = app.mongooseDB.get(source); model = conn.model('MatchSign', schema, 'matchSign'); } else { const { mongoose } = app; model = mongoose.model('MatchSign', schema, 'matchSign'); } return model; };