|
|
@@ -1,15 +1,11 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
-import com.izouma.nineth.domain.AuctionOrder;
|
|
|
-import com.izouma.nineth.domain.User;
|
|
|
+import com.izouma.nineth.domain.*;
|
|
|
import com.izouma.nineth.dto.AuctionPaymentType;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
-import com.izouma.nineth.enums.AuctionOrderStatus;
|
|
|
-import com.izouma.nineth.enums.AuctionSource;
|
|
|
-import com.izouma.nineth.enums.AuctionType;
|
|
|
+import com.izouma.nineth.enums.*;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
-import com.izouma.nineth.repo.AuctionOrderRepo;
|
|
|
-import com.izouma.nineth.repo.UserRepo;
|
|
|
+import com.izouma.nineth.repo.*;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
@@ -24,68 +20,132 @@ import java.util.Arrays;
|
|
|
@AllArgsConstructor
|
|
|
public class AuctionOrderService {
|
|
|
|
|
|
- private AuctionOrderRepo auctionOrderRepo;
|
|
|
- private SysConfigService sysConfigService;
|
|
|
- private UserRepo userRepo;
|
|
|
- private AssetService assetService;
|
|
|
+ private AuctionOrderRepo auctionOrderRepo;
|
|
|
+ private SysConfigService sysConfigService;
|
|
|
+ private UserRepo userRepo;
|
|
|
+ private AssetService assetService;
|
|
|
+ private AuctionActivityRepo auctionActivityRepo;
|
|
|
+ private AuctionRecordRepo auctionRecordRepo;
|
|
|
+ private AssetRepo assetRepo;
|
|
|
|
|
|
public Page<AuctionOrder> all(PageQuery pageQuery) {
|
|
|
return auctionOrderRepo.findAll(JpaUtils.toSpecification(pageQuery, AuctionOrder.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
|
|
|
|
- public void create(Long userId, Long auctionId, Long addressId, AuctionPaymentType paymentType) {
|
|
|
+ public AuctionOrder create(Long userId, Long auctionId, Long addressId, Long auctionRecordId, AuctionPaymentType type) {
|
|
|
+ User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
+
|
|
|
+ AuctionActivity auction = auctionActivityRepo.findById(auctionId)
|
|
|
+ .orElseThrow(new BusinessException("无拍卖信息"));
|
|
|
+
|
|
|
+ switch (auction.getStatus()) {
|
|
|
+ case NOTSTARTED:
|
|
|
+ throw new BusinessException("拍卖还未开始");
|
|
|
+ case PURCHASED:
|
|
|
+ throw new BusinessException("拍卖成交中");
|
|
|
+ case PASS:
|
|
|
+ case FINISH:
|
|
|
+ throw new BusinessException("拍卖已结束");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (AuctionPaymentType.DEPOSIT.equals(type)) {
|
|
|
+ return this.createDeposit(user, auction, auctionRecordId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (AuctionSource.TRANSFER.equals(auction.getSource())) {
|
|
|
+ Asset asset = assetRepo.findById(auction.getAssetId()).orElseThrow(new BusinessException("资产不存在"));
|
|
|
+ asset.setStatus(AssetStatus.AUCTIONING);
|
|
|
+ assetRepo.save(asset);
|
|
|
+ }
|
|
|
+
|
|
|
+ auction.setStatus(AuctionStatus.PURCHASED);
|
|
|
+ auctionActivityRepo.save(auction);
|
|
|
+
|
|
|
+ BigDecimal price = AuctionPaymentType.FIXED_PRICE.equals(type) ? auction.getFixedPrice() : auction.getPurchasePrice();
|
|
|
+ AuctionOrder order = AuctionOrder.builder()
|
|
|
+ .auctionId(auction.getId())
|
|
|
+ .userId(user.getId())
|
|
|
+ .nickname(user.getNickname())
|
|
|
+ .paymentType(type)
|
|
|
+ .name(auction.getName())
|
|
|
+ .pic(auction.getPic())
|
|
|
+ .serviceCharge(auction.getServiceCharge())
|
|
|
+ .royalties(auction.getRoyalties())
|
|
|
+ .source(auction.getSource())
|
|
|
+ .price(price)
|
|
|
+ .totalPrice(price)
|
|
|
+ .auctionRecordId(auctionRecordId)
|
|
|
+ .status(AuctionOrderStatus.NOT_PAID)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ return auctionOrderRepo.save(order);
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void createDeposit(Long userId, Long auctionId, Long auctionRecordId) {
|
|
|
- User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
+
|
|
|
+ public AuctionOrder createDeposit(User user, AuctionActivity auction, Long auctionRecordId) {
|
|
|
+ if (user.getId().equals(auction.getSellerId())) {
|
|
|
+ throw new BusinessException("不可自己出价自己的");
|
|
|
+ }
|
|
|
|
|
|
//保证金
|
|
|
- BigDecimal deposit = sysConfigService.getBigDecimal("deposit");
|
|
|
- AuctionOrder order = auctionOrderRepo.findByUserIdAndAuctionIdAndPaymentTypeAndStatusIn(userId, auctionId,
|
|
|
- AuctionPaymentType.deposit, Arrays.asList(AuctionOrderStatus.NOT_PAID, AuctionOrderStatus.FINISH));
|
|
|
+// BigDecimal deposit = sysConfigService.getBigDecimal("deposit");
|
|
|
+ AuctionOrder order = auctionOrderRepo.findByUserIdAndAuctionIdAndPaymentTypeAndStatusIn(user.getId(), auction.getId(),
|
|
|
+ AuctionPaymentType.DEPOSIT, Arrays.asList(AuctionOrderStatus.NOT_PAID, AuctionOrderStatus.FINISH));
|
|
|
if (ObjectUtils.isNotEmpty(order)) {
|
|
|
if (AuctionOrderStatus.FINISH.equals(order.getStatus())) {
|
|
|
throw new BusinessException("保证金已交过,无需再交");
|
|
|
}
|
|
|
- throw new BusinessException("保证金未支付,取消后在支付");
|
|
|
-
|
|
|
+ throw new BusinessException("保证金未支付,取消后再重新出价");
|
|
|
}
|
|
|
|
|
|
- //查询拍卖信息
|
|
|
- //..
|
|
|
-
|
|
|
order = AuctionOrder.builder()
|
|
|
- .auctionId(auctionId)
|
|
|
- .userId(userId)
|
|
|
+ .auctionId(auction.getId())
|
|
|
+ .userId(user.getId())
|
|
|
.nickname(user.getNickname())
|
|
|
- .paymentType(AuctionPaymentType.deposit)
|
|
|
- .price(deposit)
|
|
|
- .totalPrice(deposit)
|
|
|
+ .paymentType(AuctionPaymentType.DEPOSIT)
|
|
|
+ .name(auction.getName())
|
|
|
+ .pic(auction.getPic())
|
|
|
+ .serviceCharge(auction.getServiceCharge())
|
|
|
+ .royalties(auction.getRoyalties())
|
|
|
+ .source(auction.getSource())
|
|
|
+ .price(auction.getDeposit())
|
|
|
+ .totalPrice(auction.getDeposit())
|
|
|
.auctionRecordId(auctionRecordId)
|
|
|
.status(AuctionOrderStatus.NOT_PAID)
|
|
|
.build();
|
|
|
|
|
|
- auctionOrderRepo.save(order);
|
|
|
+ return auctionOrderRepo.save(order);
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void notify(Long id) {
|
|
|
+ public void notify(Long id, PayMethod payMethod, String transactionId) {
|
|
|
AuctionOrder order = auctionOrderRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
order.setStatus(AuctionOrderStatus.FINISH);
|
|
|
+ order.setPayMethod(payMethod);
|
|
|
+ order.setTransactionId(transactionId);
|
|
|
+ order.setPayTime(LocalDateTime.now());
|
|
|
|
|
|
- if (AuctionPaymentType.deposit.equals(order.getPaymentType())) {
|
|
|
+ if (AuctionPaymentType.DEPOSIT.equals(order.getPaymentType())) {
|
|
|
//改出价记录表
|
|
|
-
|
|
|
- } else {
|
|
|
- //此拍卖结束
|
|
|
- //退保证金
|
|
|
+ AuctionRecord record = auctionRecordRepo.findById(order.getAuctionRecordId())
|
|
|
+ .orElseThrow(new BusinessException("无出价记录"));
|
|
|
+ record.setPayDeposit(true);
|
|
|
+ auctionRecordRepo.save(record);
|
|
|
+ auctionOrderRepo.save(order);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- if (AuctionSource.OFFICIAL.equals(order.getAuctionSource())) {
|
|
|
- } else {
|
|
|
+ //此拍卖结束
|
|
|
+ //退保证金
|
|
|
+ AuctionActivity auction = auctionActivityRepo.findById(order.getAuctionId())
|
|
|
+ .orElseThrow(new BusinessException("无拍卖活动"));
|
|
|
+
|
|
|
+ if (AuctionSource.TRANSFER.equals(order.getSource())) {
|
|
|
+ Asset asset = assetRepo.findById(auction.getAssetId()).orElseThrow(new BusinessException("资产不存在"));
|
|
|
+ User user = userRepo.findById(order.getUserId()).orElseThrow(new BusinessException("无用户"));
|
|
|
//转让流程
|
|
|
-// assetService.transfer();
|
|
|
+ assetService.transfer(asset, order.getTotalPrice(), user, "拍卖", order.getId());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -94,27 +154,27 @@ public class AuctionOrderService {
|
|
|
order.setCancelTime(LocalDateTime.now());
|
|
|
|
|
|
switch (order.getPaymentType()) {
|
|
|
- case deposit:
|
|
|
+ case DEPOSIT:
|
|
|
//删除出价记录
|
|
|
break;
|
|
|
case FIXED_PRICE:
|
|
|
//返回拍卖状态
|
|
|
break;
|
|
|
- case purchase_price:
|
|
|
+ case PURCHASE_PRICE:
|
|
|
//获取时长
|
|
|
//超过时长不返回保证金
|
|
|
//状态为流拍
|
|
|
//退换其余保证金
|
|
|
|
|
|
}
|
|
|
- if (AuctionPaymentType.deposit.equals(order.getPaymentType())) {
|
|
|
+ if (AuctionPaymentType.DEPOSIT.equals(order.getPaymentType())) {
|
|
|
//删除出价记录
|
|
|
|
|
|
} else {
|
|
|
//退保证金
|
|
|
}
|
|
|
|
|
|
- if (AuctionSource.OFFICIAL.equals(order.getAuctionSource())) {
|
|
|
+ if (AuctionSource.OFFICIAL.equals(order.getSource())) {
|
|
|
} else {
|
|
|
//改回资产状态
|
|
|
|