| | |
| | | import cc.mrbird.febs.mall.entity.*; |
| | | import cc.mrbird.febs.mall.mapper.*; |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberWalletService; |
| | | import cc.mrbird.febs.mall.service.IMallAchieveService; |
| | | import cc.mrbird.febs.mall.service.IMallMoneyFlowService; |
| | | import cc.mrbird.febs.mall.service.IMemberProfitService; |
| | | import cn.hutool.core.collection.CollUtil; |
| | |
| | | import java.math.RoundingMode; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | private final IMallMoneyFlowService moneyFlowService; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final MallMoneyFlowMapper mallMoneyFlowMapper; |
| | | private final IMallAchieveService mallAchieveService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | } |
| | | |
| | | Date profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); |
| | | BigDecimal totalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D"); |
| | | // 套餐业绩 |
| | | BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2); |
| | | // 普通商品业绩 |
| | | BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1); |
| | | BigDecimal totalIncome = tcIncome.add(normalIncome); |
| | | |
| | | if (totalIncome.compareTo(BigDecimal.ZERO) == 0) { |
| | | return; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void dynamicProfit(Long orderId) { |
| | | dynamicProfit(orderId, 2); |
| | | } |
| | | |
| | | /** |
| | | * 直推20%,隔代收益为直推奖励金额的30%,a_b_c_d,d购买1000套餐,c得200,b得200*30%=60元,a得60*30%=18元。。。 |
| | | * 以此类推,结算到一元为止。 |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void dynamicProfit(Long orderId) { |
| | | public void dynamicProfit(Long orderId, Integer isNormal) { |
| | | log.info("######直推奖励, 订单ID:{}######", orderId); |
| | | MallOrderInfo orderInfo = mallOrderInfoMapper.selectById(orderId); |
| | | if (orderInfo.getOrderType() == 2) { |
| | |
| | | continue; |
| | | } |
| | | |
| | | Integer isReturn = null; |
| | | if (item.getIsNormal() == 1) { |
| | | isReturn = 2; |
| | | // 判断套餐或者普通商品,结算对应商品的动态分红 |
| | | if (!Objects.equals(item.getIsNormal(), isNormal)) { |
| | | continue; |
| | | } |
| | | |
| | | // =======直推返利== start ===== |
| | |
| | | |
| | | walletService.add(dynamicProfit, parent.getId(), "commission"); |
| | | |
| | | moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue(), isReturn); |
| | | moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit.negate(), MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); |
| | | // =======直推返利== end ===== |
| | | |
| | |
| | | } |
| | | |
| | | walletService.add(direct, parentMember.getId(), "commission"); |
| | | moneyFlowService.addMoneyFlow(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue(), isReturn); |
| | | moneyFlowService.addMoneyFlow(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(parentMember.getId(), direct.negate(), MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); |
| | | } |
| | | // =======隔代奖== end ===== |
| | | |
| | | item.setHasSettle(1); |
| | | mallOrderItemMapper.updateById(item); |
| | | |
| | | // 添加业绩 |
| | | mallAchieveService.add(item.getId()); |
| | | } |
| | | } |
| | | |
| | |
| | | if (profitDate == null) { |
| | | profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); |
| | | } |
| | | BigDecimal totalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D"); |
| | | |
| | | // 套餐业绩 |
| | | BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2); |
| | | // 普通商品业绩 |
| | | BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1); |
| | | BigDecimal totalIncome = tcIncome.add(normalIncome); |
| | | |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.AGENT_BONUS.getType(), DataDictionaryEnum.AGENT_BONUS.getCode()); |
| | | BigDecimal profit = totalIncome.divide(new BigDecimal(dic.getValue()), 2, RoundingMode.HALF_UP); |
| | |
| | | return; |
| | | } |
| | | |
| | | BigDecimal totalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M"); |
| | | // 套餐业绩 |
| | | BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 2); |
| | | // 普通商品业绩 |
| | | BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 1); |
| | | BigDecimal totalIncome = tcIncome.add(normalIncome); |
| | | |
| | | List<DataDictionaryCustom> rankAward = dataDictionaryCustomMapper.selectDicByType("RANK_AWARD"); |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.RANK_BONUS.getType(), DataDictionaryEnum.RANK_BONUS.getCode()); |
| | |
| | | } |
| | | |
| | | BigDecimal reduceProfit = income.multiply(prop); |
| | | if (reduceProfit.compareTo(BigDecimal.ZERO) > 0) { |
| | | if (reduceProfit.compareTo(BigDecimal.ZERO) < 1) { |
| | | continue; |
| | | } |
| | | |
| | | int reduce = walletService.reduce(reduceProfit.negate(), mallMember.getId(), "commission"); |
| | | int reduce = walletService.reduce(reduceProfit, mallMember.getId(), "commission"); |
| | | if (reduce == 2) { |
| | | continue; |
| | | } |
| | |
| | | continue; |
| | | } |
| | | |
| | | int reduce1 = walletService.reduce(preProfit.negate(), child.getId(), "score"); |
| | | int reduce1 = walletService.reduce(preProfit, child.getId(), "score"); |
| | | if (reduce1 == 2) { |
| | | continue; |
| | | } |
| | |
| | | } |
| | | log.info("######==感恩奖==end==####"); |
| | | } |
| | | |
| | | @Override |
| | | public void storeAndDirectorProfit(Date profitDate) { |
| | | log.info("#####==店补/董事==start==######"); |
| | | if (profitDate == null) { |
| | | profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); |
| | | } |
| | | // 套餐业绩 |
| | | BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2); |
| | | // 普通商品业绩 |
| | | BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1); |
| | | BigDecimal totalIncome = tcIncome.add(normalIncome); |
| | | |
| | | // 董事 |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.DIRECTOR_BONUS.getType(), DataDictionaryEnum.DIRECTOR_BONUS.getCode()); |
| | | List<MallMember> directors = mallMemberMapper.selectDirectorsOrStoreMaster(1); |
| | | if (CollUtil.isNotEmpty(directors)) { |
| | | BigDecimal total = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP)); |
| | | BigDecimal pre = total.divide(new BigDecimal(directors.size()), 2, RoundingMode.HALF_UP); |
| | | |
| | | for (MallMember director : directors) { |
| | | if (pre.compareTo(BigDecimal.ZERO) < 1) { |
| | | continue; |
| | | } |
| | | |
| | | int reduce = walletService.reduce(pre, director.getId(), "score"); |
| | | if (reduce == 2) { |
| | | continue; |
| | | } |
| | | |
| | | walletService.add(pre, director.getId(), "commission"); |
| | | moneyFlowService.addMoneyFlow(director.getId(), pre, MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(director.getId(), pre.negate(), MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue()); |
| | | } |
| | | } |
| | | |
| | | // 店补 |
| | | dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.COMMUNITY_BONUS.getType(), DataDictionaryEnum.COMMUNITY_BONUS.getCode()); |
| | | List<MallMember> storeMasters = mallMemberMapper.selectDirectorsOrStoreMaster(2); |
| | | if (CollUtil.isNotEmpty(storeMasters)) { |
| | | BigDecimal total = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP)); |
| | | BigDecimal pre = total.divide(new BigDecimal(storeMasters.size()), 2, RoundingMode.HALF_UP); |
| | | |
| | | for (MallMember storeMaster : storeMasters) { |
| | | if (pre.compareTo(BigDecimal.ZERO) < 1) { |
| | | continue; |
| | | } |
| | | |
| | | int reduce = walletService.reduce(pre, storeMaster.getId(), "score"); |
| | | if (reduce == 2) { |
| | | continue; |
| | | } |
| | | |
| | | walletService.add(pre, storeMaster.getId(), "commission"); |
| | | moneyFlowService.addMoneyFlow(storeMaster.getId(), pre, MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(storeMaster.getId(), pre.negate(), MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue()); |
| | | } |
| | | } |
| | | |
| | | log.info("#####==店补/董事==end==######"); |
| | | } |
| | | } |