Browse Source

修复计算程序没有试试获取用户的钱包

Yangzw 8 months ago
parent
commit
ed84e09809

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

@@ -28,7 +28,8 @@ public enum CaclEnum {
     ORDER_PAY_INTEGRAL_CONSUMER(21, "购物获得","消费者购物,获得冻结积分"),//购物者本人 获得积分
     SMALL_QUOTA_CRASH_SETTLE(22, "合赢奖结算获得","每天计算的合赢奖7天后结算"),
     ORDER_PAY_FREEZE_HIGH_QUOTA(23, "购物获得","消费者购物,获得冻结峰值"),
-    ORDER_REFUND_ORDER_PAY_FREEZE_HIGH_QUOTA(24, "订单退款-撤回峰值奖","消费者购物,获得冻结峰值")
+    ORDER_REFUND_ORDER_PAY_FREEZE_HIGH_QUOTA(24, "订单退款-撤回峰值奖","消费者购物,获得冻结峰值"),
+    MANUAL_RETURN_INTEGRAL(25, "人工返回最早七天未获得的超出额度的合赢奖","人工返回最早七天未获得的合赢奖,超额的")
     ;
 
     /**

+ 8 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/integral/IntegralController.java

@@ -99,4 +99,12 @@ public class IntegralController {
         integralService.initializeIntegralHighQuotaTotal();
         return success("success");
     }
+
+    @GetMapping("/CalcIntegral")
+    @Operation(summary = "计算积分")
+    @PreAuthorize("@ss.hasPermission('distri:integral:CalcIntegral')")
+    public CommonResult<String> CalcIntegral() {
+        integralService.calcIntegral();
+        return success("success");
+    }
 }

+ 2 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/integral/IntegralService.java

@@ -110,4 +110,6 @@ public interface IntegralService {
      * @param orderNum 订单号
      */
     void updateUserIntegral(Long userId, CaclEnum caclEnum, Long payIntegral, Long tradeOrderId, String orderNum);
+
+    void calcIntegral();
 }

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

@@ -1,9 +1,13 @@
 package cn.newfeifan.mall.module.distri.service.integral;
 
 import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.newfeifan.mall.module.distri.controller.admin.ptprofit.vo.PtProfitSaveReqVO;
+import cn.newfeifan.mall.module.distri.controller.admin.ptprofitlog.vo.PtProfitLogSaveReqVO;
+import cn.newfeifan.mall.module.distri.dal.dataobject.ptprofit.PtProfitDO;
 import cn.newfeifan.mall.module.distri.dal.dataobject.ptprofitlog.PtProfitLogDO;
 import cn.newfeifan.mall.module.distri.dal.mysql.ptprofitlog.PtProfitLogMapper;
 import cn.newfeifan.mall.module.distri.enums.CaclEnum;
+import cn.newfeifan.mall.module.distri.service.ptprofit.PtProfitService;
 import cn.newfeifan.mall.module.distri.service.ptprofitlog.PtProfitLogService;
 import cn.newfeifan.mall.module.distri.service.sharepath.SharePathService;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -25,7 +29,9 @@ import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
 import cn.newfeifan.mall.module.distri.dal.mysql.integral.IntegralMapper;
 
 import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.newfeifan.mall.module.distri.constant.DistriConstants.PT_ID;
 import static cn.newfeifan.mall.module.distri.enums.CaclEnum.DIRECT_REFERRAL_QUOTA;
+import static cn.newfeifan.mall.module.distri.enums.CaclEnum.MANUAL_RETURN_INTEGRAL;
 import static cn.newfeifan.mall.module.distri.enums.ErrorCodeConstants.*;
 
 /**
@@ -50,6 +56,9 @@ public class IntegralServiceImpl implements IntegralService {
     @Resource
     private PtProfitLogService ptProfitLogService;
 
+    @Resource
+    private PtProfitService ptProfitService;
+
     @Override
     public Long createIntegral(IntegralSaveReqVO createReqVO) {
         // 插入
@@ -198,4 +207,56 @@ public class IntegralServiceImpl implements IntegralService {
         ptProfitLogService.addMessage(userId,userId,caclEnum,payIntegral,integralDO.getCurrentQuota(),0L,0L,null,tradeOrderId,orderNum);
     }
 
+    @Override
+    public void calcIntegral() {
+        List<PtProfitLogDO> ptProfitLogDOS = ptProfitLogService.calcIntegral();
+        for (PtProfitLogDO ptProfitLogDO : ptProfitLogDOS) {
+            IntegralDO integralDO = integralMapper.selectOne(new LambdaQueryWrapper<IntegralDO>().eq(IntegralDO::getUserId, ptProfitLogDO.getUserId()));
+            //加积分余额
+            integralDO.setCurrentQuota(integralDO.getCurrentQuota() + ptProfitLogDO.getAccumulatedQuotaAmount());
+            //加累计积分余额
+            integralDO.setAccumulatedQuota(integralDO.getAccumulatedQuota() + ptProfitLogDO.getAccumulatedQuotaAmount());
+            //减可用峰值
+            integralDO.setHighQuota(integralDO.getHighQuota() - ptProfitLogDO.getAccumulatedQuotaAmount());
+
+            integralMapper.updateById(integralDO);
+
+            PtProfitDO ptProfit = ptProfitService.getPtProfit();
+            IntegralDO ptIntegralDO = selectByUser(PT_ID);
+
+            //平台用户扣除积分
+            ptProfit.setPtGrossAdd(ptProfit.getPtGrossAdd() - ptProfitLogDO.getAccumulatedQuotaAmount());
+            ptIntegralDO.setCurrentQuota(ptIntegralDO.getCurrentQuota() - ptProfitLogDO.getAccumulatedQuotaAmount());
+            // 平台扣除积分
+            ptProfit.setPtTotalAdd(ptProfit.getPtTotalAdd() - ptProfitLogDO.getAccumulatedQuotaAmount());
+
+            integralMapper.updateById(ptIntegralDO);
+            ptProfitService.updatePtProfit(PtProfitSaveReqVO.builder().id(ptProfit.getId())
+                    .ptAdd(ptProfit.getPtAdd())
+                    .ptGrossAdd(ptProfit.getPtGrossAdd())
+                    .ptTotalAdd(ptProfit.getPtTotalAdd()).build());
+
+            //这条记录是用户看的
+            PtProfitLogSaveReqVO ProfitLog = PtProfitLogSaveReqVO.builder()
+                    .amount(ptProfitLogDO.getAccumulatedQuotaAmount())
+                    .afterAmount(integralDO.getCurrentQuota())
+                    .userId(ptProfitLogDO.getUserId())
+                    .generateUserId(ptProfitLogDO.getGenerateUserId())
+                    .profitStatus(MANUAL_RETURN_INTEGRAL.getType())
+                    .maxAvailablePointsAmount(-ptProfitLogDO.getAccumulatedQuotaAmount())
+                    .afterMaxAvailablePointsAmount(integralDO.getHighQuota())
+                    .build();
+            ptProfitLogMapper.insert(BeanUtils.toBean(ProfitLog, PtProfitLogDO.class));
+
+            //这条是pt看的
+            PtProfitLogSaveReqVO ptProfitLog = PtProfitLogSaveReqVO.builder()
+                    .amount(ptProfitLogDO.getAccumulatedQuotaAmount())
+                    .afterAmount(ptProfit.getPtGrossAdd())
+                    .generateUserId(ptProfitLogDO.getGenerateUserId())
+                    .profitStatus(MANUAL_RETURN_INTEGRAL.getType())
+                    .build();
+            ptProfitLogMapper.insert(BeanUtils.toBean(ptProfitLog, PtProfitLogDO.class));
+        }
+    }
+
 }

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

@@ -88,4 +88,6 @@ public interface PtProfitLogService {
                     Long tradeOrderId,
                     String OrderNum
     );
+
+    List<PtProfitLogDO> calcIntegral();
 }

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

@@ -3,6 +3,7 @@ package cn.newfeifan.mall.module.distri.service.ptprofitlog;
 import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.newfeifan.mall.module.distri.enums.CaclEnum;
 import cn.newfeifan.mall.module.member.service.user.MemberUserService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -86,6 +87,7 @@ public class PtProfitLogServiceImpl implements PtProfitLogService {
             if (ptProfitLogRespVO.getProfitStatus().equals(RECOMMENDED_PERSON_QUOTA.getType()) ||
                     ptProfitLogRespVO.getProfitStatus().equals(CaclEnum.ORDER_PAY_INTEGRAL_ANCESTER.getType()) ||
                     ptProfitLogRespVO.getProfitStatus().equals(CaclEnum.ORDER_REFUND_INTEGRAL_ANCESTER.getType()) ||
+                    ptProfitLogRespVO.getProfitStatus().equals(CaclEnum.MANUAL_RETURN_INTEGRAL.getType()) ||
                     ptProfitLogRespVO.getProfitStatus().equals(SMALL_QUOTA_CRASH.getType())) {
                 ptProfitLogRespVO.setUsername(memberUserService.getUser(ptProfitLogRespVO.getGenerateUserId()).getUsername());
             }
@@ -206,4 +208,13 @@ public class PtProfitLogServiceImpl implements PtProfitLogService {
 
     }
 
+    @Override
+    public List<PtProfitLogDO> calcIntegral() {
+        return ptProfitLogMapper.selectList(new LambdaQueryWrapper<PtProfitLogDO>()
+                .eq(PtProfitLogDO::getProfitStatus, SMALL_QUOTA_CRASH.getType())
+                .ne(PtProfitLogDO::getAccumulatedQuotaAmount, 0)
+                .lt(PtProfitLogDO::getCreateTime, LocalDateTime.now().minusDays(5))
+        );
+    }
+
 }