|
|
@@ -17,10 +17,7 @@ import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
|
import com.huifu.adapay.model.AdapayCommon;
|
|
|
import com.huifu.adapay.model.Payment;
|
|
|
import com.huifu.adapay.model.Refund;
|
|
|
-import com.izouma.nineth.config.AdapayProperties;
|
|
|
-import com.izouma.nineth.config.AlipayProperties;
|
|
|
-import com.izouma.nineth.config.GeneralProperties;
|
|
|
-import com.izouma.nineth.config.WxPayProperties;
|
|
|
+import com.izouma.nineth.config.*;
|
|
|
import com.izouma.nineth.domain.Collection;
|
|
|
import com.izouma.nineth.domain.*;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
@@ -425,7 +422,7 @@ public class OrderService {
|
|
|
log.info("createOrderResponse {}", JSON.toJSONString(response, SerializerFeature.PrettyFormat));
|
|
|
AdapayService.checkSuccess(response);
|
|
|
|
|
|
- BoundSetOperations<String, Object> ops = redisTemplate.boundSetOps("orderNotify::" + order.getId());
|
|
|
+ BoundSetOperations<String, Object> ops = redisTemplate.boundSetOps(RedisKeys.PAY_RECORD + order.getId());
|
|
|
ops.add(MapUtils.getString(response, "id"));
|
|
|
ops.expire(7, TimeUnit.DAYS);
|
|
|
}
|
|
|
@@ -478,9 +475,7 @@ public class OrderService {
|
|
|
public void notifyOrder(Long orderId, PayMethod payMethod, String transactionId) {
|
|
|
log.info("订单回调 orderId: {}, payMethod: {}, transactionId: {}", orderId, payMethod, transactionId);
|
|
|
|
|
|
- BoundValueOperations<String, Object> ops = redisTemplate.boundValueOps("orderLock::" + orderId);
|
|
|
- Boolean flag = ops.setIfAbsent(1, 1, TimeUnit.DAYS);
|
|
|
- if (!Boolean.TRUE.equals(flag)) {
|
|
|
+ if (!getOrderLock(orderId)) {
|
|
|
log.info("订单回调失败 orderId: {} redis锁定, 重新发送到队列", orderId);
|
|
|
rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
|
|
|
new OrderNotifyEvent(orderId, payMethod, transactionId, System.currentTimeMillis()));
|
|
|
@@ -502,7 +497,7 @@ public class OrderService {
|
|
|
BlindBoxItem winItem = null;
|
|
|
try {
|
|
|
winItem = collectionService.draw(collection.getId());
|
|
|
- } catch (BusinessException e) {
|
|
|
+ } catch (BusinessException ignored) {
|
|
|
}
|
|
|
if (winItem == null) {
|
|
|
log.info("抽卡失败退款 orderId: {}", orderId);
|
|
|
@@ -519,7 +514,7 @@ public class OrderService {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
orderRepo.save(order);
|
|
|
- return;
|
|
|
+ throw new BusinessException("抽卡失败, 已退款 " + orderId);
|
|
|
}
|
|
|
log.info("抽卡成功 orderId: {}, collectionId: {}, winCollectionId: {}", orderId, collection.getId(), winItem.getCollectionId());
|
|
|
order.setWinCollectionId(winItem.getCollectionId());
|
|
|
@@ -565,7 +560,7 @@ public class OrderService {
|
|
|
errorOrderRepo.save(errorOrder);
|
|
|
|
|
|
}
|
|
|
- redisTemplate.delete("orderLock::" + orderId);
|
|
|
+ releaseOrderLock(orderId);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -605,9 +600,7 @@ public class OrderService {
|
|
|
}
|
|
|
|
|
|
public void cancel(Order order) {
|
|
|
- BoundValueOperations<String, Object> ops = redisTemplate.boundValueOps("orderLock::" + order.getId());
|
|
|
- Boolean flag = ops.setIfAbsent(1, 1, TimeUnit.DAYS);
|
|
|
- if (!Boolean.TRUE.equals(flag)) {
|
|
|
+ if (!getOrderLock(order.getId())) {
|
|
|
log.error("订单取消失败 {}, redis锁了", order.getId());
|
|
|
return;
|
|
|
}
|
|
|
@@ -617,7 +610,7 @@ public class OrderService {
|
|
|
throw new BusinessException("已支付订单无法取消");
|
|
|
}
|
|
|
|
|
|
- Set<Object> transactionIds = redisTemplate.opsForSet().members("orderNotify::" + order.getId());
|
|
|
+ Set<Object> transactionIds = redisTemplate.opsForSet().members(RedisKeys.PAY_RECORD + order.getId());
|
|
|
if (transactionIds != null && transactionIds.size() > 0) {
|
|
|
if (transactionIds.parallelStream().anyMatch(transactionId -> {
|
|
|
try {
|
|
|
@@ -629,8 +622,7 @@ public class OrderService {
|
|
|
}
|
|
|
return false;
|
|
|
})) {
|
|
|
- log.info("订单已经支付成功或待支付,不能取消 {}", order.getId());
|
|
|
- return;
|
|
|
+ throw new BusinessException("订单已经支付成功或待支付,不能取消 " + order.getId());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -664,7 +656,7 @@ public class OrderService {
|
|
|
} catch (Exception e) {
|
|
|
log.error("订单取消错误 orderId: " + order.getId(), e);
|
|
|
}
|
|
|
- redisTemplate.delete("orderLock::" + order.getId());
|
|
|
+ releaseOrderLock(order.getId());
|
|
|
}
|
|
|
|
|
|
public void refundCancelled(Order order) {
|
|
|
@@ -739,6 +731,16 @@ public class OrderService {
|
|
|
}
|
|
|
|
|
|
public Object queryCreateOrder(String id) {
|
|
|
- return redisTemplate.opsForValue().get("createOrder::" + id);
|
|
|
+ return redisTemplate.opsForValue().get(RedisKeys.CREATE_ORDER + id);
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean getOrderLock(Long orderId) {
|
|
|
+ BoundValueOperations<String, Object> ops = redisTemplate.boundValueOps("orderLock::" + orderId);
|
|
|
+ Boolean flag = ops.setIfAbsent(1, 1, TimeUnit.DAYS);
|
|
|
+ return Boolean.TRUE.equals(flag);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void releaseOrderLock(Long orderId) {
|
|
|
+ redisTemplate.delete("orderLock::" + orderId);
|
|
|
}
|
|
|
}
|