浏览代码

更新订单状态

刘俊驰 6 月之前
父节点
当前提交
9fbfd6bf15

+ 51 - 37
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserOrderServiceImpl.java

@@ -269,6 +269,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public UserOrderVo detailApp(UserOrder param) {
 
         UserOrderVo userOrderVo = baseMapper.detailApp(param);
@@ -871,8 +872,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
         Payment queryPaymentData = res.getData();
 
         //支付成功
-        if (res.getStatus() && TradeStatusEnum.succeeded.getCode().equals(queryPaymentData.getStatus().getCode())
-                && (OrderStatusEnum.WAIT_PAY.equals(detail.getStatus()) || OrderStatusEnum.PAYING.equals(detail.getStatus()))) {
+        if (res.getStatus() && TradeStatusEnum.succeeded.getCode().equals(queryPaymentData.getStatus().getCode())) {
             //订单已经完成,则完成订单
             orderSuccess(detail);
             //付款单改为已完成状态
@@ -895,6 +895,10 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 
             }
             orderPaymentService.updateById(userOrderPayment);
+        } else if (res.getStatus() && TradeStatusEnum.close ==queryPaymentData.getStatus()) {
+
+            //关闭订单
+            doOrderCancel(detail, OrderStatusEnum.CLOSE, "三方订单已关闭");
         }
     }
 
@@ -1201,46 +1205,56 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void orderSuccess(UserOrderVo detail, PaymentCallBack data) {
-        //订单已完成
-        if (!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
-                && !OrderStatusEnum.PAYING.equals(detail.getStatus())) {
-            return;
-        }
+    public void orderSuccess(UserOrderVo detailInfo, PaymentCallBack data) {
 
-        //修改订单状态
-        Date now = new Date();
-        detail.setStatus(OrderStatusEnum.PAID);
-        detail.setPayTime(now);
-        detail.setUpdateTime(now);
-        updateById(detail);
-
-        if (null != data) {
-            //更新付款单
-            UserOrderPayment orderPayment = orderPaymentService
-                    .detailByTransNoOrPaymentNo(data.getId(), data.getPaymentNo());
-            if (null != orderPayment) {
-                orderPayment.setTransNo(data.getId());
-                orderPayment.setStatus(TradeStatusEnum.succeeded);
-                orderPayment.setArrivalTime(now);
-                orderPayment.setUpdateTime(now);
-
-                if (null != data.getExecutePaymentCallBack()) {
-                    orderPayment.setBackPayAmt(
-                            new BigDecimal(data.getExecutePaymentCallBack().getPayAmt()));
-
-                    BigDecimal feeAmt = new BigDecimal(data.getExecutePaymentCallBack().getFeeAmt());
-                    if (BigDecimal.ZERO.compareTo(feeAmt) == 0) {
-                        orderPayment.setFeeAmt(orderPayment.getPayAmt().subtract(orderPayment.getBackPayAmt()));
-                    } else {
-                        orderPayment.setFeeAmt(feeAmt);
+        // 加订单锁
+
+        // 用户下单请求锁
+        String lockName = redisCacheService.getPaymentCacheKey(detailInfo.getOrderNo());
+        DistributedLock.of(redissonClient).runIfLockCanGet(lockName, () -> {
+
+            UserOrderVo detail= detail(detailInfo.getId());
+            //订单已完成
+            if (!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
+                    && !OrderStatusEnum.PAYING.equals(detail.getStatus())) {
+                return;
+            }
+
+            //修改订单状态
+            Date now = new Date();
+            detail.setStatus(OrderStatusEnum.PAID);
+            detail.setPayTime(now);
+            detail.setUpdateTime(now);
+            updateById(detail);
+
+            if (null != data) {
+                //更新付款单
+                UserOrderPayment orderPayment = orderPaymentService
+                        .detailByTransNoOrPaymentNo(data.getId(), data.getPaymentNo());
+                if (null != orderPayment) {
+                    orderPayment.setTransNo(data.getId());
+                    orderPayment.setStatus(TradeStatusEnum.succeeded);
+                    orderPayment.setArrivalTime(now);
+                    orderPayment.setUpdateTime(now);
+
+                    if (null != data.getExecutePaymentCallBack()) {
+                        orderPayment.setBackPayAmt(
+                                new BigDecimal(data.getExecutePaymentCallBack().getPayAmt()));
+
+                        BigDecimal feeAmt = new BigDecimal(data.getExecutePaymentCallBack().getFeeAmt());
+                        if (BigDecimal.ZERO.compareTo(feeAmt) == 0) {
+                            orderPayment.setFeeAmt(orderPayment.getPayAmt().subtract(orderPayment.getBackPayAmt()));
+                        } else {
+                            orderPayment.setFeeAmt(feeAmt);
+                        }
                     }
+                    orderPaymentService.updateById(orderPayment);
                 }
-                orderPaymentService.updateById(orderPayment);
             }
-        }
 
-        paySuccess(detail);
+            paySuccess(detail);
+
+        },10L,TimeUnit.SECONDS);
     }
 
     /**