Sfoglia il codice sorgente

余额交易密码

xiongzhu 4 anni fa
parent
commit
babd018268
1 ha cambiato i file con 14 aggiunte e 20 eliminazioni
  1. 14 20
      src/main/java/com/izouma/nineth/service/OrderPayService.java

+ 14 - 20
src/main/java/com/izouma/nineth/service/OrderPayService.java

@@ -93,16 +93,7 @@ public class OrderPayService {
         if (order.getStatus() != OrderStatus.NOT_PAID) {
             throw new BusinessException("订单状态错误");
         }
-        if (!Objects.equals(order.getUserId(), userId)) {
-            throw new BusinessException("订单不属于该用户");
-        }
-        String encodedPwd = userRepo.findTradeCode(userId);
-        if (StringUtils.isEmpty(encodedPwd)) {
-            throw new BusinessException("请先设置交易密码");
-        }
-        if (!passwordEncoder.matches(tradeCode, encodedPwd)) {
-            throw new BusinessException("交易码错误");
-        }
+        checkTradeCode(userId, tradeCode, order.getUserId());
         BalanceRecord record = userBalanceService.balancePay(order.getUserId(), order.getTotalPrice(), orderId, order.getName());
         rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
                 new OrderNotifyEvent(orderId, PayMethod.BALANCE, record.getId().toString(),
@@ -175,12 +166,7 @@ public class OrderPayService {
         if (order.getStatus() != OrderStatus.NOT_PAID) {
             throw new BusinessException("订单状态错误");
         }
-        if (!Objects.equals(order.getUserId(), userId)) {
-            throw new BusinessException("订单不属于该用户");
-        }
-        if (!Objects.equals(userRepo.findTradeCode(userId), tradeCode)) {
-            throw new BusinessException("交易码错误");
-        }
+        checkTradeCode(userId, tradeCode, order.getUserId());
         BalanceRecord record = userBalanceService.balancePay(order.getUserId(), order.getGasPrice(), orderId, "转赠");
         giftOrderService.giftNotify(orderId, PayMethod.BALANCE, record.getId().toString());
     }
@@ -237,14 +223,22 @@ public class OrderPayService {
         if (order.getStatus() != MintOrderStatus.NOT_PAID) {
             throw new BusinessException("订单状态错误");
         }
-        if (!Objects.equals(order.getUserId(), userId)) {
+        checkTradeCode(userId, tradeCode, order.getUserId());
+        BalanceRecord record = userBalanceService.balancePay(order.getUserId(), order.getGasPrice(), orderId, "铸造活动");
+        giftOrderService.giftNotify(orderId, PayMethod.BALANCE, record.getId().toString());
+    }
+
+    private void checkTradeCode(Long userId, String tradeCode, Long orderUserId) {
+        if (!Objects.equals(orderUserId, userId)) {
             throw new BusinessException("订单不属于该用户");
         }
-        if (!Objects.equals(userRepo.findTradeCode(userId), tradeCode)) {
+        String encodedPwd = userRepo.findTradeCode(userId);
+        if (StringUtils.isEmpty(encodedPwd)) {
+            throw new BusinessException("请先设置交易密码");
+        }
+        if (!passwordEncoder.matches(tradeCode, encodedPwd)) {
             throw new BusinessException("交易码错误");
         }
-        BalanceRecord record = userBalanceService.balancePay(order.getUserId(), order.getGasPrice(), orderId, "铸造活动");
-        giftOrderService.giftNotify(orderId, PayMethod.BALANCE, record.getId().toString());
     }
 
     @Cacheable(value = "payOrder", key = "'mint#'+#orderId")