'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin'); const MoneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-plugin'); // 账单 const bill = { match_id: { type: String, required: false, zh: '赛事id', ref: 'Race.Match' }, // group_id: { type: String, required: false, zh: '组别id', ref: 'Race.MatchGroup' }, // project_id: { type: String, required: false, zh: '组别项目id', ref: 'Race.MatchProject' }, // payer_id: { type: String, required: false, zh: '支付人id', ref: 'Race.User' }, // 比赛模块用户数据id pay_id: { type: String, required: false, zh: '支付id', ref: 'Race.PayOrder' }, // is_pay: { type: String, required: false, zh: '是否支付' }, // 0:未支付;1:支付成功;-1:支付失败;-3:已退款 time: { type: String, required: false, zh: '时间' }, // type: { type: String, required: false, zh: '来源' }, // 1:报名缴费;-1退赛 }; const schema = new Schema(bill, { 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({ pay_id: 1 }); schema.index({ time: 1 }); schema.index({ type: 1 }); schema.plugin(metaPlugin); schema.plugin(MoneyPlugin({ zh: '金额', required: false })); 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('Bill', schema, 'bill'); } else { const { mongoose } = app; model = mongoose.model('Bill', schema, 'bill'); } return model; };