Переглянути джерело

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

Yangzw 6 місяців тому
батько
коміт
740a155d44
11 змінених файлів з 81 додано та 30 видалено
  1. 2 1
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/mysql/ordercalc/OrderCalcMapper.java
  2. 5 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/mq/message/order/DistriOrderMessage.java
  3. 5 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/mq/message/order/OrderItemMessage.java
  4. 1 1
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ordercalc/OrderCalcService.java
  5. 22 16
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ordercalc/OrderCalcServiceImpl.java
  6. 31 10
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/partitioncrash/PartitionCrashServiceImpl.java
  7. 4 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/socialstatus/SocialStatusServiceImpl.java
  8. 5 0
      feifan-module-distri/feifan-module-distri-biz/src/main/resources/mapper/ordercalc/OrderCalcMapper.xml
  9. 1 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/order/TradeOrderController.java
  10. 2 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/job/order/TradeOrderAutoCalcJob.java
  11. 3 2
      feifan-module-mall/feifan-module-trade-biz/src/main/resources/mapper/order/BrokerageUserMapper.xml

+ 2 - 1
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/mysql/ordercalc/OrderCalcMapper.java

@@ -1,6 +1,5 @@
 package cn.newfeifan.mall.module.distri.dal.mysql.ordercalc;
 
-import java.util.*;
 
 import cn.newfeifan.mall.framework.common.pojo.PageResult;
 import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
@@ -8,6 +7,7 @@ import cn.newfeifan.mall.framework.mybatis.core.mapper.BaseMapperX;
 import cn.newfeifan.mall.module.distri.dal.dataobject.ordercalc.OrderCalcDO;
 import org.apache.ibatis.annotations.Mapper;
 import cn.newfeifan.mall.module.distri.controller.admin.ordercalc.vo.*;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 订单产生数据计算 Mapper
@@ -37,4 +37,5 @@ public interface OrderCalcMapper extends BaseMapperX<OrderCalcDO> {
                 .orderByDesc(OrderCalcDO::getId));
     }
 
+    void updateOrderItemById(@Param("orderItemId")Long orderItemId);
 }

+ 5 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/mq/message/order/DistriOrderMessage.java

@@ -69,6 +69,11 @@ public class DistriOrderMessage {
      */
     private Long orderId;
 
+    /**
+     * 订单明细ID
+     */
+    private Long orderItemId;
+
     /**
      * 用户自得积分
      */

+ 5 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/mq/message/order/OrderItemMessage.java

@@ -42,4 +42,9 @@ public class OrderItemMessage {
      * 用户自得积分
      */
     private Long increaseIntegral;
+
+    /**
+     * 订单项ID
+     */
+    private Long orderItemId;
 }

+ 1 - 1
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ordercalc/OrderCalcService.java

@@ -7,7 +7,6 @@ import javax.validation.*;
 import cn.newfeifan.mall.module.distri.controller.admin.ordercalc.vo.*;
 import cn.newfeifan.mall.module.distri.dal.dataobject.ordercalc.OrderCalcDO;
 import cn.newfeifan.mall.framework.common.pojo.PageResult;
-import cn.newfeifan.mall.module.distri.mq.message.order.DistriOrderMessage;
 import cn.newfeifan.mall.module.distri.mq.message.order.OrderCalcMessage;
 
 /**
@@ -64,4 +63,5 @@ public interface OrderCalcService {
 
     List<OrderCalcDO> queryTodayCalcByUserIds(LocalDateTime todayStart, LocalDateTime todayEnd,List<Long> userList);
 
+    void updateOrderItem(Long orderItemId);
 }

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

@@ -20,7 +20,6 @@ import cn.newfeifan.mall.module.distri.service.integral.IntegralService;
 import cn.newfeifan.mall.module.distri.service.orderpercentage.OrderPercentageService;
 import cn.newfeifan.mall.module.distri.service.partitioncrash.PartitionCrashService;
 import cn.newfeifan.mall.module.distri.service.ptprofit.PtProfitService;
-import cn.newfeifan.mall.module.distri.service.ptprofitdailystatisticslog.PtProfitDailyStatisticsLogService;
 import cn.newfeifan.mall.module.distri.service.ptprofitlog.PtProfitLogService;
 import cn.newfeifan.mall.module.distri.service.sharepath.SharePathService;
 import org.springframework.context.annotation.Lazy;
@@ -84,9 +83,6 @@ public class OrderCalcServiceImpl implements OrderCalcService {
     @Resource
     private PartitionCrashService partitionCrashService;
 
-    @Resource
-    private PtProfitDailyStatisticsLogService ptProfitDailyStatisticsLogService;
-
     @Override
     public Long createOrderCalc(OrderCalcSaveReqVO createReqVO) {
         // 插入
@@ -147,7 +143,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
             String percentTemplate = JsonUtils.toJsonString(orderPercentageDO);
             calc(tradeOrderDO, orderPercentageDO, percentTemplate);
         } catch (Exception e) {
-
+            System.out.println(e.getMessage());
         } finally {
             // todo 计算当天用户的碰撞
             // 计算兄弟分区, 以及后代分区
@@ -162,6 +158,11 @@ public class OrderCalcServiceImpl implements OrderCalcService {
                 .in(OrderCalcDO::getUserId, userList));
     }
 
+    @Override
+    public void updateOrderItem(Long orderItemId) {
+        orderCalcMapper.updateOrderItemById(orderItemId);
+    }
+
     private void calc(List<OrderCalcMessage> tradeOrderDO, OrderPercentageDO orderPercentageDO, String percentTemplate) {
 
         List<PtProfitSaveReqVO> savePFitMap = new ArrayList<>();
@@ -207,6 +208,8 @@ public class OrderCalcServiceImpl implements OrderCalcService {
                 BigDecimal oneGrossProfit = onePrice.subtract(oneCostPrice).multiply(productCount);
                 profit[0] = profit[0].add(oneGrossProfit);  // 注意这里的改动
                 profit[1] = profit[1].add(new BigDecimal(j.getIncreaseIntegral()));     //自得积分
+
+                updateOrderItem(j.getOrderItemId());
             });
 
 
@@ -256,14 +259,14 @@ public class OrderCalcServiceImpl implements OrderCalcService {
 
             // ========== 身价计算 ==============
             //推荐人身价计算
-            BigDecimal orderAncestorSocialStatus = new BigDecimal(orderPercentageDO.getOrderAncestorSocialStatus());
-            Long ancestorSocial = k.getOrderItemMessages().get(0).getTotalPrice() * orderAncestorSocialStatus.longValue();
-            duserService.updateDuserSocial(integralDOAncestor.getUserId(), ancestorSocial, SocialStatusEnum.SHOPPING_ANCESTOR_SOCIAL.getStatus());
+            double orderAncestorSocialStatus = Double.parseDouble(orderPercentageDO.getOrderAncestorSocialStatus());
+            double ancestorSocial = k.getOrderItemMessages().get(0).getTotalPrice() * orderAncestorSocialStatus;
+            duserService.updateDuserSocial(integralDOAncestor.getUserId(), (long) ancestorSocial, SocialStatusEnum.SHOPPING_ANCESTOR_SOCIAL.getStatus());
 
             //自得身价计算
-            BigDecimal orderUserSocialStatus = new BigDecimal(orderPercentageDO.getOrderUserSocialStatus());
-            Long descendantSocial = k.getOrderItemMessages().get(0).getTotalPrice() * orderUserSocialStatus.longValue();
-            duserService.updateDuserSocial(integralDOAncestor.getUserId(), descendantSocial, SocialStatusEnum.SHOPPING_SOCIAL.getStatus());
+            double orderUserSocialStatus = Double.parseDouble(orderPercentageDO.getOrderUserSocialStatus());
+            double descendantSocial = k.getOrderItemMessages().get(0).getTotalPrice() * orderUserSocialStatus;
+            duserService.updateDuserSocial(integralDO.getUserId(), (long) descendantSocial, SocialStatusEnum.SHOPPING_SOCIAL.getStatus());
 
 
             // ========== 汇总计算 =================
@@ -285,11 +288,13 @@ public class OrderCalcServiceImpl implements OrderCalcService {
             // ========== 修改用户钱包 =================
             //直推奖也要限制额度
             Long ancestorHighQuota = integralDOAncestor.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();//加上基础的最大额度值
-            if (ancestorHighQuota > ancestorQuotaInt) {
-                ancestorQuotaInt = 0L;
+            if (ancestorHighQuota < ancestorQuotaInt) {
+                changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, 0L,
+                        descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt);
+            } else {
+                changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, ancestorQuotaInt,
+                        descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt);
             }
-            changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, ancestorQuotaInt,
-                    descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt);
             // ========== 修改平台信息 =================
             // 每个订单计算的过程
             // 增加平台收益
@@ -302,7 +307,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
 
             // 当直推人获取的积分额度不足时,平台收益要加回来,并生成log
             calcIntegral(ptProfitSaveReqVOS, ptProfitSaveReqVO, ancestorHighQuota, ancestorQuotaInt,
-                    k.getOrderId(), k.getNo(), k.getUserId());
+                    k.getOrderId(), k.getNo(), integralDOAncestor.getUserId());
 
             ptProfitSaveReqVOS.add(ptProfitSaveReqVO);
             // ========== 增加日志记录 =================
@@ -381,6 +386,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
                               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)

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

@@ -264,26 +264,28 @@ 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)) {
+                if (compare(highQuota, multiply) && multiply.longValue() != 0) {
                     integralDO.setCurrentQuota(integralDO.getCurrentQuota() + multiply.intValue());
-                    integralDO.setHighQuota(parentIntegralDo.getHighQuota() - multiply.intValue());
-                    integralDO.setAccumulatedQuota(parentIntegralDo.getAccumulatedQuota() + multiply.intValue());
+//                    integralDO.setHighQuota(integralDO.getHighQuota() - 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));
-                } else {
-                    calcIntegral(multiply.longValue(),integralDO.getUserId(),JsonUtils.toJsonString(orderPercentageDO));
                 }
-                if (compare(parentHighQuota, multiply)) {
+                if (compare(parentHighQuota, multiply) && multiply.longValue() != 0) {
                     // 减去最高额度
                     parentIntegralDo.setCurrentQuota(parentIntegralDo.getCurrentQuota() + multiply.intValue());
-                    parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - 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));
+                }
+                if(highQuota < multiply.longValue() && multiply.longValue() != 0L){
+                    calcIntegral(multiply.longValue(), integralDO.getUserId(), JsonUtils.toJsonString(orderPercentageDO));
+                }
+                if(parentHighQuota < multiply.longValue() && multiply.longValue() != 0L){
+                    calcIntegral(multiply.longValue(), parentIntegralDo.getUserId(), JsonUtils.toJsonString(orderPercentageDO));
                 }
 
                 // 获取计算后积分, Long为userId, Integer为碰撞后额度
@@ -331,6 +333,25 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
                     continue;
                 }
 
+                // 获取当前用户的钱包
+                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();       //加上基础的最大额度值
+                Long parentHighQuota = parentIntegralDo.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();
+                if(highQuota  < entry.getValue()){
+                    continue;
+                }
+                if(parentHighQuota < entry.getValue()){
+                    continue;
+                }
+
+                integralDO.setHighQuota(integralDO.getHighQuota() - entry.getValue());
+                parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - entry.getValue());
+                integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
+                integralService.updateIntegral(BeanUtils.toBean(parentIntegralDo, IntegralSaveReqVO.class));
+
                 // 扣除平台收益
                 log.info("扣除平台收益[合赢奖] " + "用户 " + entry.getKey() + "额度: " + entry.getValue());
                 ptProfit.setPtGrossAdd(ptProfit.getPtGrossAdd() - entry.getValue());
@@ -364,7 +385,7 @@ 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() + multiply, jsonString);
+                ptProfit.getPtTotalAdd(), jsonString);
     }
 
     private void createPtProfitDailyStatisticsLog(Long sum) {

+ 4 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/socialstatus/SocialStatusServiceImpl.java

@@ -92,6 +92,10 @@ public class SocialStatusServiceImpl implements SocialStatusService {
                 break;
             }
         }
+        if(socialStatusBO.getId() == null){
+            socialStatusBO.setId(socialStatusDOS.get(socialStatusDOS.size() - 1).getId());
+            socialStatusBO.setSocialUpNeed(0L);
+        }
         return socialStatusBO;
     }
 

+ 5 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/resources/mapper/ordercalc/OrderCalcMapper.xml

@@ -9,4 +9,9 @@
         文档可见:https://www.zhongxing.cn/MyBatis/x-plugins/
      -->
 
+    <update id="updateOrderItemById">
+        update trade_order_item
+        set distribute_benefit = 1
+        where id = #{orderItemId}
+    </update>
 </mapper>

+ 1 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/order/TradeOrderController.java

@@ -260,6 +260,7 @@ public class TradeOrderController {
                         .costPrice(k.getCostPrice())
                         .orderId(k.getOrderId())
                         .count(k.getCount())
+                        .orderItemId(k.getOrderItemId())
                         .increaseIntegral(k.getIncreaseIntegral())
                         .totalPrice(k.getTotalPrice()).build())
                 .collect(Collectors.groupingBy(OrderItemMessage::getOrderId));

+ 2 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/job/order/TradeOrderAutoCalcJob.java

@@ -40,6 +40,8 @@ public class TradeOrderAutoCalcJob implements JobHandler {
                         .costPrice(k.getCostPrice())
                         .orderId(k.getOrderId())
                         .count(k.getCount())
+                        .orderItemId(k.getOrderItemId())
+                        .increaseIntegral(k.getIncreaseIntegral())
                         .totalPrice(k.getTotalPrice()).build())
                 .collect(Collectors.groupingBy(OrderItemMessage::getOrderId));
 

+ 3 - 2
feifan-module-mall/feifan-module-trade-biz/src/main/resources/mapper/order/BrokerageUserMapper.xml

@@ -57,10 +57,11 @@
         tor.user_id as userId,
         ps.merchant_id as merchantId,
         ps.shop_id as shopId,
-        ps.shop_id as shopId,
         mu.`name` as name,
         mu.nickname as nickname,
-        toi.count as `count`
+        toi.count as `count`,
+        toi.id as orderItemId,
+        toi.increase_integral AS increaseIntegral
         from trade_order tor
         LEFT JOIN member_user mu
         ON tor.user_id = mu.id