'use strict'; const { CrudService } = require('naf-framework-mongoose-free/lib/service'); const { BusinessError, ErrorCode } = require('naf-core').Error; const _ = require('lodash'); const assert = require('assert'); const moment = require('moment'); // class CashOutService extends CrudService { constructor(ctx) { super(ctx, 'cashout'); this.model = this.ctx.model.User.CashOut; } async beforeCreate(data) { const { customer } = data; if (!customer) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '缺少提款人'); const num = await this.model.count({ customer, status: '0' }); if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '您有未处理提现申请,请联系管理员先处理之前的申请'); return data; } } module.exports = CashOutService;