Przeglądaj źródła

修改查询用户积分的问题

gaohp 1 rok temu
rodzic
commit
b932cf72c1

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

@@ -10,5 +10,6 @@ public class DistriConstants {
     public static final Integer INTEGRAL2MONEY = PERCENT/100;
 
     public static final Double ONE_HUNDRED = 1d;
+    public static final Long PT_ID = 1L;
 
 }

+ 5 - 2
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/app/duser/AppDuserController.java

@@ -1,5 +1,6 @@
 package cn.newfeifan.mall.module.distri.controller.app.duser;
 
+import cn.newfeifan.mall.framework.security.core.LoginUser;
 import cn.newfeifan.mall.module.distri.controller.admin.duser.vo.DuserInfoVO;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
@@ -26,6 +27,7 @@ import cn.newfeifan.mall.framework.excel.core.util.ExcelUtils;
 
 import cn.newfeifan.mall.framework.operatelog.core.annotations.OperateLog;
 import static cn.newfeifan.mall.framework.operatelog.core.enums.OperateTypeEnum.*;
+import static cn.newfeifan.mall.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
 
 import cn.newfeifan.mall.module.distri.controller.app.duser.vo.*;
 import cn.newfeifan.mall.module.distri.dal.dataobject.duser.DuserDO;
@@ -42,8 +44,9 @@ public class AppDuserController {
 
     @GetMapping("/getDuserInfo")
     @Operation(summary = "获取分销人员信息")
-    public CommonResult<DuserInfoVO> getDuserInfo(@RequestParam("userId") Long userId) {
-        DuserInfoVO duserInfo = duserService.getDuserInfo(userId);
+    public CommonResult<DuserInfoVO> getDuserInfo() {
+
+        DuserInfoVO duserInfo = duserService.getDuserInfo(getLoginUserId());
         return success(duserInfo);
     }
 

+ 1 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/duser/DuserService.java

@@ -55,6 +55,7 @@ public interface DuserService {
 
 
     void hasUserAndCreat(SharePathSaveReqVO saveReqVO);
+    void hasUserAndCreat(Long userId);
 
     DuserInfoVO getDuserInfo(Long userId);
 }

+ 13 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/duser/DuserServiceImpl.java

@@ -103,12 +103,25 @@ public class DuserServiceImpl implements DuserService {
         checkAndCreat(saveReqVO.getAncestor());
     }
 
+    @Override
+    public void hasUserAndCreat(Long userId) {
+        checkAndCreat(userId);
+    }
+
     @Override
     public DuserInfoVO getDuserInfo(Long userId) {
 
+
+        hasUserAndCreat(userId);
+        // 先初始化
+        // 判断当前下单人是否有有上级, 如果没有, 创建直推人关系
+        sharePathService.createSharePathByUserId(userId);
+
+
         List<Long> sonsId = sharePathService.sonsId(userId);
         IntegralDO integral = integralService.getIntegral(userId);
         if (integral == null){
+            // 初始化积分表
             throw exception(INTEGRAL_NOT_EXISTS);
         }
         DuserInfoVO.DuserInfoVOBuilder duserInfoVOBuilder = DuserInfoVO.builder()

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

@@ -1,5 +1,6 @@
 package cn.newfeifan.mall.module.distri.service.integral;
 
+import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.springframework.stereotype.Service;
 
@@ -67,7 +68,7 @@ public class IntegralServiceImpl implements IntegralService {
 
     @Override
     public IntegralDO getIntegral(Long id) {
-        return integralMapper.selectById(id);
+        return integralMapper.selectOne(new LambdaQueryWrapperX<IntegralDO>().eq(IntegralDO::getUserId,id));
     }
 
     @Override

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

@@ -23,6 +23,7 @@ public interface SharePathService {
     Long createSharePath(@Valid SharePathSaveReqVO createReqVO);
 
     void createSharePathByUserId(SharePathSaveReqVO createReqVO);
+    void createSharePathByUserId(Long userId);
 
 
 
@@ -69,4 +70,5 @@ public interface SharePathService {
 
     List<Long> sonsId(Long userId);
 
+    Boolean hasParent(Long userId);
 }

+ 17 - 2
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/sharepath/SharePathServiceImpl.java

@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.stream.Collectors;
 
 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.ErrorCodeConstants.*;
 
 /**
@@ -88,7 +89,22 @@ public class SharePathServiceImpl implements SharePathService {
 
     }
 
-    private Boolean hasParent(Long descendant) {
+    @Override
+    public void createSharePathByUserId(Long userId) {
+        Boolean has = hasParent(userId);
+        if (has) {
+            return;
+        }
+        // 如果是没有父亲, 将其推荐人设置为平台
+        SharePathSaveReqVO build = SharePathSaveReqVO.builder()
+                .ancestor(PT_ID)
+                .descendant(userId)
+                .build();
+        createSharePathByUserId(build);
+    }
+
+    @Override
+    public Boolean hasParent(Long descendant) {
         SharePathDO sharePathDO = sharePathMapper.selectOne(new LambdaQueryWrapperX<SharePathDO>()
                 .eqIfPresent(SharePathDO::getDescendant, descendant)
                 .eqIfPresent(SharePathDO::getDepth, 1));
@@ -148,5 +164,4 @@ public class SharePathServiceImpl implements SharePathService {
     }
 
 
-
 }