From b3c8303ecd936182e2df4933dbf1ad167b81266e Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Wed, 25 Oct 2023 14:26:23 +0800 Subject: [PATCH] 版本管理 --- src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java | 82 +++++++++++++++++++++++++++++++++-------- 1 files changed, 66 insertions(+), 16 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java index c1ad6f2..b40eef9 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java @@ -6,6 +6,7 @@ import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum; import cc.mrbird.febs.common.utils.AppContants; import cc.mrbird.febs.common.utils.RedisUtils; +import cc.mrbird.febs.mall.dto.ScorePoorDto; import cc.mrbird.febs.mall.entity.*; import cc.mrbird.febs.mall.mapper.*; import cc.mrbird.febs.mall.service.IApiMallMemberWalletService; @@ -17,7 +18,9 @@ import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -49,6 +52,8 @@ private final DataDictionaryCustomMapper dataDictionaryCustomMapper; private final MallMoneyFlowMapper mallMoneyFlowMapper; private final MallAchieveRecordMapper mallAchieveRecordMapper; + private final RedisUtils redisUtils; + private final MallMemberWalletMapper mallMemberWalletMapper; @Override @Transactional(rollbackFor = Exception.class) @@ -59,6 +64,9 @@ return; } + /** + * + */ if (profitDate == null) { profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); } @@ -66,6 +74,7 @@ // BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2); // 普通商品业绩 // BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1); + //今日总业绩 BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate); if (totalIncome.compareTo(BigDecimal.ZERO) == 0) { @@ -111,9 +120,9 @@ BigDecimal preStaticProfit = staticProfit.divide(new BigDecimal(list.size()), 2, RoundingMode.HALF_UP); for (Map<String, Object> item : list) { - Long memberId = (Long) item.get("memberId"); +// Long memberId = (Long) item.get("memberId"); String orderNo = (String) item.get("orderNo"); - + changeAllScoreAndCommission(preStaticProfit,orderNo); // int reduce = walletService.reduce(preStaticProfit, memberId, "score"); // if (reduce == 2) { // break; @@ -122,9 +131,16 @@ // walletService.add(preStaticProfit, memberId, "commission"); // moneyFlowService.addMoneyFlow(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo, FlowTypeEnum.COMMISSION.getValue()); // moneyFlowService.addMoneyFlow(memberId, preStaticProfit.negate(), MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo, FlowTypeEnum.SCORE.getValue()); - changeScoreAndCommission(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo); +// changeScoreAndCommission(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo); } } + } + } + + public void changeAllScoreAndCommission(BigDecimal preStaticProfit,String orderNo){ + List<MallMember> members = mallMemberMapper.selectList(null); + for(MallMember mallMember : members){ + changeScoreAndCommission(mallMember.getId(), preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo); } } @@ -173,9 +189,9 @@ } // 判断套餐或者普通商品,结算对应商品的动态分红 - if (!Objects.equals(item.getIsNormal(), isNormal)) { - continue; - } +// if (!Objects.equals(item.getIsNormal(), isNormal)) { +// continue; +// } // =======直推返利== start ===== // 直接奖励收益 @@ -481,22 +497,33 @@ log.info("#####==店补/董事==end==######"); } - private final RedisUtils redisUtils; - @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% * 每天释放1%,给全体用户 */ //前一天的所有消费的10% + DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SCORE_POOR_RADIO.getType(), DataDictionaryEnum.SCORE_POOR_RADIO.getCode()); + if(ObjectUtil.isEmpty(dic)){ + return; + } + ScorePoorDto scorePoorDto = JSONUtil.toBean(dic.getValue(), ScorePoorDto.class); + BigDecimal everydayRatio = scorePoorDto.getEverydayRatio().multiply(new BigDecimal(0.01)); + BigDecimal dividEquallyRatio = scorePoorDto.getDividEquallyRatio().multiply(new BigDecimal(0.01)); + Date date = DateUtil.offsetDay(new Date(), -1); BigDecimal totalAmount = mallOrderInfoMapper.selectTotalAmountByPayDoneAndDataString(1, date); - BigDecimal multiplyTotalAmount = totalAmount.multiply(new BigDecimal(0.1)); - - String redisKey = "scorePool"; + BigDecimal multiplyTotalAmount = totalAmount.multiply(everydayRatio); String scorePoolRedis = redisUtils.getString(redisKey); if(StrUtil.isBlank(scorePoolRedis)){ redisUtils.set(redisKey,0,0L); @@ -506,22 +533,45 @@ BigDecimal scorePoolNew = scorePoolOld.add(multiplyTotalAmount); //每天释放1%给全体用户 - BigDecimal scorePoolToDay = scorePoolNew.multiply(new BigDecimal(0.01)); + BigDecimal scorePoolToDay = scorePoolNew.multiply(dividEquallyRatio); redisUtils.set(redisKey,scorePoolNew.subtract(scorePoolToDay).intValue(),0L); - List<MallMember> mallMembers = mallMemberMapper.selectList(new QueryWrapper<>()); + 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){ - walletService.add(income, mallMember.getId(), "score"); - moneyFlowService.addMoneyFlow(mallMember.getId(), income, MoneyFlowTypeEnum.SCORE_POOL.getValue(), null, FlowTypeEnum.SCORE.getValue()); + /* + 平分成佣金,一比一减少赠送积分 + 如果没有赠送积分,则平分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==######"); + log.info("#####==积分池==end==######;" + + "今日新增积分:" + multiplyTotalAmount.setScale(2, RoundingMode.HALF_UP) + +";平分积分数量:"+scorePoolToDay.setScale(2, RoundingMode.HALF_UP) + +";人数:"+cnt); } } -- Gitblit v1.9.1