|
|
@@ -40,6 +40,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.EncoderException;
|
|
|
import org.apache.commons.codec.net.URLCodec;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.rocketmq.client.producer.SendResult;
|
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
@@ -109,6 +110,11 @@ public class OrderService {
|
|
|
throw new BusinessException("签名已过期");
|
|
|
}
|
|
|
|
|
|
+ Integer stock = collectionService.getStock(collectionId);
|
|
|
+ if (stock == null || stock <= 0) {
|
|
|
+ throw new BusinessException("藏品已售罄", ErrorCode.SOLD_OUT);
|
|
|
+ }
|
|
|
+
|
|
|
Long id = snowflakeIdWorker.nextId();
|
|
|
SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
|
|
|
new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip), 100000);
|
|
|
@@ -123,15 +129,15 @@ public class OrderService {
|
|
|
qty = 1;
|
|
|
int stock = Optional.ofNullable(collectionService.decreaseStock(collectionId, qty))
|
|
|
.map(Math::toIntExact)
|
|
|
- .orElseThrow(new BusinessException("很遗憾,藏品已售罄"));
|
|
|
+ .orElseThrow(new BusinessException("很遗憾,藏品已售罄", ErrorCode.SOLD_OUT));
|
|
|
// 创建订单出错后需要回滚库存,所以需要try-catch
|
|
|
try {
|
|
|
if (stock < 0) {
|
|
|
- throw new BusinessException("很遗憾,藏品已售罄");
|
|
|
+ throw new BusinessException("很遗憾,藏品已售罄", ErrorCode.SOLD_OUT);
|
|
|
}
|
|
|
Collection collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("藏品不存在"));
|
|
|
if (collection.getAssetId() != null && collection.getAssetId().equals(778359L)) {
|
|
|
- throw new BusinessException("很遗憾,藏品已售罄");
|
|
|
+ throw new BusinessException("很遗憾,藏品已售罄", ErrorCode.SOLD_OUT);
|
|
|
}
|
|
|
if (collection.getAssetId() != null) {
|
|
|
Asset asset = assetRepo.findById(collection.getAssetId()).orElseThrow(new BusinessException("藏品不存在"));
|
|
|
@@ -196,6 +202,10 @@ public class OrderService {
|
|
|
if (user.getVipPurchase() - purchase <= 0) {
|
|
|
throw new BusinessException("vip名额已使用完毕!");
|
|
|
}
|
|
|
+ // vip扣除额度
|
|
|
+ if (ObjectUtils.isNotEmpty(collection.getVipQuota())) {
|
|
|
+ collectionService.decreaseQuota(collectionId, 1);
|
|
|
+ }
|
|
|
} else {
|
|
|
// long count = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, userId);
|
|
|
// int sub = collection.getAssignment() - (int) count;
|
|
|
@@ -725,8 +735,9 @@ public class OrderService {
|
|
|
});
|
|
|
}
|
|
|
//加上积分
|
|
|
- if (order.getVipPoint() > 0) {
|
|
|
+ if (ObjectUtils.isNotEmpty(order.getVipPoint()) && order.getVipPoint() > 0) {
|
|
|
userRepo.updateVipPoint(order.getUserId(), order.getVipPoint());
|
|
|
+ log.info("取消加积分用户ID:{},订单ID:{},积分:{}", order.getUserId(), order.getId(), order.getVipPoint());
|
|
|
}
|
|
|
|
|
|
rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), order.getCollectionId(), 10000);
|