payOrder.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 payOrder = {
  7. openid: { type: String, required: false, zh: '微信id' }, //
  8. match_id: { type: String, required: false, zh: '赛事id', ref: 'Race.Match' }, //
  9. group_id: { type: String, required: false, zh: '组别id', ref: 'Race.MatchGroup' }, //
  10. project_id: { type: String, required: false, zh: '组别项目id', ref: 'Race.MatchProject' }, //
  11. payer_id: { type: String, required: false, zh: '支付用户id', ref: 'Race.User' }, // 比赛模块用户数据id
  12. order_no: { type: String, required: false, zh: '订单号' }, //
  13. time: { type: String, required: false, zh: '时间' }, //
  14. desc: { type: String, required: false, zh: '支付说明' }, //
  15. status: { type: String, required: false, zh: '支付状态', default: '0' }, // 0:未支付;1:已支付;-1:支付失败;-3:已退款
  16. config: { type: String, required: false, zh: '设置' }, //
  17. };
  18. const schema = new Schema(payOrder, { toJSON: { getters: true, virtuals: true } });
  19. schema.index({ id: 1 });
  20. schema.index({ 'meta.createdAt': 1 });
  21. schema.index({ payer_id: 1 });
  22. schema.index({ order_no: 1 });
  23. schema.index({ status: 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('PayOrder', schema, 'payOrder');
  33. } else {
  34. const { mongoose } = app;
  35. model = mongoose.model('PayOrder', schema, 'payOrder');
  36. }
  37. return model;
  38. };