소스 검색

首信易

xiongzhu 4 년 전
부모
커밋
5fe45ba170

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

@@ -3,6 +3,7 @@ package com.izouma.nineth.service;
 import com.alibaba.fastjson.JSONObject;
 import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.domain.*;
+import com.izouma.nineth.dto.UserBankCard;
 import com.izouma.nineth.enums.MintOrderStatus;
 import com.izouma.nineth.enums.OrderStatus;
 import com.izouma.nineth.enums.PayMethod;
@@ -45,6 +46,8 @@ public class OrderPayService {
     private final RechargeOrderRepo  rechargeOrderRepo;
     private final SysConfigService   sysConfigService;
     private final PasswordEncoder    passwordEncoder;
+    private final PayEaseService     payEaseService;
+    private final UserBankCardRepo   userBankCardRepo;
 
     public static void setPayChannel(String payChannel) {
         if ("hmPay".equals(payChannel) || "sandPay".equals(payChannel)) {
@@ -103,13 +106,23 @@ public class OrderPayService {
                         System.currentTimeMillis()));
     }
 
-    public void payOrderAgreement(Long orderId) {
+    public void payOrderAgreement(Long orderId, String bindCardId) {
         Order order = orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
         if (order.getStatus() != OrderStatus.NOT_PAID) {
             throw new BusinessException("订单状态错误");
         }
+        if (StringUtils.isEmpty(bindCardId)) {
+            bindCardId = userBankCardRepo.findByUserId(order.getUserId())
+                    .stream().map(UserBankCard::getBindCardId).findFirst().orElse(null);
+        }
+        if (StringUtils.isEmpty(bindCardId)) {
+            throw new BusinessException("请先绑定银行卡");
+        }
+        payEaseService.pay(order.getName(), orderId.toString(), order.getTotalPrice(),
+                order.getUserId().toString(), bindCardId);
     }
 
+
     @Cacheable(value = "payOrder", key = "'gift#'+#orderId")
     public String payGiftOrder(Long orderId) {
         GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));

+ 12 - 1
src/main/java/com/izouma/nineth/service/PayEaseService.java

@@ -28,6 +28,8 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Objects;
 
 @Service
@@ -130,7 +132,7 @@ public class PayEaseService {
     }
 
 
-    public void pay(String subject, String orderId, BigDecimal amount, String userId, String bindCardId) {
+    public Map<String, Object> pay(String subject, String orderId, BigDecimal amount, String userId, String bindCardId) {
         String amountStr = amount.multiply(new BigDecimal("100")).setScale(0, RoundingMode.FLOOR)
                 .stripTrailingZeros().toPlainString();
         //通知地址
@@ -168,6 +170,15 @@ public class PayEaseService {
             String error = response.getString("error");
             throw new BusinessException(error);
         }
+        boolean needCaptcha = response.getBoolean("needKaptcha");
+        String paymentOrderId = response.getString("paymentOrderId");
+        String requestId = response.getString("requestId");
+        Map<String, Object> map = new HashMap<>();
+        map.put("needCaptcha", needCaptcha);
+        map.put("paymentOrderId", paymentOrderId);
+        map.put("requestId", requestId);
+        map.put("orderId", orderId);
+        return map;
     }
 
     public void payConfirm(String orderId, String paymentOrderId, String code) {

+ 7 - 2
src/main/java/com/izouma/nineth/service/UserBankCardService.java

@@ -17,6 +17,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Optional;
 
 @Service
@@ -29,12 +31,15 @@ public class UserBankCardService {
     private final IdentityAuthRepo identityAuthRepo;
     private final PayEaseService   payEaseService;
 
-    public String bindCard(Long userId, String phone, String bankNo) {
+    public Map<String, String> bindCard(Long userId, String phone, String bankNo) {
         IdentityAuth identityAuth = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(userId, AuthStatus.SUCCESS)
                 .orElseThrow(new BusinessException("请先完成实名认证"));
         BindCardRequest request = new BindCardRequest(userId.toString(), bankNo, phone, identityAuth.getRealName(),
                 identityAuth.getIdNo(), null);
-        return payEaseService.bindCard(request);
+        String bindCardId = payEaseService.bindCard(request);
+        Map<String, String> map = new HashMap<>();
+        map.put("bindCardId", bindCardId);
+        return map;
     }
 
     public void bindCardConfirm(String bindCardId, String code) {

+ 3 - 1
src/main/java/com/izouma/nineth/web/UserBankCardController.java

@@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Map;
+
 @RestController
 @RequestMapping("/userBankCard")
 @Slf4j
@@ -18,7 +20,7 @@ public class UserBankCardController {
     private final UserBankCardService userBankCardService;
 
     @PostMapping("/bindCard")
-    public String bindCard(@RequestParam String phone, @RequestParam String bankNo) {
+    public Map<String, String> bindCard(@RequestParam String phone, @RequestParam String bankNo) {
         return userBankCardService.bindCard(SecurityUtils.getAuthenticatedUser().getId(), phone, bankNo);
     }