Pārlūkot izejas kodu

app商城申请退款和小程序申请退款

xw 4 dienas atpakaļ
vecāks
revīzija
1a7ee60980

+ 10 - 0
fs-service/src/main/java/com/fs/his/mapper/MerchantAppConfigMapper.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fs.common.annotation.DataSource;
 import com.fs.common.enums.DataSourceType;
 import com.fs.his.domain.MerchantAppConfig;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 商户应用配置Mapper接口
@@ -74,4 +75,13 @@ public interface MerchantAppConfigMapper extends BaseMapper<MerchantAppConfig>{
      * @return 结果
      */
     int deleteMerchantAppConfigByIds(Long[] ids);
+
+    /**
+     * 根据appId和支付类型查询商户信息
+     *
+     * @param appId
+     * @param payType
+     * @return
+     */
+    MerchantAppConfig selectMerchantAppConfigByAppId(@Param("appId") String appId, @Param("payType") String payType);
 }

+ 7 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsStorePaymentScrmMapper.java

@@ -371,6 +371,13 @@ public interface FsStorePaymentScrmMapper
     @Select("select * from fs_store_payment_scrm where business_type=2 and order_id=#{orderId} and status=1   ")
     List<FsStorePaymentScrm> selectFsStorePaymentByOrderId(Long orderId);
 
+    /** App 发货(business_type=8),不对接小程序/ERP,仅本地订单发货 */
+    @Select("select * from fs_store_payment_scrm where business_type=8 and order_id=#{orderId} and status=1 order by payment_id desc")
+    List<FsStorePaymentScrm> selectFsStorePaymentByOrderIdBusinessType8(Long orderId);
+
+    @Select("select * from fs_store_payment_scrm where (business_type=2 or business_type=8)  and order_id=#{orderId} and status=1   ")
+    List<FsStorePaymentScrm> selectFsStorePaymentByOrderIdApp(Long orderId);
+
 
     Long selectFsStorePaymentCount(@Param("type") int type,@Param("companyId") Long companyId,@Param("companyUserId") Long companyUserId);
 

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/service/IFsStorePaymentScrmService.java

@@ -169,4 +169,6 @@ public interface IFsStorePaymentScrmService
     R oneClickShipping();
 
     R processPaymentScrm(PayOrderParam payOrderParam);
+
+    List<FsStorePaymentScrm> selectFsStorePaymentByOrderIdApp(Long id);
 }

+ 96 - 19
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreAfterSalesScrmServiceImpl.java

@@ -29,6 +29,7 @@ import com.fs.erp.dto.ErpRefundUpdateRequest;
 import com.fs.erp.mapper.FsJstAftersalePushMapper;
 import com.fs.erp.mapper.FsJstAftersalePushScrmMapper;
 import com.fs.erp.service.IErpOrderService;
+import com.fs.his.config.AppConfig;
 import com.fs.his.config.FsSysConfig;
 import com.fs.his.domain.*;
 import com.fs.his.enums.FsStoreAfterSalesStatusEnum;
@@ -70,6 +71,7 @@ import com.github.binarywang.wxpay.bean.result.WxPayRefundV3Result;
 import com.github.binarywang.wxpay.config.WxPayConfig;
 import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.WxPayService;
+import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
 import com.google.gson.Gson;
 import lombok.Synchronized;
 import org.apache.commons.beanutils.BeanUtils;
@@ -84,6 +86,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.sql.Timestamp;
 import java.text.DecimalFormat;
 import java.text.ParseException;
@@ -858,27 +861,29 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
 
         //将钱退还给用户
         if(order.getPayMoney().compareTo(BigDecimal.ZERO)==1){
-            List<FsStorePaymentScrm> payments=paymentService.selectFsStorePaymentByOrderId(order.getId());
+            List<FsStorePaymentScrm> payments=paymentService.selectFsStorePaymentByOrderIdApp(order.getId());
             if(payments!=null){
+                SysConfig sysConfig = configService.selectConfigByConfigKey("app.config");
+                AppConfig config = new Gson().fromJson(sysConfig.getConfigValue(), AppConfig.class);
 
                 for(FsStorePaymentScrm payment:payments){
+                    if (order.getPayType().equals("99")||order.getPayType().equals("5")){
+                        payment.setAppId(config.getAppId());
+                    }
                     if (StringUtils.isBlank(payment.getAppId())) {
                         throw new IllegalArgumentException("appId不能为空");
                     }
-                    FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId(payment.getAppId());
-                    if (fsCoursePlaySourceConfig == null) {
-                        throw new CustomException("未找到appId对应的小程序配置: " + payment.getAppId());
-                    }
-                    Long merchantConfigId = fsCoursePlaySourceConfig.getMerchantConfigId();
-                    if (merchantConfigId == null || merchantConfigId <= 0) {
-                        throw new CustomException("小程序没有配置商户信息");
+                    String payType = payment.getPayMode();
+                    if ("wxApp".equals(payment.getPayMode())){
+                        payType = "wx";
                     }
-                    MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
-                    FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
 
                     if (payment.getPayMode()==null||payment.getPayMode().equals("wx")){
+                        MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigByAppId(payment.getAppId(),payType);
+                        FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
+
                         WxPayConfig payConfig = new WxPayConfig();
-                        payConfig.setAppId(fsCoursePlaySourceConfig.getAppid());
+                        payConfig.setAppId(payment.getAppId());
                         payConfig.setMchId(fsPayConfig.getWxMchId());
                         payConfig.setMchKey(fsPayConfig.getWxMchKey());
                         payConfig.setKeyPath(fsPayConfig.getKeyPath());
@@ -917,20 +922,20 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
                             return R.error("退款请求失败"+e.getErrCodeDes());
                         }
                     }else if (payment.getPayMode()!=null&&payment.getPayMode().equals("hf")){
+                        MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigByAppId(payment.getAppId(),payType);
+                        FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
+
                         String huifuId="";
-                        FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
                         if (payment.getAppId() != null) {
-                            FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(payment.getAppId());
-                            if (fsHfpayConfig == null){
+                            if (merchantAppConfig == null){
                                 huifuId = fsPayConfig.getHuifuId();
                             }else {
-                                huifuId = fsHfpayConfig.getHuifuId();
+                                huifuId = merchantAppConfig.getMerchantId();
                             }
                         } else {
                             if (("益善缘".equals(cloudHostProper.getCompanyName()))) {
 
-                                FsHfpayConfig fsPayConfig2 = fsHfpayConfigMapper.selectByAppId("wx0d1a3dd485268521");
-                                huifuId = fsPayConfig2.getHuifuId();
+                                huifuId = merchantAppConfig.getMerchantId();
                             }else {
                                 huifuId=fsPayConfig.getHuifuId();
                             }
@@ -943,9 +948,17 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
                         request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
                         request.setReqSeqId("refund-"+payment.getPayCode());
                         Map<String, Object> extendInfoMap = new HashMap<>();
-                        extendInfoMap.put("org_party_order_id", payment.getBankSerialNo());
+                        if (order.getPayType().equals("99")){
+                            request.setOrdAmt(payment.getPayMoney().setScale(2, RoundingMode.DOWN).toString());
+                            extendInfoMap.put("org_req_seq_id", "store-"+payment.getPayCode());
+                        }else {
+                            request.setOrdAmt(payment.getPayMoney().toString());
+                            extendInfoMap.put("org_party_order_id", payment.getBankSerialNo());
+                            request.setAppId(payment.getAppId());
+                        }
+                        request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
+                        request.setReqSeqId("refund-"+payment.getPayCode());
                         request.setExtendInfo(extendInfoMap);
-                        request.setAppId(payment.getAppId());
                         HuiFuRefundResult refund = huiFuService.refund(request);
                         logger.info("退款:"+refund);
                         if((refund.getResp_code().equals("00000000")||refund.getResp_code().equals("00000100"))&&(refund.getTrans_stat().equals("S")||refund.getTrans_stat().equals("P"))){
@@ -957,6 +970,42 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
                             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                             return R.error(refund.getResp_desc());
                         }
+                    }else if ("wxApp".equals(payment.getPayMode()) && "wx_app".equals(payment.getPayTypeCode())) {
+                        // 处理微信退款
+                        WxPayService wxPayService = getWxPayService();
+                        WxPayRefundRequest refundRequest = new WxPayRefundRequest();
+                        refundRequest.setOutTradeNo("store-"+payment.getPayCode());
+                        refundRequest.setOutRefundNo("store-"+payment.getPayCode());
+                        refundRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
+                        refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
+                        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(payment.getPaymentId());
+                                paymentMap.setStatus(-1);
+                                paymentMap.setRefundTime(DateUtils.getNowDate());
+                                paymentMap.setRefundMoney(payment.getPayMoney());
+                                paymentService.updateFsStorePayment(paymentMap);
+                            } else {
+                                throw new CustomException("退款请求失败" + refundQueryResult.getReturnMsg());
+                            }
+
+                        } catch (WxPayException e) {
+                            throw new CustomException("退款请求失败" + e);
+                        }
+
+//                    }else if (payment.getPayMode()!=null&&payment.getPayMode().equals("cz")) {
+//                        FsStorePaymentScrm paymentMap = new FsStorePaymentScrm();
+//                        paymentMap.setPaymentId(payment.getPaymentId());
+//                        paymentMap.setStatus(-1);
+//                        paymentMap.setRefundTime(DateUtils.getNowDate());
+//                        paymentMap.setRefundMoney(payment.getPayMoney());
+//                        paymentService.updateFsStorePayment(paymentMap);
+//                        FsUserScrm fsUserScrm = userService.selectFsUserById(order.getUserId());
+//                        processStoreRechargePayment(payment,fsUserScrm,order);
+
 
                     }else {
                         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -980,6 +1029,34 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
         return R.ok();
     }
 
+    /**
+     * 封装微信参数
+     *
+     * @return
+     */
+    private WxPayService getWxPayService(){
+        SysConfig sysConfig = configService.selectConfigByConfigKey("app.config");
+        AppConfig config = new Gson().fromJson(sysConfig.getConfigValue(), AppConfig.class);
+        FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId(config.getAppId());
+        if (fsCoursePlaySourceConfig == null) {
+            throw new CustomException("未找到appId对应的小程序配置: " + config.getAppId());
+        }
+        MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
+        FsPayConfig payConfig1 = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
+
+        WxPayConfig payConfig = new WxPayConfig();
+        payConfig.setAppId(merchantAppConfig.getAppId());
+        payConfig.setMchId(payConfig1.getWxMchId());
+        payConfig.setMchKey(payConfig1.getWxMchKey());
+        payConfig.setSubAppId(StringUtils.trimToNull(null));
+        payConfig.setSubMchId(StringUtils.trimToNull(null));
+        payConfig.setKeyPath(payConfig1.getKeyPath());
+        payConfig.setNotifyUrl(payConfig1.getNotifyUrlScrm());
+        WxPayServiceImpl payService = new WxPayServiceImpl();
+        payService.setConfig(payConfig);
+        return payService;
+    }
+
     @Autowired
     private IFsStoreProductPurchaseLimitScrmService purchaseLimitService;
 

+ 210 - 31
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -17,6 +17,8 @@ import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fs.api.param.OrderListParam;
 import com.fs.api.vo.OrderListVO;
 import com.fs.api.vo.ProductListVO;
@@ -61,18 +63,16 @@ import com.fs.erp.dto.ErpRefundUpdateRequest;
 import com.fs.erp.dto.df.*;
 import com.fs.erp.mapper.FsErpFinishPushMapper;
 import com.fs.erp.service.IErpOrderService;
+import com.fs.his.config.AppConfig;
 import com.fs.his.config.FsSysConfig;
 import com.fs.his.domain.*;
-import com.fs.his.dto.FsPrescribeUsageDTO;
-import com.fs.his.dto.FsProdItemDTO;
-import com.fs.his.dto.FsStoreOrderAmountScrmStatsQueryDto;
-import com.fs.his.dto.FsStoreOrderItemDTO;
-import com.fs.his.enums.FsStoreOrderLogEnum;
-import com.fs.his.enums.FsStoreOrderStatusEnum;
-import com.fs.his.enums.FsUserIntegralLogTypeEnum;
+import com.fs.his.dto.*;
+import com.fs.his.enums.*;
 import com.fs.his.mapper.*;
+import com.fs.his.param.FsIntegralOrderDoPayParam;
 import com.fs.his.param.FsStoreOrderSalesParam;
 import com.fs.his.param.FsUserAddIntegralTemplateParam;
+import com.fs.his.param.PayOrderParam;
 import com.fs.his.service.IFsPrescribeService;
 import com.fs.his.service.IFsUserIntegralLogsService;
 import com.fs.his.service.IFsUserWatchService;
@@ -88,7 +88,17 @@ import com.fs.hisStore.config.StoreIntegralConfig;
 import com.fs.hisStore.constants.StoreConstants;
 import com.fs.hisStore.domain.*;
 import com.fs.hisStore.dto.*;
+import com.fs.hisStore.dto.ErpRemarkDTO;
+import com.fs.hisStore.dto.ExpressDataDTO;
+import com.fs.hisStore.dto.ExpressInfoDTO;
+import com.fs.hisStore.dto.ExpressNotifyDTO;
+import com.fs.hisStore.dto.ExpressResultDTO;
+import com.fs.hisStore.dto.FsStoreCartDTO;
+import com.fs.hisStore.dto.StoreOrderExpressExportDTO;
+import com.fs.hisStore.dto.StorePackageProductDTO;
+import com.fs.hisStore.dto.StoreProductGroupDTO;
 import com.fs.hisStore.enums.*;
+import com.fs.hisStore.enums.ShipperCodeEnum;
 import com.fs.hisStore.mapper.*;
 import com.fs.hisStore.param.*;
 import com.fs.hisStore.service.*;
@@ -109,9 +119,12 @@ import com.fs.huifuPay.domain.HuifuCreateOrderResult;
 import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayRefundRequest;
 import com.fs.huifuPay.sdk.opps.core.utils.HuiFuUtils;
 import com.fs.huifuPay.service.HuiFuService;
+import com.fs.live.domain.LiveOrder;
+import com.fs.live.mapper.LiveOrderMapper;
 import com.fs.pay.pay.dto.OrderQueryDTO;
 import com.fs.pay.pay.dto.RefundDTO;
 import com.fs.pay.service.IPayService;
+import com.fs.system.domain.SysConfig;
 import com.fs.system.mapper.SysConfigMapper;
 import com.fs.system.service.ISysConfigService;
 import com.fs.system.service.ISysDictTypeService;
@@ -126,14 +139,18 @@ import com.fs.wx.order.utils.WxShippingErrorHandler;
 import com.fs.ybPay.domain.OrderResult;
 import com.fs.ybPay.domain.RefundResult;
 import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
+import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
 import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request;
 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.bean.result.WxPayRefundV3Result;
 import com.github.binarywang.wxpay.config.WxPayConfig;
 import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.WxPayService;
+ import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
 import com.google.common.base.Joiner;
+    import com.google.gson.Gson;
 import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxErrorException;
@@ -157,6 +174,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import javax.annotation.PostConstruct;
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.nio.charset.Charset;
 import java.sql.Timestamp;
 import java.text.ParseException;
@@ -295,6 +313,8 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
     private WxPayService wxPayService;
     @Autowired
     private WxPayProperties wxPayProperties;
+    @Autowired
+    private IFsStorePaymentScrmService storePaymentService;
 
     @Autowired
     private FsErpFinishPushMapper fsErpFinishPushMapper;
@@ -2608,24 +2628,26 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             //货到付款
         } else {
             //将钱退还给用户
-            List<FsStorePaymentScrm> payments = paymentService.selectFsStorePaymentByOrderId(order.getId());
+            List<FsStorePaymentScrm> payments = paymentService.selectFsStorePaymentByOrderIdApp(order.getId());
             if (payments != null) {
+                 SysConfig sysConfig = configService.selectConfigByConfigKey("app.config");
+                 AppConfig config = new Gson().fromJson(sysConfig.getConfigValue(), AppConfig.class);
                 for (FsStorePaymentScrm payment : payments) {
+                    if (order.getPayType().equals("99")){
+                        payment.setAppId(config.getAppId());
+                    }
                     if (StringUtils.isBlank(payment.getAppId())) {
                         throw new IllegalArgumentException("appId不能为空");
                     }
-                    FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId(payment.getAppId());
-                    if (fsCoursePlaySourceConfig == null) {
-                        throw new CustomException("未找到appId对应的小程序配置: " + payment.getAppId());
-                    }
-                    Long merchantConfigId = fsCoursePlaySourceConfig.getMerchantConfigId();
-                    if (merchantConfigId == null || merchantConfigId <= 0) {
-                        throw new CustomException("小程序没有配置商户信息");
+                    String payType = payment.getPayMode();
+                    if ("wxApp".equals(payment.getPayMode())){
+                        payType = "wx";
                     }
-                    MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
-                    FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
 
                     if (payment.getPayMode() == null || payment.getPayMode().equals("wx")) {
+
+                        MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigByAppId(payment.getAppId(),payType);
+                        FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
                         WxPayConfig payConfig = new WxPayConfig();
                         payConfig.setAppId(payment.getAppId());
                         payConfig.setMchId(fsPayConfig.getWxMchId());
@@ -2666,20 +2688,20 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                             return R.error("退款请求失败" + e.getErrCodeDes());
                         }
                     } else if (payment.getPayMode() != null && payment.getPayMode().equals("hf")) {
+                        MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigByAppId(payment.getAppId(),payType);
+                        FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
+
                         String huifuId="";
-                        FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
                         if (payment.getAppId() != null) {
-                            FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(payment.getAppId());
-                            if (fsHfpayConfig == null){
+                            if (merchantAppConfig == null){
                                 huifuId = fsPayConfig.getHuifuId();
                             }else {
-                                huifuId = fsHfpayConfig.getHuifuId();
+                                huifuId = merchantAppConfig.getMerchantId();
                             }
                         } else {
                             if (("益善缘".equals(cloudHostProper.getCompanyName()))) {
 
-                                FsHfpayConfig fsPayConfig2 = fsHfpayConfigMapper.selectByAppId("wx0d1a3dd485268521");
-                                huifuId = fsPayConfig2.getHuifuId();
+                                huifuId = merchantAppConfig.getMerchantId();
                             }else {
                                 huifuId=fsPayConfig.getHuifuId();
                             }
@@ -2689,12 +2711,18 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                         V2TradePaymentScanpayRefundRequest request = new V2TradePaymentScanpayRefundRequest();
                         request.setOrgHfSeqId(payment.getTradeNo());
                         request.setHuifuId(huifuId);
-                        request.setOrdAmt(payment.getPayMoney().toString());
+                        Map<String, Object> extendInfoMap = new HashMap<>();
+                        if (order.getPayType().equals("99")){
+                            request.setOrdAmt(payment.getPayMoney().setScale(2, RoundingMode.DOWN).toString());
+                            extendInfoMap.put("org_req_seq_id", "store-"+payment.getPayCode());
+                        }else {
+                            request.setOrdAmt(payment.getPayMoney().toString());
+                            extendInfoMap.put("org_party_order_id", payment.getBankSerialNo());
+                            request.setAppId(payment.getAppId());
+                        }
+
                         request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
                         request.setReqSeqId("refund-" + payment.getPayCode());
-                        Map<String, Object> extendInfoMap = new HashMap<>();
-                        extendInfoMap.put("org_party_order_id", payment.getBankSerialNo());
-                        request.setExtendInfo(extendInfoMap);
                         request.setAppId(payment.getAppId());
                         HuiFuRefundResult refund = huiFuService.refund(request);
                         logger.info("退款:" + refund);
@@ -2707,7 +2735,41 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                             return R.error(refund.getResp_desc());
                         }
+                    }else if ("wxApp".equals(payment.getPayMode()) && "wx_app".equals(payment.getPayTypeCode())) {
+                        // 处理微信退款
+                        WxPayService wxPayService = getWxPayService();
+                        WxPayRefundRequest refundRequest = new WxPayRefundRequest();
+                        refundRequest.setOutTradeNo("store-"+payment.getPayCode());
+                        refundRequest.setOutRefundNo("store-"+payment.getPayCode());
+                        refundRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
+                        refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
+                        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(payment.getPaymentId());
+                                paymentMap.setStatus(-1);
+                                paymentMap.setRefundTime(DateUtils.getNowDate());
+                                paymentMap.setRefundMoney(payment.getPayMoney());
+                                paymentService.updateFsStorePayment(paymentMap);
+                            } else {
+                                throw new CustomException("退款请求失败" + refundQueryResult.getReturnMsg());
+                            }
+
+                        } catch (WxPayException e) {
+                            throw new CustomException("退款请求失败" + e);
+                        }
 
+//                    }else if (payment.getPayMode()!=null&&payment.getPayMode().equals("cz")) {
+//                        FsStorePaymentScrm paymentMap = new FsStorePaymentScrm();
+//                        paymentMap.setPaymentId(payment.getPaymentId());
+//                        paymentMap.setStatus(-1);
+//                        paymentMap.setRefundTime(DateUtils.getNowDate());
+//                        paymentMap.setRefundMoney(payment.getPayMoney());
+//                        paymentService.updateFsStorePayment(paymentMap);
+//                        FsUserScrm fsUserScrm = userService.selectFsUserById(order.getUserId());
+//                        processStoreRechargePayment(payment,fsUserScrm,order);
                     } else {
                         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                         return R.error("支付类型异常");
@@ -2793,6 +2855,34 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
 
     }
 
+    /**
+     * 封装微信参数
+     *
+     * @return
+     */
+    private WxPayService getWxPayService(){
+        SysConfig sysConfig = configService.selectConfigByConfigKey("app.config");
+        AppConfig config = new Gson().fromJson(sysConfig.getConfigValue(), AppConfig.class);
+        FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId(config.getAppId());
+        if (fsCoursePlaySourceConfig == null) {
+            throw new CustomException("未找到appId对应的小程序配置: " + config.getAppId());
+        }
+        MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
+        FsPayConfig payConfig1 = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
+
+        WxPayConfig payConfig = new WxPayConfig();
+        payConfig.setAppId(merchantAppConfig.getAppId());
+        payConfig.setMchId(payConfig1.getWxMchId());
+        payConfig.setMchKey(payConfig1.getWxMchKey());
+        payConfig.setSubAppId(StringUtils.trimToNull(null));
+        payConfig.setSubMchId(StringUtils.trimToNull(null));
+        payConfig.setKeyPath(payConfig1.getKeyPath());
+        payConfig.setNotifyUrl(payConfig1.getNotifyUrlScrm());
+        WxPayServiceImpl payService = new WxPayServiceImpl();
+        payService.setConfig(payConfig);
+        return payService;
+    }
+
     @Override
     public R updateExpress(FsStoreOrderExpressEditParam param) {
         FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderById(param.getOrderId());
@@ -4644,14 +4734,21 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                         .add(vo);
             }
 
-            // 按小程序appId分组订单(从支付记录中获取)
+            // 按小程序appId分组订单(从支付记录中获取);business_type=8 为 App 发货,跳过小程序仅更新本地已发货
             Map<String, List<FsOrderDeliveryNoteDTO>> ordersByAppId = new HashMap<>();
+            List<FsOrderDeliveryNoteDTO> appDeliveryBusinessType8List = new ArrayList<>();
             for (FsOrderDeliveryNoteDTO dto : successList) {
                 String orderNumber = dto.getOrderNumber();
                 // 通过订单号查询订单
                 FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderByOrderCode(orderNumber);
                 if (order != null) {
-                    // 查询订单的支付记录获取appId
+                    List<FsStorePaymentScrm> appDeliveryPayments = fsStorePaymentMapper.selectFsStorePaymentByOrderIdBusinessType8(order.getId());
+                    if (!appDeliveryPayments.isEmpty()) {
+                        appDeliveryBusinessType8List.add(dto);
+                        log.debug("订单号: {} 为 business_type=8(App发货),跳过小程序发货流程", orderNumber);
+                        continue;
+                    }
+                    // 查询订单的支付记录获取appId(business_type=2)
                     List<FsStorePaymentScrm> paymentList = fsStorePaymentMapper.selectFsStorePaymentByOrderId(order.getId());
                     if (!paymentList.isEmpty() && paymentList.get(0).getAppId() != null) {
                         String orderAppId = paymentList.get(0).getAppId();
@@ -4669,11 +4766,13 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                 }
             }
 
-            if (ordersByAppId.isEmpty()) {
+            if (ordersByAppId.isEmpty() && appDeliveryBusinessType8List.isEmpty()) {
                 return R.error("所有订单都无法获取对应的小程序appId,请确保订单已支付");
             }
 
-            log.info("导入订单涉及{}个小程序,开始分组处理", ordersByAppId.size());
+            if (!ordersByAppId.isEmpty()) {
+                log.info("导入订单涉及{}个小程序,开始分组处理", ordersByAppId.size());
+            }
 
             // 按小程序分组批量上传微信发货信息
             for (Map.Entry<String, List<FsOrderDeliveryNoteDTO>> entry : ordersByAppId.entrySet()) {
@@ -4728,6 +4827,25 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                 }
             }
 
+            // business_type=8:仅更新本地订单物流与已发货状态,不上传微信小程序
+            if (!appDeliveryBusinessType8List.isEmpty()) {
+                log.info("business_type=8(App发货) 订单共{}条,跳过小程序,仅更新本地发货信息", appDeliveryBusinessType8List.size());
+            }
+            for (FsOrderDeliveryNoteDTO dto : appDeliveryBusinessType8List) {
+                int rowNum = successList.indexOf(dto) + 2;
+                if (StringUtils.isEmpty(dto.getOrderNumber())) {
+                    continue;
+                }
+                String deliverySn = expressDeliveryMap.get(dto.getDeliveryName());
+                if (deliverySn == null) {
+                    result.addFailure(rowNum, dto.getOrderNumber(), dto.getDeliveryId(), "物流公司名称异常");
+                    continue;
+                }
+                dto.setDeliverySn(deliverySn);
+                updateList.add(dto);
+                result.addSuccess();
+            }
+
             //批量更新数据
             if (!updateList.isEmpty()) {
                 batchUpdateDeliveryNotes(updateList);
@@ -6321,4 +6439,65 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             return WxShippingErrorHandler.handleExceptionErrorWithDetail(e.getMessage(), dto.getOrderNumber());
         }
     }
+
+
+    /**
+     * 预支付
+     */
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public R payment(FsIntegralOrderDoPayParam param, PaymentMethodEnum paymentMethod) {
+        FsStoreOrderScrm order = buildPayment(param);
+        if (Objects.isNull(order) || !order.getStatus().equals(0)
+                || order.getPayMoney().compareTo(BigDecimal.ZERO) <= 0){
+            return R.error("非法操作");
+        }
+
+        PayOrderParam payOrderParam = buildPayOrderParam(paymentMethod, order);
+        return storePaymentService.processPaymentScrm(payOrderParam);
+    }
+
+    @Autowired
+    private LiveOrderMapper liveOrderMapper;
+
+    public FsStoreOrderScrm buildPayment(FsIntegralOrderDoPayParam param){
+        if(param.getType().equals("live")){
+            LiveOrder liveOrder = liveOrderMapper.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
+            if (ObjectUtil.isNotEmpty(liveOrder)){
+                FsStoreOrderScrm orderScrm = new FsStoreOrderScrm();
+                BeanUtils.copyProperties(liveOrder,orderScrm);
+                orderScrm.setId(liveOrder.getOrderId());
+                orderScrm.setUserId(Long.valueOf(liveOrder.getUserId()));
+                orderScrm.setIsLive(true);
+                return orderScrm;
+            }
+        }
+        if (param.getType().equals("store")){
+            FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderById(param.getOrderId());
+            if (ObjectUtil.isNotEmpty(order)){
+                return order;
+            }
+        }
+
+        return null;
+    }
+    /**
+     * 构建参数
+     */
+    private static PayOrderParam buildPayOrderParam(PaymentMethodEnum paymentMethod, FsStoreOrderScrm order) {
+        PayOrderParam payOrderParam = new PayOrderParam();
+        payOrderParam.setOrderId(order.getId());
+        payOrderParam.setOrderCode(order.getOrderCode());
+        payOrderParam.setAmount(order.getPayMoney());
+        payOrderParam.setUserId(order.getUserId());
+        payOrderParam.setCompanyId(order.getCompanyId());
+        payOrderParam.setCompanyUserId(order.getCompanyUserId());
+        payOrderParam.setPaymentMethod(paymentMethod);
+        if (order.getIsLive()){
+            payOrderParam.setBusinessType(BusinessTypeEnum.LIVE_ORDER);
+        }else {
+            payOrderParam.setBusinessType(BusinessTypeEnum.ORDER_ORDER);
+        }
+        return payOrderParam;
+    }
 }

+ 5 - 0
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStorePaymentScrmServiceImpl.java

@@ -1522,6 +1522,11 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
         return createThirdPartyPaymentScrm(payConfig, storePayment, user, payOrderParam);
     }
 
+    @Override
+    public List<FsStorePaymentScrm> selectFsStorePaymentByOrderIdApp(Long id) {
+        return fsStorePaymentMapper.selectFsStorePaymentByOrderIdApp(id);
+    }
+
     /**
      * 判断是否为储值支付
      * @param payOrderParam 支付订单参数

+ 7 - 1
fs-service/src/main/java/com/fs/huifuPay/service/impl/HuiFuServiceImpl.java

@@ -2,6 +2,7 @@ package com.fs.huifuPay.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.StringUtils;
 import com.fs.common.utils.spring.SpringUtils;
@@ -158,12 +159,17 @@ public class HuiFuServiceImpl implements HuiFuService {
     public HuiFuRefundResult refund(V2TradePaymentScanpayRefundRequest request) {
         HuiFuRefundResult huiFuRefundResult=null;
         try {
-            doInit(getMerConfig(request.getAppId()));
+            if(ObjectUtils.isNotNull(request.getAppId())){
+                doInit(getMerConfig(request.getAppId()));
+            } else {
+                doInit(getMerConfig());
+            }
             request.setReqDate(DateTools.getCurrentDateYYYYMMDD());
             Map<String, Object> response = doExecute(request);
             String jsonString = JSONObject.toJSONString(response);
             huiFuRefundResult = JSON.parseObject(jsonString, HuiFuRefundResult.class);
         } catch (Exception e){
+            e.printStackTrace();
             throw  new CustomException("退款创建失败");
         }
         return huiFuRefundResult;

+ 9 - 0
fs-service/src/main/resources/mapper/MerchantAppConfigMapper.xml

@@ -67,6 +67,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectMerchantAppConfigVo"/>
         where id = #{id}
     </select>
+    <select id="selectMerchantAppConfigByAppId" resultMap="MerchantAppConfigResult">
+        select a.id, a.merchant_type, a.app_id, a.merchant_id, a.callback_url,
+               a.data_json, a.created_time, a.updated_time, a.is_deleted,
+               a.created_by, a.updated_by
+        from merchant_app_config a
+                 left join fs_course_play_source_config fcpsc on a.id = fcpsc.merchant_config_id
+        where a.merchant_type = #{payType}
+          and fcpsc.appid like CONCAT('%', #{appId}, '%')
+    </select>
 
     <insert id="insertMerchantAppConfig" parameterType="MerchantAppConfig" useGeneratedKeys="true" keyProperty="id">
         insert into merchant_app_config