bill.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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: 'Race.Match' }, //
  8. group_id: { type: String, required: false, zh: '组别id', ref: 'Race.MatchGroup' }, //
  9. project_id: { type: String, required: false, zh: '组别项目id', ref: 'Race.MatchProject' }, //
  10. payer_id: { type: String, required: false, zh: '支付人id', ref: 'Race.User' }, // 比赛模块用户数据id
  11. pay_id: { type: String, required: false, zh: '支付id', ref: 'Race.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.index({ type: 1 });
  25. schema.plugin(metaPlugin);
  26. schema.plugin(MoneyPlugin({ zh: '金额', required: false }));
  27. const source = 'race';
  28. module.exports = app => {
  29. const is_multiple = app.mongooseDB.clients;
  30. let model;
  31. if (is_multiple) {
  32. const conn = app.mongooseDB.get(source);
  33. model = conn.model('Bill', schema, 'bill');
  34. } else {
  35. const { mongoose } = app;
  36. model = mongoose.model('Bill', schema, 'bill');
  37. }
  38. return model;
  39. };