|
|
@@ -222,6 +222,28 @@ public class OrderService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public Object checkLimit(Long collectionId, Long userId) {
|
|
|
+ Collection collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("藏品不存在"));
|
|
|
+ int limit = collection.getMaxCount();
|
|
|
+ int count = 0;
|
|
|
+ if (collection.getMaxCount() > 0) {
|
|
|
+ if (StringUtils.isNotBlank(collection.getCountId())) {
|
|
|
+ count = orderRepo.countByUserIdAndCountIdAndStatusIn(userId, collection.getCountId(),
|
|
|
+ Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
|
|
|
+ } else {
|
|
|
+ count = orderRepo.countByUserIdAndCollectionIdAndStatusIn(userId, collectionId,
|
|
|
+ Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
|
|
|
+ }
|
|
|
+ if (count >= collection.getMaxCount()) {
|
|
|
+ throw new BusinessException("限购" + collection.getMaxCount() + "件");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("limit", limit);
|
|
|
+ map.put("count", count);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
public void payOrderAlipay(Long id, Model model) {
|
|
|
try {
|
|
|
Order order = orderRepo.findByIdAndDelFalse(id).orElseThrow(new BusinessException("订单不存在"));
|