wangqifan 3 年 前
コミット
d038967c0d

+ 22 - 0
src/main/java/com/izouma/nineth/service/OrderPayService.java

@@ -69,6 +69,7 @@ public class OrderPayService {
     private final AlipayService            alipayService;
     private final PhotoAssetRepo           photoAssetRepo;
     private final PhotoAssetService        photoAssetService;
+    private final TradeAuctionRepo         tradeAuctionRepo;
 
     public static void setPayChannel(String payChannel) {
         log.info("set pay channel {}", payChannel);
@@ -707,9 +708,30 @@ public class OrderPayService {
 
     public void payTradeAuctionOrderBalance(Long orderId, Long userId, String tradeCode) {
         TradeAuctionOrder order = tradeAuctionOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
+        TradeAuction tradeAuction = tradeAuctionRepo.findById(order.getTradeAuctionId())
+                .orElseThrow(new BusinessException("暂无"));
         if (order.getStatus() != AuctionOrderStatus.NOT_PAID) {
             throw new BusinessException("订单状态错误");
         }
+        if (tradeAuction.getStock() < 1) {
+            throw new BusinessException("库存不足");
+        }
+        if (tradeAuction.getCurrentOwnerId() != null) {
+            if (tradeAuction.getCurrentOwnerId().equals(userId)) {
+                throw new BusinessException("不可竞价持有的易拍产品");
+            }
+        }
+        if (LocalDateTime.now().compareTo(tradeAuction.getCurrentStartTime()) < 0) {
+            throw new BusinessException("未到竞价时间");
+        }
+        if (!tradeAuction.getStatus().equals(TradeAuctionStatus.ONGOING)) {
+            throw new BusinessException("易拍产品未处在竞价状态");
+        }
+        if (order.getPaymentType().equals(AuctionPaymentType.DEPOSIT)) {
+            if (order.getPrice().compareTo(tradeAuction.getNextPrice()) != 0) {
+                throw new BusinessException("购买资格已经没有");
+            }
+        }
         checkTradeCode(userId, tradeCode, order.getUserId());
         BigDecimal amount;
         if (order.getPaymentType() != AuctionPaymentType.DEPOSIT) {

+ 5 - 0
src/main/java/com/izouma/nineth/service/TradeAuctionOrderService.java

@@ -59,6 +59,11 @@ public class TradeAuctionOrderService {
         if (!tradeAuction.getStatus().equals(TradeAuctionStatus.ONGOING)) {
             throw new BusinessException("易拍产品未处在竞价状态");
         }
+        if (auctionPaymentType.equals(AuctionPaymentType.DEPOSIT)) {
+            if (price.compareTo(tradeAuction.getNextPrice()) != 0) {
+                throw new BusinessException("购买资格已经没有");
+            }
+        }
         tradeAuctionService.decreaseStock(auctionId, 1);
         BigDecimal serviceCharge = (BigDecimal.valueOf(3).multiply(tradeAuction.getNextPrice())
                 .divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP))