Browse Source

更新合赢奖和直推奖的计算

Yangzw 9 months ago
parent
commit
fd791bee04

+ 2 - 2
feifan-module-distri/feifan-module-distri-api/src/main/java/cn/newfeifan/mall/module/distri/enums/CaclEnum.java

@@ -9,8 +9,8 @@ public enum CaclEnum {
     PLATFORM_TOTAL_ADD(0, "平台总收益", "平台总收益"),
     PLATFORM_SERVICE_FEE(1, "平台服务费", "平台服务费"),
     PLATFORM_REVENUE(2, "平台收益", "平台收益"),
-    RECOMMENDED_PERSON_QUOTA(3, "推荐人额度", "推荐人额度"),
-    DIRECT_REFERRAL_QUOTA(4, "直推人额度", "直推人额度"),
+    RECOMMENDED_PERSON_QUOTA(3, "直推奖额度", "直推奖额度"),
+    DIRECT_REFERRAL_QUOTA(4, "用户自得额度", "用户自得额度"),
     TOGETHER_AWARD(5, "合赢奖", "合赢奖"),
     HIGH_QUOTA(6, "最高可以获得积分", "最高可以获得积分"),
     SMALL_QUOTA_CRASH(7, "小区额度分配", "小区额度分配"),

+ 6 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/ptprofitlog/vo/PtProfitLogPageReqVO.java

@@ -39,6 +39,12 @@ public class PtProfitLogPageReqVO extends PageParam {
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private LocalDateTime[] createTime;
 
+    @Schema(description = "变动的冻结积分值(可为负数)")
+    private Long freezeAmount;
+
+    @Schema(description = "变动后冻结积分钱包的余额")
+    private Long afterFreezeAmount;
+
     @Schema(description = "最大可用积分变化值")
     private Long maxAvailablePointsAmount;
 

+ 6 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/ptprofitlog/vo/PtProfitLogRespVO.java

@@ -49,6 +49,12 @@ public class PtProfitLogRespVO {
     @ExcelProperty("创建时间")
     private LocalDateTime createTime;
 
+    @Schema(description = "变动的冻结积分值(可为负数)")
+    private Long freezeAmount;
+
+    @Schema(description = "变动后冻结积分钱包的余额")
+    private Long afterFreezeAmount;
+
     @Schema(description = "最大可用积分变化值")
     @ExcelProperty("最大可用积分变化值")
     private Long maxAvailablePointsAmount;

+ 3 - 1
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/mysql/ptprofitlog/PtProfitLogMapper.java

@@ -29,7 +29,8 @@ public interface PtProfitLogMapper extends BaseMapperX<PtProfitLogDO> {
                 DIRECT_REFERRAL_QUOTA.getType(),
                 HIGH_QUOTA.getType(),
                 ORDER_PAY_INTEGRAL.getType(),
-                FREEZE_CHANGE_INTEGRAL.getType()
+                FREEZE_CHANGE_INTEGRAL.getType(),
+                SMALL_QUOTA_CRASH.getType()
         );
 
         if(reqVO.getUserId().equals(PT_ID)){
@@ -42,6 +43,7 @@ public interface PtProfitLogMapper extends BaseMapperX<PtProfitLogDO> {
                     GROSS_PROFIT_BONUS_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT.getType(),
                     GROSS_PROFIT_ANCESTOR_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT.getType()
             );
+            reqVO.setUserId(null);
         }
 
         return selectPage(reqVO, new LambdaQueryWrapperX<PtProfitLogDO>()

+ 123 - 42
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ordercalc/OrderCalcServiceImpl.java

@@ -226,7 +226,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
             // 用户所得: 毛利 * 0.35
             BigDecimal descendantQuota = profit[1];
 
-            // 直推奖: 毛利 * 0.35 (上一级)
+            // 直推奖: 毛利 * 0.3 (上一级)
             BigDecimal ancestorQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitAncestorQuotaPerc())).setScale(4, RoundingMode.DOWN);
 
             // 合赢将: 毛利 * 0.08
@@ -286,15 +286,32 @@ public class OrderCalcServiceImpl implements OrderCalcService {
                     .percentTemplate(percentTemplate).build();
             saveList.add(orderCalcSaveReqVO);
             // ========== 修改用户钱包 =================
+
             //直推奖也要限制额度
             Long ancestorHighQuota = integralDOAncestor.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();//加上基础的最大额度值
-            if (ancestorHighQuota < ancestorQuotaInt) {
-                changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, 0L,
-                        descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt);
-            } else {
-                changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, ancestorQuotaInt,
-                        descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt);
+
+            //amount用于记录本次添加的值
+            Long amount = 0L;
+            //平台需要补回的收益
+            Long ptReplenish = ancestorQuotaInt;
+
+            //如果直推人的可获取额度大于0,则能够获取
+            if (ancestorHighQuota.compareTo(0L) > 0) {
+                if (ancestorHighQuota.compareTo(ancestorQuotaInt) > 0) {
+                    //如果最大额度 > 直推人可获取额度,则直接获取
+                    amount = ancestorQuotaInt;
+                    //平台没有需要补回的收益
+                    ptReplenish = 0L;
+                } else {
+                    //如果最大额度 < 直推人可获取额度,则获取自己的最大额度
+                    amount = ancestorHighQuota;
+                    //用户本次没有拿到的直推奖
+                    ptReplenish = ancestorQuotaInt - ancestorHighQuota;
+                }
             }
+            changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, amount,
+                    descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt);
+
             // ========== 修改平台信息 =================
             // 每个订单计算的过程
             // 增加平台收益
@@ -305,9 +322,12 @@ public class OrderCalcServiceImpl implements OrderCalcService {
                             .ptGrossAdd(grossProfitAfterBonusInt)
                             .ptTotalAdd(platformQuotaInt + grossProfitAfterBonusInt).build();
 
+
             // 当直推人获取的积分额度不足时,平台收益要加回来,并生成log
-            calcIntegral(ptProfitSaveReqVOS, ptProfitSaveReqVO, ancestorHighQuota, ancestorQuotaInt,
-                    k.getOrderId(), k.getNo(), integralDOAncestor.getUserId());
+            if (ptReplenish.compareTo(0L) > 0) {
+                calcIntegral(ptProfitSaveReqVOS, ptProfitSaveReqVO, ptReplenish,
+                        k.getOrderId(), k.getNo());
+            }
 
             ptProfitSaveReqVOS.add(ptProfitSaveReqVO);
             // ========== 增加日志记录 =================
@@ -315,43 +335,91 @@ public class OrderCalcServiceImpl implements OrderCalcService {
             // 平台记录
             // 平台总收益
             // 平台总收益
-            PtProfitLogSaveReqVO ptTotal = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId())
-                    .profitStatus(CaclEnum.PLATFORM_TOTAL_ADD.getType()).orderNo(k.getNo())
-                    .amount(platformQuotaInt + grossProfitAfterBonusInt).afterAmount(ptProfitDO.getPtTotalAdd() + platformQuotaInt + grossProfitAfterBonusInt).percentTemplate(percentTemplate).build();
+            PtProfitLogSaveReqVO ptTotal = PtProfitLogSaveReqVO.builder()
+                    .orderId(k.getOrderId())
+                    .profitStatus(CaclEnum.PLATFORM_TOTAL_ADD.getType())
+                    .orderNo(k.getNo())
+                    .amount(platformQuotaInt + grossProfitAfterBonusInt)
+                    .afterAmount(ptProfitDO.getPtTotalAdd() + platformQuotaInt + grossProfitAfterBonusInt)
+                    .percentTemplate(percentTemplate)
+                    .build();
             // 平台收益
-            PtProfitLogSaveReqVO ptGrossAddLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId())
-                    .profitStatus(CaclEnum.PLATFORM_REVENUE.getType()).orderNo(k.getNo())
-                    .amount(grossProfitAfterBonusInt).afterAmount(ptProfitDO.getPtGrossAdd() + ptProfitSaveReqVO.getPtGrossAdd()).percentTemplate(percentTemplate).build();
+            PtProfitLogSaveReqVO ptGrossAddLog = PtProfitLogSaveReqVO.builder()
+                    .orderId(k.getOrderId())
+                    .profitStatus(CaclEnum.PLATFORM_REVENUE.getType())
+                    .orderNo(k.getNo())
+                    .amount(grossProfitAfterBonusInt)
+                    .afterAmount(ptProfitDO.getPtGrossAdd() + ptProfitSaveReqVO.getPtGrossAdd())
+                    .percentTemplate(percentTemplate)
+                    .build();
 
             // 平台服务费
-            PtProfitLogSaveReqVO ptAddLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId())
-                    .profitStatus(CaclEnum.PLATFORM_SERVICE_FEE.getType()).orderNo(k.getNo())
-                    .amount(platformQuotaInt).afterAmount(ptProfitDO.getPtAdd() + ptProfitSaveReqVO.getPtAdd()).percentTemplate(percentTemplate).build();
+            PtProfitLogSaveReqVO ptAddLog = PtProfitLogSaveReqVO.builder()
+                    .orderId(k.getOrderId())
+                    .profitStatus(CaclEnum.PLATFORM_SERVICE_FEE.getType())
+                    .orderNo(k.getNo())
+                    .amount(platformQuotaInt)
+                    .afterAmount(ptProfitDO.getPtAdd() + ptProfitSaveReqVO.getPtAdd())
+                    .percentTemplate(percentTemplate)
+                    .build();
 
 
-            // 推荐人记录
-            PtProfitLogSaveReqVO tjrLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.RECOMMENDED_PERSON_QUOTA.getType()).orderNo(k.getNo()).userId(sharePath.getAncestor()).amount(ancestorQuotaInt).afterAmount(integralDOAncestor.getCurrentQuota() + ancestorQuotaInt).percentTemplate(percentTemplate).build();
+            // 直推奖记录
+            PtProfitLogSaveReqVO tjrLog = PtProfitLogSaveReqVO.builder()
+                    .orderId(k.getOrderId())
+                    .profitStatus(CaclEnum.RECOMMENDED_PERSON_QUOTA.getType())
+                    .orderNo(k.getNo())
+                    .userId(sharePath.getAncestor())
+                    .amount(amount)
+                    .afterAmount(integralDOAncestor.getCurrentQuota())
+                    .ancestorQuotaAmount(ptReplenish)
+                    .percentTemplate(percentTemplate)
+                    .build();
 
 
-            // 直推人记录
-            PtProfitLogSaveReqVO ztrLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.DIRECT_REFERRAL_QUOTA.getType()).orderNo(k.getNo()).userId(sharePath.getDescendant()).amount(descendantQuotaInt).afterAmount(integralDO.getCurrentQuota() + descendantQuotaInt).percentTemplate(percentTemplate).build();
-            // 直推人冻结积分转化成可用记录
+            // 用户自得记录
+            PtProfitLogSaveReqVO ztrLog = PtProfitLogSaveReqVO.builder()
+                    .orderId(k.getOrderId())
+                    .profitStatus(CaclEnum.DIRECT_REFERRAL_QUOTA.getType())
+                    .orderNo(k.getNo())
+                    .userId(sharePath.getDescendant())
+                    .amount(descendantQuotaInt)
+                    .afterAmount(integralDO.getCurrentQuota() + descendantQuotaInt)
+                    .percentTemplate(percentTemplate)
+                    .build();
+            // 用户冻结积分转化成可用记录
             PtProfitLogSaveReqVO freezeLog = PtProfitLogSaveReqVO.builder()
                     .orderId(k.getOrderId())
                     .profitStatus(CaclEnum.FREEZE_CHANGE_INTEGRAL.getType())
                     .orderNo(k.getNo())
                     .userId(sharePath.getDescendant())
+                    .amount(descendantQuotaInt)
+                    .afterAmount(integralDO.getCurrentQuota() + descendantQuotaInt)
                     .freezeAmount(descendantQuotaInt)
-                    .afterFreezeAmount(integralDO.getFreezeQuota() - descendantQuotaInt)
+                    .afterFreezeAmount(integralDO.getFreezeQuota())
                     .percentTemplate(percentTemplate)
                     .amount(descendantQuotaInt)
                     .afterAmount(integralDO.getCurrentQuota() + descendantQuotaInt)
                     .build();
 
-            PtProfitLogSaveReqVO highQuotaLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.HIGH_QUOTA.getType()).orderNo(k.getNo()).userId(sharePath.getDescendant()).amount(highQuotaInt).afterAmount(integralDO.getHighQuota() + highQuotaInt).percentTemplate(percentTemplate).build();
+            PtProfitLogSaveReqVO highQuotaLog = PtProfitLogSaveReqVO.builder()
+                    .orderId(k.getOrderId())
+                    .profitStatus(CaclEnum.HIGH_QUOTA.getType())
+                    .orderNo(k.getNo())
+                    .userId(sharePath.getDescendant())
+                    .amount(highQuotaInt)
+                    .afterAmount(integralDO.getHighQuota() + highQuotaInt)
+                    .percentTemplate(percentTemplate)
+                    .build();
 
             // 合赢奖记录
-            PtProfitLogSaveReqVO hyjLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.TOGETHER_AWARD.getType()).orderNo(k.getNo()).amount(bonusQuotaInt).afterAmount(0L).percentTemplate(percentTemplate).build();
+            PtProfitLogSaveReqVO hyjLog = PtProfitLogSaveReqVO.builder()
+                    .orderId(k.getOrderId())
+                    .profitStatus(CaclEnum.TOGETHER_AWARD.getType())
+                    .orderNo(k.getNo())
+                    .amount(bonusQuotaInt)
+                    .afterAmount(0L)
+                    .percentTemplate(percentTemplate).build();
 
 
             ptProfitLogSaveReqVOS.add(ptTotal);
@@ -392,22 +460,22 @@ public class OrderCalcServiceImpl implements OrderCalcService {
 
     }
 
-    private void calcIntegral(List<PtProfitSaveReqVO> ptProfitSaveReqVOS, PtProfitSaveReqVO ptProfitSaveReqVO,
-                              Long highQuotaInt, Long ancestorQuotaInt, Long orderId, String orderNo, Long userId) {
-        if (highQuotaInt < ancestorQuotaInt) {
-            ptProfitSaveReqVO.setPtGrossAdd(ptProfitSaveReqVO.getPtGrossAdd() + ancestorQuotaInt);
-            ptProfitSaveReqVO.setPtTotalAdd(ptProfitSaveReqVO.getPtGrossAdd() + ptProfitSaveReqVO.getPtAdd());
-
-            PtProfitLogSaveReqVO ptProfitLog = PtProfitLogSaveReqVO.builder()
-                    .orderId(orderId)
-                    .profitStatus(CaclEnum.GROSS_PROFIT_ANCESTOR_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT.getType())
-                    .orderNo(orderNo)
-                    .userId(userId)
-                    .amount(ancestorQuotaInt)
-                    .afterAmount(ptProfitSaveReqVOS.stream().mapToLong(PtProfitSaveReqVO::getPtGrossAdd).sum() + ancestorQuotaInt)
-                    .build();
-            ptProfitLogService.createPtProfitLog(ptProfitLog);
-        }
+    /**
+     * 在用户获取直推奖的时候溢出的需要加入到平台,并记录log
+     */
+    private void calcIntegral(List<PtProfitSaveReqVO> ptProfitSaveReqVOS, PtProfitSaveReqVO ptProfitSaveReqVO
+            , Long ancestorQuotaInt, Long orderId, String orderNo) {
+        ptProfitSaveReqVO.setPtGrossAdd(ptProfitSaveReqVO.getPtGrossAdd() + ancestorQuotaInt);
+        ptProfitSaveReqVO.setPtTotalAdd(ptProfitSaveReqVO.getPtGrossAdd() + ptProfitSaveReqVO.getPtAdd());
+
+        PtProfitLogSaveReqVO ptProfitLog = PtProfitLogSaveReqVO.builder()
+                .orderId(orderId)
+                .profitStatus(CaclEnum.GROSS_PROFIT_ANCESTOR_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT.getType())
+                .orderNo(orderNo)
+                .amount(ancestorQuotaInt)
+                .afterAmount(ptProfitSaveReqVOS.stream().mapToLong(PtProfitSaveReqVO::getPtGrossAdd).sum() + ancestorQuotaInt)
+                .build();
+        ptProfitLogService.createPtProfitLog(ptProfitLog);
     }
 
     private PtProfitDO calcPtProfit(PtProfitDO ptProfitDO, List<PtProfitSaveReqVO> ptProfitSaveReqVOS) {
@@ -442,6 +510,19 @@ public class OrderCalcServiceImpl implements OrderCalcService {
         saveList.add(orderCalcSaveReqVO);
     }
 
+    /**
+     * 修改用户钱包
+     *
+     * @param integralSaveReqVOS
+     * @param integralDO
+     * @param integralDOAncestor
+     * @param pt
+     * @param ancestorQuota
+     * @param descendantQuota
+     * @param highQuota
+     * @param ptA
+     * @param ptB
+     */
     private void changeUserWallet(List<IntegralSaveReqVO> integralSaveReqVOS, IntegralDO integralDO, IntegralDO integralDOAncestor, IntegralDO pt,
                                   Long ancestorQuota, Long descendantQuota, Long highQuota, Long ptA, Long ptB) {
         // 修改用户钱包

+ 116 - 37
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/partitioncrash/PartitionCrashServiceImpl.java

@@ -267,44 +267,99 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
 
                 BigDecimal smallBigDecimal = new BigDecimal(String.valueOf(smallQuota));
                 BigDecimal multiply = smallBigDecimal.divide(new BigDecimal("2.0"), 4, RoundingMode.DOWN);
-                if (compare(highQuota, multiply) && multiply.longValue() != 0) {
-                    integralDO.setCurrentQuota(integralDO.getCurrentQuota() + multiply.intValue());
-                    integralDO.setHighQuota(integralDO.getHighQuota() - multiply.intValue());
+                //直推人的本次添加积分
+                Long amount = 0L;
+                //平台需要补回的收益(也可以理解为用户溢出)
+                Long ptReplenish = multiply.longValue();
+
+                //直推人
+                if (multiply.longValue() != 0) {
+                    if (highQuota.compareTo(0L) > 0) {
+
+                        if (highQuota.compareTo(multiply.longValue()) > 0) {
+                            amount = multiply.longValue();
+                            ptReplenish = 0L;
+                        } else {
+                            amount = highQuota;
+                            ptReplenish = multiply.longValue() - highQuota;
+                        }
+                        addHighQuota(userHighQuotaMap, integralDO.getUserId(), amount);
+                    }
+                    integralDO.setCurrentQuota(integralDO.getCurrentQuota() + amount);
+                    integralDO.setHighQuota(integralDO.getHighQuota() - amount);
 
-                    addHighQuota(userHighQuotaMap, integralDO.getUserId(), (long) multiply.intValue());
 
-                    integralDO.setAccumulatedQuota(integralDO.getAccumulatedQuota() + multiply.intValue());
+                    integralDO.setAccumulatedQuota(integralDO.getAccumulatedQuota() + amount);
                     // 碰撞后的额度添加到日志中 增加日志模块
                     integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
-                    ptProfitLogService.addMessage(k.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, Long.parseLong(String.valueOf(multiply.intValue())), integralDO.getCurrentQuota(), JsonUtils.toJsonString(orderPercentageDO));
+                    ptProfitLogService.addMessage(k.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, amount,
+                            integralDO.getCurrentQuota(), JsonUtils.toJsonString(orderPercentageDO), ptReplenish);
                 }
-                if (compare(parentHighQuota, multiply) && multiply.longValue() != 0) {
-                    // 减去最高额度
-                    parentIntegralDo.setCurrentQuota(parentIntegralDo.getCurrentQuota() + multiply.intValue());
-                    parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - multiply.intValue());
 
-                    addHighQuota(userHighQuotaMap, parentIntegralDo.getUserId(), (long) multiply.intValue());
+                //直推人的上级的本次添加积分
+                Long parentAmount = 0L;
+                //平台需要补回的收益(也可以理解为用户溢出)
+                Long parentPtReplenish = multiply.longValue();
+                //直推人的父级
+                if (multiply.longValue() != 0) {
+                    if (parentHighQuota.compareTo(0L) > 0) {
+                        if (parentHighQuota.compareTo(multiply.longValue()) > 0) {
+                            parentAmount = multiply.longValue();
+                            parentPtReplenish = 0L;
+                        } else {
+                            parentAmount = highQuota;
+                            parentPtReplenish = multiply.longValue() - highQuota;
+                        }
+                        addHighQuota(userHighQuotaMap, parentIntegralDo.getUserId(), parentAmount);
+                    }
+                    // 减去最高额度
+                    parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - parentAmount);
+                    parentIntegralDo.setCurrentQuota(parentIntegralDo.getCurrentQuota() + parentAmount);
 
-                    parentIntegralDo.setAccumulatedQuota(parentIntegralDo.getAccumulatedQuota() + multiply.intValue());
+                    parentIntegralDo.setAccumulatedQuota(parentIntegralDo.getAccumulatedQuota() + parentAmount);
                     // 碰撞后的额度添加到日志中 增加日志模块
                     integralService.updateIntegral(BeanUtils.toBean(parentIntegralDo, IntegralSaveReqVO.class));
-                    ptProfitLogService.addMessage(parentIntegralDo.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, Long.parseLong(String.valueOf(multiply.intValue())), parentIntegralDo.getCurrentQuota(), JsonUtils.toJsonString(orderPercentageDO));
+                    ptProfitLogService.addMessage(parentIntegralDo.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, parentAmount,
+                            parentIntegralDo.getCurrentQuota(), JsonUtils.toJsonString(orderPercentageDO), parentPtReplenish);
                 }
-                if (highQuota < multiply.longValue() && multiply.longValue() != 0L) {
-                    calcIntegral(multiply.longValue(), integralDO.getUserId(), JsonUtils.toJsonString(orderPercentageDO));
+//                if (compare(highQuota, multiply) && multiply.longValue() != 0) {
+//                    integralDO.setCurrentQuota(integralDO.getCurrentQuota() + multiply.intValue());
+//                    integralDO.setHighQuota(integralDO.getHighQuota() - multiply.intValue());
+//
+//                    addHighQuota(userHighQuotaMap, integralDO.getUserId(), (long) multiply.intValue());
+//
+//                    integralDO.setAccumulatedQuota(integralDO.getAccumulatedQuota() + multiply.intValue());
+//                    // 碰撞后的额度添加到日志中 增加日志模块
+//                    integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
+//                    ptProfitLogService.addMessage(k.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, Long.parseLong(String.valueOf(multiply.intValue())), integralDO.getCurrentQuota(), JsonUtils.toJsonString(orderPercentageDO));
+//                }
+//                if (compare(parentHighQuota, multiply) && multiply.longValue() != 0) {
+//                    // 减去最高额度
+//                    parentIntegralDo.setCurrentQuota(parentIntegralDo.getCurrentQuota() + multiply.intValue());
+//                    parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - multiply.intValue());
+//
+//                    addHighQuota(userHighQuotaMap, parentIntegralDo.getUserId(), (long) multiply.intValue());
+//
+//                    parentIntegralDo.setAccumulatedQuota(parentIntegralDo.getAccumulatedQuota() + multiply.intValue());
+//                    // 碰撞后的额度添加到日志中 增加日志模块
+//                    integralService.updateIntegral(BeanUtils.toBean(parentIntegralDo, IntegralSaveReqVO.class));
+//                    ptProfitLogService.addMessage(parentIntegralDo.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, Long.parseLong(String.valueOf(multiply.intValue())), parentIntegralDo.getCurrentQuota(), JsonUtils.toJsonString(orderPercentageDO));
+//                }
+                if (!ptReplenish.equals(0L)) {
+                    calcIntegral(ptReplenish, integralDO.getUserId(), JsonUtils.toJsonString(orderPercentageDO));
                 }
-                if (parentHighQuota < multiply.longValue() && multiply.longValue() != 0L) {
-                    calcIntegral(multiply.longValue(), parentIntegralDo.getUserId(), JsonUtils.toJsonString(orderPercentageDO));
+                if (!parentPtReplenish.equals(0L)) {
+                    calcIntegral(parentPtReplenish, parentIntegralDo.getUserId(), JsonUtils.toJsonString(orderPercentageDO));
                 }
 
                 // 获取计算后积分, Long为userId, Integer为碰撞后额度
                 HashMap<Long, Long> map = new HashMap<>();
                 // 如果为当前用户为平台,则不需要存入这个地方
                 if (!k.getUserId().equals(PT_ID)) {
-                    map.put(k.getUserId(), multiply.longValue());
+                    map.put(k.getUserId(), amount);
                 }
                 if (!parentIntegralDo.getUserId().equals(PT_ID)) {
-                    map.put(parentIntegralDo.getUserId(), multiply.longValue());
+                    map.put(parentIntegralDo.getUserId(), parentAmount);
                 }
                 afterCrashMap.add(map);
 
@@ -335,8 +390,6 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
 //                if (ptProfit.getPtGrossAdd() <= 0) {
 //                    break;
 //                }
-                // 当前平台总积分
-//                Integer ptTotalAdd = ptProfit.getPtTotalAdd();
 
                 if (entry.getValue() == 0) {
                     continue;
@@ -345,8 +398,6 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
                 // 获取当前用户的钱包
                 IntegralDO integralDO = integralDOMap.get(entry.getKey());
                 // 获取当前父亲的钱包
-//                Long parent = sonAndParent.get(entry.getKey());
-//                IntegralDO parentIntegralDo = integralDOMap.get(parent);
                 Long highQuota = integralDO.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();       //加上基础的最大额度值
 
                 for (Long key : userHighQuotaMap.keySet()) {
@@ -359,27 +410,55 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
                     }
                 }
 
-//                Long parentHighQuota = parentIntegralDo.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();
-                if (highQuota >= entry.getValue()) {
-//                    integralDO.setHighQuota(integralDO.getHighQuota() - entry.getValue());
+
+                //amount用于记录本次添加的值
+                Long amount = 0L;
+                //平台需要补回的收益
+                Long ptReplenish = entry.getValue();
+
+                //如果直推人的可获取额度大于0,则能够获取
+                if (highQuota.compareTo(0L) > 0) {
+                    if (highQuota.compareTo(entry.getValue()) > 0) {
+                        //如果最大额度 > 直推人可获取额度,则直接获取
+                        amount = entry.getValue();
+                        //平台没有需要补回的收益
+                        ptReplenish = 0L;
+                    } else {
+                        //如果最大额度 < 直推人可获取额度,则获取自己的最大额度
+                        amount = highQuota;
+                        //用户本次没有拿到的直推奖
+                        ptReplenish = entry.getValue() - highQuota;
+                    }
+
                     integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
-//                if (parentHighQuota >= entry.getValue()) {
-//                    parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - entry.getValue());
-//                    integralService.updateIntegral(BeanUtils.toBean(parentIntegralDo, IntegralSaveReqVO.class));
-//                }
 
 
                     // 扣除平台收益
-                    log.info("扣除平台收益[合赢奖] " + "用户 " + entry.getKey() + "额度: " + entry.getValue());
-                    ptProfit.setPtGrossAdd(ptProfit.getPtGrossAdd() - entry.getValue());
+                    log.info("扣除平台收益[合赢奖] " + "用户 " + entry.getKey() + "额度: " + amount);
+                    ptProfit.setPtGrossAdd(ptProfit.getPtGrossAdd() - amount);
                     // 平台扣除积分
-                    ptProfit.setPtTotalAdd(ptProfit.getPtTotalAdd() - entry.getValue());
+                    ptProfit.setPtTotalAdd(ptProfit.getPtTotalAdd() - amount);
                     // 碰撞后的额度添加到日志中 增加日志模块
                     ptProfitLogService.addMessage(entry.getKey(), CaclEnum.AFTER_CRASH_CALC_PT_TOTAL_QUOTA
-                            , -entry.getValue(), ptProfit.getPtTotalAdd(), JsonUtils.toJsonString(orderPercentageDO));
+                            , -entry.getValue(), ptProfit.getPtTotalAdd(), JsonUtils.toJsonString(orderPercentageDO), null);
                     ptProfitLogService.addMessage(entry.getKey(), CaclEnum.AFTER_CRASH_CALC_PT_TOTAL_GROSS_QUOTA
-                            , -entry.getValue(), ptProfit.getPtTotalAdd(), JsonUtils.toJsonString(orderPercentageDO));
+                            , -entry.getValue(), ptProfit.getPtGrossAdd(), JsonUtils.toJsonString(orderPercentageDO), null);
                 }
+//                if (highQuota.compareTo(0L) > 0) {
+//                    integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
+//
+//
+//                    // 扣除平台收益
+//                    log.info("扣除平台收益[合赢奖] " + "用户 " + entry.getKey() + "额度: " + entry.getValue());
+//                    ptProfit.setPtGrossAdd(ptProfit.getPtGrossAdd() - entry.getValue());
+//                    // 平台扣除积分
+//                    ptProfit.setPtTotalAdd(ptProfit.getPtTotalAdd() - entry.getValue());
+//                    // 碰撞后的额度添加到日志中 增加日志模块
+//                    ptProfitLogService.addMessage(entry.getKey(), CaclEnum.AFTER_CRASH_CALC_PT_TOTAL_QUOTA
+//                            , -entry.getValue(), ptProfit.getPtTotalAdd(), JsonUtils.toJsonString(orderPercentageDO),null);
+//                    ptProfitLogService.addMessage(entry.getKey(), CaclEnum.AFTER_CRASH_CALC_PT_TOTAL_GROSS_QUOTA
+//                            , -entry.getValue(), ptProfit.getPtTotalAdd(), JsonUtils.toJsonString(orderPercentageDO),null);
+//                }
             }
         }
         ptProfitService.updatePtProfit(PtProfitSaveReqVO.builder().id(ptProfit.getId())
@@ -413,8 +492,8 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
 
     private void calcIntegral(Long multiply, Long userId, String jsonString) {
         PtProfitDO ptProfit = ptProfitService.getPtProfit();
-        ptProfitLogService.addMessage(userId, CaclEnum.GROSS_PROFIT_BONUS_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT, multiply,
-                ptProfit.getPtTotalAdd(), jsonString);
+        ptProfitLogService.addMessage(null, CaclEnum.GROSS_PROFIT_BONUS_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT, multiply,
+                ptProfit.getPtTotalAdd(), jsonString, userId);
     }
 
     private void createPtProfitDailyStatisticsLog(Long sum) {

+ 2 - 1
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ptprofitlog/PtProfitLogService.java

@@ -63,8 +63,9 @@ public interface PtProfitLogService {
      * @param amount      增加额度
      * @param afterAmount 增加之后的额度
      * @param jsonString  百分比计算模板
+     * @param accumulatedQuotAmount  合赢奖溢出
      */
-    void addMessage(Long userId, CaclEnum caclEnum, Long amount, Long afterAmount, String jsonString);
+    void addMessage(Long userId, CaclEnum caclEnum, Long amount, Long afterAmount, String jsonString,Long accumulatedQuotAmount);
     void addMessage(Long userId, CaclEnum caclEnum, Integer amount, Integer afterAmount);
 
     /**

+ 2 - 1
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ptprofitlog/PtProfitLogServiceImpl.java

@@ -89,13 +89,14 @@ public class PtProfitLogServiceImpl implements PtProfitLogService {
     }
 
     @Override
-    public void addMessage(Long userId, CaclEnum caclEnum, Long amount, Long afterAmount, String percentTemplate) {
+    public void addMessage(Long userId, CaclEnum caclEnum, Long amount, Long afterAmount, String percentTemplate,Long accumulatedQuotAmount) {
         PtProfitLogSaveReqVO ptProfitLog = PtProfitLogSaveReqVO.builder()
                 .afterAmount(afterAmount)
                 .amount(amount)
                 .percentTemplate(percentTemplate)
                 .userId(userId)
                 .profitStatus(caclEnum.getType())
+                .accumulatedQuotaAmount(accumulatedQuotAmount)
                 .build();
         ptProfitLogMapper.insert(BeanUtils.toBean(ptProfitLog, PtProfitLogDO.class));
         // todo 发送通知