Browse Source

直播订单补偿机制

yuhongqi 2 weeks ago
parent
commit
0890e349cd

+ 2 - 0
fs-service-system/src/main/java/com/fs/live/service/ILiveOrderPaymentService.java

@@ -65,4 +65,6 @@ public interface ILiveOrderPaymentService {
     LiveOrderPaymentVo selectLiveOrderPaymentByPaymentIdNew(Long paymentId);
 
     List<LiveOrderPayment> selectLiveOrderPaymentByOrderId(Long id);
+
+    boolean queryHf(LiveOrderPayment liveOrderPayment);
 }

+ 41 - 0
fs-service-system/src/main/java/com/fs/live/service/impl/LiveOrderPaymentServiceImpl.java

@@ -2,13 +2,20 @@ package com.fs.live.service.impl;
 
 
 import com.fs.common.utils.DateUtils;
+import com.fs.huifuPay.domain.HuiFuQueryOrderResult;
+import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayQueryRequest;
+import com.fs.huifuPay.service.HuiFuService;
 import com.fs.live.domain.LiveOrderPayment;
 import com.fs.live.mapper.LiveOrderPaymentMapper;
 import com.fs.live.service.ILiveOrderPaymentService;
+import com.fs.live.service.ILiveOrderService;
 import com.fs.live.vo.LiveOrderPaymentVo;
+import lombok.extern.slf4j.Slf4j;
+import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.text.SimpleDateFormat;
 import java.util.Collections;
 import java.util.List;
 
@@ -19,6 +26,7 @@ import java.util.List;
  * @date 2025-08-07
  */
 @Service
+@Slf4j
 public class LiveOrderPaymentServiceImpl implements ILiveOrderPaymentService {
     @Autowired
     private LiveOrderPaymentMapper baseMapper;
@@ -62,6 +70,39 @@ public class LiveOrderPaymentServiceImpl implements ILiveOrderPaymentService {
         return baseMapper.selectLiveOrderPaymentByOrderId(id);
     }
 
+    @Autowired
+    private HuiFuService huiFuService;
+    @Autowired
+    private ILiveOrderService liveOrderService;
+    @Override
+    public boolean queryHf(LiveOrderPayment liveOrderPayment) {
+        V2TradePaymentScanpayQueryRequest request = new V2TradePaymentScanpayQueryRequest();
+        request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(liveOrderPayment.getCreateTime()));
+        request.setOrgHfSeqId(liveOrderPayment.getTradeNo());
+        HuiFuQueryOrderResult huiFuQueryOrderResult;
+        try {
+            huiFuQueryOrderResult = huiFuService.queryOrder(request);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        log.info("汇付返回"+huiFuQueryOrderResult);
+        if ("00000000".equals(huiFuQueryOrderResult.getResp_code())) {
+            if (huiFuQueryOrderResult.getTrans_stat().equals("S")) {
+                // 如果查询支付成功 更新订单状态
+                String bankTrxId = huiFuQueryOrderResult.getOut_trans_id();
+                String bankOrderId = huiFuQueryOrderResult.getParty_order_id();
+                liveOrderService.payConfirm(1, Long.valueOf(liveOrderPayment.getBusinessId()), liveOrderPayment.getPayCode(),
+                        liveOrderPayment.getTradeNo(),bankTrxId, bankOrderId);
+                return true;
+            } else if(huiFuQueryOrderResult.getTrans_stat().equals("F")){
+                liveOrderPayment.setStatus(-2);
+                this.updateLiveOrderPayment(liveOrderPayment);
+                return false;
+            }
+        }
+        return false;
+    }
+
     /**
      * 新增支付明细
      *

+ 13 - 0
fs-user-app/src/main/java/com/fs/app/controller/LiveOrderController.java

@@ -18,10 +18,12 @@ import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.common.utils.sign.Md5Utils;
 import com.fs.live.domain.Live;
 import com.fs.live.domain.LiveOrder;
+import com.fs.live.domain.LiveOrderPayment;
 import com.fs.live.enums.LiveOrderCancleReason;
 import com.fs.live.param.FsUserLiveOrderPayUParam;
 import com.fs.live.param.LiveOrderCancelParam;
 import com.fs.live.param.LiveOrderConfirmParam;
+import com.fs.live.service.ILiveOrderPaymentService;
 import com.fs.live.service.ILiveOrderService;
 import com.fs.live.vo.LiveOrderListVo;
 import com.fs.store.domain.FsStoreOrder;
@@ -35,6 +37,7 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.transaction.annotation.Transactional;
@@ -67,6 +70,8 @@ public class LiveOrderController extends AppBaseController
     private IFsExpressService expressService;
     @Autowired
     private JwtUtils jwtUtils;
+    @Autowired
+    private ILiveOrderPaymentService liveOrderPaymentService;
 
 
     @Login
@@ -350,6 +355,7 @@ public class LiveOrderController extends AppBaseController
         return liveOrderService.liveOrderUser(liveId);
     }
 
+
     @Login
     @ApiOperation("取消订单")
     @PostMapping("/cancelOrder")
@@ -360,6 +366,13 @@ public class LiveOrderController extends AppBaseController
         if (ObjectUtil.isNull(order)) {
             throw new CustomException("订单不存在");
         }
+        List<LiveOrderPayment> liveOrderPayments = liveOrderPaymentService.selectLiveOrderPaymentByOrderId(order.getOrderId());
+        if(CollectionUtils.isNotEmpty(liveOrderPayments)){
+            LiveOrderPayment liveOrderPayment = liveOrderPayments.get(0);
+            if(liveOrderPaymentService.queryHf(liveOrderPayment)){
+                return R.error("当前订单状态不为待支付,请刷新页面!");
+            }
+        }
         return liveOrderService.cancelOrder(order);
 
     }