From 34f741f39e22bf48df33321230380b40c23110c3 Mon Sep 17 00:00:00 2001
From: huliguo <2023611923@qq.com>
Date: 星期五, 18 四月 2025 21:34:13 +0800
Subject: [PATCH] 店铺、积分、订单

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
index 2142a97..7a2b9dc 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
@@ -10,11 +10,15 @@
 import com.ruoyi.account.vo.UserPointDetailVO;
 import com.ruoyi.account.vo.UserPointStatistics;
 import com.ruoyi.account.vo.UserPointVO;
+import com.ruoyi.common.core.annotation.Excel;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.utils.PhoneNumberValidator;
+import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.web.page.PageInfo;
 import com.ruoyi.common.security.service.TokenService;
 import com.ruoyi.other.api.enums.PointChangeType;
+import com.ruoyi.system.api.domain.SysConfig;
+import com.ruoyi.system.api.feignClient.SysConfigClient;
 import com.ruoyi.system.api.model.LoginUser;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -42,6 +46,8 @@
     private TokenService tokenService;
     @Resource
     private UserPointService userPointService;
+    @Resource
+    private SysConfigClient sysConfigClient;
     
 
 
@@ -51,13 +57,23 @@
     public UserPointVO getUserPoint(Long userId) {
         AppUser appUser = appUserService.getById(userId);
         UserPointVO userPointVO = new UserPointVO();
-        userPointVO.setTotalPoint(appUser.getUserTotalPoint() );
+        userPointVO.setTotalPoint(appUser.getTotalPoint() );
         userPointVO.setConsumePoint(appUser.getAvailablePoint());
         userPointVO.setRechargePoint(appUser.getRechargePoint());
         userPointVO.setCancelPoint(appUser.getCancelPoint());
         userPointVO.setExpendPoint(appUser.getExchangePoint());
         userPointVO.setTransferableInPoint(appUser.getTransferableInPoint());
         userPointVO.setTransferableOutPoint(appUser.getTransferableOutPoint());
+        R<SysConfig> info = sysConfigClient.getInfo(9L);
+        if (info == null || info.getData() == null) {
+            throw new RuntimeException("获取积分兑换比例配置失败");
+        }
+        String configValue = info.getData().getConfigValue();
+        if (StringUtils.isBlank(configValue)) {
+            throw new RuntimeException("积分兑换比例配置值为空");
+        }
+        Boolean isTransferable = Boolean.valueOf(configValue.trim());
+        userPointVO.setIsTransferable(isTransferable);
         return userPointVO;
     }
 
@@ -70,12 +86,16 @@
         for (UserPointDetailVO userPointDetailVO : userPointDetail) {
             Integer type1 = userPointDetailVO.getType();
             if (type1 != null && type1.equals(12)){
-                AppUser appUser = appUserService.getById(userPointDetailVO.getReceiveUserId());
+                //他人赠送
+                AppUser appUser = appUserService.getById(userPointDetailVO.getObjectId());
                 userPointDetailVO.setName(appUser.getName());
+                userPointDetailVO.setTransferUserId(appUser.getId());
             }
             if (type1 != null && type1.equals(13)){
-                AppUser appUser = appUserService.getById(userPointDetailVO.getTransferUserId());
+                //赠予他人
+                AppUser appUser = appUserService.getById(userPointDetailVO.getObjectId());
                 userPointDetailVO.setName(appUser.getName());
+                userPointDetailVO.setReceiveUserId(appUser.getId());
             }
             Integer historicalPoint = userPointDetailVO.getHistoricalPoint();
             Integer balance = userPointDetailVO.getBalance();
@@ -119,11 +139,22 @@
             return R.fail("不能转增给自己");
         }
 
+        if (null==appUserForPhoe.getTotalPoint()){
+            appUserForPhoe.setTotalPoint(0);
+        }
+        if (null==appUserForPhoe.getTransferableInPoint()){
+            appUserForPhoe.setTransferableInPoint(0);
+        }
+        if(null==appUserForPhoe.getAvailablePoint()){
+            appUserForPhoe.setAvailablePoint(0);
+        }
+
         Integer historicalPoint = appUserForPhoe.getAvailablePoint();//历史积分
         Integer balance = historicalPoint +point;//变动后积分
 
         appUserForPhoe.setAvailablePoint(balance);//可用积分增加
-        appUserForPhoe.setTotalPoint(appUserForPhoe.getUserTotalPoint() + point);//总积分增加
+
+        appUserForPhoe.setTotalPoint(appUserForPhoe.getTotalPoint() + point);//总积分增加
         appUserForPhoe.setTransferableInPoint(appUserForPhoe.getTransferableInPoint() + point);//转入积分增加
 
         appUserService.updateById(appUserForPhoe);
@@ -141,11 +172,22 @@
             userPointService.save(userPoint);
         }
 
-        Integer historicalPoint2 = appUserForPhoe.getAvailablePoint();//历史积分
-        Integer balance2 = historicalPoint - point;//变动后积分
+        if (null==appUser.getTotalPoint()){
+            appUser.setTotalPoint(0);
+        }
+        if (null==appUser.getTransferableOutPoint()){
+            appUser.setTransferableOutPoint(0);
+        }
+        if (null==appUser.getAvailablePoint()){
+            appUser.setAvailablePoint(0);
+        }
+        Integer historicalPoint2 = appUser.getAvailablePoint();//历史积分
+        Integer balance2 = historicalPoint2 - point;//变动后积分
 
-        appUser.setAvailablePoint(balance);//可用积分减少
-        appUser.setTransferableOutPoint(appUserForPhoe.getTransferableOutPoint() + point);//转出积分增加
+
+        appUser.setAvailablePoint(balance2);//可用积分减少
+        appUser.setTotalPoint(appUser.getTotalPoint() + point);//总积分增加
+        appUser.setTransferableOutPoint(appUser.getTransferableOutPoint() + point);//转出积分增加
 
         appUserService.updateById(appUser);
         //构建积分流水记录

--
Gitblit v1.7.1