From b597374d300e39dd43261c8f21bc8aa56ab5af18 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Thu, 02 Jun 2022 15:15:24 +0800 Subject: [PATCH] fix --- src/test/java/cc/mrbird/febs/ProfitTest.java | 26 +++++++++++++ src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java | 3 + src/main/java/cc/mrbird/febs/mall/service/impl/MallMoneyFlowServiceImpl.java | 12 ++++- src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java | 50 +++++++++++++++++-------- src/main/java/cc/mrbird/febs/mall/service/IMallMoneyFlowService.java | 4 + 5 files changed, 74 insertions(+), 21 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java b/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java index 6f4806f..a172447 100644 --- a/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java +++ b/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java @@ -17,7 +17,8 @@ //佣金中奖概率 WIN_CASH("WIN_PROBABILITY", "WIN_CASH"), RANK_BONUS("BONUS_TYPE", "RANK_BONUS"), - CASHOUT_SETTING("CASHOUT_SET", "CASHOUT_SETTING"); + CASHOUT_SETTING("CASHOUT_SET", "CASHOUT_SETTING"), + INDIRECT_BONUS_SETTING("INDIRECT_BONUS_SETTING", ""); private String type; diff --git a/src/main/java/cc/mrbird/febs/mall/service/IMallMoneyFlowService.java b/src/main/java/cc/mrbird/febs/mall/service/IMallMoneyFlowService.java index fba7e4a..5b35700 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/IMallMoneyFlowService.java +++ b/src/main/java/cc/mrbird/febs/mall/service/IMallMoneyFlowService.java @@ -7,10 +7,12 @@ public interface IMallMoneyFlowService extends IService<MallMoneyFlow> { - void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, String description, String remark, Long rtMemberId, Integer status, Integer flowType); + void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, String description, String remark, Long rtMemberId, Integer status, Integer flowType, Integer isReturn); void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, Integer flowType); + void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, Integer flowType, Integer isReturn); + void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, Long rtMemberId, Integer flowType); } diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MallMoneyFlowServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MallMoneyFlowServiceImpl.java index 290b8c9..54e1212 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/MallMoneyFlowServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MallMoneyFlowServiceImpl.java @@ -20,7 +20,7 @@ public class MallMoneyFlowServiceImpl extends ServiceImpl<MallMoneyFlowMapper, MallMoneyFlow> implements IMallMoneyFlowService { @Override - public void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, String description, String remark, Long rtMemberId, Integer status, Integer flowType) { + public void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, String description, String remark, Long rtMemberId, Integer status, Integer flowType, Integer isReturn) { MallMoneyFlow flow = new MallMoneyFlow(); flow.setMemberId(memberId); flow.setAmount(amount); @@ -31,16 +31,22 @@ flow.setRtMemberId(rtMemberId); flow.setStatus(status); flow.setFlowType(flowType); + flow.setIsReturn(isReturn); this.baseMapper.insert(flow); } @Override public void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, Integer flowType) { - this.addMoneyFlow(memberId, amount, type, orderNo, null, null, null, null, flowType); + this.addMoneyFlow(memberId, amount, type, orderNo, null, null, null, null, flowType, null); + } + + @Override + public void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, Integer flowType, Integer isReturn) { + this.addMoneyFlow(memberId, amount, type, orderNo, null, null, null, null, flowType, isReturn); } @Override public void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, Long rtMemberId, Integer flowType) { - this.addMoneyFlow(memberId, amount, type, orderNo, null, null, rtMemberId, null, flowType); + this.addMoneyFlow(memberId, amount, type, orderNo, null, null, rtMemberId, null, flowType, null); } } 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 42b04dd..b2e2e65 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 @@ -107,10 +107,10 @@ if (StrUtil.isBlank(member.getReferrerId())) { return; } + // 直推奖励字典 DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.DYNAMIC_BONUS.getType(), DataDictionaryEnum.DYNAMIC_BONUS.getCode()); - // 隔代字典 - DataDictionaryCustom indrectDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.INDRECT_BONUS.getType(), DataDictionaryEnum.INDRECT_BONUS.getCode()); + // 直接父级 MallMember parent = mallMemberMapper.selectInfoByInviteId(member.getReferrerId()); @@ -120,6 +120,11 @@ BigDecimal amount = item.getPrice().subtract(item.getCostPrice()).multiply(BigDecimal.valueOf(item.getCnt())); if (amount.compareTo(BigDecimal.ZERO) < 1) { continue; + } + + Integer isReturn = null; + if (item.getIsNormal() == 1) { + isReturn = 2; } // =======直推返利== start ===== @@ -137,7 +142,7 @@ walletService.add(dynamicProfit, parent.getId(), "commission"); - moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue()); + moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue(), isReturn); moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit.negate(), MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); // =======直推返利== end ===== @@ -151,19 +156,34 @@ if (CollUtil.isEmpty(members)) { return; } - // 隔代比例 - BigDecimal indrectDicProp = new BigDecimal(indrectDic.getValue()); - // 隔代推荐奖 收益 - BigDecimal direct = dynamicProfit.divide(indrectDicProp, 2, RoundingMode.HALF_UP); - - // direct 收益小于1,则跳出 - if (direct.compareTo(BigDecimal.ONE) < 1) { - continue; - } - + BigDecimal direct = dynamicProfit; for (MallMember parentMember : members) { if (parent.getInviteId().equals(parentMember.getInviteId())) { + continue; + } + + // 直推数量 + Integer directCnt = mallMemberMapper.selectOwnCntByInviteId(member.getReferrerId()); + List<DataDictionaryCustom> dataDices = dataDictionaryCustomMapper.selectDicByType(DataDictionaryEnum.INDIRECT_BONUS_SETTING.getType()); + + directCnt = directCnt == null ? 0 :directCnt; + // 隔代字典 + DataDictionaryCustom indrectDic = new DataDictionaryCustom(); + for (DataDictionaryCustom dataDic : dataDices) { + if (directCnt > Integer.parseInt(dataDic.getValue())) { + indrectDic = dataDic; + } + } + + // 隔代比例 + BigDecimal indrectDicProp = new BigDecimal(indrectDic.getValue()); + + // 隔代推荐奖 收益 + direct = direct.divide(indrectDicProp, 2, RoundingMode.HALF_UP); + + // direct 收益小于1,则跳出 + if (direct.compareTo(BigDecimal.ONE) < 1) { continue; } @@ -173,10 +193,8 @@ } walletService.add(direct, parentMember.getId(), "commission"); - moneyFlowService.addMoneyFlow(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue()); + moneyFlowService.addMoneyFlow(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue(), isReturn); moneyFlowService.addMoneyFlow(parentMember.getId(), direct.negate(), MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); - - direct = direct.divide(indrectDicProp, 2, RoundingMode.HALF_UP); } // =======隔代奖== end ===== } diff --git a/src/test/java/cc/mrbird/febs/ProfitTest.java b/src/test/java/cc/mrbird/febs/ProfitTest.java new file mode 100644 index 0000000..b6bc5a2 --- /dev/null +++ b/src/test/java/cc/mrbird/febs/ProfitTest.java @@ -0,0 +1,26 @@ +package cc.mrbird.febs; + +import cc.mrbird.febs.mall.service.IAgentService; +import cc.mrbird.febs.rabbit.consumer.AgentConsumer; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +/** + * @author wzy + * @date 2022-06-02 + **/ +@SpringBootTest +public class ProfitTest { + + @Autowired + private AgentConsumer agentConsumer; + + @Autowired + private IAgentService agentService; + + @Test + public void dynamicProfit() { + agentService.rankReturnMoney(7L); + } +} -- Gitblit v1.9.1