| | |
| | | public class GuideWithdrawalStateService { |
| | | static final String PENDING = "PENDING"; |
| | | static final String TRANSFERRING = "TRANSFERRING"; |
| | | static final String TRANSFER_FAILED = "TRANSFER_FAILED"; |
| | | static final String TRANSFERRED = "TRANSFERRED"; |
| | | static final String PROCESSING = "PROCESSING"; |
| | | static final String APPROVED = "APPROVED"; |
| | |
| | | @Transactional |
| | | public WithdrawalResponse reject(Long id, String remark, String processor) { |
| | | GuideWithdrawal withdrawal = requireForUpdate(id); |
| | | if (!PENDING.equals(withdrawal.getStatus())) throw new BusinessException(409, "提现申请已处理"); |
| | | if (!canProcess(withdrawal)) throw new BusinessException(409, "提现申请已处理"); |
| | | if (!StringUtils.hasText(remark)) throw new BusinessException(400, "驳回提现时请填写处理备注"); |
| | | balanceService.credit(withdrawal.getGuideId(), withdrawal.getAmount()); |
| | | if (withdrawal.getTeamId() == null) { |
| | | balanceService.credit(withdrawal.getGuideId(), withdrawal.getAmount()); |
| | | } else { |
| | | balanceService.creditTeam(withdrawal.getTeamId(), withdrawal.getAmount()); |
| | | } |
| | | withdrawal.setStatus(REJECTED); |
| | | withdrawal.setAuditRemark(remark.trim()); |
| | | withdrawal.setProcessor(processor); |
| | |
| | | @Transactional |
| | | public GuideWithdrawal prepareTransfer(Long id, String remark, String processor) { |
| | | GuideWithdrawal withdrawal = requireForUpdate(id); |
| | | if (!PENDING.equals(withdrawal.getStatus())) throw new BusinessException(409, "提现申请已处理"); |
| | | if (!canProcess(withdrawal)) throw new BusinessException(409, "提现申请已处理"); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | withdrawal.setStatus(TRANSFERRING); |
| | | withdrawal.setTransferReqSeqId(sequence("TF")); |
| | |
| | | public GuideWithdrawal markTransferFailed(Long id, String message) { |
| | | GuideWithdrawal withdrawal = requireForUpdate(id); |
| | | if (!TRANSFERRING.equals(withdrawal.getStatus())) return withdrawal; |
| | | withdrawal.setStatus(PENDING); |
| | | withdrawal.setStatus(TRANSFER_FAILED); |
| | | withdrawal.setPayoutMessage(limit(message)); |
| | | update(withdrawal); |
| | | return withdrawal; |
| | |
| | | return withdrawal; |
| | | } |
| | | |
| | | private boolean canProcess(GuideWithdrawal withdrawal) { |
| | | return PENDING.equals(withdrawal.getStatus()) || TRANSFER_FAILED.equals(withdrawal.getStatus()); |
| | | } |
| | | |
| | | private void update(GuideWithdrawal withdrawal) { |
| | | withdrawal.setUpdatedAt(LocalDateTime.now()); |
| | | if (withdrawalMapper.updateById(withdrawal) != 1) { |