| | |
| | | private final IMallMoneyFlowService mallMoneyFlowService; |
| | | private final MallMemberWalletMapper mallMemberWalletMapper; |
| | | private final SqlSessionTemplate sqlSessionTemplate; |
| | | private final IApiMallMemberWalletService memberWalletService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | //分享补贴金额 |
| | | BigDecimal sharePerkAmount = amount.multiply(sharePerkPercent); |
| | | |
| | | iApiMallMemberWalletService.addBalance(sharePerkAmount, mallMemberUp.getId()); |
| | | //所有合伙人补贴至消费礼包的三倍额度需要复购一次。 |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(mallMemberUp.getId()); |
| | | BigDecimal totalScore = mallMemberWallet.getTotalScore(); |
| | | if(totalScore.compareTo(sharePerkAmount) < 0){ |
| | | sharePerkAmount = totalScore; |
| | | } |
| | | if(BigDecimal.ZERO.compareTo(sharePerkAmount) < 0){ |
| | | //减少补贴额度 |
| | | memberWalletService.reduce(sharePerkAmount, memberId, "totalScore"); |
| | | |
| | | mallMoneyFlowService.addMoneyFlow( |
| | | mallMemberUp.getId(), |
| | | sharePerkAmount, |
| | | MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), |
| | | mallOrderInfo.getOrderNo(), |
| | | FlowTypeEnum.BALANCE.getValue()); |
| | | iApiMallMemberWalletService.addBalance(sharePerkAmount, mallMemberUp.getId()); |
| | | |
| | | mallMoneyFlowService.addMoneyFlow( |
| | | mallMemberUp.getId(), |
| | | sharePerkAmount, |
| | | MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), |
| | | mallOrderInfo.getOrderNo(), |
| | | FlowTypeEnum.BALANCE.getValue()); |
| | | } |
| | | } |
| | | /** |
| | | * 星级奖励 |
| | |
| | | * @return |
| | | */ |
| | | public List<MallMember> getStarRecord(List<MallMember> mallMembersOlds,String LevelParam,BigDecimal amount,String orderNo,Long memberId,int starPerkType){ |
| | | long start = System.currentTimeMillis(); |
| | | //根据用户的level获取用户 |
| | | List<MallMember> mallMemberStars = memberMapper.selectMemberWithLevel(LevelParam); |
| | | if(CollUtil.isNotEmpty(mallMembersOlds)){ |
| | |
| | | //给当前等级的每个用户发放星级奖励 |
| | | int count = 0; |
| | | List<Map<String,Object>> result = new ArrayList<>(); |
| | | List<Map<String,Object>> resultReduce = new ArrayList<>(); |
| | | List<MallMoneyFlow> mallMoneyFlows = new ArrayList<>(); |
| | | for(MallMemberWallet mallMemberWallet : mallMemberWallets){ |
| | | Map<String,Object> hashMap = new HashMap<>(); |
| | |
| | | //当前用户的星级奖励 |
| | | BigDecimal starPerkAmount = starPerkAmountAva |
| | | .multiply(new BigDecimal(starCnt)).abs().setScale(2, BigDecimal.ROUND_DOWN); |
| | | hashMap.put("id",mallMemberWallet.getId()); |
| | | hashMap.put("starPerkAmount",starPerkAmount); |
| | | result.add(hashMap); |
| | | //生成星级奖励的流水对象 |
| | | MallMoneyFlow mallMoneyFlow = new MallMoneyFlow(); |
| | | mallMoneyFlow.setMemberId(mallMemberWallet.getMemberId()); |
| | | mallMoneyFlow.setAmount(starPerkAmount); |
| | | mallMoneyFlow.setType(starPerkType); |
| | | mallMoneyFlow.setOrderNo(orderNo); |
| | | mallMoneyFlow.setRtMemberId(memberId); |
| | | mallMoneyFlow.setStatus(2); |
| | | mallMoneyFlow.setFlowType(FlowTypeEnum.BALANCE.getValue()); |
| | | mallMoneyFlows.add(mallMoneyFlow); |
| | | BigDecimal totalScorePerk = mallMemberWallet.getTotalScore(); |
| | | if(totalScorePerk.compareTo(starPerkAmount) < 0){ |
| | | starPerkAmount = totalScorePerk; |
| | | } |
| | | if(BigDecimal.ZERO.compareTo(starPerkAmount) < 0){ |
| | | hashMap.put("id",mallMemberWallet.getId()); |
| | | hashMap.put("starPerkAmount",starPerkAmount); |
| | | result.add(hashMap); |
| | | resultReduce.add(hashMap); |
| | | //生成星级奖励的流水对象 |
| | | MallMoneyFlow mallMoneyFlow = new MallMoneyFlow(); |
| | | mallMoneyFlow.setMemberId(mallMemberWallet.getMemberId()); |
| | | mallMoneyFlow.setAmount(starPerkAmount); |
| | | mallMoneyFlow.setType(starPerkType); |
| | | mallMoneyFlow.setOrderNo(orderNo); |
| | | mallMoneyFlow.setRtMemberId(memberId); |
| | | mallMoneyFlow.setStatus(2); |
| | | mallMoneyFlow.setFlowType(FlowTypeEnum.BALANCE.getValue()); |
| | | mallMoneyFlows.add(mallMoneyFlow); |
| | | } |
| | | count = count + 1; |
| | | if (count % 1000 == 0 || count == mallMemberWallets.size()) { |
| | | int updateCount = mallMemberWalletMapper.updateStarByList(result); |
| | | if(updateCount>0){ |
| | | log.info("============更新============第{}条数据===========",count); |
| | | if(CollUtil.isNotEmpty(result)){ |
| | | int resultCount = mallMemberWalletMapper.updateStarByList(result); |
| | | if(resultCount>0){ |
| | | log.info("============余额新增============第{}条数据===========",resultCount); |
| | | } |
| | | //每更新完一批数据,在result内进行删除操作。 |
| | | result.clear(); |
| | | |
| | | int resultReduceCount = mallMemberWalletMapper.updateTotalScoreByList(resultReduce); |
| | | if(resultReduceCount>0){ |
| | | log.info("============额度减少============第{}条数据===========",resultReduceCount); |
| | | } |
| | | //每更新完一批数据,在result内进行删除操作。 |
| | | resultReduce.clear(); |
| | | } |
| | | //每更新完一批数据,在result内进行删除操作。 |
| | | result.clear(); |
| | | } |
| | | } |
| | | SqlSession sqlSession = sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH,false); |
| | | MallMoneyFlowMapper mallMoneyFlowMapper = sqlSession.getMapper(MallMoneyFlowMapper.class); |
| | | long start = System.currentTimeMillis(); |
| | | for(int i = 1; i <= mallMoneyFlows.size(); i++){ |
| | | mallMoneyFlowMapper.insertMoneyFlow(mallMoneyFlows.get(i-1)); |
| | | if (i % 1000 == 0 || i == mallMoneyFlows.size()) { |
| | | long end = System.currentTimeMillis(); |
| | | log.info("============插入============第{}条数据,时间:{}===========",mallMoneyFlows.size(),(end - start)/1000); |
| | | sqlSession.commit(); |
| | | sqlSession.clearCache(); |
| | | if(CollUtil.isNotEmpty(mallMoneyFlows)){ |
| | | SqlSession sqlSession = sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH,false); |
| | | MallMoneyFlowMapper mallMoneyFlowMapper = sqlSession.getMapper(MallMoneyFlowMapper.class); |
| | | |
| | | for(int i = 1; i <= mallMoneyFlows.size(); i++){ |
| | | mallMoneyFlowMapper.insertMoneyFlow(mallMoneyFlows.get(i-1)); |
| | | if (i % 1000 == 0 || i == mallMoneyFlows.size()) { |
| | | log.info("============插入流水============第{}条数据===========",mallMoneyFlows.size()); |
| | | sqlSession.commit(); |
| | | sqlSession.clearCache(); |
| | | } |
| | | } |
| | | sqlSession.close(); |
| | | } |
| | | sqlSession.close(); |
| | | } |
| | | } |
| | | long end = System.currentTimeMillis(); |
| | | log.info("============订单:{},时间:{}===========",orderNo,(end - start)/1000); |
| | | return mallMemberStars; |
| | | } |
| | | } |