Prechádzať zdrojové kódy

合并订单 部分代码提交

yuhongqi 1 deň pred
rodič
commit
a27fd34213

+ 28 - 5
fs-common/src/main/java/com/fs/common/utils/SnowflakeUtil.java

@@ -2,6 +2,10 @@ package com.fs.common.utils;
 
 import cn.hutool.core.lang.Snowflake;
 import cn.hutool.core.util.IdUtil;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
 
 /**
  * 雪花算法ID生成器
@@ -10,27 +14,42 @@ import cn.hutool.core.util.IdUtil;
  * @author zhangqin
  * @date 2025-11-03
  */
+@Component
 public class SnowflakeUtil {
 
     /**
-     * 工作机器ID(0-31)
+     * 工作机器ID(0-31),从配置文件读取,默认值为1
      */
-    private static final long WORKER_ID = 1;
+    @Value("${snowflake.worker-id:1}")
+    private long workerId;
 
     /**
-     * 数据中心ID(0-31)
+     * 数据中心ID(0-31),从配置文件读取,默认值为1
      */
-    private static final long DATACENTER_ID = 1;
+    @Value("${snowflake.datacenter-id:1}")
+    private long datacenterId;
 
     /**
      * 雪花算法实例(单例)
      */
-    private static final Snowflake SNOWFLAKE = IdUtil.getSnowflake(WORKER_ID, DATACENTER_ID);
+    private static Snowflake SNOWFLAKE;
+
+    /**
+     * 初始化雪花算法实例
+     */
+    @PostConstruct
+    public void init() {
+        SNOWFLAKE = IdUtil.getSnowflake(workerId, datacenterId);
+    }
 
     /**
      * 生成Long型ID
      */
     public static Long nextId() {
+        if (SNOWFLAKE == null) {
+            // 如果Spring未初始化,使用默认值
+            SNOWFLAKE = IdUtil.getSnowflake(1, 1);
+        }
         return SNOWFLAKE.nextId();
     }
 
@@ -38,6 +57,10 @@ public class SnowflakeUtil {
      * 生成String型ID
      */
     public static String nextIdStr() {
+        if (SNOWFLAKE == null) {
+            // 如果Spring未初始化,使用默认值
+            SNOWFLAKE = IdUtil.getSnowflake(1, 1);
+        }
         return SNOWFLAKE.nextIdStr();
     }
 

+ 1 - 0
fs-service/src/main/java/com/fs/hisStore/domain/FsStoreOrderScrm.java

@@ -199,6 +199,7 @@ public class FsStoreOrderScrm extends BaseEntity
 
     private String itemJson;
 
+    // 直播订单类型:2
     private Integer orderType;
 
     private Long packageId;

+ 4 - 2
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreAfterSalesScrmServiceImpl.java

@@ -884,8 +884,10 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
                         payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
                         wxPayService.setConfig(payConfig);
                         WxPayRefundRequest refundRequest = new WxPayRefundRequest();
-                        refundRequest.setOutTradeNo("store-"+payment.getPayCode());
-                        refundRequest.setOutRefundNo("store-"+payment.getPayCode());
+                        // 检查订单类型,如果是直播订单(orderType=2),使用 "live-" 前缀
+                        String prefix = (order.getOrderType() != null && order.getOrderType() == 2) ? "live-" : "store-";
+                        refundRequest.setOutTradeNo(prefix + payment.getPayCode());
+                        refundRequest.setOutRefundNo(prefix + payment.getPayCode());
                         refundRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
                         refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(refundAmount.toString()));
                         try {

+ 10 - 12
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -28,11 +28,7 @@ import com.fs.common.event.TemplateEvent;
 import com.fs.common.event.TemplateListenEnum;
 import com.fs.common.exception.CustomException;
 import com.fs.common.exception.ServiceException;
-import com.fs.common.utils.CloudHostUtils;
-import com.fs.common.utils.DateUtils;
-import com.fs.common.utils.IpUtil;
-import com.fs.common.utils.ServletUtils;
-import com.fs.common.utils.StringUtils;
+import com.fs.common.utils.*;
 import com.fs.common.utils.ip.IpUtils;
 import com.fs.common.utils.spring.SpringUtils;
 import com.fs.company.domain.*;
@@ -877,7 +873,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             FsUserAddressScrm address = userAddressMapper.selectFsUserAddressById(param.getAddressId());
             //生成分布式唯一值
 
-            String orderSn = OrderCodeUtils.getOrderSn();
+            String orderSn = SnowflakeUtil.nextIdStr();
             //是否使用积分
             Boolean isIntegral = false;
             //组合数据
@@ -1167,7 +1163,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
         List<FsPrescribeDrug> drugs = prescribeDrugMapper.selectFsPrescribeDrugList(map);
         FsStoreOrderScrm order = new FsStoreOrderScrm();
         List<FsStoreOrderItemScrm> items = new ArrayList<>();
-        String orderSn = OrderCodeUtils.getOrderSn();
+        String orderSn = SnowflakeUtil.nextIdStr();
         if (StringUtils.isEmpty(orderSn)) {
             return R.error("订单生成失败,请重试");
         }
@@ -2532,8 +2528,10 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                         payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
                         wxPayService.setConfig(payConfig);
                         WxPayRefundRequest refundRequest = new WxPayRefundRequest();
-                        refundRequest.setOutTradeNo("store-" + payment.getPayCode());
-                        refundRequest.setOutRefundNo("store-" + payment.getPayCode());
+                        // 检查订单类型,如果是直播订单(orderType=2),使用 "live-" 前缀
+                        String prefix = (order.getOrderType() != null && order.getOrderType() == 2) ? "live-" : "store-";
+                        refundRequest.setOutTradeNo(prefix + payment.getPayCode());
+                        refundRequest.setOutRefundNo(prefix + payment.getPayCode());
                         refundRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
                         refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
                         try {
@@ -4436,7 +4434,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                 }
                 this.updateFsStoreOrder(order);
             }
-            String payCode =  OrderCodeUtils.getOrderSn();
+            String payCode =  SnowflakeUtil.nextIdStr();
             if((order.getPayType().equals("1")||order.getPayType().equals("2")||order.getPayType().equals("3")||order.getPayType().equals("5")) && order.getPayMoney().compareTo(new BigDecimal(0))>0){
                 if (StringUtils.isBlank(param.getAppId())) {
                     throw new IllegalArgumentException("appId不能为空");
@@ -4588,7 +4586,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             if(!order.getIsPayRemain().equals(0)){
                 return R.error("此订单已支付");
             }
-            String payCode =  OrderCodeUtils.getOrderSn();
+            String payCode =  SnowflakeUtil.nextIdStr();
             if (StringUtils.isBlank(param.getAppId())) {
                 throw new IllegalArgumentException("appId不能为空");
             }
@@ -4832,7 +4830,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
         }
         FsUserScrm user=userService.selectFsUserById(order.getUserId());
         if(user!=null){
-            String payCode =  OrderCodeUtils.getOrderSn();
+            String payCode =  SnowflakeUtil.nextIdStr();
             if (StringUtils.isBlank(param.getAppId())) {
                 throw new IllegalArgumentException("appId不能为空");
             }

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

@@ -95,4 +95,6 @@ public interface ILiveAfterSalesService {
     R handleImmediatelyRefund(Long orderId);
 
     List<LiveAfterSalesVo> selectLiveAfterSalesVoListExport(LiveAfterSalesVo liveAfterSales);
+
+    R applyForStoreAfterSales(String userId, LiveAfterSalesParam param);
 }

+ 4 - 0
fs-service/src/main/java/com/fs/live/service/ILiveOrderService.java

@@ -275,4 +275,8 @@ public interface ILiveOrderService {
     void updateTime(LiveOrder order);
 
     void initStock();
+
+    R createStoreOrder(LiveOrder param);
+
+    R handleStoreOrderPay(LiveOrderPayParam param);
 }

+ 27 - 1
fs-service/src/main/java/com/fs/live/service/impl/LiveAfterSalesItemServiceImpl.java

@@ -4,9 +4,12 @@ package com.fs.live.service.impl;
 import com.fs.live.domain.LiveAfterSalesItem;
 import com.fs.live.mapper.LiveAfterSalesItemMapper;
 import com.fs.live.service.ILiveAfterSalesItemService;
+import com.fs.hisStore.domain.FsStoreAfterSalesItemScrm;
+import com.fs.hisStore.service.IFsStoreAfterSalesItemScrmService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -21,6 +24,9 @@ public class LiveAfterSalesItemServiceImpl  implements ILiveAfterSalesItemServic
 
     @Autowired
     private LiveAfterSalesItemMapper baseMapper;
+    
+    @Autowired
+    private IFsStoreAfterSalesItemScrmService fsStoreAfterSalesItemScrmService;
 
     /**
      * 查询售后子
@@ -96,6 +102,26 @@ public class LiveAfterSalesItemServiceImpl  implements ILiveAfterSalesItemServic
 
     @Override
     public List<LiveAfterSalesItem> selectLiveAfterSalesItemByAfterId(Long afterId) {
-        return baseMapper.selectLiveAfterSalesItemByAfterId(afterId);
+        // 查询商城售后商品信息
+        FsStoreAfterSalesItemScrm queryItem = new FsStoreAfterSalesItemScrm();
+        queryItem.setStoreAfterSalesId(afterId);
+        List<FsStoreAfterSalesItemScrm> storeItems = fsStoreAfterSalesItemScrmService.selectFsStoreAfterSalesItemList(queryItem);
+        
+        if (storeItems == null || storeItems.isEmpty()) {
+            return Collections.emptyList();
+        }
+        
+        // 转换为 LiveAfterSalesItem(为了兼容性)
+        List<LiveAfterSalesItem> liveItems = new ArrayList<>();
+        for (FsStoreAfterSalesItemScrm storeItem : storeItems) {
+            LiveAfterSalesItem liveItem = new LiveAfterSalesItem();
+            liveItem.setId(storeItem.getId());
+            liveItem.setAfterSalesId(storeItem.getStoreAfterSalesId());
+            liveItem.setProductId(storeItem.getProductId());
+            liveItem.setJsonInfo(storeItem.getJsonInfo());
+            liveItem.setIsDel(storeItem.getIsDel());
+            liveItems.add(liveItem);
+        }
+        return liveItems;
     }
 }

+ 264 - 31
fs-service/src/main/java/com/fs/live/service/impl/LiveAfterSalesServiceImpl.java

@@ -49,9 +49,15 @@ import com.fs.hisStore.config.FsErpConfig;
 import com.fs.hisStore.domain.*;
 import com.fs.hisStore.dto.StoreOrderProductDTO;
 import com.fs.hisStore.enums.*;
+import com.fs.hisStore.param.FsStoreAfterSalesParam;
 import com.fs.hisStore.param.FsStoreAfterSalesProductParam;
-import com.fs.hisStore.service.IFsStoreProductScrmService;
-import com.fs.hisStore.service.IFsUserScrmService;
+import com.fs.hisStore.service.*;
+import com.fs.hisStore.mapper.FsStoreAfterSalesScrmMapper;
+import com.fs.hisStore.domain.FsStoreAfterSalesScrm;
+import com.fs.hisStore.domain.FsStoreAfterSalesItemScrm;
+import com.fs.hisStore.domain.FsStoreAfterSalesStatusScrm;
+import com.fs.hisStore.enums.AfterSalesStatusEnum;
+import com.fs.hisStore.enums.SysConfigEnum;
 import com.fs.hisStore.vo.FsStoreAfterSalesQueryVO;
 import com.fs.hisStore.vo.FsStoreOrderItemVO;
 import com.fs.huifuPay.domain.HuiFuRefundResult;
@@ -189,7 +195,36 @@ public class LiveAfterSalesServiceImpl implements ILiveAfterSalesService {
     @Override
     public LiveAfterSales selectLiveAfterSalesById(Long id)
     {
-        return baseMapper.selectLiveAfterSalesById(id);
+        // 查询商城售后信息
+        FsStoreAfterSalesScrm storeAfterSales = fsStoreAfterSalesScrmMapper.selectFsStoreAfterSalesById(id);
+        if (storeAfterSales == null) {
+            return null;
+        }
+        
+        // 转换为 LiveAfterSales(为了兼容性)
+        LiveAfterSales liveAfterSales = new LiveAfterSales();
+        liveAfterSales.setId(storeAfterSales.getId());
+        liveAfterSales.setRefundAmount(storeAfterSales.getRefundAmount());
+        liveAfterSales.setRefundType(storeAfterSales.getServiceType());
+        liveAfterSales.setReasons(storeAfterSales.getReasons());
+        liveAfterSales.setExplains(storeAfterSales.getExplains());
+        liveAfterSales.setExplainImg(storeAfterSales.getExplainImg());
+        liveAfterSales.setStatus(storeAfterSales.getStatus());
+        liveAfterSales.setSalesStatus(storeAfterSales.getSalesStatus());
+        liveAfterSales.setCreateTime(storeAfterSales.getCreateTime());
+        liveAfterSales.setIsDel(storeAfterSales.getIsDel());
+        liveAfterSales.setUserId(storeAfterSales.getUserId());
+        liveAfterSales.setOrderStatus(storeAfterSales.getOrderStatus());
+        liveAfterSales.setCompanyId(storeAfterSales.getCompanyId());
+        liveAfterSales.setCompanyUserId(storeAfterSales.getCompanyUserId());
+        
+        // 通过订单号查询订单ID
+        FsStoreOrderScrm order = fsStoreOrderScrmService.selectFsStoreOrderByOrderCode(storeAfterSales.getOrderCode());
+        if (order != null) {
+            liveAfterSales.setOrderId(order.getId());
+        }
+        
+        return liveAfterSales;
     }
 
     /**
@@ -262,6 +297,189 @@ public class LiveAfterSalesServiceImpl implements ILiveAfterSalesService {
         }
         return liveAfterSalesVos;
     }
+
+    @Override
+    @Transactional
+    public R applyForStoreAfterSales(String userId, LiveAfterSalesParam param) {
+        log.info("申请退款请求信息:"+JSONUtil.toJsonStr(param));
+        // 使用Redis分布式锁,确保同一订单只能有一个服务器处理申请售后 因为卓美有一个订单生成了三个售后订单,数据一摸一样,除了id
+        String lockKey = "live:afterSales:apply:" + param.getOrderCode();
+        RLock lock = redissonClient.getLock(lockKey);
+
+
+
+        // 查询配置:是否删除历史售后数据
+        try {
+
+            // 尝试获取锁,等待时间3秒,锁过期时间30秒
+            boolean locked = lock.tryLock(3, 30, TimeUnit.SECONDS);
+            if (!locked) {
+                log.warn("申请售后订单锁获取失败,订单号:{}", param.getOrderCode());
+                return R.error("系统繁忙,请稍后重试");
+            }
+
+            String deleteAfterSalesConfig = configService.selectConfigByKey("delete_after_sales");
+            if (StringUtils.isNotEmpty(deleteAfterSalesConfig) && "true".equalsIgnoreCase(deleteAfterSalesConfig.trim())) {
+                // 查询历史售后数据,将 is_del 设置为 1
+                FsStoreAfterSalesScrm queryAfterSales = new FsStoreAfterSalesScrm();
+                queryAfterSales.setOrderCode(param.getOrderCode());
+                List<FsStoreAfterSalesScrm> historyAfterSalesList = fsStoreAfterSalesScrmMapper.selectFsStoreAfterSalesList(queryAfterSales);
+                if (historyAfterSalesList != null && !historyAfterSalesList.isEmpty()) {
+                    for (FsStoreAfterSalesScrm historyAfterSales : historyAfterSalesList) {
+                        if (historyAfterSales.getIsDel() != null && historyAfterSales.getIsDel() == 0) {
+                            FsStoreAfterSalesScrm updateAfterSales = new FsStoreAfterSalesScrm();
+                            updateAfterSales.setId(historyAfterSales.getId());
+                            updateAfterSales.setIsDel(1);
+                            fsStoreAfterSalesScrmMapper.updateFsStoreAfterSales(updateAfterSales);
+                            log.info("删除历史售后数据,售后ID:{},订单号:{}", historyAfterSales.getId(), param.getOrderCode());
+                        }
+                    }
+                }
+            }
+        
+            // 查询商城订单
+            FsStoreOrderScrm order = fsStoreOrderScrmService.selectFsStoreOrderByOrderCode(param.getOrderCode());
+            Integer orderStatus = order.getStatus();
+            Long userIdLong = Long.parseLong(userId);
+            if(!order.getUserId().equals(userIdLong)){
+                throw new CustomException("非法操作");
+            }
+            if(order.getStatus()==0){
+                return R.error("未支付订单不能申请售后");
+            }
+            if("1".equals(configUtil.generateConfigByKey(SysConfigEnum.HIS_CONFIG.getKey()).getString("erpOpen"))
+                    && StringUtils.isEmpty(order.getExtendOrderId())
+                    && !CloudHostUtils.hasCloudHostName("康年堂")){
+                log.info("erpOpen:{}",configUtil.generateConfigByKey(SysConfigEnum.HIS_CONFIG.getKey()).getString("erpOpen"));
+                return R.error("仓库未生成订单,暂时不能申请退款,请联系客服");
+            }
+            if(order.getStatus()== OrderInfoEnum.STATUS_NE3.getValue()){
+                return R.error("已取消订单不能申请售后");
+            }
+            if(order.getStatus()== OrderInfoEnum.STATUS_NE1.getValue()){
+                return R.error("已提交申请,等待处理");
+            }
+            //已完成订单七天后不能申请退款
+            if(order.getStatus().equals(OrderInfoEnum.STATUS_3.getValue())) {
+                String json=configService.selectConfigByKey("store.config");
+                StoreConfig config=JSONUtil.toBean(json,StoreConfig.class);
+                //已完成订单
+                if (order.getFinishTime() != null) {
+                    if (config.getStoreAfterSalesDay() != null && config.getStoreAfterSalesDay() > 0) {
+                        //判断完成时间是否超过指定时间
+                        Calendar calendarAfterSales = new GregorianCalendar();
+                        calendarAfterSales.setTime(order.getFinishTime());
+                        calendarAfterSales.add(Calendar.DATE, config.getStoreAfterSalesDay()); //把日期往后增加一天,整数  往后推,负数往前移动
+                        if (calendarAfterSales.getTime().getTime() < new Date().getTime()) {
+                            return R.error("此订单已超过售后时间,不能提交售后");
+                        }
+                    }
+                }
+            }
+            //拿到所有的商品
+            List<FsStoreOrderItemVO> orderItems=fsStoreOrderItemScrmService.selectFsStoreOrderItemListByOrderId(order.getId());
+            // 转换商品列表
+            List<FsStoreAfterSalesProductParam> productList = new ArrayList<>();
+            if (param.getProductList() != null) {
+                for (com.fs.live.param.LiveAfterSalesProductParam liveProduct : param.getProductList()) {
+                    FsStoreAfterSalesProductParam storeProduct = new FsStoreAfterSalesProductParam();
+                    storeProduct.setProductId(liveProduct.getProductId());
+                    storeProduct.setNum(liveProduct.getNum());
+                    productList.add(storeProduct);
+                }
+            }
+            for (FsStoreOrderItemVO item : orderItems) {
+                FsStoreAfterSalesProductParam productParam = productList.stream().filter(p -> p.getProductId().equals(item.getProductId())).findFirst().orElse(new FsStoreAfterSalesProductParam());
+                if (productParam.getProductId() != null) {
+                    item.setIsAfterSales(1);
+                    FsStoreOrderItemScrm orderItem=new FsStoreOrderItemScrm();
+                    try {
+                        BeanUtils.copyProperties(orderItem,item);
+                    } catch (IllegalAccessException e) {
+                        throw new RuntimeException(e);
+                    } catch (InvocationTargetException e) {
+                        throw new RuntimeException(e);
+                    }
+                    fsStoreOrderItemScrmService.updateFsStoreOrderItem(orderItem);
+                }
+            }
+            //更新订单状态
+            order.setStatus(OrderInfoEnum.STATUS_NE1.getValue());
+            order.setRefundStatus(OrderInfoEnum.REFUND_STATUS_1.getValue());
+            order.setRefundReasonWap(param.getReasons());
+            order.setRefundReasonWapExplain(param.getExplains());
+            order.setRefundReasonTime(new Date());
+            fsStoreOrderScrmService.updateFsStoreOrder(order);
+            //生成售后订单
+            FsStoreAfterSalesScrm storeAfterSales = new FsStoreAfterSalesScrm();
+            storeAfterSales.setOrderCode(param.getOrderCode());
+            storeAfterSales.setRefundAmount(param.getRefundAmount());
+            storeAfterSales.setServiceType(param.getServiceType());
+            storeAfterSales.setReasons(param.getReasons());
+            storeAfterSales.setExplains(param.getExplains());
+            storeAfterSales.setExplainImg(param.getExplainImg());
+            storeAfterSales.setStatus(AfterSalesStatusEnum.STATUS_0.getValue());
+            storeAfterSales.setSalesStatus(0);
+            storeAfterSales.setCreateTime(Timestamp.valueOf(LocalDateTime.now()));
+            storeAfterSales.setIsDel(0);
+            storeAfterSales.setUserId(userIdLong);
+            storeAfterSales.setOrderStatus(orderStatus);
+            storeAfterSales.setCompanyId(order.getCompanyId());
+            storeAfterSales.setCompanyUserId(order.getCompanyUserId());
+            storeAfterSales.setPackageJson(order.getPackageJson());
+            storeAfterSales.setIsPackage(order.getIsPackage());
+            fsStoreAfterSalesScrmMapper.insertFsStoreAfterSales(storeAfterSales);
+            //售后商品详情
+            for (FsStoreAfterSalesProductParam productParam : productList) {
+                FsStoreOrderItemVO item = orderItems.stream().filter(p -> p.getProductId().equals(productParam.getProductId())).findFirst().orElse(new FsStoreOrderItemVO());
+                FsStoreAfterSalesItemScrm storeAfterSalesItem = new FsStoreAfterSalesItemScrm();
+                storeAfterSalesItem.setStoreAfterSalesId(storeAfterSales.getId());
+                storeAfterSalesItem.setProductId(item.getProductId());
+                storeAfterSalesItem.setNum(productParam.getNum());
+                storeAfterSalesItem.setJsonInfo(item.getJsonInfo());
+                storeAfterSalesItem.setIsDel(0);
+                fsStoreAfterSalesItemScrmService.insertFsStoreAfterSalesItem(storeAfterSalesItem);
+            }
+            //操作记录
+            FsStoreAfterSalesStatusScrm storeAfterSalesStatus = new FsStoreAfterSalesStatusScrm();
+            storeAfterSalesStatus.setStoreAfterSalesId(storeAfterSales.getId());
+            storeAfterSalesStatus.setChangeType(0);
+            storeAfterSalesStatus.setChangeMessage(AfterSalesStatusEnum.STATUS_0.getDesc());
+            storeAfterSalesStatus.setChangeTime(Timestamp.valueOf(LocalDateTime.now()));
+            FsUserScrm user=userService.selectFsUserById(userIdLong);
+            storeAfterSalesStatus.setOperator(user.getNickname());
+            fsStoreAfterSalesStatusScrmService.insertFsStoreAfterSalesStatus(storeAfterSalesStatus);
+
+            //更新OMS
+            IErpOrderService erpOrderService = getErpService();
+            ErpRefundUpdateRequest request=new ErpRefundUpdateRequest();
+            request.setTid(order.getOrderCode());
+            request.setOid(order.getOrderCode());
+            request.setRefund_state(1);
+            request.setStoreAfterSalesId(storeAfterSales.getId());
+            request.setOrderStatus(orderStatus);
+            if (StringUtils.isNotBlank(order.getExtendOrderId())){
+                BaseResponse response=erpOrderService.refundUpdateScrm(request);
+                if(response.getSuccess()){
+                    return R.ok();
+                }
+                else{
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    return R.error(response.getErrorDesc());
+                }
+            }
+            return R.ok();
+        } catch (Exception e) {
+            log.error("查询或更新历史售后数据失败", e);
+            return R.error("系统繁忙,请稍后再试!");
+        } finally {
+            // 释放锁
+            if (lock.isHeldByCurrentThread()) {
+                lock.unlock();
+            }
+        }
+    }
+
     /**
      * 查询售后记录列表
      *
@@ -995,53 +1213,53 @@ public class LiveAfterSalesServiceImpl implements ILiveAfterSalesService {
     @Override
     @Transactional
     public R revoke(String userId, LiveAfterSalesRevokeParam param) throws ParseException {
-        LiveAfterSales storeAfterSales = baseMapper.selectLiveAfterSalesById(param.getId());
+        // 查询商城售后信息
+        FsStoreAfterSalesScrm storeAfterSales = fsStoreAfterSalesScrmMapper.selectFsStoreAfterSalesById(param.getId());
         if (storeAfterSales == null) {
             throw new CustomException("未查询到售后订单信息");
         }
-        if (storeAfterSales.getSalesStatus() != 0) {
+        if(storeAfterSales.getSalesStatus()!=0){
             throw new CustomException("非法操作");
         }
-        if (storeAfterSales.getStatus().equals(LiveAfterSalesStatusEnum.STATUS_2.getValue()) || storeAfterSales.getStatus().equals(LiveAfterSalesStatusEnum.STATUS_3.getValue()) || storeAfterSales.getStatus().equals(LiveAfterSalesStatusEnum.STATUS_4.getValue())) {
+        if (storeAfterSales.getStatus().equals(AfterSalesStatusEnum.STATUS_2.getValue()) || storeAfterSales.getStatus().equals(AfterSalesStatusEnum.STATUS_3.getValue())|| storeAfterSales.getStatus().equals(AfterSalesStatusEnum.STATUS_4.getValue())) {
             throw new CustomException("已发货退款单不能撤销");
         }
         //只有未发货的可以撤销,
-        if (!storeAfterSales.getOrderStatus().equals(OrderInfoEnum.STATUS_1.getValue())) {
+        if (!storeAfterSales.getOrderStatus().equals(OrderInfoEnum.STATUS_1.getValue()) ) {
             throw new CustomException("只有未发货的订单可以撤销售后");
         }
+
         storeAfterSales.setSalesStatus(1);
-        LiveOrder order = liveOrderService.selectLiveOrderByOrderId(String.valueOf(storeAfterSales.getOrderId()));
+        FsStoreOrderScrm order = fsStoreOrderScrmService.selectFsStoreOrderByOrderCode(storeAfterSales.getOrderCode());
         order.setStatus(storeAfterSales.getOrderStatus());
-        order.setRefundStatus(OrderInfoEnum.REFUND_STATUS_0.getValue().toString());
-        liveOrderService.updateLiveOrder(order);
+        order.setRefundStatus(OrderInfoEnum.REFUND_STATUS_0.getValue());
+        fsStoreOrderScrmService.updateFsStoreOrder(order);
+
         //操作记录
-        LiveAfterSalesLogs logs = new LiveAfterSalesLogs();
-        logs.setChangeTime(new DateTime());
-        logs.setChangeType(5);
-        FsUserScrm user = userService.selectFsUserByUserId(Long.valueOf(order.getUserId()));
-        logs.setOperator(user.getNickname());
-        logs.setStoreAfterSalesId(storeAfterSales.getId());
-        logs.setChangeMessage(OrderInfoEnum.REFUND_STATUS_1.getDesc());
-        liveAfterSalesLogsMapper.insertLiveAfterSalesLogs(logs);
-        if (storeAfterSales.getOrderStatus().equals(1)) {
-            if (StringUtils.isNotEmpty(order.getExtendOrderId())) {
+        FsStoreAfterSalesStatusScrm storeAfterSalesStatus = new FsStoreAfterSalesStatusScrm();
+        storeAfterSalesStatus.setStoreAfterSalesId(storeAfterSales.getId());
+        storeAfterSalesStatus.setChangeType(5);
+        storeAfterSalesStatus.setChangeMessage(AfterSalesStatusEnum.STATUS_5.getDesc());
+        storeAfterSalesStatus.setChangeTime(Timestamp.valueOf(LocalDateTime.now()));
+        FsUserScrm user=userService.selectFsUserById(Long.parseLong(userId));
+        storeAfterSalesStatus.setOperator(user.getNickname());
+        fsStoreAfterSalesStatusScrmService.insertFsStoreAfterSalesStatus(storeAfterSalesStatus);
+        if (storeAfterSales.getOrderStatus().equals(OrderInfoEnum.STATUS_1.getValue()) ) {
+            if(StringUtils.isNotEmpty(order.getExtendOrderId())){
                 //更新订单code
                 String orderSn = OrderCodeUtils.getOrderSn();
-                if (StringUtils.isEmpty(orderSn)) {
-                    return R.error("订单生成失败,请重试");
-                }
-                LiveOrder orderMap = new LiveOrder();
-                orderMap.setOrderId(order.getOrderId());
+                FsStoreOrderScrm orderMap=new FsStoreOrderScrm();
+                orderMap.setId(order.getId());
                 orderMap.setOrderCode(orderSn);
-                orderMap.setStatus(order.getStatus());
-                liveOrderService.updateLiveOrder(orderMap);
-                liveOrderItemService.updateFsStoreOrderCode(order.getOrderId(), orderSn);
-                liveOrderService.createOmsOrder(order.getOrderId());
+                fsStoreOrderScrmService.updateFsStoreOrder(orderMap);
+                storeAfterSales.setOrderCode(orderSn);
+                fsStoreOrderItemScrmService.updateFsStoreOrderCode(order.getId(),orderSn);
+                //生成新的订单
+                fsStoreOrderScrmService.createOmsOrder(order.getId());
             }
         }
-        baseMapper.updateLiveAfterSales(storeAfterSales);
+        fsStoreAfterSalesScrmMapper.updateFsStoreAfterSales(storeAfterSales);
         return R.ok();
-
     }
 
 
@@ -1066,6 +1284,21 @@ public class LiveAfterSalesServiceImpl implements ILiveAfterSalesService {
 
     @Autowired
     private LiveAfterSalesMapper liveAfterSalesMapper;
+    
+    @Autowired
+    private IFsStoreOrderScrmService fsStoreOrderScrmService;
+    
+    @Autowired
+    private IFsStoreOrderItemScrmService fsStoreOrderItemScrmService;
+    
+    @Autowired
+    private com.fs.hisStore.mapper.FsStoreAfterSalesScrmMapper fsStoreAfterSalesScrmMapper;
+    
+    @Autowired
+    private IFsStoreAfterSalesItemScrmService fsStoreAfterSalesItemScrmService;
+    
+    @Autowired
+    private IFsStoreAfterSalesStatusScrmService fsStoreAfterSalesStatusScrmService;
 
     @Override
     @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)

+ 458 - 6
fs-service/src/main/java/com/fs/live/service/impl/LiveOrderServiceImpl.java

@@ -42,6 +42,7 @@ import com.fs.common.event.TemplateListenEnum;
 import com.fs.common.exception.CustomException;
 import com.fs.common.exception.ServiceException;
 import com.fs.common.utils.*;
+import com.fs.common.utils.ServletUtils;
 import com.fs.common.utils.ip.IpUtils;
 import com.fs.common.utils.spring.SpringUtils;
 import com.fs.company.domain.Company;
@@ -73,14 +74,23 @@ import com.fs.his.service.IFsUserService;
 import com.fs.his.utils.ConfigUtil;
 import com.fs.hisStore.config.FsErpConfig;
 import com.fs.hisStore.config.StoreConfig;
+import com.fs.hisStore.constants.StoreConstants;
 import com.fs.hisStore.domain.*;
 import com.fs.hisStore.dto.*;
 import com.fs.hisStore.enums.*;
+import com.fs.hisStore.mapper.FsStoreOrderItemScrmMapper;
+import com.fs.hisStore.mapper.FsStoreOrderScrmMapper;
+import com.fs.hisStore.mapper.FsStorePaymentScrmMapper;
 import com.fs.hisStore.mapper.FsStoreProductAttrValueScrmMapper;
 import com.fs.hisStore.mapper.FsStoreProductScrmMapper;
 import com.fs.hisStore.mapper.FsUserScrmMapper;
 import com.fs.hisStore.param.*;
 import com.fs.hisStore.service.*;
+import com.fs.common.utils.SnowflakeUtil;
+import com.fs.huifuPay.sdk.opps.core.utils.HuiFuUtils;
+import com.fs.his.domain.MerchantAppConfig;
+import com.fs.his.domain.FsPayConfig;
+import org.springframework.aop.framework.AopContext;
 import com.fs.hisStore.service.IFsStoreProductPurchaseLimitScrmService;
 import com.fs.hisStore.domain.FsStoreProductPurchaseLimitScrm;
 import com.fs.hisStore.vo.*;
@@ -296,8 +306,27 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
     private FSSysConfig sysConfig;
     @Autowired
     private LiveOrderMapper liveOrderMapper;
+    
+    @Autowired
+    private FsStoreOrderScrmMapper fsStoreOrderScrmMapper;
+    
+    @Autowired
+    private FsStoreOrderItemScrmMapper fsStoreOrderItemScrmMapper;
+    
+    @Autowired
+    private IFsStoreOrderStatusScrmService orderStatusService;
+    
     @Autowired
     private ILiveGoodsService liveGoodsService;
+    
+    @Autowired
+    private IFsStoreOrderScrmService fsStoreOrderScrmService;
+    
+    @Autowired
+    private FsStorePaymentScrmMapper fsStorePaymentScrmMapper;
+    
+    @Autowired
+    private CloudHostProper cloudHostProper;
 
     @Autowired
     private ILiveUserFirstEntryService liveUserFirstEntryService;
@@ -2171,7 +2200,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
         liveOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
         liveOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
 
-        String orderSn = OrderCodeUtils.getOrderSn();
+        String orderSn = SnowflakeUtil.nextIdStr();
         log.info("订单生成:" + orderSn);
         liveOrder.setOrderCode(orderSn);
         BigDecimal totalPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum()));
@@ -3155,7 +3184,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
             MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
 
 
-            String payCode = OrderCodeUtils.getOrderSn();
+            String payCode = SnowflakeUtil.nextIdStr();
             if (StringUtils.isEmpty(payCode)) {
                 return R.error("订单生成失败,请重试");
             }
@@ -3239,6 +3268,183 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
         return baseMapper.selectLiveOrderListZmNew(liveOrder);
     }
 
+    @Override
+    public R handleStoreOrderPay(LiveOrderPayParam param) {
+        // 直播订单已合并到商城订单表:改为查询商城订单表
+        FsStoreOrderScrm order = fsStoreOrderScrmService.selectFsStoreOrderById(param.getOrderId());
+        if(order == null){
+            return R.error("订单不存在");
+        }
+        if(order.getStatus() != OrderInfoEnum.STATUS_0.getValue()){
+            return R.error("订单状态不正确");
+        }
+        String orderId = redisCache.getCacheObject("isPaying:" + param.getOrderId());
+        if(StringUtils.isNotEmpty(orderId) && orderId.equals(order.getId().toString())){
+            return R.error("正在支付中...");
+        }
+
+        FsUserScrm user = userService.selectFsUserById(order.getUserId());
+        if(user != null){
+            //已改价处理
+            if(order.getIsEditMoney() != null && order.getIsEditMoney() == 1){
+                //改过价不做处理
+            }
+            else{
+                String config = configService.selectConfigByKey("his.store");
+                com.fs.store.config.StoreConfig storeConfig = JSONUtil.toBean(config, com.fs.store.config.StoreConfig.class);
+                if(param.getPayType().equals(1)){
+                    order.setPayType("1");
+                    order.setPayMoney(order.getPayPrice());
+                    if(!"广州郑多燕".equals(cloudHostProper.getCompanyName())){
+                        order.setPayDelivery(BigDecimal.ZERO);
+                    }else {
+                        // 郑多燕单独设置支付类型
+                        order.setPayType(order.getPayPrice().compareTo(order.getTotalPrice()) == 0 ?"1":"5");
+                        log.info("支付------------实际支付金额和总金额:{},{},", order.getPayPrice(), order.getTotalPrice());
+                    }
+                }
+                else if(param.getPayType().equals(2)){
+                    order.setPayType("2");
+                    BigDecimal payMoney = order.getPayPrice().multiply(new BigDecimal(storeConfig.getPayRate())).divide(new BigDecimal(100));
+                    payMoney = new BigDecimal(payMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+                    // 如果小程序需要支付的金额小于0.01元,不能走物流代收,让走货到付款 xgb
+                    if (payMoney.compareTo(new BigDecimal("0.01")) < 0) {
+                        return R.error("物流代收计算支付金额为0,不允许选择物流代收");
+                    }
+                    order.setPayDelivery(order.getPayPrice().subtract(payMoney));
+                    order.setPayMoney(payMoney);
+                }
+                else if(param.getPayType().equals(3)){
+                    //货到付款
+                    order.setPayType("3");
+                    BigDecimal amount = redisCache.getCacheObject("orderAmount:" + order.getId());
+                    BigDecimal payMoney = BigDecimal.ZERO;
+                    if (amount != null){
+                        payMoney = amount;
+                    }
+                    //运费
+                    BigDecimal payPostage = order.getPayPostage();
+                    if (payPostage == null || payPostage.compareTo(BigDecimal.ZERO) <= 0){
+                        payPostage = storeConfig.getPayPostage();
+                        if (payPostage == null){
+                            payPostage = BigDecimal.ZERO;
+                        }
+                        order.setPayPrice(order.getPayPrice().add(payPostage));
+                    }
+                    order.setPayPostage(payPostage);
+                    payMoney = payMoney.add(payPostage);
+                    order.setPayMoney(payMoney);
+                    order.setPayDelivery(order.getPayPrice().subtract(payMoney));
+                }
+                fsStoreOrderScrmService.updateFsStoreOrder(order);
+            }
+            String payCode = SnowflakeUtil.nextIdStr();
+            if((order.getPayType().equals("1") || order.getPayType().equals("2") || order.getPayType().equals("3") || order.getPayType().equals("5")) && order.getPayMoney().compareTo(new BigDecimal(0)) > 0){
+                if (StringUtils.isBlank(param.getAppId())) {
+                    throw new IllegalArgumentException("appId不能为空");
+                }
+                FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId(param.getAppId());
+                if (fsCoursePlaySourceConfig == null) {
+                    throw new CustomException("未找到appId对应的小程序配置: " + param.getAppId());
+                }
+                Long merchantConfigId = fsCoursePlaySourceConfig.getMerchantConfigId();
+                if (merchantConfigId == null || merchantConfigId <= 0) {
+                    throw new CustomException("小程序没有配置商户信息");
+                }
+                MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
+                FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
+                FsStorePaymentScrm storePayment = new FsStorePaymentScrm();
+                storePayment.setCompanyId(order.getCompanyId());
+                storePayment.setCompanyUserId(order.getCompanyUserId());
+                storePayment.setPayMode(merchantAppConfig.getMerchantType());
+                storePayment.setStatus(0);
+                storePayment.setPayCode(payCode);
+                storePayment.setPayMoney(order.getPayMoney());
+                storePayment.setCreateTime(new Date());
+                storePayment.setPayTypeCode("weixin");
+                storePayment.setBusinessType(5); // 直播订单业务类型
+                storePayment.setRemark("直播订单支付");
+                storePayment.setOpenId(user.getRealName());
+                storePayment.setUserId(user.getUserId());
+                storePayment.setBusinessOrderId(order.getId().toString());
+                storePayment.setOrderId(order.getId());
+                storePayment.setAppId(fsCoursePlaySourceConfig.getAppid() == null ? "" : fsCoursePlaySourceConfig.getAppid());
+                storePayment.setMerConfigId(merchantAppConfig.getId());
+                storePayment.setBusinessCode(order.getOrderCode());
+                fsStorePaymentScrmMapper.insertFsStorePayment(storePayment);
+
+                if (merchantAppConfig.getMerchantType().equals("hf")){
+                    HuiFuCreateOrder o = new HuiFuCreateOrder();
+                    o.setTradeType("T_MINIAPP");
+                    o.setOpenid(user.getMaOpenId());
+                    o.setReqSeqId("live-" + storePayment.getPayCode());
+                    o.setTransAmt(storePayment.getPayMoney().toString());
+                    o.setGoodsDesc("直播订单支付");
+                    o.setAppId(param.getAppId());
+                    try {
+                        HuiFuUtils.doDiv(o, order.getCompanyId(), storePayment.getMerConfigId());
+                        //存储分账明细
+                        HuiFuUtils.saveDivItem(o, order.getOrderCode(), storePayment.getPayCode());
+                    } catch (Exception e) {
+                        log.error("-------------分账出错:{}", e.getMessage());
+                    }
+                    HuifuCreateOrderResult result = huiFuService.createOrder(o);
+                    if(result.getResp_code() != null && (result.getResp_code().equals("00000000") || result.getResp_code().equals("00000100"))){
+                        FsStorePaymentScrm mt = new FsStorePaymentScrm();
+                        mt.setPaymentId(storePayment.getPaymentId());
+                        mt.setTradeNo(result.getHf_seq_id());
+                        mt.setAppId(param.getAppId());
+                        mt.setBusinessCode(order.getOrderCode());
+                        fsStorePaymentScrmMapper.updateFsStorePayment(mt);
+                        redisCache.setCacheObject("isPaying:" + order.getId(), order.getId().toString(), 1, TimeUnit.MINUTES);
+                        Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
+                        String s = (String) resultMap.get("package");
+                        resultMap.put("packageValue", s);
+                        return R.ok().put("payType", param.getPayType()).put("result", resultMap);
+                    }
+                    else{
+                        return R.error(result.getResp_desc());
+                    }
+                }else if (merchantAppConfig.getMerchantType().equals("wx")){
+                    WxPayConfig payConfig = new WxPayConfig();
+                    payConfig.setAppId(fsCoursePlaySourceConfig.getAppid());
+                    payConfig.setMchId(fsPayConfig.getWxMchId());
+                    payConfig.setMchKey(fsPayConfig.getWxMchKey());
+                    payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
+                    payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
+                    payConfig.setKeyPath(fsPayConfig.getKeyPath());
+                    payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
+                    wxPayService.setConfig(payConfig);
+                    WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
+                    orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid
+                    orderRequest.setBody("直播订单支付");
+                    orderRequest.setOutTradeNo("live-" + storePayment.getPayCode());
+                    orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));
+                    orderRequest.setTradeType("JSAPI");
+                    orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
+                    //调用统一下单接口,获取"预支付交易会话标识"
+                    try {
+                        WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
+                        return R.ok().put("result", orderResult).put("type", "wx").put("isPay", 0).put("payType", param.getPayType());
+                    } catch (WxPayException e) {
+                        e.printStackTrace();
+                        throw new CustomException("支付失败" + e.getMessage());
+                    }
+                }
+            }
+            else if(order.getPayType().equals("3") && order.getPayMoney().compareTo(new BigDecimal(0)) <= 0){
+                //货到付款
+                IFsStoreOrderScrmService fsStoreOrderScrmService = (IFsStoreOrderScrmService) AopContext.currentProxy();
+                fsStoreOrderScrmService.payConfirm(2, order.getId(), null, null, null, null);
+                return R.ok().put("payType", param.getPayType());
+            }
+            return R.error();
+        }
+        else{
+            return R.error("用户OPENID不存在");
+        }
+    }
+
     @Override
     @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
     public R handleLiveOrderPay(LiveOrderPayParam param) {
@@ -3334,7 +3540,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
                 }
                 baseMapper.updateLiveOrder(order);
             }
-            String payCode = OrderCodeUtils.getOrderSn();
+            String payCode = SnowflakeUtil.nextIdStr();
 //            order.setOrderCode(orderCode);
 //            if(order.getPayType().equals("1")||order.getPayType().equals("2")){
             if ((order.getPayType().equals("1") || order.getPayType().equals("2") || order.getPayType().equals("3")) && order.getPayMoney().compareTo(new BigDecimal(0)) > 0) {
@@ -3768,6 +3974,252 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
         });
     }
 
+
+    @Override
+    public R createStoreOrder(LiveOrder liveOrder) {
+        String orderKey= redisCache.getCacheObject("orderKey:"+liveOrder.getOrderKey());
+        if (StringUtils.isEmpty(orderKey)) {
+            return R.error("订单已过期");
+        }
+        if (liveOrder.getLiveId() == null) return R.error("直播ID不能为空");
+        if (liveOrder.getProductId() == null) return R.error("购物商品ID不能为空");
+        if (liveOrder.getUserName() == null) return R.error("用户名不能为空");
+        if (liveOrder.getUserPhone() == null) return R.error("用户手机号不能为空");
+        if (liveOrder.getUserAddress() == null) return R.error("用户地址不能为空");
+        if (liveOrder.getTotalNum() == null) return R.error("商品数量不能为空");
+        LiveGoods goods = liveGoodsMapper.selectLiveGoodsByProductId(liveOrder.getLiveId(), liveOrder.getProductId());
+        if (goods == null) return R.error("当前商品不存在");
+        String configJson = configService.selectConfigByKey("his.store");
+        if (org.apache.commons.lang3.StringUtils.isNotEmpty(configJson)) {
+            com.fs.hisStore.config.StoreConfig config = com.alibaba.fastjson.JSON.parseObject(configJson, com.fs.hisStore.config.StoreConfig.class);
+            if (config != null && Boolean.TRUE.equals(config.getCheckStock())) {
+                CompletableFuture<Boolean> completableFuture = stockDeductService.deductStockAsync(liveOrder.getProductId(), liveOrder.getLiveId(), Integer.parseInt(liveOrder.getTotalNum()), Long.parseLong(liveOrder.getUserId()));
+                try {
+                    log.info("{}, 商品REDIS 库存扣减成功!", goods.getLiveId());
+                    if (!completableFuture.get()) {
+                        return R.error("抱歉,这款商品已被抢光,暂时无库存~");
+                    }
+                    log.info("{}, 商品REDIS 库存扣减成功!", goods.getLiveId());
+                } catch (InterruptedException e) {
+                    log.error("高并发处理失败", e);
+                    return R.error("订单创建失败:" + e.getMessage());
+                } catch (ExecutionException e) {
+                    log.error("高并发处理失败", e);
+                    return R.error("订单创建失败:" + e.getMessage());
+                }
+                if (goods.getStock() == null) return R.error("直播间商品库存不足");
+            }
+        }
+        Live live = liveService.selectLiveByLiveId(liveOrder.getLiveId());
+        if (live == null) return R.error("当前直播不存在");
+        FsStoreProductScrm fsStoreProduct = fsStoreProductService.selectFsStoreProductById(liveOrder.getProductId());
+        if (fsStoreProduct == null) return R.error("商品不存在,购买失败");
+        if (fsStoreProduct.getIsShow() == 0 || goods.getStatus() == 0) return R.error("商品已下架,购买失败");
+        if (!"1".equals(fsStoreProduct.getIsAudit())) return R.error("商品已下架,购买失败");
+        if (liveOrder.getTotalNum() == null || StringUtils.isEmpty(liveOrder.getTotalNum())) liveOrder.setTotalNum("1");
+        FsStoreProductAttrValueScrm attrValue = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueById(liveOrder.getAttrValueId());
+//        if(fsStoreProduct.getStock() < Integer.parseInt(liveOrder.getTotalNum()) || goods.getStock() < Integer.parseInt(liveOrder.getTotalNum()) || attrValue.getStock() < Integer.parseInt(liveOrder.getTotalNum())){
+//            return R.error("抱歉,这款商品已被抢光,暂时无库存~");
+//        }
+
+
+        // 检查限购
+        Long userId = Long.parseLong(liveOrder.getUserId());
+        Integer purchaseNum = Integer.parseInt(liveOrder.getTotalNum());
+        checkPurchaseLimitForLiveOrder(userId, liveOrder.getProductId(), purchaseNum);
+        LiveGoodsUploadMqVo vo = LiveGoodsUploadMqVo.builder().goodsId(goods.getGoodsId()).goodsNum(Integer.parseInt(liveOrder.getTotalNum())).build();
+        try {
+            log.info("订单提交MQ:{}", vo);
+            rocketMQTemplate.syncSend("live-goods-upload", JSON.toJSONString(vo));
+        }catch (Exception e){
+            log.error("更新库存失败!{}", vo, e);
+        }
+        // 复制到商城订单
+        FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
+        copyLiveToStore(liveOrder, storeOrder);
+
+        //判断是否是三种特定产品
+        String storeHouseCode;
+        if (fsStoreProduct.getProductId() != null && (fsStoreProduct.getProductId().equals(3168L)
+                || fsStoreProduct.getProductId().equals(3184L)
+                || fsStoreProduct.getProductId().equals(3185L))) {
+            storeHouseCode = "YDSP001";
+        } else {
+            storeHouseCode = "CQDS001";
+        }
+        storeOrder.setStoreHouseCode(storeHouseCode);
+
+        LiveUserFirstEntry liveUserFirstEntry = liveUserFirstEntryService.selectEntityByLiveIdUserId(liveOrder.getLiveId(), Long.parseLong(liveOrder.getUserId()));
+        if (ObjectUtil.isNotEmpty(liveUserFirstEntry)) {
+            storeOrder.setCompanyId(liveUserFirstEntry.getCompanyId());
+            storeOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
+            storeOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
+        }
+
+//        String orderSn = SnowflakeUtil.nextIdStr();
+        String orderSn = SnowflakeUtil.nextIdStr();
+        log.info("订单生成:" + orderSn);
+        storeOrder.setOrderCode(orderSn);
+        // 注意:bizOrderType 字段需要在 FsStoreOrderScrm 实体类中添加
+        // storeOrder.setBizOrderType(1); // 设置为直播订单
+        
+        BigDecimal payPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum()));
+        if (attrValue != null) {
+            payPrice = attrValue.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum()));
+        }
+        
+        // 计算运费
+        BigDecimal deliveryMoney = handleDeliveryMoney(liveOrder);
+        if (deliveryMoney.compareTo(BigDecimal.valueOf(-1)) == 0) {
+            return R.error("偏远地区暂不可购买");
+        }
+        payPrice = payPrice.add(deliveryMoney);
+        BigDecimal discountMoney = BigDecimal.ZERO;
+
+        //优惠券处理
+        if (liveOrder.getCouponUserId() != null) {
+            LiveCouponUser couponUser = liveCouponUserService.selectLiveCouponUserById(liveOrder.getCouponUserId());
+            if (couponUser != null && couponUser.getStatus() == 0) {
+                if (!couponUser.getUserId().toString().equals(liveOrder.getUserId())) {
+                    return R.error("非法操作");
+                }
+                if (couponUser.getUseMinPrice().compareTo(payPrice) < 1) {
+                    discountMoney = couponUser.getCouponPrice();
+                    storeOrder.setCouponId(couponUser.getId());
+                    storeOrder.setCouponPrice(couponUser.getCouponPrice());
+                    //更新优惠券状态
+                    couponUser.setStatus(1);
+                    couponUser.setUseTime(new Date());
+                    liveCouponUserService.updateLiveCouponUser(couponUser);
+                }
+            }
+        }
+        
+        // 设置商城订单字段(按照 createOrder 的逻辑)
+        storeOrder.setUserId(Long.parseLong(liveOrder.getUserId()));
+        storeOrder.setTotalNum(Long.parseLong(liveOrder.getTotalNum()));
+        storeOrder.setTotalPrice(payPrice);
+        storeOrder.setTotalPostage(deliveryMoney);
+        storeOrder.setPayPostage(deliveryMoney);
+        storeOrder.setPayDelivery(deliveryMoney);
+        storeOrder.setCouponPrice(discountMoney);
+        storeOrder.setDeductionPrice(BigDecimal.ZERO);
+        storeOrder.setPaid(0);
+        storeOrder.setPayType(StringUtils.isEmpty(liveOrder.getPayType()) ? "1" :liveOrder.getPayType());
+        storeOrder.setUseIntegral(BigDecimal.ZERO);
+        storeOrder.setBackIntegral(BigDecimal.ZERO);
+        storeOrder.setGainIntegral(BigDecimal.ZERO);
+        storeOrder.setCost(BigDecimal.ZERO);
+        storeOrder.setIsChannel(1);
+        storeOrder.setShippingType(1);
+        storeOrder.setCreateTime(new Date());
+        storeOrder.setIsPrescribe(0);
+        storeOrder.setOrderType(2);
+        
+        // 获取配置
+        String json = configService.selectConfigByKey("store.config");
+        StoreConfig config = JSONUtil.toBean(json, StoreConfig.class);
+        if (config != null && config.getServiceFee() != null) {
+            storeOrder.setServiceFee(config.getServiceFee());
+        }
+        
+        // 设置支付金额
+        storeOrder.setPayPrice(payPrice.subtract(discountMoney));
+        storeOrder.setPayMoney(storeOrder.getPayPrice());
+        
+        // 设置订单状态
+        storeOrder.setStatus(0); // 待支付
+        
+        try {
+            // 插入商城订单
+            Integer flag = fsStoreOrderScrmMapper.insertFsStoreOrder(storeOrder);
+            if (flag == 0) {
+                return R.error("订单创建失败");
+            }
+            
+            // 保存订单明细
+            FsStoreCartDTO fsStoreCartDTO = new FsStoreCartDTO();
+            fsStoreCartDTO.setProductId(fsStoreProduct.getProductId());
+            fsStoreCartDTO.setPrice(attrValue != null ? attrValue.getPrice() : fsStoreProduct.getPrice());
+            fsStoreCartDTO.setSku(attrValue != null ? (attrValue.getSku() != null ? attrValue.getSku() : "") : "");
+            fsStoreCartDTO.setProductName(fsStoreProduct.getProductName());
+            fsStoreCartDTO.setNum(Integer.parseInt(liveOrder.getTotalNum()));
+            fsStoreCartDTO.setImage(fsStoreProduct.getImage());
+
+            if (attrValue != null) {
+                fsStoreCartDTO.setBarCode(attrValue.getBarCode());
+                fsStoreCartDTO.setGroupBarCode(attrValue.getGroupBarCode());
+            }
+            
+            FsStoreOrderItemScrm orderItem = new FsStoreOrderItemScrm();
+            orderItem.setOrderId(storeOrder.getId());
+            orderItem.setOrderCode(orderSn);
+            orderItem.setProductId(fsStoreProduct.getProductId());
+            orderItem.setProductAttrValueId(attrValue != null ? attrValue.getId() : null);
+            orderItem.setJsonInfo(JSONUtil.toJsonStr(fsStoreCartDTO));
+            orderItem.setNum(Integer.parseInt(liveOrder.getTotalNum()));
+            orderItem.setIsAfterSales(0);
+            orderItem.setIsPrescribe(0);
+            fsStoreOrderItemScrmMapper.insertFsStoreOrderItem(orderItem);
+            
+            // 更新订单的 itemJson
+            List<FsStoreOrderItemScrm> listOrderItem = new ArrayList<>();
+            listOrderItem.add(orderItem);
+            String itemJson = JSONUtil.toJsonStr(listOrderItem);
+            storeOrder.setItemJson(itemJson);
+            fsStoreOrderScrmMapper.updateFsStoreOrder(storeOrder);
+            
+            // 添加订单日志
+            orderStatusService.create(storeOrder.getId(), OrderLogEnum.CREATE_ORDER.getValue(),
+                    OrderLogEnum.CREATE_ORDER.getDesc());
+            
+            // 设置直播订单的 orderId 为商城订单的 id
+
+            // 加入redis,24小时自动取消
+            String redisKey = StoreConstants.REDIS_ORDER_OUTTIME_UNPAY + storeOrder.getId();
+            if (config != null && config.getUnPayTime() != null && config.getUnPayTime() > 0) {
+                redisCache.setCacheObject(redisKey, storeOrder.getId(), config.getUnPayTime(), TimeUnit.MINUTES);
+            } else {
+                redisCache.setCacheObject(redisKey, storeOrder.getId(), 30, TimeUnit.MINUTES);
+            }
+            
+            redisCache.deleteObject("orderKey:" + liveOrder.getOrderKey());
+            //添加支付到期时间
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(storeOrder.getCreateTime());
+            if (config != null && config.getUnPayTime() != null) {
+                calendar.add(Calendar.MINUTE, config.getUnPayTime());
+            }
+            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            String payLimitTime = format.format(calendar.getTime());
+            return R.ok("下单成功").put("order", storeOrder).put("payLimitTime", payLimitTime);
+        } catch (Exception e) {
+            // 异常处理
+            log.error("订单创建失败", e);
+            return R.error("订单创建失败:" + e.getMessage());
+        }
+    }
+
+
+
+    private void copyLiveToStore(LiveOrder liveOrder, FsStoreOrderScrm storeOrder) {
+        // 复制基本信息
+        if (liveOrder.getUserId() != null) {
+            storeOrder.setUserId(Long.parseLong(liveOrder.getUserId()));
+        }
+        storeOrder.setRealName(liveOrder.getUserName());
+        storeOrder.setUserPhone(liveOrder.getUserPhone());
+        storeOrder.setUserAddress(liveOrder.getUserAddress());
+        if (liveOrder.getTotalNum() != null) {
+            storeOrder.setTotalNum(Long.parseLong(liveOrder.getTotalNum()));
+        }
+        storeOrder.setCompanyId(liveOrder.getCompanyId());
+        storeOrder.setCompanyUserId(liveOrder.getCompanyUserId());
+        storeOrder.setTuiUserId(liveOrder.getTuiUserId());
+        storeOrder.setStoreId(liveOrder.getStoreId());
+        storeOrder.setMark(liveOrder.getRemark());
+    }
+
     public void deStockIncSale(List<FsStoreCartQueryVO> cartInfo) {
         for (FsStoreCartQueryVO storeCartVO : cartInfo) {
             fsStoreProductService.decProductStock(storeCartVO.getProductId(),
@@ -3879,7 +4331,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
             liveOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
             liveOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
         }
-        String orderSn = OrderCodeUtils.getOrderSn();
+        String orderSn = SnowflakeUtil.nextIdStr();
 //        String orderSn = "123"; // todo yhq
         log.info("订单生成:" + orderSn);
         liveOrder.setOrderCode(orderSn);
@@ -4045,7 +4497,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
             liveOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
             liveOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
         }
-        String orderSn = OrderCodeUtils.getOrderSn();
+        String orderSn = SnowflakeUtil.nextIdStr();
 //        String orderSn = "123"; // todo yhq
         log.info("订单生成:" + orderSn);
         liveOrder.setOrderCode(orderSn);
@@ -4254,7 +4706,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
 
     @Override
     public R confirmOrder(LiveOrderConfirmParam param) {
-        String uuid = OrderCodeUtils.getOrderSn();
+        String uuid = SnowflakeUtil.nextIdStr();
         redisCache.setCacheObject("orderKey:" + uuid, uuid, 200, TimeUnit.MINUTES);
         return R.ok().put("orderKey", uuid);
     }

+ 1 - 8
fs-user-app/src/main/java/com/fs/app/controller/HuifuPayController.java

@@ -60,6 +60,7 @@ public class HuifuPayController {
                     }
                     break;
                 case "store":
+                case "live":
                     storeOrderService.payConfirm("",orderId[1],huiFuResult.getHf_seq_id(),"",1,huiFuResult.getOut_trans_id(),huiFuResult.getParty_order_id());
                     try {
                         HuiFuUtils.updateDivItem(orderId[1]);
@@ -115,14 +116,6 @@ public class HuifuPayController {
                         logger.error("-------分账明细回调错误{}", e.getMessage());
                     }
                     break;
-                case "live":
-                    liveOrderService.payConfirm(1,null,orderId[1], huiFuResult.getHf_seq_id(),huiFuResult.getOut_trans_id(),huiFuResult.getParty_order_id());
-//                    try {
-//                        HuiFuUtils.updateDivItem(orderId[1]);
-//                    } catch (Exception e) {
-//                        logger.error("-------分账明细回调错误{}", e.getMessage());
-//                    }
-                    break;
             }
         }
 

+ 5 - 1
fs-user-app/src/main/java/com/fs/app/controller/live/LiveAfterSalesController.java

@@ -21,6 +21,9 @@ import com.fs.live.service.ILiveOrderItemService;
 import com.fs.live.service.ILiveOrderService;
 import com.fs.live.vo.LiveAfterSalesQueryVO;
 import com.fs.live.vo.LiveOrderItemVo;
+import com.fs.hisStore.service.IFsStoreAfterSalesScrmService;
+import com.fs.hisStore.param.FsStoreAfterSalesParam;
+import com.fs.hisStore.param.FsStoreAfterSalesProductParam;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
@@ -32,6 +35,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import java.text.ParseException;
+import java.util.ArrayList;
 import java.util.List;
 
 @Slf4j
@@ -66,7 +70,7 @@ public class LiveAfterSalesController extends AppBaseController {
     @ApiOperation(value = "申请售后", notes = "申请售后")
     @RepeatSubmit
     public R applyAfterSales(@RequestBody LiveAfterSalesParam param) {
-        return storeAfterSalesService.applyForAfterSales(getUserId(), param);
+        return storeAfterSalesService.applyForStoreAfterSales(getUserId(), param);
     }
     @Login
     @PostMapping("/revoke")

+ 164 - 0
fs-user-app/src/main/java/com/fs/app/controller/live/LiveCartController.java

@@ -1,6 +1,7 @@
 package com.fs.app.controller.live;
 
 
+import com.alibaba.fastjson.JSON;
 import com.fs.app.annotation.Login;
 import com.fs.app.controller.AppBaseController;
 import com.fs.common.annotation.Log;
@@ -8,12 +9,42 @@ import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.domain.R;
 import com.fs.common.enums.BusinessType;
+import com.fs.common.exception.CustomException;
+import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.course.domain.FsCoursePlaySourceConfig;
+import com.fs.course.mapper.FsCoursePlaySourceConfigMapper;
+import com.fs.his.domain.FsPayConfig;
+import com.fs.his.domain.MerchantAppConfig;
+import com.fs.his.mapper.MerchantAppConfigMapper;
 import com.fs.live.domain.LiveCart;
 import com.fs.live.service.ILiveCartService;
 import com.fs.live.vo.LiveCartVo;
+import com.fs.hisStore.service.IFsStoreOrderScrmService;
+import com.fs.hisStore.mapper.FsStorePaymentScrmMapper;
+import com.fs.hisStore.domain.FsStoreOrderScrm;
+import com.fs.hisStore.domain.FsStorePaymentScrm;
+import com.fs.hisStore.service.IFsStorePaymentScrmService;
+import com.fs.huifuPay.domain.HuiFuQueryOrderResult;
+import com.fs.huifuPay.domain.HuiFuRefundResult;
+import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayQueryRequest;
+import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayRefundRequest;
+import com.fs.huifuPay.service.HuiFuService;
+import com.fs.his.domain.FsHfpayConfig;
+import com.fs.his.mapper.FsHfpayConfigMapper;
+import com.fs.config.cloud.CloudHostProper;
+import com.fs.common.utils.spring.SpringUtils;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
+import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
+import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult;
+import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
+import com.github.binarywang.wxpay.config.WxPayConfig;
+import com.github.binarywang.wxpay.exception.WxPayException;
+import com.github.binarywang.wxpay.service.WxPayService;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import lombok.extern.slf4j.Slf4j;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
@@ -21,7 +52,13 @@ import io.swagger.annotations.ApiParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import com.fs.common.utils.StringUtils;
 
 /**
  * 购物车Controller
@@ -29,6 +66,7 @@ import java.util.List;
  * @author fs
  * @date 2025-07-08
  */
+@Slf4j
 @RestController
 @RequestMapping("/live/liveCart")
 @Api(tags = "购物车管理")
@@ -36,6 +74,21 @@ public class LiveCartController extends AppBaseController
 {
     @Autowired
     private ILiveCartService liveCartService;
+    
+    @Autowired
+    private IFsStoreOrderScrmService fsStoreOrderScrmService;
+    
+    @Autowired
+    private FsStorePaymentScrmMapper fsStorePaymentScrmMapper;
+    
+    @Autowired
+    private HuiFuService huiFuService;
+    
+    @Autowired
+    private IFsStorePaymentScrmService fsStorePaymentScrmService;
+    
+    @Autowired
+    private CloudHostProper cloudHostProper;
 
     /**
      * 查询购物车列表
@@ -135,6 +188,117 @@ public class LiveCartController extends AppBaseController
             return R.error("操作异常");
         }
     }
+    @Autowired
+    FsCoursePlaySourceConfigMapper fsCoursePlaySourceConfigMapper;
+    @Autowired
+    MerchantAppConfigMapper merchantAppConfigMapper;
+    @Autowired
+    private WxPayService wxPayService;
+    @GetMapping("/test1")
+    public void test1() {
+        FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId("wx9bb2cd1e3afe714e");
+        if (fsCoursePlaySourceConfig == null) {
+            throw new CustomException("未找到appId对应的小程序配置: " );
+        }
+        Long merchantConfigId = fsCoursePlaySourceConfig.getMerchantConfigId();
+        if (merchantConfigId == null || merchantConfigId <= 0) {
+            throw new CustomException("小程序没有配置商户信息");
+        }
+        MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
+        FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
+        WxPayConfig payConfig = new WxPayConfig();
+        payConfig.setAppId(fsCoursePlaySourceConfig.getAppid());
+        payConfig.setMchId(fsPayConfig.getWxMchId());
+        payConfig.setMchKey(fsPayConfig.getWxMchKey());
+        payConfig.setKeyPath(fsPayConfig.getKeyPath());
+        payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
+        payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
+        wxPayService.setConfig(payConfig);
+        WxPayRefundRequest refundRequest = new WxPayRefundRequest();
+        refundRequest.setOutTradeNo("live-live-" + "2017147035307872256");
+        refundRequest.setOutRefundNo("live-live-" + "2017147035307872256");
+        refundRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen("0.10"));
+        refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen("0.10"));
+        try {
+            WxPayRefundResult refundResult = wxPayService.refund(refundRequest);
+            WxPayRefundQueryResult refundQueryResult = wxPayService.refundQuery("", refundResult.getOutTradeNo(), refundResult.getOutRefundNo(), refundResult.getRefundId());
+            if(refundQueryResult!=null&&refundQueryResult.getResultCode().equals("SUCCESS")){
+                FsStorePaymentScrm paymentMap=new FsStorePaymentScrm();
+                paymentMap.setPaymentId(41868L);
+                paymentMap.setStatus(-1);
+                paymentMap.setRefundTime(DateUtils.getNowDate());
+                paymentMap.setRefundMoney(BigDecimal.valueOf(0.1));
+                fsStorePaymentScrmMapper.updateFsStorePayment(paymentMap);
+                log.error("成功");
+            }
+            else {
+                log.error("失败");
+            }
+        } catch (WxPayException e) {
+            log.error("失败");
+        }
+    }
+
+
+    /**
+     * 确认支付(银行回调补偿)
+     */
+    @GetMapping("/confirmPay/{orderCode}")
+    @ApiOperation("确认支付")
+    @ApiImplicitParam(name = "orderCode", value = "订单号", required = true, dataType = "String", paramType = "path")
+    public R confirmPay(@PathVariable("orderCode") String orderCode)
+    {
+        try {
+            log.info("确认支付请求,订单号: {}", orderCode);
+
+            // 查询商城订单
+            FsStoreOrderScrm order = fsStoreOrderScrmService.selectFsStoreOrderByOrderCode(orderCode);
+            if (order == null) {
+                return R.error("订单不存在");
+            }
+
+            // 查询未支付的支付记录
+            List<FsStorePaymentScrm> orderPayments = fsStorePaymentScrmMapper.selectNoPayByOrderId(order.getId());
+            if (orderPayments == null || orderPayments.isEmpty()) {
+                return R.error("未找到待支付的支付记录");
+            }
+
+            // 遍历支付记录,查询汇付订单状态
+            for (FsStorePaymentScrm payment : orderPayments) {
+                V2TradePaymentScanpayQueryRequest request = new V2TradePaymentScanpayQueryRequest();
+                request.setOrgReqDate(new java.text.SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
+                request.setOrgHfSeqId(payment.getTradeNo());
+                request.setAppId(payment.getAppId());
+
+                HuiFuQueryOrderResult queryResult = null;
+                try {
+                    queryResult = huiFuService.queryOrder(request);
+                } catch (Exception e) {
+                    log.error("查询汇付订单失败,订单号: {}, 错误: {}", orderCode, e.getMessage());
+                    continue;
+                }
+
+                log.info("汇付返回结果: {}", queryResult);
+
+                // 如果支付成功,进行回调保存
+                if ("00000000".equals(queryResult.getResp_code()) && "S".equals(queryResult.getTrans_stat())) {
+                    String[] orderSplit = queryResult.getOrg_req_seq_id().split("-");
+                    if (orderSplit.length > 1) {
+                        String payCode = orderSplit[1];
+                        // 调用支付确认
+                        fsStoreOrderScrmService.payConfirm(1, null, payCode, queryResult.getOrg_hf_seq_id(),
+                                queryResult.getOut_trans_id(), queryResult.getParty_order_id());
+                        return R.ok("支付确认成功");
+                    }
+                }
+            }
+
+            return R.error("未找到已支付的记录");
+        } catch (Exception e) {
+            log.error("确认支付异常,订单号: {}", orderCode, e);
+            return R.error("确认支付失败: " + e.getMessage());
+        }
+    }
 
 
 

+ 40 - 6
fs-user-app/src/main/java/com/fs/app/controller/live/LiveOrderController.java

@@ -343,7 +343,7 @@ public class LiveOrderController extends AppBaseController
         String userId= getUserId();
         log.info("开始创建订单,登录用户id:{}", userId);
         param.setUserId(userId);
-        return orderService.createLiveOrder(param);
+        return orderService.createStoreOrder(param);
     }
     @Login
     @ApiOperation("创建订单测试")
@@ -385,16 +385,49 @@ public class LiveOrderController extends AppBaseController
         Long orderId = param.getOrderId();
         logger.info("开始处理支付请求, 订单号: {}, 支付类型: {}", orderId, param.getPayType());
         try{
-            Long existPayedRecordId = orderService.isExistPayedRecord(param.getOrderId());
-            if (null != existPayedRecordId) {
-                orderService.payConfirmPayment(existPayedRecordId);
+            // 查询商城订单
+            FsStoreOrderScrm storeOrder = fsStoreOrderScrmService.selectFsStoreOrderById(orderId);
+            if (storeOrder == null) {
+                return R.error("订单不存在");
+            }
+
+            // 检查订单状态,如果不是待支付状态,说明订单已支付
+            if (storeOrder.getStatus() != null && storeOrder.getStatus() != OrderInfoEnum.STATUS_0.getValue()) {
+                return R.error("当前订单已支付");
+            }
+
+            // 查询商城支付记录
+            List<FsStorePaymentScrm> paymentList = fsStorePaymentScrmMapper.selectFsStorePaymentByOrderId(orderId);
+            Long payCode = null;
+            if (paymentList != null && !paymentList.isEmpty()) {
+                // 检查是否有已支付的支付记录
+                for (FsStorePaymentScrm payment : paymentList) {
+                    if (payment.getStatus() != null && payment.getStatus() == 1) {
+                        V2TradePaymentScanpayQueryRequest bankRequest = new V2TradePaymentScanpayQueryRequest();
+                        bankRequest.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
+                        bankRequest.setOrgHfSeqId(payment.getTradeNo());
+                        bankRequest.setAppId(payment.getAppId());
+                        HuiFuQueryOrderResult queryOrderResult = null;
+                        try {
+                            queryOrderResult = huiFuService.queryOrder(bankRequest);
+                        } catch (Exception e) {
+                            throw new RuntimeException(e);
+                        }
+                        if ("00000000".equals(queryOrderResult.getResp_code())) {
+                            if (queryOrderResult.getTrans_stat().equals("S")) {
+                                payCode = payment.getPaymentId();
+                            }
+                        }
+                    }
+                }
+            }
+            if (payCode != null) {
                 return R.error("当前订单已支付");
             }
         } catch(Exception ex){
             log.error("校验当前订单是否存在已经支付的支付记录异常,param:{}",param,ex);
         }
 
-
         RLock lock = redissonClient.getLock(String.format(LOCK_KEY_PAY,orderId));
         R result = null;
 
@@ -405,7 +438,8 @@ public class LiveOrderController extends AppBaseController
                 return R.error("订单正在处理中,请勿重复提交");
             }
 
-            result = orderService.handleLiveOrderPay(param);
+//            result = orderService.handleLiveOrderPay(param);
+            result = orderService.handleStoreOrderPay(param);
 
         } catch (InterruptedException e) {
             logger.error("获取支付锁的过程被中断, 订单号: {}", orderId, e);

+ 1 - 8
fs-user-app/src/main/java/com/fs/app/controller/store/PayScrmController.java

@@ -81,6 +81,7 @@ public class PayScrmController {
             String[] order=o.getReq_seq_id().split("-");
             switch (order[0]) {
                 case "store":
+                case "live":
                     try {
                         HuiFuUtils.updateDivItem(order[1]);
                     } catch (Exception e) {
@@ -101,14 +102,6 @@ public class PayScrmController {
                         logger.error("-------分账明细回调错误{}", e.getMessage());
                     }
                     return storePaymentService.payConfirm(order[1],o.getHf_seq_id(),o.getOut_trans_id(),o.getParty_order_id());
-                case "live":
-                    liveOrderService.payConfirm(1,null,order[1], o.getHf_seq_id(),o.getOut_trans_id(),o.getParty_order_id());
-//                    try {
-//                        HuiFuUtils.updateDivItem(orderId[1]);
-//                    } catch (Exception e) {
-//                        logger.error("-------分账明细回调错误{}", e.getMessage());
-//                    }
-                    break;
             }
 
         }