|
|
@@ -7,7 +7,6 @@ import com.alipay.api.AlipayClient;
|
|
|
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
|
|
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult;
|
|
|
-import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
|
|
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
import com.github.binarywang.wxpay.constant.WxPayConstants;
|
|
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
@@ -57,6 +56,7 @@ import org.springframework.ui.Model;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.time.Duration;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
@@ -110,10 +110,11 @@ public class OrderService {
|
|
|
throw new BusinessException("签名已过期");
|
|
|
}
|
|
|
|
|
|
- Integer stock = collectionService.getStock(collectionId);
|
|
|
- if (stock == null || stock <= 0) {
|
|
|
- throw new BusinessException("藏品已售罄", ErrorCode.SOLD_OUT);
|
|
|
- }
|
|
|
+// Integer stock = collectionService.getStock(collectionId);
|
|
|
+// if (stock == null || stock <= 0) {
|
|
|
+// throw new BusinessException("藏品已售罄", ErrorCode.SOLD_OUT);
|
|
|
+// }
|
|
|
+ limitReq(collectionId);
|
|
|
|
|
|
Long id = snowflakeIdWorker.nextId();
|
|
|
SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
|
|
|
@@ -123,6 +124,15 @@ public class OrderService {
|
|
|
return String.valueOf(id);
|
|
|
}
|
|
|
|
|
|
+ public void limitReq(Long collectionId) {
|
|
|
+ BoundValueOperations<String, Object> ops = redisTemplate.boundValueOps(RedisKeys.LIMIT_REQ + collectionId);
|
|
|
+ ops.setIfAbsent(3000, Duration.ofSeconds(30));
|
|
|
+ Long val = ops.decrement();
|
|
|
+ if (val == null || val < 0) {
|
|
|
+ throw new BusinessException("很遗憾,藏品已售罄");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public Order create(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor,
|
|
|
Long id, boolean vip) {
|
|
|
long t = System.currentTimeMillis();
|