| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.Set; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private final AgentProducer agentProducer; |
| | | private final RunNodeSetMapper runNodeSetMapper; |
| | | private final AsyncService asyncService; |
| | | private final RunVipGrowMapper runVipGrowMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | @Override |
| | | public void buyVipSuccessMsg(Long chargeId) { |
| | | MallCharge mallCharge = mallChargeMapper.selectById(chargeId); |
| | | //更新会员的等级和会员升级的时间 |
| | | |
| | | Long memberId = mallCharge.getMemberId(); |
| | | String vipCode = mallCharge.getVipCode(); |
| | | |
| | | //判断mallCharge.getVipName()的最后两个字符是否等于“权益” |
| | | if("权益".equals(mallCharge.getVipName().substring(mallCharge.getVipName().length()-2,mallCharge.getVipName().length()))){ |
| | | MallMember mallMember = mallMemberMapper.selectById(memberId); |
| | | |
| | | RunVipGrow runVipGrow = runVipGrowMapper.selectOne( |
| | | new LambdaQueryWrapper<RunVipGrow>() |
| | | .eq(RunVipGrow::getMemberId, memberId) |
| | | .eq(RunVipGrow::getLevelNow, mallMember.getLevel()) |
| | | ); |
| | | BigDecimal amount = mallCharge.getAmount(); |
| | | //有升级权益的记录 |
| | | if(runVipGrow != null){ |
| | | //判断金额是否满足升级条件 |
| | | BigDecimal amountNow = runVipGrow.getAmountNow(); |
| | | BigDecimal amountAll = runVipGrow.getAmountAll(); |
| | | BigDecimal subtract = amountAll.subtract(amountNow); |
| | | |
| | | if(subtract.compareTo(amount) <= 0){ |
| | | runVipGrow.setAmountNow(amountAll); |
| | | }else{ |
| | | runVipGrow.setAmountNow(amountNow.add(amount).setScale(2, RoundingMode.DOWN)); |
| | | } |
| | | runVipGrow.setAmount(amount); |
| | | runVipGrowMapper.updateById(runVipGrow); |
| | | }else{ |
| | | List<RunVip> runVips = runVipMapper.selectList(null); |
| | | Map<String, RunVip> runVipMap = runVips.stream() |
| | | .collect(Collectors.toMap(RunVip::getVipCode, runVip -> runVip)); |
| | | |
| | | RunVip runVipNow = runVipMap.get(mallMember.getLevel()); |
| | | RunVip runVipNext = runVips.stream().filter(runVip -> runVip.getOrderNumber() == runVipNow.getOrderNumber() + 1).findFirst().orElse(null); |
| | | if(null != runVipNext){ |
| | | runVipGrow = new RunVipGrow(); |
| | | runVipGrow.setMemberId(memberId); |
| | | runVipGrow.setLevelNow(mallMember.getLevel()); |
| | | runVipGrow.setLevelNext(runVipNext.getVipCode()); |
| | | runVipGrow.setAmountAll(runVipNext.getPresentPrice()); |
| | | runVipGrow.setAmount(amount); |
| | | runVipGrow.setAmountNow(amount); |
| | | runVipGrowMapper.insert(runVipGrow); |
| | | } |
| | | } |
| | | } |
| | | //更新会员的等级和会员升级的时间 |
| | | mallMemberMapper.updateVipLevelTimeAndLevel(memberId,DateUtil.date(),vipCode); |
| | | |
| | | agentProducer.sendNodeUpMsg(memberId); |