'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 payOrder = { openid: { type: String, required: false, zh: '微信id' }, // 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 order_no: { type: String, required: false, zh: '订单号' }, // time: { type: String, required: false, zh: '时间' }, // desc: { type: String, required: false, zh: '支付说明' }, // status: { type: String, required: false, zh: '支付状态', default: '0' }, // 0:未支付;1:已支付;-1:支付失败;-3:已退款 config: { type: String, required: false, zh: '设置' }, // }; const schema = new Schema(payOrder, { toJSON: { getters: true, virtuals: true } }); schema.index({ id: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.index({ payer_id: 1 }); schema.index({ order_no: 1 }); schema.index({ status: 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('PayOrder', schema, 'payOrder'); } else { const { mongoose } = app; model = mongoose.model('PayOrder', schema, 'payOrder'); } return model; };