| | |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.NumberUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | |
| | | } |
| | | |
| | | // 判断套餐或者普通商品,结算对应商品的动态分红 |
| | | if (!Objects.equals(item.getIsNormal(), isNormal)) { |
| | | continue; |
| | | } |
| | | // if (!Objects.equals(item.getIsNormal(), isNormal)) { |
| | | // continue; |
| | | // } |
| | | |
| | | // =======直推返利== start ===== |
| | | // 直接奖励收益 |
| | |
| | | @Override |
| | | public void scorePool() { |
| | | log.info("#####==积分池==start==######"); |
| | | |
| | | String redisKey = "scorePool"; |
| | | // List<MallOrderInfo> mallOrderInfos = mallOrderInfoMapper.selectList(new QueryWrapper<>()); |
| | | // if(CollUtil.isEmpty(mallOrderInfos)){ |
| | | // redisUtils.set(redisKey,0,0L); |
| | | // return; |
| | | // } |
| | | /** |
| | | * 后一天2点,结算前一天的所有消费 |
| | | * 积分池增加每日消费的10% |
| | |
| | | Date date = DateUtil.offsetDay(new Date(), -1); |
| | | BigDecimal totalAmount = mallOrderInfoMapper.selectTotalAmountByPayDoneAndDataString(1, date); |
| | | BigDecimal multiplyTotalAmount = totalAmount.multiply(everydayRatio); |
| | | |
| | | String redisKey = "scorePool"; |
| | | String scorePoolRedis = redisUtils.getString(redisKey); |
| | | if(StrUtil.isBlank(scorePoolRedis)){ |
| | | redisUtils.set(redisKey,0,0L); |
| | |
| | | BigDecimal scorePoolToDay = scorePoolNew.multiply(dividEquallyRatio); |
| | | |
| | | redisUtils.set(redisKey,scorePoolNew.subtract(scorePoolToDay).intValue(),0L); |
| | | redisUtils.set(AppContants.SCORE_POOL_TODAY,scorePoolToDay.intValue(),0L); |
| | | |
| | | QueryWrapper<MallMember> formalMember = new QueryWrapper<>(); |
| | | formalMember.ne("level", AgentLevelEnum.ZERO_LEVEL.name()); |
| | | List<MallMember> mallMembers = mallMemberMapper.selectList(formalMember); |
| | | int cnt = 0; |
| | | if(CollUtil.isNotEmpty(mallMembers)){ |
| | | BigDecimal income = new BigDecimal(scorePoolToDay.divide(new BigDecimal(mallMembers.size()), 2, RoundingMode.HALF_UP).intValue()); |
| | | if(income.compareTo(BigDecimal.ZERO) < 1){ |
| | | return; |
| | | } |
| | | for(MallMember mallMember : mallMembers){ |
| | | /* |
| | | 平分成佣金,一比一减少赠送积分 |
| | | 如果没有赠送积分,则平分0 |
| | | */ |
| | | BigDecimal outCome = BigDecimal.ZERO; |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(mallMember.getId()); |
| | | if(mallMemberWallet.getScore().compareTo(BigDecimal.ZERO) < 1){ |
| | | continue; |
| | | } |
| | | if(mallMemberWallet.getScore().compareTo(income) < 0){ |
| | | outCome = new BigDecimal(mallMemberWallet.getScore().intValue()); |
| | | }else{ |
| | | outCome = income; |
| | | } |
| | | walletService.add(outCome, mallMember.getId(), "commission"); |
| | | walletService.reduce(outCome, mallMember.getId(), "score"); |
| | | moneyFlowService.addMoneyFlow(mallMember.getId(), outCome, MoneyFlowTypeEnum.SCORE_POOL.getValue(), null, FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(mallMember.getId(), outCome.negate(), MoneyFlowTypeEnum.SCORE_POOL.getValue(), null, FlowTypeEnum.SCORE.getValue()); |
| | | cnt ++; |
| | | } |
| | | } |
| | | log.info("#####==积分池==end==######;" + |
| | | "今日新增积分:" + multiplyTotalAmount.setScale(2, RoundingMode.HALF_UP) |
| | | +";平分积分数量:"+scorePoolToDay.setScale(2, RoundingMode.HALF_UP) |
| | | +";人数:"+cnt); |
| | | // QueryWrapper<MallMember> formalMember = new QueryWrapper<>(); |
| | | // formalMember.ne("level", AgentLevelEnum.ZERO_LEVEL.name()); |
| | | // List<MallMember> mallMembers = mallMemberMapper.selectList(formalMember); |
| | | // int cnt = 0; |
| | | // if(CollUtil.isNotEmpty(mallMembers)){ |
| | | // BigDecimal income = new BigDecimal(scorePoolToDay.divide(new BigDecimal(mallMembers.size()), 2, RoundingMode.HALF_UP).intValue()); |
| | | // if(income.compareTo(BigDecimal.ZERO) < 1){ |
| | | // return; |
| | | // } |
| | | // for(MallMember mallMember : mallMembers){ |
| | | // /* |
| | | // 平分成佣金,一比一减少赠送积分 |
| | | // 如果没有赠送积分,则平分0 |
| | | // */ |
| | | // BigDecimal outCome = BigDecimal.ZERO; |
| | | // MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(mallMember.getId()); |
| | | // if(mallMemberWallet.getScore().compareTo(BigDecimal.ZERO) < 1){ |
| | | // continue; |
| | | // } |
| | | // if(mallMemberWallet.getScore().compareTo(income) < 0){ |
| | | // outCome = new BigDecimal(mallMemberWallet.getScore().intValue()); |
| | | // }else{ |
| | | // outCome = income; |
| | | // } |
| | | // |
| | | // outCome = new BigDecimal(RandomUtil.randomBigDecimal(BigDecimal.ZERO,outCome).intValue()).setScale(2,BigDecimal.ROUND_DOWN); |
| | | //// walletService.add(outCome, mallMember.getId(), "commission"); |
| | | //// walletService.reduce(outCome, mallMember.getId(), "score"); |
| | | // moneyFlowService.addMoneyFlow(1,mallMember.getId(), outCome, MoneyFlowTypeEnum.SCORE_POOL.getValue(), null, FlowTypeEnum.COMMISSION.getValue()); |
| | | // moneyFlowService.addMoneyFlow(1,mallMember.getId(), outCome.negate(), MoneyFlowTypeEnum.SCORE_POOL.getValue(), null, FlowTypeEnum.SCORE.getValue()); |
| | | // cnt ++; |
| | | // } |
| | | // } |
| | | // log.info("#####==积分池==end==######;" + |
| | | // "今日新增积分:" + multiplyTotalAmount.setScale(2, RoundingMode.HALF_UP) |
| | | // +";平分积分数量:"+scorePoolToDay.setScale(2, RoundingMode.HALF_UP) |
| | | // +";人数:"+cnt); |
| | | } |
| | | |
| | | } |