Kaynağa Gözat

Merge branch 'dev/2024/0430/update-admin' of Harper/feifan-backend-zx-admin into master

计算订单身价,修改合赢奖和直推奖的限制
Yangzw 4 ay önce
ebeveyn
işleme
60c5bafe80
22 değiştirilmiş dosya ile 291 ekleme ve 94 silme
  1. 1 1
      feifan-module-distri/feifan-module-distri-api/src/main/java/cn/newfeifan/mall/module/distri/constant/DistriConstants.java
  2. 6 3
      feifan-module-distri/feifan-module-distri-api/src/main/java/cn/newfeifan/mall/module/distri/enums/CaclEnum.java
  3. 1 0
      feifan-module-distri/feifan-module-distri-api/src/main/java/cn/newfeifan/mall/module/distri/enums/ErrorCodeConstants.java
  4. 15 9
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/integral/vo/IntegralPageReqVO.java
  5. 20 11
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/integral/vo/IntegralRespVO.java
  6. 18 10
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/integral/vo/IntegralSaveReqVO.java
  7. 18 12
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/ptprofitlog/vo/PtProfitLogSaveReqVO.java
  8. 21 7
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/dataobject/integral/IntegralDO.java
  9. 12 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/dataobject/orderpercentage/OrderPercentageDO.java
  10. 23 16
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/dataobject/ptprofitlog/PtProfitLogDO.java
  11. 2 1
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/mysql/ordercalc/OrderCalcMapper.java
  12. 10 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/mq/message/order/DistriOrderMessage.java
  13. 9 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/mq/message/order/OrderItemMessage.java
  14. 7 1
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/integral/IntegralServiceImpl.java
  15. 1 1
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ordercalc/OrderCalcService.java
  16. 70 13
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ordercalc/OrderCalcServiceImpl.java
  17. 40 7
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/partitioncrash/PartitionCrashServiceImpl.java
  18. 4 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/socialstatus/SocialStatusServiceImpl.java
  19. 5 0
      feifan-module-distri/feifan-module-distri-biz/src/main/resources/mapper/ordercalc/OrderCalcMapper.xml
  20. 2 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/order/TradeOrderController.java
  21. 2 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/job/order/TradeOrderAutoCalcJob.java
  22. 4 2
      feifan-module-mall/feifan-module-trade-biz/src/main/resources/mapper/order/BrokerageUserMapper.xml

+ 1 - 1
feifan-module-distri/feifan-module-distri-api/src/main/java/cn/newfeifan/mall/module/distri/constant/DistriConstants.java

@@ -10,5 +10,5 @@ public class DistriConstants {
 
     public static final Boolean IS_EFFECTIVE  = true;
 
-
+    public static final double GROSS_PROFIT_BONUS_QUOTA_PERC = 0.2;
 }

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

@@ -15,10 +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, "购物获得积分", "购物获得冻结积分"),
     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, "直推奖超额", "直推奖的获取超出最高可获取");
 
     /**
      * 来源
@@ -43,4 +46,4 @@ public enum CaclEnum {
         return null;
     }
 
-}
+}

+ 1 - 0
feifan-module-distri/feifan-module-distri-api/src/main/java/cn/newfeifan/mall/module/distri/enums/ErrorCodeConstants.java

@@ -26,5 +26,6 @@ public interface ErrorCodeConstants {
 
     ErrorCode PT_PROFIT_DAILY_STATISTICS_LOG_NOT_EXISTS = new ErrorCode(1_002_030_020, "查询该日的记录不存在");
     ErrorCode SOCIAL_STATUS_CHANGE_LOG_NOT_EXISTS = new ErrorCode(1_002_030_021, "查询日志记录不存在");
+    ErrorCode GROSS_PROFIT_BONUS_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT = new ErrorCode(1_002_030_022, "合赢奖不能超过最大限制");
 
 }

+ 15 - 9
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/integral/vo/IntegralPageReqVO.java

@@ -17,12 +17,6 @@ public class IntegralPageReqVO extends PageParam {
     @Schema(description = "用户ID", example = "19778")
     private Long userId;
 
-    @Schema(description = "当前积分")
-    private Long currentQuota;
-
-    @Schema(description = "冻结积分")
-    private Long freezeQuota;
-
     @Schema(description = "用户类型", example = "17348")
     private Long categoryId;
 
@@ -30,14 +24,26 @@ public class IntegralPageReqVO extends PageParam {
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private LocalDateTime[] createTime;
 
-    @Schema(description = "最高可获取积分")
-    private Long highQuota;
-
     @Schema(description = "用户名称", example = "赵六")
     private String name;
 
     @Schema(description = "用户昵称", example = "赵六")
     private String nickName;
 
+    @Schema(description = "当前积分")
+    private Long currentQuota;
+
+    @Schema(description = "冻结积分")
+    private Long freezeQuota;
+
+    @Schema(description = "合赢奖累计获取积分")
+    private Long accumulatedQuota;
+
+    @Schema(description = "直推奖累计获取积分")
+    private Long ancestorQuota;
+
+    @Schema(description = "最高可获取积分")
+    private Long highQuota;
+
 
 }

+ 20 - 11
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/integral/vo/IntegralRespVO.java

@@ -18,14 +18,6 @@ public class IntegralRespVO {
     @ExcelProperty("用户ID")
     private Long userId;
 
-    @Schema(description = "当前积分")
-    @ExcelProperty("当前积分")
-    private Long currentQuota;
-
-    @Schema(description = "冻结积分")
-    @ExcelProperty("冻结积分")
-    private Long freezeQuota;
-
     @Schema(description = "用户类型", example = "17348")
     @ExcelProperty("用户类型")
     private Long categoryId;
@@ -34,9 +26,6 @@ public class IntegralRespVO {
     @ExcelProperty("创建时间")
     private LocalDateTime createTime;
 
-    @Schema(description = "最高可获取积分")
-    @ExcelProperty("最高可获取积分")
-    private Long highQuota;
     @Schema(description = "用户名称", example = "赵六")
     @ExcelProperty("用户名称")
     private String name;
@@ -44,4 +33,24 @@ public class IntegralRespVO {
     @Schema(description = "用户昵称", example = "赵六")
     @ExcelProperty("用户昵称")
     private String nickName;
+
+    @Schema(description = "当前积分", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("当前积分")
+    private Long currentQuota;
+
+    @Schema(description = "冻结积分")
+    @ExcelProperty("冻结积分")
+    private Long freezeQuota;
+
+    @Schema(description = "合赢奖累计获取积分")
+    @ExcelProperty("合赢奖累计获取积分")
+    private Long accumulatedQuota;
+
+    @Schema(description = "直推奖累计获取积分")
+    @ExcelProperty("直推奖累计获取积分")
+    private Long ancestorQuota;
+
+    @Schema(description = "最高可获取积分", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("最高可获取积分")
+    private Long highQuota;
 }

+ 18 - 10
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/integral/vo/IntegralSaveReqVO.java

@@ -3,6 +3,8 @@ package cn.newfeifan.mall.module.distri.controller.admin.integral.vo;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.*;
 
+import javax.validation.constraints.NotNull;
+
 
 @Schema(description = "管理后台 - 推荐用户积分新增/修改 Request VO")
 @Data
@@ -17,23 +19,29 @@ public class IntegralSaveReqVO {
     @Schema(description = "用户ID", example = "19778")
     private Long userId;
 
-    @Schema(description = "当前积分")
-    private Long currentQuota;
-
-    @Schema(description = "冻结积分")
-    private Long freezeQuota;
-
     @Schema(description = "用户类型", example = "17348")
     private Long categoryId;
 
-    @Schema(description = "最高可获取积分")
-    private Long highQuota;
-
-
     @Schema(description = "用户名称", example = "赵六")
     private String name;
 
     @Schema(description = "用户昵称", example = "赵六")
     private String nickName;
 
+    @Schema(description = "当前积分", requiredMode = Schema.RequiredMode.REQUIRED)
+    @NotNull(message = "当前积分不能为空")
+    private Long currentQuota;
+
+    @Schema(description = "冻结积分")
+    private Long freezeQuota;
+
+    @Schema(description = "合赢奖累计获取积分")
+    private Long accumulatedQuota;
+
+    @Schema(description = "直推奖累计获取积分")
+    private Long ancestorQuota;
+
+    @Schema(description = "最高可获取积分", requiredMode = Schema.RequiredMode.REQUIRED)
+    private Long highQuota;
+
 }

+ 18 - 12
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/ptprofitlog/vo/PtProfitLogSaveReqVO.java

@@ -11,18 +11,6 @@ import lombok.*;
 @NoArgsConstructor
 public class PtProfitLogSaveReqVO {
 
-    @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12046")
-    private Long id;
-
-    @Schema(description = "增加金额")
-    private Long amount;
-
-    @Schema(description = "增加后金额")
-    private Long afterAmount;
-
-    @Schema(description = "收益类型 1:平台服务器费 2:平台收益 3推荐人额度 4直推人额度 5合赢奖 6最高可以获得积分", example = "2")
-    private Integer profitStatus;
-
     @Schema(description = "用户ID , 只有收益类型为 3,4才有值", example = "6982")
     private Long userId;
 
@@ -32,7 +20,25 @@ public class PtProfitLogSaveReqVO {
     @Schema(description = "订单编号")
     private String orderNo;
 
+    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "5931")
+    private Long id;
+
     @Schema(description = "计算百分比模板")
     private String percentTemplate;
 
+    @Schema(description = "变动的当前可用积分值(可为负数)")
+    private Long amount;
+
+    @Schema(description = "变动后当前可用积分钱包的余额")
+    private Long afterAmount;
+
+    @Schema(description = "收益类型 1:平台服务器费 2:平台收益 3用户下单返回毛利额度 4直推人额度 5合赢奖", example = "1")
+    private Integer profitStatus;
+
+    @Schema(description = "变动的冻结积分值(可为负数)")
+    private Long freezeAmount;
+
+    @Schema(description = "变动后冻结积分钱包的余额")
+    private Long afterFreezeAmount;
+
 }

+ 21 - 7
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/dataobject/integral/IntegralDO.java

@@ -28,6 +28,18 @@ public class IntegralDO extends BaseDO {
      * 用户ID
      */
     private Long userId;
+    /**
+     * 用户类型
+     */
+    private Long categoryId;
+    /**
+     * 用户名称
+     */
+    private String name;
+    /**
+     * 用户昵称
+     */
+    private String nickName;
     /**
      * 当前积分
      */
@@ -37,13 +49,15 @@ public class IntegralDO extends BaseDO {
      */
     private Long freezeQuota;
     /**
-     * 用户类型
+     * 合赢奖累计获取积分
+     */
+    private Long accumulatedQuota;
+    /**
+     * 直推奖累计获取积分
+     */
+    private Long ancestorQuota;
+    /**
+     * 最高可获取积分
      */
-    private Long categoryId;
-
     private Long highQuota;
-
-    private String name;
-
-    private String nickName;
 }

+ 12 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/dataobject/orderpercentage/OrderPercentageDO.java

@@ -4,6 +4,10 @@ import lombok.*;
 import com.baomidou.mybatisplus.annotation.*;
 import cn.newfeifan.mall.framework.mybatis.core.dataobject.BaseDO;
 
+import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.newfeifan.mall.module.distri.constant.DistriConstants.GROSS_PROFIT_BONUS_QUOTA_PERC;
+import static cn.newfeifan.mall.module.distri.enums.ErrorCodeConstants.GROSS_PROFIT_BONUS_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT;
+
 /**
  * 积分相关计算浮动百分比设置 DO
  *
@@ -73,4 +77,12 @@ public class OrderPercentageDO extends BaseDO {
      */
     private String baseMaxQuota;
 
+    public String getGrossProfitBonusQuotaPerc() {
+        double grossProfitBonusQuotaPerc = Double.parseDouble(this.grossProfitBonusQuotaPerc);
+        if(grossProfitBonusQuotaPerc > GROSS_PROFIT_BONUS_QUOTA_PERC){
+            throw exception(GROSS_PROFIT_BONUS_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT);
+        }
+        return this.grossProfitBonusQuotaPerc;
+    }
+
 }

+ 23 - 16
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/dataobject/ptprofitlog/PtProfitLogDO.java

@@ -20,16 +20,32 @@ import cn.newfeifan.mall.framework.mybatis.core.dataobject.BaseDO;
 public class PtProfitLogDO extends BaseDO {
 
     /**
-     * 用户编号
+     * 用户ID , 只有收益类型为 3,4才有值
+     */
+    private Long userId;
+    /**
+     * 订单Id
+     */
+    private Long orderId;
+    /**
+     * 订单编号
+     */
+    private String orderNo;
+    /**
+     * 编号
      */
     @TableId
     private Long id;
     /**
-     * 增加金额
+     * 计算百分比模板
+     */
+    private String percentTemplate;
+    /**
+     * 变动的当前可用积分值(可为负数)
      */
     private Long amount;
     /**
-     * 增加后金额
+     * 变动后当前可用积分钱包的余
      */
     private Long afterAmount;
     /**
@@ -37,22 +53,13 @@ public class PtProfitLogDO extends BaseDO {
      */
     private Integer profitStatus;
     /**
-     * 用户ID , 只有收益类型为 3,4才有值
-     */
-    private Long userId;
-
-    /**
-     * 订单Id
-     */
-    private Long orderId;
-    /**
-     * 订单编号
+     * 变动的冻结积分值(可为负数)
      */
-    private String orderNo;
+    private Long freezeAmount;
     /**
-     * 计算百分比模板
+     * 变动后冻结积分钱包的余额
      */
-    private String percentTemplate;
+    private Long afterFreezeAmount;
 
 
 }

+ 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);
 }

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

@@ -69,6 +69,16 @@ public class DistriOrderMessage {
      */
     private Long orderId;
 
+    /**
+     * 订单明细ID
+     */
+    private Long orderItemId;
+
+    /**
+     * 用户自得积分
+     */
+    private Long increaseIntegral;
+
 
     @Override
     public boolean equals(Object o) {

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

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

+ 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 {
         );
     }
 
-}
+}

+ 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);
 }

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

@@ -11,6 +11,7 @@ import cn.newfeifan.mall.module.distri.dal.dataobject.orderpercentage.OrderPerce
 import cn.newfeifan.mall.module.distri.dal.dataobject.ptprofit.PtProfitDO;
 import cn.newfeifan.mall.module.distri.dal.dataobject.sharepath.SharePathDO;
 import cn.newfeifan.mall.module.distri.enums.CaclEnum;
+import cn.newfeifan.mall.module.distri.enums.SocialStatusEnum;
 import cn.newfeifan.mall.module.distri.mq.message.order.DistriOrderMessage;
 import cn.newfeifan.mall.module.distri.mq.message.order.OrderCalcMessage;
 import cn.newfeifan.mall.module.distri.mq.message.order.OrderItemMessage;
@@ -19,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;
@@ -83,9 +83,6 @@ public class OrderCalcServiceImpl implements OrderCalcService {
     @Resource
     private PartitionCrashService partitionCrashService;
 
-    @Resource
-    private PtProfitDailyStatisticsLogService ptProfitDailyStatisticsLogService;
-
     @Override
     public Long createOrderCalc(OrderCalcSaveReqVO createReqVO) {
         // 插入
@@ -146,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 计算当天用户的碰撞
             // 计算兄弟分区, 以及后代分区
@@ -161,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<>();
@@ -198,13 +200,16 @@ public class OrderCalcServiceImpl implements OrderCalcService {
 
             // 计算
             // 计算利润: (价格 - 成本价格) * 产品数量
-            final BigDecimal[] profit = {new BigDecimal("0")};
+            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());
                 BigDecimal productCount = new BigDecimal(j.getCount());
                 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());
             });
 
 
@@ -219,7 +224,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
             }
 
             // 用户所得: 毛利 * 0.35
-            BigDecimal descendantQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitUserQuotaPerc())).setScale(4, RoundingMode.DOWN);
+            BigDecimal descendantQuota = profit[1];
 
             // 直推奖: 毛利 * 0.35 (上一级)
             BigDecimal ancestorQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitAncestorQuotaPerc())).setScale(4, RoundingMode.DOWN);
@@ -237,7 +242,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
             // 乘以 10000 并转换为整数
             Long grossProfitInt = grossProfit.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
             Long ancestorQuotaInt = ancestorQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
-            Long descendantQuotaInt = descendantQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
+            Long descendantQuotaInt = descendantQuota.longValue();
             Long bonusQuotaInt = bonusQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
             Long highQuotaInt = highQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
             Long grossProfitAfterBonusInt = grossProfitAfterBonus.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
@@ -250,6 +255,20 @@ public class OrderCalcServiceImpl implements OrderCalcService {
             IntegralDO integralDOAncestor = integralService.selectByUser(sharePath.getAncestor());
             IntegralDO integralDO = integralService.selectByUser(sharePath.getDescendant());
             IntegralDO ptIntegral = integralService.selectByUser(1L);
+
+
+            // ========== 身价计算 ==============
+            //推荐人身价计算
+            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());
+
+            //自得身价计算
+            double orderUserSocialStatus = Double.parseDouble(orderPercentageDO.getOrderUserSocialStatus());
+            double descendantSocial = k.getOrderItemMessages().get(0).getTotalPrice() * orderUserSocialStatus;
+            duserService.updateDuserSocial(integralDO.getUserId(), (long) descendantSocial, SocialStatusEnum.SHOPPING_SOCIAL.getStatus());
+
+
             // ========== 汇总计算 =================
             OrderCalcSaveReqVO orderCalcSaveReqVO = OrderCalcSaveReqVO.builder()
                     .userId(k.getUserId())
@@ -267,7 +286,15 @@ public class OrderCalcServiceImpl implements OrderCalcService {
                     .percentTemplate(percentTemplate).build();
             saveList.add(orderCalcSaveReqVO);
             // ========== 修改用户钱包 =================
-            changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, ancestorQuotaInt, descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt);
+            //直推奖也要限制额度
+            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);
+            }
             // ========== 修改平台信息 =================
             // 每个订单计算的过程
             // 增加平台收益
@@ -277,6 +304,11 @@ public class OrderCalcServiceImpl implements OrderCalcService {
                             .ptAdd(platformQuotaInt)
                             .ptGrossAdd(grossProfitAfterBonusInt)
                             .ptTotalAdd(platformQuotaInt + grossProfitAfterBonusInt).build();
+
+            // 当直推人获取的积分额度不足时,平台收益要加回来,并生成log
+            calcIntegral(ptProfitSaveReqVOS, ptProfitSaveReqVO, ancestorHighQuota, ancestorQuotaInt,
+                    k.getOrderId(), k.getNo(), integralDOAncestor.getUserId());
+
             ptProfitSaveReqVOS.add(ptProfitSaveReqVO);
             // ========== 增加日志记录 =================
 
@@ -303,6 +335,9 @@ public class OrderCalcServiceImpl implements OrderCalcService {
 
             // 直推人记录
             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()).freezeAmount(descendantQuotaInt).afterFreezeAmount(integralDO.getCurrentQuota() - descendantQuotaInt).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();
 
             // 合赢奖记录
@@ -314,6 +349,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
             ptProfitLogSaveReqVOS.add(ptAddLog);
             ptProfitLogSaveReqVOS.add(tjrLog);
             ptProfitLogSaveReqVOS.add(ztrLog);
+            ptProfitLogSaveReqVOS.add(freezeLog);
             ptProfitLogSaveReqVOS.add(hyjLog);
             ptProfitLogSaveReqVOS.add(highQuotaLog);
 
@@ -346,6 +382,24 @@ 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);
+        }
+    }
+
     private PtProfitDO calcPtProfit(PtProfitDO ptProfitDO, List<PtProfitSaveReqVO> ptProfitSaveReqVOS) {
 
         Long currentPtAdd = 0L;
@@ -386,10 +440,14 @@ public class OrderCalcServiceImpl implements OrderCalcService {
         // todo 增加累计额度
 
         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);
 
@@ -397,7 +455,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));
 
     }
@@ -409,4 +466,4 @@ public class OrderCalcServiceImpl implements OrderCalcService {
     }
 
 
-}
+}

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

@@ -259,26 +259,34 @@ 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)) {
+                if (compare(highQuota, multiply) && multiply.longValue() != 0) {
                     integralDO.setCurrentQuota(integralDO.getCurrentQuota() + multiply.intValue());
-                    integralDO.setHighQuota(parentIntegralDo.getHighQuota() - 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));
                 }
-                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));
                 }
+                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为碰撞后额度
                 HashMap<Long, Long> map = new HashMap<>();
@@ -325,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());
@@ -355,6 +382,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(), jsonString);
+    }
+
     private void createPtProfitDailyStatisticsLog(Long sum) {
         LocalDate now = LocalDate.now();
 
@@ -426,4 +459,4 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
     }
 
 
-}
+}

+ 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>

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

@@ -260,6 +260,8 @@ 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));
 

+ 4 - 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
@@ -71,6 +72,7 @@
         <where>
             tor.pay_status = 1
             and toi.distribute_benefit = 0
+            and (toi.after_sale_status = 0 or toi.after_sale_status = 61)
             <if test="orderIds!=null">
                 and tor.id in (
                 <foreach collection="orderIds" item="orderId" separator=",">