Przeglądaj źródła

二维码付款多小程序支付

zyp 1 tydzień temu
rodzic
commit
53ff73681e

+ 6 - 0
fs-service/src/main/java/com/fs/hisStore/service/IFsUserScrmService.java

@@ -1,11 +1,14 @@
 package com.fs.hisStore.service;
 
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.domain.ResponseResult;
 import com.fs.common.core.page.TableDataInfo;
+import com.fs.common.param.LoginMaWxParam;
 import com.fs.course.param.newfs.FsUserCourseBeMemberParam;
 import com.fs.course.vo.newfs.FsCourseAnalysisVO;
 import com.fs.his.domain.FsStoreProductAttrValue;
+import com.fs.his.domain.FsUser;
 import com.fs.his.vo.OptionsVO;
 import com.fs.hisStore.domain.FsStoreProductAttrValueScrm;
 import com.fs.live.domain.LiveOrder;
@@ -286,4 +289,7 @@ public interface IFsUserScrmService
     void addTuiLiveMoney(LiveOrder order, List<FsStoreProductAttrValueScrm> productAttrValues);
 
     void subLiveTuiMoney(LiveOrder liveOrder);
+
+    void handleFsUserWx(FsUserScrm user, LoginMaWxParam param, WxMaJscode2SessionResult session);
+
 }

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

@@ -13,6 +13,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.common.annotation.DataScope;
 import com.fs.common.config.FSSysConfig;
 import com.fs.common.core.domain.R;
@@ -34,6 +36,7 @@ import com.fs.course.service.IFsCourseRedPacketLogService;
 import com.fs.his.config.FsSysConfig;
 import com.fs.his.domain.FsUser;
 import com.fs.his.domain.FsUserWx;
+import com.fs.his.mapper.FsUserWxMapper;
 import com.fs.his.service.IFsUserService;
 import com.fs.his.service.IFsUserWxService;
 import com.fs.his.utils.ConfigUtil;
@@ -851,6 +854,8 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
 
     @Autowired
     private IFsUserService fsUserService;
+    @Autowired
+    private FsUserWxMapper fsUserWxMapper;
 
     @Override
     public R paymentByWxaCode(FsStorePaymentPayParam param) {
@@ -874,6 +879,26 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
 
         //生成支付流水
         String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
+
+        //获取用户openid
+        String openId = null;
+        String appId = param.getAppId();
+
+        //查询fs_user_wx的openId
+        Wrapper<FsUserWx> queryWrapper = Wrappers.<FsUserWx>lambdaQuery()
+                .eq(FsUserWx::getFsUserId, param.getUserId())
+                .eq(FsUserWx::getAppId, appId);
+        FsUserWx fsUserWx = fsUserWxMapper.selectOne(queryWrapper);
+        if (fsUserWx != null) {
+            openId = fsUserWx.getOpenId();
+        }else {
+            openId = user.getMaOpenId();
+        }
+
+        if (StringUtils.isEmpty(openId)){
+            return R.error("openId参数错误!");
+        }
+
         FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
         storePayment.setCompanyId(param.getCompanyId());
         //判断销售是否存在
@@ -887,7 +912,7 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
         storePayment.setPayTypeCode("weixin");
         storePayment.setBusinessType(1);//微信收款
         storePayment.setRemark(StringUtils.isNotBlank(param.getRemark()) ? param.getRemark() : "商城收款订单支付");
-        storePayment.setOpenId(user.getMaOpenId());
+        storePayment.setOpenId(openId);
         storePayment.setUserId(user.getUserId());
         storePayment.setPayMode("hf");//目前微信收款仅支持汇付
         storePayment.setAppId(param.getAppId());
@@ -896,7 +921,7 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
         //汇付支付
         HuiFuCreateOrder o = new HuiFuCreateOrder();
         o.setTradeType("T_MINIAPP");
-        o.setOpenid(user.getMaOpenId());
+        o.setOpenid(openId);
         o.setReqSeqId("payment-"+storePayment.getPayCode());
         o.setTransAmt(storePayment.getPayMoney().toString());
         o.setGoodsDesc("商城订单支付");

+ 23 - 0
fs-service/src/main/java/com/fs/hisStore/service/impl/FsUserScrmServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fs.hisStore.service.impl;
 
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
@@ -8,6 +9,7 @@ import com.fs.common.core.domain.R;
 import com.fs.common.core.domain.ResponseResult;
 import com.fs.common.core.domain.entity.SysDictData;
 import com.fs.common.core.page.TableDataInfo;
+import com.fs.common.param.LoginMaWxParam;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.DictUtils;
 import com.fs.common.utils.ParseUtils;
@@ -30,7 +32,10 @@ import com.fs.course.param.newfs.UserCourseVideoPageParam;
 import com.fs.course.vo.newfs.FsCourseAnalysisCountVO;
 import com.fs.course.vo.newfs.FsCourseAnalysisVO;
 import com.fs.course.vo.newfs.FsUserCourseVideoPageListVO;
+import com.fs.his.domain.FsUser;
 import com.fs.his.domain.FsUserBill;
+import com.fs.his.domain.FsUserWx;
+import com.fs.his.service.IFsUserWxService;
 import com.fs.his.vo.OptionsVO;
 import com.fs.live.domain.LiveOrder;
 import com.fs.qw.param.QwFsUserParam;
@@ -1130,4 +1135,22 @@ public class FsUserScrmServiceImpl implements IFsUserScrmService
     public List<OptionsVO> selectUserListByMap(Map<String, Object> params) {
         return fsUserMapper.selectUserListByMap(params);
     }
+
+
+    @Autowired
+    private IFsUserWxService fsUserWxService;
+
+    @Override
+    public void handleFsUserWx(FsUserScrm user, LoginMaWxParam param, WxMaJscode2SessionResult session) {
+        FsUserWx fsUserWx = new FsUserWx();
+        fsUserWx.setType(1);
+        fsUserWx.setFsUserId(user.getUserId());
+        fsUserWx.setAppId(param.getAppId());
+        fsUserWx.setOpenId(session.getOpenid());
+        fsUserWx.setUnionId(session.getUnionid() != null ? session.getUnionid() : null);
+        fsUserWx.setCreateTime(new Date());
+        fsUserWx.setUpdateTime(new Date());
+        fsUserWxService.saveOrUpdateByUniqueKey(fsUserWx);
+        log.info("zyp \n 【更新或插入用户与小程序{}的绑定关系】:{}", param.getAppId(), user.getUserId());
+    }
 }

+ 9 - 3
fs-user-app/src/main/java/com/fs/app/controller/store/WxUserScrmController.java

@@ -11,6 +11,7 @@ import com.fs.app.utils.JwtUtils;
 import com.fs.common.OrderUtils;
 import com.fs.common.core.domain.R;
 import com.fs.common.exception.CustomException;
+import com.fs.common.param.LoginMaWxParam;
 import com.fs.common.utils.IpUtil;
 import com.fs.core.config.WxMaConfiguration;
 import com.fs.core.config.WxMpProperties;
@@ -358,6 +359,11 @@ public class WxUserScrmController extends AppBaseController {
                 }
                 userService.updateFsUser(userMap);
             }
+            LoginMaWxParam loginMaWxParam = new LoginMaWxParam();
+            loginMaWxParam.setAppId(param.getAppId());
+            loginMaWxParam.setCompanyId(user.getCompanyId());
+
+            userService.handleFsUserWx(user,loginMaWxParam,session);
             String token = jwtUtils.generateToken(user.getUserId());
             return R.ok("登录成功").put("token",token).put("user", user);
         } catch (WxErrorException e) {
@@ -520,12 +526,12 @@ public class WxUserScrmController extends AppBaseController {
         if (StringUtils.isEmpty(newAppId)) {
             return currentAppIds == null ? "" : currentAppIds;
         }
-        
+
         // 如果当前appId为空,直接返回新appId
         if (StringUtils.isEmpty(currentAppIds)) {
             return newAppId;
         }
-        
+
         // 检查是否已存在
         String[] appIdArray = currentAppIds.split(",");
         for (String appId : appIdArray) {
@@ -534,7 +540,7 @@ public class WxUserScrmController extends AppBaseController {
                 return currentAppIds;
             }
         }
-        
+
         // 不存在,追加到末尾
         return currentAppIds + "," + newAppId;
     }