charge.js 1.3 KB

1234567891011121314151617181920212223242526272829
  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 charge = {
  7. school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
  8. payer_id: { type: String, required: false, zh: '充值用户角色id', refPath: 'payer_role', getProp: [ 'name' ] }, //
  9. payer_role: { type: String, required: false, zh: '充值用户角色' }, //
  10. pay_id: { type: String, required: false, zh: '支付id', ref: 'Payorder' }, //
  11. is_pay: { type: String, required: false, zh: '支付状态' }, // 0:未支付;1:支付成功;-1:支付失败;-3:已退款
  12. type: { type: String, default: '0', zh: '类型' }, // 0:充值;1:退款至余额
  13. time: { type: String, required: false, zh: '时间' }, //
  14. };
  15. const schema = new Schema(charge, { toJSON: { getters: true, virtuals: true } });
  16. schema.index({ id: 1 });
  17. schema.index({ 'meta.createdAt': 1 });
  18. schema.index({ school_id: 1 });
  19. schema.index({ payer_id: 1 });
  20. schema.index({ payer_role: 1 });
  21. schema.index({ is_pay: 1 });
  22. schema.plugin(metaPlugin);
  23. schema.plugin(moneyPlugin({ zh: '充值金额' }));
  24. module.exports = app => {
  25. const { mongoose } = app;
  26. return mongoose.model('Charge', schema, 'charge');
  27. };