|
@@ -12,6 +12,7 @@ import com.izouma.nineth.utils.SnowflakeIdWorker;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.redis.core.BoundValueOperations;
|
|
import org.springframework.data.redis.core.BoundValueOperations;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -42,6 +43,7 @@ public class AuctionOrderService {
|
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
private SnowflakeIdWorker snowflakeIdWorker;
|
|
private SnowflakeIdWorker snowflakeIdWorker;
|
|
|
private AuctionPassRecordRepo auctionPassRecordRepo;
|
|
private AuctionPassRecordRepo auctionPassRecordRepo;
|
|
|
|
|
+ private OrderPayService orderPayService;
|
|
|
|
|
|
|
|
public Page<AuctionOrder> all(PageQuery pageQuery) {
|
|
public Page<AuctionOrder> all(PageQuery pageQuery) {
|
|
|
return auctionOrderRepo
|
|
return auctionOrderRepo
|
|
@@ -54,7 +56,7 @@ public class AuctionOrderService {
|
|
|
AuctionActivity auction = auctionActivityRepo.findById(auctionId)
|
|
AuctionActivity auction = auctionActivityRepo.findById(auctionId)
|
|
|
.orElseThrow(new BusinessException("无拍卖信息"));
|
|
.orElseThrow(new BusinessException("无拍卖信息"));
|
|
|
|
|
|
|
|
- if (!auction.isOnShelf()){
|
|
|
|
|
|
|
+ if (!auction.isOnShelf()) {
|
|
|
throw new BusinessException("拍卖已结束");
|
|
throw new BusinessException("拍卖已结束");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -106,8 +108,6 @@ public class AuctionOrderService {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
|
|
|
- // auction.setStatus(AuctionStatus.PURCHASED);
|
|
|
|
|
-// auctionActivityRepo.save(auction);
|
|
|
|
|
auctionActivityService.changeStatus(auctionId, AuctionPaymentType.FIXED_PRICE
|
|
auctionActivityService.changeStatus(auctionId, AuctionPaymentType.FIXED_PRICE
|
|
|
.equals(type) ? AuctionStatus.FIXED_PRICE_PURCHASED : AuctionStatus.PURCHASED);
|
|
.equals(type) ? AuctionStatus.FIXED_PRICE_PURCHASED : AuctionStatus.PURCHASED);
|
|
|
|
|
|
|
@@ -230,8 +230,6 @@ public class AuctionOrderService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//此拍卖结束
|
|
//此拍卖结束
|
|
|
-// auction.setStatus(AuctionStatus.FINISH);
|
|
|
|
|
-// auctionActivityRepo.save(auction);
|
|
|
|
|
auctionActivityService.changeStatus(order.getAuctionId(), AuctionStatus.FINISH);
|
|
auctionActivityService.changeStatus(order.getAuctionId(), AuctionStatus.FINISH);
|
|
|
|
|
|
|
|
if (AuctionSource.TRANSFER.equals(order.getSource())) {
|
|
if (AuctionSource.TRANSFER.equals(order.getSource())) {
|
|
@@ -254,12 +252,8 @@ public class AuctionOrderService {
|
|
|
//退保证金
|
|
//退保证金
|
|
|
List<AuctionOrder> orders = auctionOrderRepo.findAllByAuctionIdAndPaymentTypeAndStatus(order.getAuctionId(),
|
|
List<AuctionOrder> orders = auctionOrderRepo.findAllByAuctionIdAndPaymentTypeAndStatus(order.getAuctionId(),
|
|
|
AuctionPaymentType.DEPOSIT, AuctionOrderStatus.FINISH);
|
|
AuctionPaymentType.DEPOSIT, AuctionOrderStatus.FINISH);
|
|
|
- orders.forEach(o -> {
|
|
|
|
|
- //退款(暂未写)
|
|
|
|
|
- o.setRefundTime(LocalDateTime.now());
|
|
|
|
|
- o.setStatus(AuctionOrderStatus.REFUNDING);
|
|
|
|
|
- auctionOrderRepo.save(o);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ //退款
|
|
|
|
|
+ orders.forEach(this::refund);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void cancel(AuctionOrder order) {
|
|
public void cancel(AuctionOrder order) {
|
|
@@ -268,6 +262,7 @@ public class AuctionOrderService {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ boolean isRefund = false;
|
|
|
try {
|
|
try {
|
|
|
AuctionActivity auction = auctionActivityRepo.findById(order.getAuctionId())
|
|
AuctionActivity auction = auctionActivityRepo.findById(order.getAuctionId())
|
|
|
.orElseThrow(new BusinessException("无记录"));
|
|
.orElseThrow(new BusinessException("无记录"));
|
|
@@ -277,8 +272,6 @@ public class AuctionOrderService {
|
|
|
int time = sysConfigService.getInt("auction_cancel_time");
|
|
int time = sysConfigService.getInt("auction_cancel_time");
|
|
|
if (LocalDateTime.now().isAfter(auction.getEndTime().plusMinutes(time))) {
|
|
if (LocalDateTime.now().isAfter(auction.getEndTime().plusMinutes(time))) {
|
|
|
//超过支付时长
|
|
//超过支付时长
|
|
|
-// auction.setStatus(AuctionStatus.PASS);
|
|
|
|
|
-// auctionActivityRepo.save(auction);
|
|
|
|
|
auctionActivityService.changeStatus(order.getAuctionId(), AuctionStatus.PASS);
|
|
auctionActivityService.changeStatus(order.getAuctionId(), AuctionStatus.PASS);
|
|
|
//添加到流拍记录表里
|
|
//添加到流拍记录表里
|
|
|
auctionPassRecordRepo.save(AuctionPassRecord.builder()
|
|
auctionPassRecordRepo.save(AuctionPassRecord.builder()
|
|
@@ -286,21 +279,8 @@ public class AuctionOrderService {
|
|
|
.userId(auction.getPurchaserId())
|
|
.userId(auction.getPurchaserId())
|
|
|
.purchasePrice(auction.getPurchasePrice())
|
|
.purchasePrice(auction.getPurchasePrice())
|
|
|
.build());
|
|
.build());
|
|
|
-
|
|
|
|
|
- //退其余保证金
|
|
|
|
|
- List<AuctionOrder> orders = auctionOrderRepo
|
|
|
|
|
- .findAllByAuctionIdAndPaymentTypeAndStatus(order.getAuctionId(),
|
|
|
|
|
- AuctionPaymentType.DEPOSIT, AuctionOrderStatus.FINISH);
|
|
|
|
|
- orders.stream()
|
|
|
|
|
- .filter(o -> !order.getUserId().equals(o.getUserId()))
|
|
|
|
|
- .forEach(o -> {
|
|
|
|
|
- //退款(暂未写)
|
|
|
|
|
- o.setRefundTime(LocalDateTime.now());
|
|
|
|
|
- o.setStatus(AuctionOrderStatus.REFUNDING);
|
|
|
|
|
- auctionOrderRepo.save(o);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- //违约处罚
|
|
|
|
|
|
|
+ //流拍不退自己的保证金
|
|
|
|
|
+ isRefund = true;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
} else if (AuctionPaymentType.DEPOSIT.equals(order.getPaymentType())) {
|
|
} else if (AuctionPaymentType.DEPOSIT.equals(order.getPaymentType())) {
|
|
@@ -310,31 +290,11 @@ public class AuctionOrderService {
|
|
|
//拍卖是否结束
|
|
//拍卖是否结束
|
|
|
if (LocalDateTime.now().isBefore(auction.getEndTime())) {
|
|
if (LocalDateTime.now().isBefore(auction.getEndTime())) {
|
|
|
//返回拍卖状态
|
|
//返回拍卖状态
|
|
|
-// auction.setStatus(AuctionStatus.ONGOING);
|
|
|
|
|
auctionActivityService.changeStatus(order.getAuctionId(), AuctionStatus.ONGOING);
|
|
auctionActivityService.changeStatus(order.getAuctionId(), AuctionStatus.ONGOING);
|
|
|
-
|
|
|
|
|
} else {
|
|
} else {
|
|
|
-// auction.setStatus(AuctionStatus.PASS);
|
|
|
|
|
- //退还保证金
|
|
|
|
|
- List<AuctionOrder> orders = auctionOrderRepo
|
|
|
|
|
- .findAllByAuctionIdAndPaymentTypeAndStatus(order.getAuctionId(),
|
|
|
|
|
- AuctionPaymentType.DEPOSIT, AuctionOrderStatus.FINISH);
|
|
|
|
|
- orders.forEach(o -> {
|
|
|
|
|
- //退款(暂未写)
|
|
|
|
|
- o.setRefundTime(LocalDateTime.now());
|
|
|
|
|
- o.setStatus(AuctionOrderStatus.REFUNDING);
|
|
|
|
|
- auctionOrderRepo.save(o);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ //最后一个出价的人得
|
|
|
|
|
+ auctionActivityService.changeStatus(order.getAuctionId(), AuctionStatus.PURCHASED);
|
|
|
}
|
|
}
|
|
|
-// auctionActivityRepo.save(auction);
|
|
|
|
|
- auctionActivityService.changeStatus(order.getAuctionId(), AuctionStatus.PASS);
|
|
|
|
|
- //添加到流拍记录表里
|
|
|
|
|
- auctionPassRecordRepo.save(AuctionPassRecord.builder()
|
|
|
|
|
- .auctionId(auction.getId())
|
|
|
|
|
- .userId(auction.getPurchaserId())
|
|
|
|
|
- .purchasePrice(auction.getPurchasePrice())
|
|
|
|
|
- .build());
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (AuctionSource.TRANSFER.equals(order.getSource())) {
|
|
if (AuctionSource.TRANSFER.equals(order.getSource())) {
|
|
@@ -352,9 +312,59 @@ public class AuctionOrderService {
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("订单取消错误 orderId: " + order.getId(), e);
|
|
log.error("订单取消错误 orderId: " + order.getId(), e);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (isRefund) {
|
|
|
|
|
+ //退其余保证金
|
|
|
|
|
+ List<AuctionOrder> orders = auctionOrderRepo
|
|
|
|
|
+ .findAllByAuctionIdAndPaymentTypeAndStatus(order.getAuctionId(),
|
|
|
|
|
+ AuctionPaymentType.DEPOSIT, AuctionOrderStatus.FINISH);
|
|
|
|
|
+ //退款
|
|
|
|
|
+ orders.stream()
|
|
|
|
|
+ .filter(o -> !order.getUserId().equals(o.getUserId()))
|
|
|
|
|
+ .forEach(this::refund);
|
|
|
|
|
+ }
|
|
|
releaseOrderLock(order.getId());
|
|
releaseOrderLock(order.getId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 退款方法
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param order 订单
|
|
|
|
|
+ */
|
|
|
|
|
+ private void refund(AuctionOrder order) {
|
|
|
|
|
+ log.info("退款拍卖保证金订单{}", order.getId());
|
|
|
|
|
+ PayMethod payMethod = order.getPayMethod();
|
|
|
|
|
+ if (PayMethod.ALIPAY == payMethod) {
|
|
|
|
|
+ if (StringUtils.length(order.getTransactionId()) == 28) {
|
|
|
|
|
+ payMethod = PayMethod.HMPAY;
|
|
|
|
|
+ } else if (StringUtils.length(order.getTransactionId()) == 30) {
|
|
|
|
|
+ payMethod = PayMethod.SANDPAY;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ switch (payMethod) {
|
|
|
|
|
+ case HMPAY:
|
|
|
|
|
+ orderPayService.refund(order.getId()
|
|
|
|
|
+ .toString(), order.getTotalPrice(), "hmPay");
|
|
|
|
|
+ log.info("退款成功");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case SANDPAY:
|
|
|
|
|
+ orderPayService.refund(order.getId()
|
|
|
|
|
+ .toString(), order.getTotalPrice(), "sandPay");
|
|
|
|
|
+ log.info("退款成功");
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ order.setRefundTime(LocalDateTime.now());
|
|
|
|
|
+ order.setStatus(AuctionOrderStatus.REFUNDED);
|
|
|
|
|
+ auctionOrderRepo.save(order);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("拍卖保证金订单退款失败 {} ", order.getId(), e);
|
|
|
|
|
+ order.setRefundTime(LocalDateTime.now());
|
|
|
|
|
+ order.setStatus(AuctionOrderStatus.REFUNDING);
|
|
|
|
|
+ auctionOrderRepo.save(order);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public boolean getOrderLock(Long orderId) {
|
|
public boolean getOrderLock(Long orderId) {
|
|
|
BoundValueOperations<String, Object> ops = redisTemplate.boundValueOps(RedisKeys.AUCTION_ORDER_LOCK + orderId);
|
|
BoundValueOperations<String, Object> ops = redisTemplate.boundValueOps(RedisKeys.AUCTION_ORDER_LOCK + orderId);
|
|
|
Boolean flag = ops.setIfAbsent(1, 1, TimeUnit.DAYS);
|
|
Boolean flag = ops.setIfAbsent(1, 1, TimeUnit.DAYS);
|