licailing 4 éve
szülő
commit
73c75117a4

+ 5 - 4
src/main/java/com/izouma/nineth/service/AuctionOrderService.java

@@ -344,15 +344,16 @@ public class AuctionOrderService {
         try {
             switch (payMethod) {
                 case HMPAY:
-                    orderPayService.refund(order.getId()
-                            .toString(), order.getTotalPrice(), "hmPay");
+                    orderPayService.refund(order.getId().toString(), order.getTotalPrice(), "hmPay");
                     log.info("退款成功");
                     break;
                 case SANDPAY:
-                    orderPayService.refund(order.getId()
-                            .toString(), order.getTotalPrice(), "sandPay");
+                    orderPayService.refund(order.getId().toString(), order.getTotalPrice(), "sandPay");
                     log.info("退款成功");
                     break;
+                case PAYEASE:
+                    orderPayService.refund(order.getId().toString(), order.getTotalPrice(), "payEase");
+                    break;
             }
             order.setRefundTime(LocalDateTime.now());
             order.setStatus(AuctionOrderStatus.REFUNDED);

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

@@ -57,6 +57,7 @@ public class OrderPayService {
     private final PayEaseService     payEaseService;
     private final UserBankCardRepo   userBankCardRepo;
     private final AuctionOrderRepo   auctionOrderRepo;
+    private final AuctionOrderService auctionOrderService;
 
     public static void setPayChannel(String payChannel) {
         if (Constants.PayChannel.HM.equals(payChannel) || Constants.PayChannel.SAND.equals(payChannel)) {
@@ -393,6 +394,53 @@ public class OrderPayService {
             throw new BusinessException("交易码错误");
         }
         BalanceRecord record = userBalanceService.balancePay(order.getUserId(), order.getTotalPrice(), orderId, "拍卖");
-        giftOrderService.giftNotify(orderId, PayMethod.BALANCE, record.getId().toString());
+        auctionOrderService.notify(orderId, PayMethod.BALANCE, record.getId().toString());
     }
+
+    @Cacheable(value = "payOrder", key = "'auctionOrder#'+#orderId")
+    public Map<String, Object> payAuctionOrderAgreement(Long orderId, String bindCardId) {
+        AuctionOrder order = auctionOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
+        if (order.getStatus() != AuctionOrderStatus.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("请先绑定银行卡");
+        }
+        return payEaseService.pay("拍卖:" + order.getAuctionId(), orderId.toString(), order.getTotalPrice(),
+                order.getUserId().toString(), bindCardId, "auctionOrder");
+    }
+
+    public JSONObject refund(String orderId, BigDecimal amount, String channel) {
+        switch (channel) {
+            case "sandPay": {
+                JSONObject res = sandPayService.refund(orderId, amount);
+                if (!"000000".equals(res.getJSONObject("head").getString("respCode"))) {
+                    throw new BusinessException("退款失败");
+                }
+                break;
+            }
+            case "hmPay": {
+                JSONObject res = hmPayService.refund(orderId, amount);
+                if (!"REFUND_SUCCESS".equals(res.getString("sub_code"))) {
+                    throw new BusinessException("退款失败");
+                }
+                break;
+            }
+            case "payEase": {
+                JSONObject res = payEaseService.refund(orderId, amount);
+                String status = res.getString("status");
+                if (!"SUCCESS".equals(status)) {
+                    String error = res.getString("error");
+                    throw new BusinessException("退款失败:" + error);
+                }
+                break;
+            }
+        }
+        throw new BusinessException("退款失败");
+    }
+
 }

+ 6 - 0
src/main/java/com/izouma/nineth/web/OrderPayControllerV2.java

@@ -181,4 +181,10 @@ public class OrderPayControllerV2 {
     public void payAuctionOrderBalance(@RequestParam Long id, @RequestParam String tradeCode) {
         orderPayService.payAuctionOrderBalance(id, SecurityUtils.getAuthenticatedUser().getId(), tradeCode);
     }
+
+    @RequestMapping(value = "/auction/agreement")
+    @ResponseBody
+    public Map<String, Object> payAuctionAgreement(@RequestParam Long id, String bindCardId) {
+        return orderPayService.payAuctionOrderAgreement(id, bindCardId);
+    }
 }

+ 1 - 1
src/test/java/com/izouma/nineth/service/OrderServiceTest.java

@@ -261,7 +261,7 @@ public class OrderServiceTest extends ApplicationTests {
 
     @Test
     public void test1() {
-        orderService.queryCreateOrder("945378720611303424");
+        orderService.queryCreateOrder("1234");
     }
 
     @Test