|
|
|
@ -0,0 +1,32 @@ |
|
|
|
package com.qniao.dam.application.service.withdrawaudit; |
|
|
|
|
|
|
|
import com.qniao.dam.domain.aggregate.walletaccount.entity.WalletAccount; |
|
|
|
import com.qniao.dam.domain.aggregate.withdrawaudit.entity.WithdrawAudit; |
|
|
|
import com.qniao.dam.domain.service.withdrawaudit.ApplyWithdrawAuditDomainService; |
|
|
|
import com.qniao.dam.query.walletaccount.WalletAccountQueryService; |
|
|
|
import com.qniao.framework.exception.BizException; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class WithdrawAuditApplicationService { |
|
|
|
@Resource |
|
|
|
private WalletAccountQueryService walletAccountQueryService; |
|
|
|
@Resource |
|
|
|
private ApplyWithdrawAuditDomainService applyWithdrawAuditDomainService; |
|
|
|
|
|
|
|
public void applyWithdraw(WithdrawAudit withdrawAudit) { |
|
|
|
synchronized (withdrawAudit.getWalletAccountUserId().toString().intern()) { |
|
|
|
WalletAccount walletAccount = walletAccountQueryService.queryByUserId(withdrawAudit.getWalletAccountUserId()); |
|
|
|
if (Objects.isNull(walletAccount) || withdrawAudit.getWithdrawAmount().compareTo(walletAccount.getAvailableBalance()) > 0) { |
|
|
|
throw new BizException("超出可提现金额"); |
|
|
|
} |
|
|
|
withdrawAudit.setWalletAccountId(walletAccount.getId()); |
|
|
|
walletAccount.setAvailableBalance(walletAccount.getAvailableBalance().subtract(withdrawAudit.getWithdrawAmount())); |
|
|
|
walletAccount.setFrozenBalance(walletAccount.getFrozenBalance().add(withdrawAudit.getWithdrawAmount())); |
|
|
|
applyWithdrawAuditDomainService.handle(withdrawAudit,walletAccount); |
|
|
|
} |
|
|
|
} |
|
|
|
} |