Bladeren bron

fix(account): 修复账户退款相关余额处理逻辑

- applet端退款接口添加退款类型参数,区分不同退款状态
- 修正UserAccountServiceImpl中余额减少逻辑,删除注释代码,简化余额扣减流程
- UserInfoController中退款接口路径改为带用户ID参数,并传递退款状态
- WFTOrderService退款方法新增退款类型参数,调用时传递不同退款标识
- 保证账户余额更新及退款记录时使用正确的用户ID和退款类型参数
wzq 22 uur geleden
bovenliggende
commit
cee7110617

+ 4 - 3
src/main/java/com/zsElectric/boot/business/controller/UserInfoController.java

@@ -3,6 +3,7 @@ package com.zsElectric.boot.business.controller;
 import com.zsElectric.boot.business.service.UserInfoService;
 import com.zsElectric.boot.business.service.WFTOrderService;
 import com.zsElectric.boot.common.annotation.Log;
+import com.zsElectric.boot.common.constant.SystemConstants;
 import com.zsElectric.boot.common.enums.LogModuleEnum;
 import com.zsElectric.boot.security.util.SecurityUtils;
 import lombok.RequiredArgsConstructor;
@@ -51,10 +52,10 @@ public class UserInfoController  {
      * @return
      */
     @Operation(summary = "账户退款")
-    @PutMapping("/refundOrder")
+    @PutMapping("/refundOrder/{userId}")
     @Log(value = "账户退款", module = LogModuleEnum.APP_ORDER)
-    public Result<String> refundOrder(Long userId) throws Exception {
-        return Result.success(wftOrderService.refundOrder(userId));
+    public Result<String> refundOrder(@PathVariable("userId") Long userId) throws Exception {
+        return Result.success(wftOrderService.refundOrder(userId, SystemConstants.STATUS_ONE));
     }
 
     @Operation(summary = "新增个人用户信息")

+ 2 - 1
src/main/java/com/zsElectric/boot/business/controller/applet/AppletWFTOrderController.java

@@ -5,6 +5,7 @@ import com.zsElectric.boot.business.model.form.applet.AppUserPayForm;
 import com.zsElectric.boot.business.model.vo.applet.WFTRefundQueryVO;
 import com.zsElectric.boot.business.service.WFTOrderService;
 import com.zsElectric.boot.common.annotation.Log;
+import com.zsElectric.boot.common.constant.SystemConstants;
 import com.zsElectric.boot.common.enums.LogModuleEnum;
 import com.zsElectric.boot.common.util.IPUtils;
 import com.zsElectric.boot.core.web.Result;
@@ -143,7 +144,7 @@ public class AppletWFTOrderController {
     @Log(value = "账户退款", module = LogModuleEnum.APP_ORDER)
     public Result<String> refundOrder() throws Exception {
         Long userId = SecurityUtils.getUserId();
-        return Result.success(wftOrderService.refundOrder(userId));
+        return Result.success(wftOrderService.refundOrder(userId, SystemConstants.STATUS_TWO));
     }
 
     /**

+ 4 - 4
src/main/java/com/zsElectric/boot/business/service/WFTOrderService.java

@@ -766,7 +766,7 @@ public class WFTOrderService {
      * @return
      */
     @Transactional(rollbackFor = Exception.class)
-    public String refundOrder(Long userId) throws Exception {
+    public String refundOrder(Long userId,Integer type) throws Exception {
 
         //查询账户余额
         UserAccount userAccount =
@@ -800,7 +800,7 @@ public class WFTOrderService {
                 refundOrder(userOrderInfo,refundMoney, "账户退款", SystemConstants.STATUS_ONE);
                 //账户变动及日志记录(退款清空账户余额)
                 userAccountService.updateAccountBalanceAndLog(
-                        SecurityUtils.getUserId(),
+                        userId,
                         refundMoney,
                         SystemConstants.CHANGE_TYPE_REDUCE,
                         SystemConstants.ACCOUNT_LOG_REFUND_NOTE,
@@ -821,10 +821,10 @@ public class WFTOrderService {
             }
             if (canRefundMoney.compareTo(refundMoney) < 0) {
                 //退款金额小于订单金额,则先退订单金额
-                refundOrder(userOrderInfo, canRefundMoney, "账户退款", SystemConstants.STATUS_TWO);
+                refundOrder(userOrderInfo, canRefundMoney, "账户退款", type);
                 //账户变动及日志记录(减少账户余额)
                 userAccountService.updateAccountBalanceAndLog(
-                        SecurityUtils.getUserId(),
+                        userId,
                         canRefundMoney,
                         SystemConstants.CHANGE_TYPE_REDUCE,
                         SystemConstants.ACCOUNT_LOG_REFUND_NOTE,

+ 31 - 24
src/main/java/com/zsElectric/boot/business/service/impl/UserAccountServiceImpl.java

@@ -134,33 +134,40 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserA
             // 更新账户余额
             userAccount.setBalance(finalBalance);
         }
-        else if (SystemConstants.REDEEM_CHANGE_TYPE_ADD.equals(changeType)) {
-            // 增加兑换余额
-            finalBalance = userAccount.getRedeemBalance().subtract(changeAmount);
-            // 减去账户余额
-            userAccount.setRedeemBalance(finalBalance);
-        }
+//        else if (SystemConstants.REDEEM_CHANGE_TYPE_ADD.equals(changeType)) {
+//            // 增加兑换余额
+//            finalBalance = userAccount.getRedeemBalance().subtract(changeAmount);
+//            // 减去账户余额
+//            userAccount.setRedeemBalance(finalBalance);
+//        }
         //退款
-        else if (SystemConstants.ACCOUNT_REFUND.equals(changeType)) {
-            // 清空账户余额,兑换余额不可退
-            finalBalance = BigDecimal.ZERO;
+//        else if (SystemConstants.ACCOUNT_REFUND.equals(changeType)) {
+//            // 清空账户余额,兑换余额不可退
+//            finalBalance = BigDecimal.ZERO;
+//            userAccount.setBalance(finalBalance);
+//        }
+
+        if (SystemConstants.CHANGE_TYPE_REDUCE.equals(changeType)){
+            // 减少余额
+            finalBalance = userAccount.getBalance().subtract(changeAmount);
+            // 减去账户余额
             userAccount.setBalance(finalBalance);
         }
-        else{
-            // 减少余额,优先减少兑换余额,不够的再减抵用余额
-            if (userAccount.getRedeemBalance().compareTo(changeAmount) >= 0) {
-                // 兑换余额充足,直接减少
-                finalBalance = userAccount.getBalance().subtract(changeAmount);
-                // 减去账户余额
-                userAccount.setRedeemBalance(finalBalance);
-            } else {
-                // 账户余额不足,先减去兑换余额,不够的再减抵用余额
-                BigDecimal subtract = changeAmount.subtract(userAccount.getRedeemBalance());
-                finalBalance = userAccount.getBalance().subtract(subtract);
-                userAccount.setRedeemBalance(BigDecimal.ZERO);
-                userAccount.setBalance(finalBalance);
-            }
-        }
+//        else{
+//            // 减少余额,优先减少兑换余额,不够的再减抵用余额
+//            if (userAccount.getRedeemBalance().compareTo(BigDecimal.ZERO) > 0 && userAccount.getRedeemBalance().compareTo(changeAmount) >= 0) {
+//                // 兑换余额充足,直接减少
+//                finalBalance = userAccount.getBalance().subtract(changeAmount);
+//                // 减去账户余额
+//                userAccount.setRedeemBalance(finalBalance);
+//            } else {
+//                // 账户余额不足,先减去兑换余额,不够的再减抵用余额
+//                BigDecimal subtract = changeAmount.subtract(userAccount.getRedeemBalance());
+//                finalBalance = userAccount.getBalance().subtract(subtract);
+//                userAccount.setRedeemBalance(BigDecimal.ZERO);
+//                userAccount.setBalance(finalBalance);
+//            }
+//        }
         this.updateById(userAccount);
         
         // 保存变动日志