licailing 3 жил өмнө
parent
commit
117ae329d1

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

@@ -80,7 +80,8 @@ public class AuctionOrderService {
     }
 
     @RedisLock("'createAuctionOrder::'+#auctionId")
-    public AuctionOrder create(Long userId, Long auctionId, Long addressId, Long auctionRecordId, AuctionPaymentType type) {
+    public AuctionOrder create(Long userId, Long auctionId, Long addressId, Long auctionRecordId,
+                               AuctionPaymentType type, BigDecimal amount) {
         User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
 
         AuctionActivity auction = auctionActivityRepo.findById(auctionId)
@@ -142,7 +143,7 @@ public class AuctionOrderService {
                 throw new BusinessException("拍卖已结束");
             }
             if (AuctionPaymentType.DEPOSIT.equals(type)) {
-                return this.createDeposit(user, auction);
+                return this.createDeposit(user, auction, amount);
             }
         }
 
@@ -193,7 +194,7 @@ public class AuctionOrderService {
     }
 
 
-    public AuctionOrder createDeposit(User user, AuctionActivity auction) {
+    public AuctionOrder createDeposit(User user, AuctionActivity auction, BigDecimal amount) {
         if (user.getId().equals(auction.getSellerId())) {
             throw new BusinessException("不可自己出价自己的");
         }
@@ -224,8 +225,8 @@ public class AuctionOrderService {
 
         AuctionRecord auctionRecord = AuctionRecord.builder()
                 .auctionId(auction.getId())
-                .type(AuctionRecordType.DEPOSIT)
-                .bidderPrice(auction.getDeposit())
+                .type(AuctionRecordType.BIDDER)
+                .bidderPrice(amount)
                 .auctionPic(null)
                 .userId(SecurityUtils.getAuthenticatedUser().getId())
                 .avatar(SecurityUtils.getAuthenticatedUser().getAvatar())
@@ -283,6 +284,14 @@ public class AuctionOrderService {
                     .orElseThrow(new BusinessException("无出价记录"));
             record.setPayDeposit(true);
             auctionRecordRepo.save(record);
+            if (auction.getPurchasePrice().compareTo(record.getBidderPrice()) <= 0) {
+                auction.setPurchasePrice(record.getBidderPrice());
+                auction.setPurchaser(record.getUser());
+                auction.setPurchaserId(record.getUserId());
+                auction.setRecordId(record.getId());
+                auction.setBids(auction.getBids() + 1);
+                auctionActivityRepo.save(auction);
+            }
             return;
         }
 

+ 5 - 4
src/main/java/com/izouma/nineth/web/AuctionOrderController.java

@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.util.List;
 
 @RestController
@@ -42,7 +43,7 @@ public class AuctionOrderController extends BaseController {
     @ApiModelProperty(value = "创建拍卖订单(支付)")
     public AuctionOrder create(Long userId, @RequestParam(required = false) Long auctionId,
                                Long addressId, Long auctionRecordId, AuctionPaymentType type) {
-        return auctionOrderService.create(userId, auctionId, addressId, auctionRecordId, type);
+        return auctionOrderService.create(userId, auctionId, addressId, auctionRecordId, type, null);
     }
 
     @PostMapping("/createFixPrice")
@@ -62,13 +63,13 @@ public class AuctionOrderController extends BaseController {
 //                .purchased(false)
 //                .build();
 //        AuctionRecord record = auctionRecordRepo.save(auctionRecord);
-        return auctionOrderService.create(userId, auctionId, addressId, null, type);
+        return auctionOrderService.create(userId, auctionId, addressId, null, type, null);
     }
 
     @PostMapping("/createDeposit")
     @ApiModelProperty(value = "创建拍卖订单(保证金)")
     public AuctionOrder createDeposit(Long userId, @RequestParam(required = false) Long auctionId,
-                                      Long addressId, AuctionPaymentType type) {
+                                      Long addressId, AuctionPaymentType type, BigDecimal amount) {
 
 //        AuctionActivity auctionActivity = auctionActivityRepo.findById(auctionId)
 //                .orElseThrow(new BusinessException("暂无"));
@@ -83,7 +84,7 @@ public class AuctionOrderController extends BaseController {
 //                .purchased(false)
 //                .build();
 //        AuctionRecord record = auctionRecordRepo.save(auctionRecord);
-        return auctionOrderService.create(userId, auctionId, addressId, null, type);
+        return auctionOrderService.create(userId, auctionId, addressId, null, type, amount);
     }
 
     //@PreAuthorize("hasRole('ADMIN')")