|
@@ -6,19 +6,19 @@ import com.zanxiang.common.enums.CallBackEnum;
|
|
|
import com.zanxiang.common.enums.OrderStateEnum;
|
|
|
import com.zanxiang.common.exception.BaseException;
|
|
|
import com.zanxiang.common.utils.bean.BeanUtils;
|
|
|
+import com.zanxiang.module.util.DateUtil;
|
|
|
import com.zanxiang.mybatis.entity.*;
|
|
|
import com.zanxiang.mybatis.mapper.OrderMapper;
|
|
|
-import com.zanxiang.sdk.domain.bo.PlatformOrderBO;
|
|
|
+import com.zanxiang.sdk.constant.RedisKeyConstant;
|
|
|
import com.zanxiang.sdk.domain.dto.GamePayWayDTO;
|
|
|
import com.zanxiang.sdk.domain.dto.PlatformOrderDTO;
|
|
|
import com.zanxiang.sdk.domain.params.ProductPayParam;
|
|
|
import com.zanxiang.sdk.domain.params.UserData;
|
|
|
-import com.zanxiang.sdk.listener.OrderPaySuccessEvent;
|
|
|
import com.zanxiang.sdk.service.*;
|
|
|
+import com.zanxiang.sdk.util.RedisUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -33,7 +33,6 @@ import java.time.format.DateTimeFormatter;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-@Transactional(rollbackFor = {Exception.class, RuntimeException.class})
|
|
|
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
|
|
|
|
|
|
@Autowired
|
|
@@ -52,12 +51,13 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
private IGameUserRoleService gameUserRoleService;
|
|
|
|
|
|
@Autowired
|
|
|
- private ApplicationContext applicationContext;
|
|
|
+ private IGamePayWayService gamePayWayService;
|
|
|
|
|
|
@Autowired
|
|
|
- private IGamePayWayService gamePayWayService;
|
|
|
+ private RedisUtil<String> redisUtil;
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = {Exception.class, RuntimeException.class})
|
|
|
public Boolean createOrder(ProductPayParam payParam, UserData userData) {
|
|
|
//用户id
|
|
|
Long userId = userData.getUserId();
|
|
@@ -124,10 +124,20 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
.build());
|
|
|
//设置订单号
|
|
|
payParam.setOrderId(orderNum);
|
|
|
+ //设置订单过期
|
|
|
+ this.orderExpire(orderNum);
|
|
|
//返回
|
|
|
return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
+ private void orderExpire(String orderId) {
|
|
|
+ //过期时间
|
|
|
+ double expire = (double) DateUtil.localDateTimeToMilli(LocalDateTime.now().plusMinutes(5));
|
|
|
+ //设置缓存
|
|
|
+ redisUtil.addZSet(RedisKeyConstant.ORDER_EXPIRE, orderId, expire);
|
|
|
+ log.error("订单添加过期缓存, orderId : {}, expire : {}", orderId, expire);
|
|
|
+ }
|
|
|
+
|
|
|
private String getOrderNum(Long userId) {
|
|
|
//时间(精确到毫秒)
|
|
|
DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
|
|
@@ -147,34 +157,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
return localDate + str + randomNumeric;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean pay(PlatformOrderBO platformOrderBO) {
|
|
|
- log.info("订单支付请求参数 platformOrderBO:{}", platformOrderBO);
|
|
|
- try {
|
|
|
- Order order = getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderId, platformOrderBO.getOrderId()));
|
|
|
- //已支付情况,直接返回成功
|
|
|
- if (order.getStatus().equals(OrderStateEnum.SUCCESS_PAY.getCode())) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- if (!order.getStatus().equals(OrderStateEnum.WAIT_PAY.getCode())) {
|
|
|
- throw new BaseException("订单状态非待支付");
|
|
|
- }
|
|
|
- platformOrderBO.setPayTime(LocalDateTime.now());
|
|
|
- log.info("订单支付提交数据 data:{}", platformOrderBO);
|
|
|
- boolean result = updateById(BeanUtils.copy(platformOrderBO, Order.class));
|
|
|
- if (result) {
|
|
|
- OrderPaySuccessEvent orderPaySuccessEvent = new OrderPaySuccessEvent(this, order.getOrderId());
|
|
|
- applicationContext.publishEvent(orderPaySuccessEvent);
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("订单支付失败 platformOrderBO:{}, error:{}", platformOrderBO, e);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public PlatformOrderDTO getByOrderId(String orderId) {
|
|
|
Order order = getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderId, orderId));
|