From 9dfd9506d0743a22d404046ffe7cda6081404a8a Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Tue, 30 Jun 2026 17:09:36 +0800
Subject: [PATCH] feat(order): 添加XT支付功能和确认收款功能

---
 src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 100 insertions(+), 12 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
index b181d54..e9aee27 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -5,6 +5,7 @@
 import cc.mrbird.febs.common.exception.FebsException;
 import cc.mrbird.febs.common.properties.XcxProperties;
 import cc.mrbird.febs.common.utils.*;
+import cc.mrbird.febs.mall.controller.dependentStation.constant.OrderConstants;
 import cc.mrbird.febs.mall.conversion.MallGoodsCommentConversion;
 import cc.mrbird.febs.mall.conversion.MallOrderInfoConversion;
 import cc.mrbird.febs.mall.conversion.MallOrderRefundConversion;
@@ -32,6 +33,7 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
@@ -69,8 +71,10 @@
     private final IApiMallMemberService memberService;
     private final IMallMoneyFlowService mallMoneyFlowService;
     private final RedisUtils redisUtils;
+    private final MallCountryDeliveryMapper mallCountryDeliveryMapper;
 
     private final AgentProducer agentProducer;
+    private final ApiChatPayService apiChatPayService;
     private final IPayService payService;
     private final IXcxPayService iXcxPayService;
     private final IMallAchieveService mallAchieveService;
@@ -161,8 +165,23 @@
             mallOrderItemMapper.insert(orderItem);
         }
 
+
+
         //运费
-        BigDecimal delivaryAmount = addOrderDto.getDeliveryAmount() == null ? BigDecimal.ZERO : addOrderDto.getDeliveryAmount();
+        MallCountryDelivery delivery = mallCountryDeliveryMapper.selectOne(
+                Wrappers.lambdaQuery(MallCountryDelivery.class)
+                        .eq(MallCountryDelivery::getCountryCode, addOrderDto.getCountryCode().toUpperCase())
+                        .eq(MallCountryDelivery::getStatus, 1)
+        );
+        MallCountryDelivery defaultDelivery = mallCountryDeliveryMapper.selectOne(
+                Wrappers.lambdaQuery(MallCountryDelivery.class)
+                        .eq(MallCountryDelivery::getCountryCode, "DEFAULT")
+                        .eq(MallCountryDelivery::getStatus, 1)
+        );
+        BigDecimal delivaryAmount = defaultDelivery.getShippingFee();
+        if (delivery != null) {
+            delivaryAmount = delivery.getShippingFee();
+        }
         orderInfo.setCarriage(delivaryAmount);
 
         total = total.add(delivaryAmount);
@@ -171,12 +190,18 @@
         orderInfo.setName(address.getFristName() + address.getName());
         orderInfo.setPhone(address.getPhone());
 
-        orderInfo.setAddress(address.getArea()+ address.getAddress()+address.getCity()+address.getProvince() + address.getCountry() );
+        orderInfo.setAddress(
+                        address.getAddress() +"  -  "
+                        +address.getArea() +"  -  "
+                        +address.getCity() +"  -  "
+                        +address.getProvince() +"  -  "
+                        +address.getCountryName() +"  -  "
+                        + address.getCountry() );
         orderInfo.setLatitude(address.getLatitude());
         orderInfo.setLongitude(address.getLongitude());
         this.baseMapper.updateById(orderInfo);
-        //过期时间修改成24小时
-        agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(),  24 * 60 * 60 * 1000L);
+        //过期时间修改成30分钟
+        agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(),  30 * 60 * 1000L);
         return orderInfo.getId();
     }
 
@@ -477,6 +502,36 @@
         return map;
     }
 
+    /**
+     * 处理支付订单的请求
+     *
+     * @param payDto 包含支付订单所需信息的DTO
+     * @return 返回支付结果的AjaxResult对象
+     */
+    @Override
+    @Transactional
+    public FebsResponse payOrderByCoin(ApiOrderPayDto payDto) {
+        // 获取当前的用户
+        Long memberId = LoginUserUtil.getLoginUser().getId();
+        // 提取订单ID和支付类型
+        Long orderId = payDto.getOrderId();
+        Integer payType = payDto.getPayType();
+
+        // 验证订单是否存在
+
+        MallOrderInfo orderInfo =
+                ValidateEntityUtils.ensureColumnReturnEntity(orderId, MallOrderInfo::getId, this.baseMapper::selectOne, "Order does not exist");
+        ValidateEntityUtils.ensureEqual(memberId,orderInfo.getMemberId(),"Order does not exist");
+        ValidateEntityUtils.ensureEqual(OrderStatusEnum.WAIT_PAY.getValue(),orderInfo.getStatus(),"The order status is not pending payment");
+
+        // 根据支付类型调用相应的支付方法
+        if(OrderConstants.PAY_TYPE_USDT == payType){
+            return apiChatPayService.usPay(orderInfo);
+        }
+        // 如果支付类型不匹配或支付过程中出现异常,返回错误信息
+        return new FebsResponse().fail().message("Order exception, please contact us");
+    }
+
     private String balancePay(MallOrderInfo orderInfo, String tradePwd, String field) {
         if (StrUtil.isBlank(tradePwd)) {
             throw new FebsException("支付密码错误");
@@ -754,19 +809,23 @@
     public void goodsComment(ApiAddCommentDtos addCommentDtos) {
         Long orderId = addCommentDtos.getOrderId();
         MallMember member = LoginUserUtil.getLoginUser();
-        MallOrderInfo orderInfo = this.baseMapper.selectOrderDetailsById(orderId);
+        MallOrderInfo orderInfo = this.baseMapper.selectById(orderId);
         if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
-            throw new FebsException("订单不存在");
+            throw new FebsException("Order does not exist");
         }
         if (OrderStatusEnum.FINISH.getValue() != orderInfo.getStatus()) {
-            throw new FebsException("该状态不能评价");
+            throw new FebsException("This status cannot be evaluated");
         }
         if (MallOrderInfo.COMMENT_STATE_YES == orderInfo.getCommentState()) {
-            throw new FebsException("该状态不能评价");
+            throw new FebsException("This status cannot be evaluated");
         }
 
-        orderInfo.setCommentState(MallOrderInfo.COMMENT_STATE_YES);
-        this.baseMapper.updateById(orderInfo);
+        this.baseMapper.update(
+                null,
+                Wrappers.lambdaUpdate(MallOrderInfo.class)
+                .set(MallOrderInfo::getCommentState, MallOrderInfo.COMMENT_STATE_YES)
+                .eq(MallOrderInfo::getId, orderId)
+        );
 
         List<ApiAddCommentDto> apiAddCommentDtos = addCommentDtos.getApiAddCommentDtos();
         if(CollUtil.isNotEmpty(apiAddCommentDtos)){
@@ -782,7 +841,7 @@
                 mallGoodsComment.setSkuName(mallGoodsSku.getSkuName());
                 mallGoodsComment.setStyleId(mallGoodsSku.getStyleId());
                 mallGoodsComment.setStyleName(mallGoodsSku.getStyleName());
-                mallGoodsComment.setShowState(MallGoodsComment.SHOW_STATE_ENABLE);
+                mallGoodsComment.setShowState(MallGoodsComment.SHOW_STATE_DISABLED);
                 mallGoodsCommentMapper.insert(mallGoodsComment);
             }
         }
@@ -790,7 +849,7 @@
 
     @Autowired
     private WeixinServiceUtil weixinServiceUtil;
-    private final XcxProperties xcxProperties = SpringContextHolder.getBean(XcxProperties.class);
+    private final XcxProperties xcxProperties;
 
     @Override
     @Transactional
@@ -943,4 +1002,33 @@
         return new FebsResponse().success().data(objects);
     }
 
+    @Override
+    public FebsResponse createOrderByXtPay() {
+
+        DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                "PAY_LINK", "XT_LINK"
+        );
+
+        DataDictionaryCustom dataDictionaryCustomImg = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                "PAY_LINK", "XT_LINK_IMG"
+        );
+        if (ObjectUtil.isEmpty(dataDictionaryCustom)){
+            return new FebsResponse().fail().message("Payment channel exception");
+        }
+        if (ObjectUtil.isEmpty(dataDictionaryCustomImg)){
+            return new FebsResponse().fail().message("Payment channel exception");
+        }
+        if (StrUtil.isEmpty(dataDictionaryCustom.getValue())){
+            return new FebsResponse().fail().message("Payment channel exception");
+        }
+        if (StrUtil.isEmpty(dataDictionaryCustomImg.getValue())){
+            return new FebsResponse().fail().message("Payment channel exception");
+        }
+
+        Map<String, Object> result = new HashMap<>();
+        result.put("link", dataDictionaryCustom.getValue());
+        result.put("linkImg", dataDictionaryCustomImg.getValue());
+        return new FebsResponse().success().data(result);
+    }
+
 }

--
Gitblit v1.9.1