| | |
| | | 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; |
| | |
| | | apiGrowInfoVo.setLevelNow(runVipNow.getVipCode()); |
| | | apiGrowInfoVo.setAmountNow(runVipNow.getPresentPrice()); |
| | | |
| | | |
| | | //获取runVips中的orderNumber为runVipNow.getOrderNumber() + 1的那个元素 |
| | | RunVip runVipNext = runVips.stream().filter(runVip -> runVip.getOrderNumber() == runVipNow.getOrderNumber() + 1).findFirst().orElse(null); |
| | | if(runVipNext != null){ |
| | |
| | | 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 |
| | | public FebsResponse reduceAmount() { |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | ApiReduceAmountVo apiReduceAmountVo = new ApiReduceAmountVo(); |
| | | MallMember mallMember = mallMemberMapper.selectById(memberId); |
| | | //减免价格 |
| | | RunVip runVip = this.baseMapper.selectOne(new LambdaQueryWrapper<RunVip>().eq(RunVip::getVipCode, mallMember.getLevel())); |
| | | BigDecimal reduceAmount = runVip.getPresentPrice(); |
| | | RunVipGrow runVipGrow = runVipGrowMapper.selectList( |
| | | new LambdaQueryWrapper<RunVipGrow>() |
| | | .eq(RunVipGrow::getMemberId, memberId) |
| | | .eq(RunVipGrow::getLevelNow, mallMember.getLevel()) |
| | | .orderByDesc(RunVipGrow::getId) |
| | | ).stream().findFirst().orElse(null); |
| | | if(runVipGrow != null){ |
| | | BigDecimal amountNow = runVipGrow.getAmountNow(); |
| | | reduceAmount = reduceAmount.add(amountNow); |
| | | } |
| | | apiReduceAmountVo.setReduceAmount(reduceAmount); |
| | | return new FebsResponse().success().data(apiReduceAmountVo); |
| | | } |
| | | } |