|
|
@@ -112,11 +112,19 @@ public class OrderService {
|
|
|
if (!collection.isSalable()) {
|
|
|
throw new BusinessException("该藏品当前不可购买");
|
|
|
}
|
|
|
- if (collection.getType() == CollectionType.BLIND_BOX) {
|
|
|
- if (collection.getStartTime().isAfter(LocalDateTime.now())) {
|
|
|
- throw new BusinessException("盲盒未开售");
|
|
|
+
|
|
|
+ if (collection.getMaxCount() > 0) {
|
|
|
+ int count;
|
|
|
+ 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() + "件");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
UserAddress userAddress = null;
|
|
|
if (addressId != null) {
|
|
|
userAddress = userAddressRepo.findById(addressId).orElseThrow(new BusinessException("地址信息不存在"));
|
|
|
@@ -154,6 +162,7 @@ public class OrderService {
|
|
|
.assetId(collection.getAssetId())
|
|
|
.couponId(userCouponId)
|
|
|
.invitor(invitor)
|
|
|
+ .countId(collection.getCountId())
|
|
|
.build();
|
|
|
if (coupon != null) {
|
|
|
coupon.setUsed(true);
|