payOrder.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. const config = {
  6. useSurplus: true || false, // 是否使用余额(有该字段就是用了,没有默认)
  7. costDetail: Object || String('id'), // 消费记录(余额对应的消费记录数据/id)
  8. discoun_type: 'fixed' || 'subtract' || 'discount', // 打折类型, 学员与教练的设置
  9. number: Number, // 打折数值 学员与教练的设置
  10. };
  11. // 付款订单表
  12. const payOrder = {
  13. openid: { type: String, required: false, zh: '微信id' }, // 其实和user_id有些重复,但是这里一定要留痕,因为有可能发生更换绑定
  14. school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
  15. payer_id: { type: String, required: false, zh: '支付的用户id', refPath: 'payer_role' }, // 由payer_role决定是教练还是学员
  16. payer_role: { type: String, required: false, zh: '支付的用户角色' }, //
  17. pay_for: { type: String, required: false, zh: '支付原因' }, // lesson:上课,写表名等...; 学生上课(公开课/私教课):lessonStudent; 学生临时上课:tempLessonApply;充值:charge
  18. from_id: { type: String, required: false, zh: '关联id' }, // 支付原因的数据id.有就写,没有不写
  19. time: { type: String, required: false, zh: '时间' }, //
  20. order_no: { type: String, required: false, zh: '订单号' }, //
  21. desc: { type: String, required: false, zh: '支付说明' }, //
  22. status: { type: String, required: false, default: '0', zh: '支付状态' }, // 0:未支付;1:已支付;-1:支付失败;-3:已退款
  23. config: { type: Object, zh: '设置' },
  24. };
  25. const schema = new Schema(payOrder, { toJSON: { getters: true, virtuals: true } });
  26. schema.index({ id: 1 });
  27. schema.index({ 'meta.createdAt': 1 });
  28. schema.index({ openid: 1 });
  29. schema.index({ school_id: 1 });
  30. schema.index({ payer_id: 1 });
  31. schema.index({ from_id: 1 });
  32. schema.plugin(metaPlugin);
  33. schema.plugin(moneyPlugin({ zh: '金额' }));
  34. module.exports = app => {
  35. const { mongoose } = app;
  36. return mongoose.model('PayOrder', schema, 'payOrder');
  37. };