Browse Source

商城代码修改

xgb 3 ngày trước cách đây
mục cha
commit
2f4b563624

+ 3 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsStorePaymentPayParam.java

@@ -22,4 +22,7 @@ public class FsStorePaymentPayParam implements Serializable
     private String code;
 
     private String appId;
+
+    // 租户编码
+    private String tenantCode;
 }

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

@@ -4522,7 +4522,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                     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());
+                    payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm()+"/"+request.getHeader(HEADER_TENANT_CODE));// 加上租户的编码
                     wxPayService.setConfig(payConfig);
                     WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
                     orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid

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

@@ -958,7 +958,7 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
                 payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
                 payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
                 payConfig.setKeyPath(null);
-                payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
+                payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm()+"/"+param.getTenantCode());
                 wxPayService.setConfig(payConfig);
                 WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
                 orderRequest.setOpenid(openId);//公众号支付提供用户openid

+ 7 - 1
fs-user-app/src/main/java/com/fs/app/controller/store/PaymentScrmController.java

@@ -19,6 +19,7 @@ import com.fs.wx.miniapp.config.WxMaProperties;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import me.chanjar.weixin.common.error.WxErrorException;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -74,9 +75,14 @@ public class PaymentScrmController extends AppBaseController {
     @ApiOperation("收款订单支付")
     @PostMapping("/paymentByWxaCode")
     @RepeatSubmit
-    public R paymentByWxaCode(@Validated @RequestBody FsStorePaymentPayParam payment)
+    public R paymentByWxaCode(@Validated @RequestBody FsStorePaymentPayParam payment, HttpServletRequest request)
     {
         payment.setUserId(Long.parseLong(getUserId()));
+        payment.setTenantCode(request.getHeader("X-Tenant-Code"));
+        if (StringUtils.isEmpty(payment.getTenantCode())){
+            logger.info("未配置租户");
+            return R.error("未配置租户");
+        }
         return paymentService.paymentByWxaCode(payment);
     }
 

+ 35 - 21
fs-user-app/src/main/java/com/fs/app/controller/store/WxPayScrmController.java

@@ -1,13 +1,16 @@
 package com.fs.app.controller.store;
 
 
+import com.fs.common.config.RedisTenantContext;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.R;
-import com.fs.course.service.IFsCourseRedPacketLogService;
+import com.fs.framework.datasource.DynamicDataSourceContextHolder;
+import com.fs.framework.datasource.TenantDataSourceManager;
 import com.fs.hisStore.param.WxSendRedPacketParam;
 import com.fs.hisStore.service.*;
 import com.fs.sop.service.ISopUserLogsInfoService;
-import com.fs.system.service.ISysConfigService;
+import com.fs.tenant.domain.TenantInfo;
+import com.fs.tenant.service.TenantInfoService;
 import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
 import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
 import com.github.binarywang.wxpay.service.WxPayService;
@@ -17,8 +20,6 @@ import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationEventPublisher;
-import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
@@ -36,22 +37,15 @@ public class WxPayScrmController {
     @Autowired
     private IFsStoreOrderScrmService orderService;
     @Autowired
-    private IFsStoreOrderStatusScrmService orderStatusService;
-    @Autowired
-    private IFsUserBillScrmService billService;
-    @Autowired
-    private IFsUserScrmService userService;
-    @Autowired
-    private ApplicationEventPublisher publisher;
-    @Autowired
     private IFsStorePaymentScrmService storePaymentService;
 
     @Autowired
-    private IFsCourseRedPacketLogService redPacketLogService;
+    private ISopUserLogsInfoService iSopUserLogsInfoService;
     @Autowired
-    private ISysConfigService configService;
+    private TenantInfoService tenantInfoService;
     @Autowired
-    private ISopUserLogsInfoService iSopUserLogsInfoService;
+    private TenantDataSourceManager tenantDataSourceManager;
+
 
     /**
      * 微信回调
@@ -61,21 +55,34 @@ public class WxPayScrmController {
      * @throws Exception
      */
     @ApiOperation("微信回调")
-    @PostMapping("/wxPayNotify")
-    @Transactional
-    public String wxPayNotify(HttpServletRequest request) throws Exception {
+    @PostMapping({"/wxPayNotify", "/wxPayNotify/{tenantCode}"})
+    public String wxPayNotify(@PathVariable(value = "tenantCode", required = false) String tenantCode,
+                              HttpServletRequest request) throws Exception {
         logger.info("====================进入微信回调接口===================");
+        boolean switched = false;
         try {
+            if (tenantCode != null && !tenantCode.isEmpty()) {
+                TenantInfo tenant = tenantInfoService.selectTenantInfoByCode(tenantCode);
+                if (tenant != null) {
+                    tenantDataSourceManager.switchTenant(tenant);
+                    RedisTenantContext.setTenantId(tenant.getId());
+                    switched = true;
+                    logger.info("微信回调切库成功: tenantCode={}, tenantId={}", tenantCode, tenant.getId());
+                } else {
+                    logger.error("微信回调切库失败-租户不存在: tenantCode={}", tenantCode);
+                    return WxPayNotifyResponse.fail("租户不存在");
+                }
+            }
+
             String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
             logger.info("xml result:{}", xmlResult);
             WxPayOrderNotifyResult result = wxPayService.parseOrderNotifyResult(xmlResult,"MD5");
-            System.out.println(result.getReturnCode());
+//            WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlResult);
+//            logger.info("微信回调结果:{}", result);
             if("SUCCESS".equals(result.getReturnCode())){
                 //订单号
                 String outtradeno = result.getOutTradeNo();
                 String tradeNo = result.getTransactionId();
-                System.out.println(outtradeno);
-                System.out.println(tradeNo);
                 String[] orderId=outtradeno.split("-");
                 switch (orderId[0]){
                     case "store":
@@ -96,6 +103,13 @@ public class WxPayScrmController {
         } catch (Exception e) {
             logger.error("微信回调结果异常,异常原因{}", e.getMessage());
             return WxPayNotifyResponse.fail(e.getMessage());
+        } finally {
+            if (switched) {
+                RedisTenantContext.clear();
+                tenantDataSourceManager.clear();
+                DynamicDataSourceContextHolder.clearDataSourceType();
+                logger.info("微信回调清理租户上下文完成");
+            }
         }
     }