|
@@ -19,6 +19,7 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
@@ -44,10 +45,14 @@ import java.util.TreeMap;
|
|
|
@Log4j2
|
|
|
public class AppPayController extends BaseController {
|
|
|
|
|
|
+ public static final String QUERY_REPEAT_NUM_KEY = "queryRepeatNum:";
|
|
|
|
|
|
@Autowired
|
|
|
private TmOrderServiceImpl tmOrderService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate redisTemplate;
|
|
|
+
|
|
|
/**
|
|
|
* 获取支付的请求参数
|
|
|
*/
|
|
@@ -230,13 +235,24 @@ public class AppPayController extends BaseController {
|
|
|
|
|
|
String trade_state = MapUtils.getString("trade_state", resultUn);
|
|
|
if ("SUCCESS".equals(trade_state)) {
|
|
|
- //更新订单的状态为已支付,更新库存
|
|
|
-
|
|
|
+ //更新订单的支付状态为已支付,同时跟新订单的状态为预定成功 TODO:这里二期需要改成:审核中
|
|
|
+ tmOrderService.updateOrderStatusAndPayStatus(orderDetail ,
|
|
|
+ OrderPayStatusEnum.PAY_SUCCESS.getStatus() , OrderStatusEnum.ORDER_SUCCESS.getStatus());
|
|
|
|
|
|
return Result.success("支付成功");
|
|
|
} else if ("USERPAYING".equals(trade_state)) {
|
|
|
- // 重新查询 正在支付中
|
|
|
-
|
|
|
+ //在途,正在支付中,则递归调用3次
|
|
|
+ Integer num = (Integer) redisTemplate.opsForValue().get(QUERY_REPEAT_NUM_KEY + orderDetail.getId());
|
|
|
+ if(null == num){
|
|
|
+ redisTemplate.opsForValue().set(QUERY_REPEAT_NUM_KEY + orderDetail.getId() , 1 , 86400);
|
|
|
+ this.orderQuery(orderId);
|
|
|
+ }else if(num <= 3){
|
|
|
+ redisTemplate.opsForValue().increment(QUERY_REPEAT_NUM_KEY + orderDetail.getId() , 1L);
|
|
|
+ this.orderQuery(orderId);
|
|
|
+ }else{
|
|
|
+ redisTemplate.delete(QUERY_REPEAT_NUM_KEY + orderDetail.getId());
|
|
|
+ return Result.failure("查询失败,error=" + return_msg);
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
// 失败
|