|
@@ -38,6 +38,7 @@ import org.apache.http.client.utils.URLEncodedUtils;
|
|
|
import org.springframework.context.event.EventListener;
|
|
import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.core.env.Environment;
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.ui.Model;
|
|
|
|
|
|
|
@@ -120,6 +121,7 @@ public class OrderService {
|
|
|
public void payOrderAlipay(Long id, Model model) {
|
|
public void payOrderAlipay(Long id, Model model) {
|
|
|
try {
|
|
try {
|
|
|
Order order = orderRepo.findByIdAndDelFalse(id).orElseThrow(new BusinessException("订单不存在"));
|
|
Order order = orderRepo.findByIdAndDelFalse(id).orElseThrow(new BusinessException("订单不存在"));
|
|
|
|
|
+
|
|
|
if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
throw new BusinessException("订单状态错误");
|
|
throw new BusinessException("订单状态错误");
|
|
|
}
|
|
}
|
|
@@ -284,6 +286,8 @@ public class OrderService {
|
|
|
orderRepo.save(order);
|
|
orderRepo.save(order);
|
|
|
assetService.createAsset(order);
|
|
assetService.createAsset(order);
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if (order.getStatus() == OrderStatus.CANCELLED) {
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -302,4 +306,39 @@ public class OrderService {
|
|
|
log.error("创建asset失败");
|
|
log.error("创建asset失败");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public void cancel(Long id) {
|
|
|
|
|
+ Order order = orderRepo.findById(id).orElseThrow(new BusinessException("订单不存在"));
|
|
|
|
|
+ cancel(order);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void cancel(Order order) {
|
|
|
|
|
+ if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
|
|
+ throw new BusinessException("已支付订单无法取消");
|
|
|
|
|
+ }
|
|
|
|
|
+ Collection collection = collectionRepo.findById(order.getCollectionId())
|
|
|
|
|
+ .orElseThrow(new BusinessException("藏品不存在"));
|
|
|
|
|
+ User minter = userRepo.findById(collection.getMinterId()).orElseThrow(new BusinessException("铸造者不存在"));
|
|
|
|
|
+
|
|
|
|
|
+ collection.setSale(collection.getSale() - 1);
|
|
|
|
|
+ collection.setStock(collection.getStock() + 1);
|
|
|
|
|
+ collectionRepo.save(collection);
|
|
|
|
|
+
|
|
|
|
|
+ minter.setSales(minter.getSales() - 1);
|
|
|
|
|
+ userRepo.save(minter);
|
|
|
|
|
+
|
|
|
|
|
+ order.setStatus(OrderStatus.CANCELLED);
|
|
|
|
|
+ order.setCancelTime(LocalDateTime.now());
|
|
|
|
|
+ orderRepo.save(order);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Scheduled(fixedRate = 60000)
|
|
|
|
|
+ public void batchCancel() {
|
|
|
|
|
+ List<Order> orders = orderRepo.findByStatusAndCreatedAtBeforeAndDelFalse(OrderStatus.NOT_PAID,
|
|
|
|
|
+ LocalDateTime.now().minusMinutes(5));
|
|
|
|
|
+ orders.stream().parallel().forEach(this::cancel);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void refundCancelled(Order order) {
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|