cashOut.js 809 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose-free/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const _ = require('lodash');
  5. const assert = require('assert');
  6. const moment = require('moment');
  7. //
  8. class CashOutService extends CrudService {
  9. constructor(ctx) {
  10. super(ctx, 'cashout');
  11. this.model = this.ctx.model.User.CashOut;
  12. }
  13. async beforeCreate(data) {
  14. const { customer } = data;
  15. if (!customer) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '缺少提款人');
  16. const num = await this.model.count({ customer, status: '0' });
  17. if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '您有未处理提现申请,请联系管理员先处理之前的申请');
  18. return data;
  19. }
  20. }
  21. module.exports = CashOutService;