|
|
@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
@@ -26,6 +27,7 @@ public class AuctionOrderService {
|
|
|
private AuctionActivityRepo auctionActivityRepo;
|
|
|
private AuctionRecordRepo auctionRecordRepo;
|
|
|
private AssetRepo assetRepo;
|
|
|
+ private UserAddressRepo userAddressRepo;
|
|
|
|
|
|
public Page<AuctionOrder> all(PageQuery pageQuery) {
|
|
|
return auctionOrderRepo.findAll(JpaUtils.toSpecification(pageQuery, AuctionOrder.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
@@ -49,6 +51,17 @@ public class AuctionOrderService {
|
|
|
|
|
|
if (AuctionPaymentType.DEPOSIT.equals(type)) {
|
|
|
return this.createDeposit(user, auction, auctionRecordId);
|
|
|
+ } else if (AuctionPaymentType.PURCHASE_PRICE.equals(type)) {
|
|
|
+ if (LocalDateTime.now().isAfter(auction.getEndTime())) {
|
|
|
+ throw new BusinessException("拍卖还未结束");
|
|
|
+ }
|
|
|
+ AuctionRecord record = auctionRecordRepo.findTopByAuctionIdAndUserId(auctionId, userId);
|
|
|
+ if (ObjectUtils.isEmpty(record) || !record.isPayDeposit()) {
|
|
|
+ throw new BusinessException("未支付保证金");
|
|
|
+ }
|
|
|
+ if (record.getBidderPrice().compareTo(auction.getPurchasePrice()) != 0) {
|
|
|
+ throw new BusinessException("与成交价不否");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (AuctionSource.TRANSFER.equals(auction.getSource())) {
|
|
|
@@ -61,6 +74,12 @@ public class AuctionOrderService {
|
|
|
auctionActivityRepo.save(auction);
|
|
|
|
|
|
BigDecimal price = AuctionPaymentType.FIXED_PRICE.equals(type) ? auction.getFixedPrice() : auction.getPurchasePrice();
|
|
|
+
|
|
|
+ UserAddress userAddress = null;
|
|
|
+ if (addressId != null) {
|
|
|
+ userAddress = userAddressRepo.findById(addressId).orElseThrow(new BusinessException("地址信息不存在"));
|
|
|
+ }
|
|
|
+
|
|
|
AuctionOrder order = AuctionOrder.builder()
|
|
|
.auctionId(auction.getId())
|
|
|
.userId(user.getId())
|
|
|
@@ -75,6 +94,9 @@ public class AuctionOrderService {
|
|
|
.totalPrice(price)
|
|
|
.auctionRecordId(auctionRecordId)
|
|
|
.status(AuctionOrderStatus.NOT_PAID)
|
|
|
+ .contactName(Optional.ofNullable(userAddress).map(UserAddress::getName).orElse(null))
|
|
|
+ .contactPhone(Optional.ofNullable(userAddress).map(UserAddress::getPhone).orElse(null))
|
|
|
+ .address(Optional.ofNullable(userAddress).map(UserAddress::getDetail).orElse(null))
|
|
|
.build();
|
|
|
|
|
|
return auctionOrderRepo.save(order);
|