Browse Source

计算订单身价,修改合赢奖和直推奖的限制

杨展威 6 months ago
parent
commit
a629686967

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

@@ -15,11 +15,13 @@ public enum CaclEnum {
     HIGH_QUOTA(6, "最高可以获得积分", "最高可以获得积分"),
     SMALL_QUOTA_CRASH(7, "小区额度分配", "小区额度分配"),
     AFTER_CRASH_CALC_PT_TOTAL_QUOTA(8, "碰撞后计算平台总收益", "碰撞后计算平台总收益"),
-    AFTER_CRASH_CALC_PT_TOTAL_GROSS_QUOTA(12, "碰撞后计算平台收益", "碰撞后计算平台收益"),
     ORDER_PAY_INTEGRAL(9, "购物获得积分", "购物获得冻结积分"),
-    FREEZE_CHANGE_INTEGRAL(13, "冻结积分转化成可用积分", "冻结积分变为可用积分"),
     ORDER_REFUND_INTEGRAL(10, "订单退款,积分退回", "购物收货7天后,冻结积分变为可用积分"),
-    ORDER_INTEGRAL_UNFREEZE(11, "订单积分到账", "订单积分到账");
+    ORDER_INTEGRAL_UNFREEZE(11, "订单积分到账", "订单积分到账"),
+    AFTER_CRASH_CALC_PT_TOTAL_GROSS_QUOTA(12, "碰撞后计算平台收益", "碰撞后计算平台收益"),
+    FREEZE_CHANGE_INTEGRAL(13, "冻结积分转化成可用积分", "冻结积分变为可用积分"),
+    GROSS_PROFIT_BONUS_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT(14, "合赢奖超额", "合赢奖的获取超出最高可获取"),
+    GROSS_PROFIT_ANCESTOR_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT(15, "直推奖超额", "直推奖的获取超出最高可获取");
 
     /**
      * 来源
@@ -44,4 +46,4 @@ public enum CaclEnum {
         return null;
     }
 
-}
+}

+ 7 - 1
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/integral/IntegralServiceImpl.java

@@ -40,6 +40,8 @@ public class IntegralServiceImpl implements IntegralService {
     public Long createIntegral(IntegralSaveReqVO createReqVO) {
         // 插入
         IntegralDO integral = BeanUtils.toBean(createReqVO, IntegralDO.class);
+        integral.setAccumulatedQuota(0L);
+        integral.setAncestorQuota(0L);
         integralMapper.insert(integral);
         // 返回
         return integral.getId();
@@ -86,6 +88,10 @@ public class IntegralServiceImpl implements IntegralService {
     @Override
     public void saveBatch(List<IntegralSaveReqVO> integralSaveReqVOS) {
         List<IntegralDO> integralDOS = BeanUtils.toBean(integralSaveReqVOS, IntegralDO.class);
+        integralDOS.forEach(k -> {
+            k.setAccumulatedQuota(0L);
+            k.setAncestorQuota(0L);
+        });
         integralMapper.insertBatch(integralDOS);
     }
 
@@ -123,4 +129,4 @@ public class IntegralServiceImpl implements IntegralService {
         );
     }
 
-}
+}

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

@@ -199,7 +199,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
 
             // 计算
             // 计算利润: (价格 - 成本价格) * 产品数量
-            final BigDecimal[] profit = {new BigDecimal("0"),new BigDecimal("0")};      //用户自得不用要计算,从orderItem里面获取
+            final BigDecimal[] profit = {new BigDecimal("0"), new BigDecimal("0")};      //用户自得不用要计算,从orderItem里面获取
             k.getOrderItemMessages().forEach(j -> {
                 BigDecimal onePrice = new BigDecimal(j.getPrice());
                 BigDecimal oneCostPrice = new BigDecimal(j.getCostPrice());
@@ -283,6 +283,11 @@ public class OrderCalcServiceImpl implements OrderCalcService {
                     .percentTemplate(percentTemplate).build();
             saveList.add(orderCalcSaveReqVO);
             // ========== 修改用户钱包 =================
+            //直推奖也要限制额度
+            Long ancestorHighQuota = integralDOAncestor.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();//加上基础的最大额度值
+            if (ancestorHighQuota > ancestorQuotaInt) {
+                ancestorQuotaInt = 0L;
+            }
             changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, ancestorQuotaInt,
                     descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt);
             // ========== 修改平台信息 =================
@@ -294,6 +299,11 @@ public class OrderCalcServiceImpl implements OrderCalcService {
                             .ptAdd(platformQuotaInt)
                             .ptGrossAdd(grossProfitAfterBonusInt)
                             .ptTotalAdd(platformQuotaInt + grossProfitAfterBonusInt).build();
+
+            // 当直推人获取的积分额度不足时,平台收益要加回来,并生成log
+            calcIntegral(ptProfitSaveReqVOS, ptProfitSaveReqVO, ancestorHighQuota, ancestorQuotaInt,
+                    k.getOrderId(), k.getNo(), k.getUserId());
+
             ptProfitSaveReqVOS.add(ptProfitSaveReqVO);
             // ========== 增加日志记录 =================
 
@@ -367,6 +377,23 @@ 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);
+
+            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);
+        }
+    }
+
     private PtProfitDO calcPtProfit(PtProfitDO ptProfitDO, List<PtProfitSaveReqVO> ptProfitSaveReqVOS) {
 
         Long currentPtAdd = 0L;
@@ -408,10 +435,13 @@ public class OrderCalcServiceImpl implements OrderCalcService {
 
         integralDO.setCurrentQuota(integralDO.getCurrentQuota() + descendantQuota);
         integralDO.setFreezeQuota(integralDO.getFreezeQuota() - descendantQuota);
-
-
         // 增加推荐人额度
         integralDOAncestor.setCurrentQuota(integralDOAncestor.getCurrentQuota() + ancestorQuota);
+        // 减少推荐人的可获取额度
+        integralDOAncestor.setHighQuota(integralDOAncestor.getHighQuota() - ancestorQuota);
+        integralDOAncestor.setAncestorQuota(integralDOAncestor.getAncestorQuota() + ancestorQuota);
+        integralService.updateIntegral(BeanUtils.toBean(integralDOAncestor, IntegralSaveReqVO.class));
+
         // 增加平台额度
         pt.setCurrentQuota(pt.getCurrentQuota() + ptA + ptB);
 
@@ -419,7 +449,6 @@ public class OrderCalcServiceImpl implements OrderCalcService {
 //        integralSaveReqVOS.add(BeanUtils.toBean(integralDOAncestor, IntegralSaveReqVO.class));
 
         integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
-        integralService.updateIntegral(BeanUtils.toBean(integralDOAncestor, IntegralSaveReqVO.class));
         integralService.updateIntegral(BeanUtils.toBean(pt, IntegralSaveReqVO.class));
 
     }
@@ -431,4 +460,4 @@ public class OrderCalcServiceImpl implements OrderCalcService {
     }
 
 
-}
+}

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

@@ -259,25 +259,31 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
 
                 // 积分添加 添加的时候, 需要注意当前用户是否有足够的积分可以获取
                 // 碰撞后的额度的
-                Long highQuota = integralDO.getHighQuota();
-                Long parentHighQuota = parentIntegralDo.getHighQuota();
+                Long highQuota = integralDO.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();       //加上基础的最大额度值
+                Long parentHighQuota = parentIntegralDo.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();
 
                 BigDecimal smallBigDecimal = new BigDecimal(String.valueOf(smallQuota));
                 BigDecimal multiply = smallBigDecimal.divide(new BigDecimal("2.0"), 4, RoundingMode.DOWN);
                 if (compare(highQuota, multiply)) {
                     integralDO.setCurrentQuota(integralDO.getCurrentQuota() + multiply.intValue());
                     integralDO.setHighQuota(parentIntegralDo.getHighQuota() - multiply.intValue());
+                    integralDO.setAccumulatedQuota(parentIntegralDo.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));
+                } else {
+                    calcIntegral(multiply.longValue(),integralDO.getUserId(),JsonUtils.toJsonString(orderPercentageDO));
                 }
                 if (compare(parentHighQuota, multiply)) {
                     // 减去最高额度
                     parentIntegralDo.setCurrentQuota(parentIntegralDo.getCurrentQuota() + multiply.intValue());
                     parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - 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));
+                }else{
+                    calcIntegral(multiply.longValue(),integralDO.getUserId(),JsonUtils.toJsonString(orderPercentageDO));
                 }
 
                 // 获取计算后积分, Long为userId, Integer为碰撞后额度
@@ -355,6 +361,12 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
         createPtProfitDailyStatisticsLog(sum);
     }
 
+    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() + multiply, jsonString);
+    }
+
     private void createPtProfitDailyStatisticsLog(Long sum) {
         LocalDate now = LocalDate.now();
 
@@ -426,4 +438,4 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
     }
 
 
-}
+}