fix
Helius
2022-06-17 9507ab3e93d6a38b136fca4677851fe8645c191a
fix
4 files modified
72 ■■■■■ changed files
src/main/java/cc/mrbird/febs/mall/mapper/MallMemberMapper.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java 61 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/modules/MallMemberMapper.xml 5 ●●●●● patch | view | raw | blame | history
src/test/java/cc/mrbird/febs/ProfitTest.java 4 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/mapper/MallMemberMapper.java
@@ -83,4 +83,6 @@
    List<MallMember> selectMemberDirectForHasLevel(@Param("inviteId") String inviteId);
    List<MallMember> selectDirectorsOrStoreMaster(@Param("type") Integer type);
    List<MallMember> selectMemberWithLevel(String level);
}
src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java
@@ -45,7 +45,7 @@
    private final IMallMoneyFlowService moneyFlowService;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final MallMoneyFlowMapper mallMoneyFlowMapper;
    private final IMallAchieveService mallAchieveService;
    private final MallAchieveRecordMapper mallAchieveRecordMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -58,10 +58,10 @@
        Date profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
        // 套餐业绩
        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
//        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
        // 普通商品业绩
        BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
        BigDecimal totalIncome = tcIncome.add(normalIncome);
//        BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
        BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate);
        if (totalIncome.compareTo(BigDecimal.ZERO) == 0) {
            return;
@@ -251,42 +251,43 @@
            profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
        }
        // 套餐业绩
        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
//        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
        // 普通商品业绩
        BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
        BigDecimal totalIncome = tcIncome.add(normalIncome);
//        BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
        BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate);
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.AGENT_BONUS.getType(), DataDictionaryEnum.AGENT_BONUS.getCode());
        BigDecimal profit = totalIncome.divide(new BigDecimal(dic.getValue()), 2, RoundingMode.HALF_UP);
        BigDecimal preProfit = profit.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
        BigDecimal profit = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP));
        List<MallMember> agentMembers = mallMemberMapper.selectByIdAndNoLevel(null, AgentLevelEnum.FIRST_LEVEL.name());
        if (CollUtil.isEmpty(agentMembers)) {
            return;
        }
        for (MallMember agentMember : agentMembers) {
            DataDictionaryCustom agentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.AGENT_LEVEL_REQUIRE, agentMember.getLevel());
            if (agentDic == null) {
                continue;
            }
        List<DataDictionaryCustom> dics = dataDictionaryCustomMapper.selectDicByType(AppContants.AGENT_LEVEL_REQUIRE);
        for (DataDictionaryCustom agentDic : dics) {
            JSONObject jsonObject = JSONObject.parseObject(agentDic.getValue());
            BigDecimal profitProp = jsonObject.getBigDecimal("profitProp");
            BigDecimal income = preProfit.multiply(profitProp);
            BigDecimal profitProp = jsonObject.getBigDecimal("profitProp").divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
            int reduce = walletService.reduce(income, agentMember.getId(), "score");
            if (reduce == 2) {
            List<MallMember> agentMemberList = mallMemberMapper.selectMemberWithLevel(agentDic.getCode());
            if (CollUtil.isEmpty(agentMemberList)) {
                continue;
            }
            walletService.add(income, agentMember.getId(), "commission");
            BigDecimal income = profit.multiply(profitProp).divide(BigDecimal.valueOf(agentMemberList.size()), 2, RoundingMode.HALF_UP);
            moneyFlowService.addMoneyFlow(agentMember.getId(), income, MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
            moneyFlowService.addMoneyFlow(agentMember.getId(), income.negate(), MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
            for (MallMember agentMember : agentMemberList) {
                int reduce = walletService.reduce(income, agentMember.getId(), "score");
                if (reduce == 2) {
                    continue;
                }
                walletService.add(income, agentMember.getId(), "commission");
                moneyFlowService.addMoneyFlow(agentMember.getId(), income, MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
                moneyFlowService.addMoneyFlow(agentMember.getId(), income.negate(), MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
            }
        }
        log.info("#####==代理分红==end==#####");
    }
@@ -306,10 +307,10 @@
        }
        // 套餐业绩
        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 2);
//        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 2);
        // 普通商品业绩
        BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 1);
        BigDecimal totalIncome = tcIncome.add(normalIncome);
//        BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 1);
        BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate);
        List<DataDictionaryCustom> rankAward = dataDictionaryCustomMapper.selectDicByType("RANK_AWARD");
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.RANK_BONUS.getType(), DataDictionaryEnum.RANK_BONUS.getCode());
@@ -395,10 +396,10 @@
            profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
        }
        // 套餐业绩
        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
//        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
        // 普通商品业绩
        BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
        BigDecimal totalIncome = tcIncome.add(normalIncome);
//        BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
        BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate);
        // 董事
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.DIRECTOR_BONUS.getType(), DataDictionaryEnum.DIRECTOR_BONUS.getCode());
src/main/resources/mapper/modules/MallMemberMapper.xml
@@ -395,4 +395,9 @@
            </if>
        </where>
    </select>
    <select id="selectMemberWithLevel" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member
        where level=#{level}
    </select>
</mapper>
src/test/java/cc/mrbird/febs/ProfitTest.java
@@ -35,6 +35,10 @@
    public void dynamicProfit() {
        memberProfitService.dynamicProfit(16L);
    }
    @Test
    public void agentProfit() {
        memberProfitService.agentProfit(null);
    }
    @Test