bill.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. const MoneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-plugin');
  5. // 账单
  6. const bill = {
  7. match_id: { type: String, required: false, zh: '赛事id', ref: 'Match' }, //
  8. group_id: { type: String, required: false, zh: '组别id', ref: 'MatchGroup' }, //
  9. project_id: { type: String, required: false, zh: '组别项目id', ref: 'MatchProject' }, //
  10. payer_id: { type: String, required: false, zh: '支付人id', ref: 'User' }, // 比赛模块用户数据id
  11. pay_id: { type: String, required: false, zh: '支付id', ref: 'PayOrder' }, //
  12. is_pay: { type: String, required: false, zh: '是否支付' }, // 0:未支付;1:支付成功;-1:支付失败;-3:已退款
  13. time: { type: String, required: false, zh: '时间' }, //
  14. type: { type: String, required: false, zh: '来源' }, // 1:报名缴费;-1退赛
  15. };
  16. const schema = new Schema(bill, { toJSON: { getters: true, virtuals: true } });
  17. schema.index({ id: 1 });
  18. schema.index({ 'meta.createdAt': 1 });
  19. schema.index({ match_id: 1 });
  20. schema.index({ group_id: 1 });
  21. schema.index({ project_id: 1 });
  22. schema.index({ pay_id: 1 });
  23. schema.index({ time: 1 });
  24. schema.plugin(metaPlugin);
  25. schema.plugin(MoneyPlugin({ zh: '金额', required: false }));
  26. const source = 'race';
  27. module.exports = app => {
  28. const is_multiple = app.mongooseDB.clients;
  29. let model;
  30. if (is_multiple) {
  31. const conn = app.mongooseDB.get(source);
  32. model = conn.model('Bill', schema, 'bill');
  33. } else {
  34. const { mongoose } = app;
  35. model = mongoose.model('Bill', schema, 'bill');
  36. }
  37. return model;
  38. };