| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | if(runVipNext == null){ |
| | | throw new FebsException("无法升级会员权益"); |
| | | } |
| | | if(runVip.getOrderNumber() < runVipNext.getOrderNumber()){ |
| | | if(runVip.getOrderNumber() >= runVipNext.getOrderNumber()){ |
| | | throw new FebsException("用户无法升级"); |
| | | } |
| | | |
| | |
| | | BigDecimal subtract = amountAll.subtract(amountNow); |
| | | |
| | | if(subtract.compareTo(amount) <= 0){ |
| | | runVipGrow.setAmountNow(amountAll); |
| | | |
| | | mallCharge.setVipCode(runVipGrow.getLevelNext()); |
| | | }else{ |
| | | runVipGrow.setAmountNow(amountNow.add(amount).setScale(2, RoundingMode.DOWN)); |
| | | |
| | | mallCharge.setVipCode(memberLevel); |
| | | } |
| | | runVipGrow.setAmount(amount); |
| | | runVipGrowMapper.updateById(runVipGrow); |
| | | }else{ |
| | | runVipGrow = new RunVipGrow(); |
| | | runVipGrow.setMemberId(memberId); |
| | | runVipGrow.setLevelNow(memberLevel); |
| | | runVipGrow.setLevelNext(runVipNext.getVipCode()); |
| | | runVipGrow.setAmountAll(runVipNext.getPresentPrice()); |
| | | runVipGrow.setAmount(amount); |
| | | runVipGrow.setAmountNow(amount); |
| | | runVipGrowMapper.insert(runVipGrow); |
| | | |
| | | if(runVipGrow.getAmountAll().compareTo(amount) <= 0){ |
| | | BigDecimal presentPrice = runVip.getPresentPrice(); |
| | | BigDecimal add = presentPrice.add(amount); |
| | | |
| | | BigDecimal presentPriceNext = runVipNext.getPresentPrice(); |
| | | if(presentPriceNext.compareTo(add) <= 0){ |
| | | mallCharge.setVipCode(runVipGrow.getLevelNext()); |
| | | } |
| | | } |
| | |
| | | |
| | | agentProducer.sendBuyVipSuccessMsg(mallCharge.getId()); |
| | | |
| | | return new FebsResponse().success().data("操作成功"); |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse growCharge(ApiGrowChargeDto apiGrowChargeDto) { |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | |
| | | ApiGoChargeVo apiGoChargeVo = new ApiGoChargeVo(); |
| | | |
| | | BigDecimal amount = apiGrowChargeDto.getAmount(); |
| | | if(BigDecimal.ZERO.compareTo(amount) >= 0){ |
| | |
| | | if(runVipNext == null){ |
| | | throw new FebsException("无法升级会员权益"); |
| | | } |
| | | if(runVip.getOrderNumber() < runVipNext.getOrderNumber()){ |
| | | if(runVip.getOrderNumber() >= runVipNext.getOrderNumber()){ |
| | | throw new FebsException("用户无法升级"); |
| | | } |
| | | |
| | |
| | | mallCharge.setVipCode(runVipGrow.getLevelNext()); |
| | | } |
| | | }else{ |
| | | if(runVipGrow.getAmountAll().compareTo(amount) <= 0){ |
| | | mallCharge.setVipCode(runVipGrow.getLevelNext()); |
| | | BigDecimal add = runVip.getPresentPrice().add(amount); |
| | | if(runVipNext.getPresentPrice().compareTo(add) <= 0){ |
| | | mallCharge.setVipCode(runVipNext.getVipCode()); |
| | | } |
| | | } |
| | | |
| | | mallChargeMapper.insert(mallCharge); |
| | | return new FebsResponse().success().data("操作成功"); |
| | | |
| | | apiGoChargeVo.setFailTime(mallCharge.getFailTime()); |
| | | apiGoChargeVo.setAddress(mallCharge.getAddress()); |
| | | apiGoChargeVo.setAmount(mallCharge.getAmount()); |
| | | apiGoChargeVo.setSysAddress(mallCharge.getSysAddress()); |
| | | apiGoChargeVo.setSysAddressType(mallCharge.getType()); |
| | | |
| | | /** |
| | | * 充值接口调用后,发送一个延时队列 |
| | | * 功能:延迟时间为【failMinutes】后,更新充值记录为失败。 |
| | | */ |
| | | ApiMemberChargeFailDto apiMemberChargeFailDto = new ApiMemberChargeFailDto(); |
| | | apiMemberChargeFailDto.setChargeId(mallCharge.getId()); |
| | | apiMemberChargeFailDto.setFailTime(Integer.parseInt(failMinutes) * 60L* 1000L); |
| | | agentProducer.sendMemberChargeFailMsg(apiMemberChargeFailDto); |
| | | return new FebsResponse().success().data(apiGoChargeVo); |
| | | } |
| | | |
| | | @Override |