Browse Source

1、调整直播列表无法分页问题处理
2、调整微信签到弹出微信问题处理

yys 3 ngày trước cách đây
mục cha
commit
53206d37e1

+ 11 - 0
fs-common/src/main/java/com/fs/common/core/page/PageRequest.java

@@ -17,4 +17,15 @@ public class PageRequest {
      * 每页结果数
      */
     private int pageSize = 10;
+
+    /**
+     * 兼容前端统一分页参数 pageNum(与 currentPage 等价)
+     */
+    public void setPageNum(int pageNum) {
+        this.currentPage = pageNum;
+    }
+
+    public int getPageNum() {
+        return this.currentPage;
+    }
 }

+ 4 - 3
fs-service/src/main/java/com/fs/company/service/impl/CompanyUserServiceImpl.java

@@ -19,6 +19,7 @@ import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.PatternUtils;
 import com.fs.common.utils.SecurityUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.his.domain.FsUser;
 import com.fs.im.config.ImTypeConfig;
 import com.fs.im.service.OpenIMService;
 import com.fs.company.domain.*;
@@ -1128,7 +1129,7 @@ public class CompanyUserServiceImpl implements ICompanyUserService
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void bindFsUserAndImportFriend(Long userId, Long companyUserId) {
-        com.fs.his.domain.FsUser fsUser = fsUserMapper.selectFsUserByUserId(userId);
+        FsUser fsUser = fsUserMapper.selectFsUserByUserId(userId);
         if (fsUser == null || (fsUser.getIsDel() != null && fsUser.getIsDel() == 1)) {
             throw new CustomException("会员不存在");
         }
@@ -1147,7 +1148,7 @@ public class CompanyUserServiceImpl implements ICompanyUserService
                 batchUpdateBindCompanyUserId(Collections.singletonList(userId), companyUserId);
                 return;
             }
-            throw new CustomException("该会员已绑定销售,无法切换绑定");
+            throw new CustomException("该会员已绑定销售,请联系销售");
         }
 
         batchUpdateBindCompanyUserId(Collections.singletonList(userId), companyUserId);
@@ -1168,7 +1169,7 @@ public class CompanyUserServiceImpl implements ICompanyUserService
         if (existBind == null) {
             return FsUserSalesBindCheckVO.unbound();
         }
-        if (companyUserId.equals(existBind.getCompanyUserId())) {
+        if (!companyUserId.equals(existBind.getCompanyUserId())) {
             return FsUserSalesBindCheckVO.sameSales();
         }
         return FsUserSalesBindCheckVO.otherSales();

+ 1 - 1
fs-service/src/main/java/com/fs/company/vo/FsUserSalesBindCheckVO.java

@@ -52,7 +52,7 @@ public class FsUserSalesBindCheckVO implements Serializable {
         FsUserSalesBindCheckVO vo = new FsUserSalesBindCheckVO();
         vo.setBindStatus(STATUS_OTHER_SALES);
         vo.setNeedBind(false);
-        vo.setTip("该会员已绑定其他销售,无法切换");
+        vo.setTip("该会员已绑定其他销售,请联系销售!");
         return vo;
     }
 }

+ 1 - 1
fs-service/src/main/java/com/fs/live/param/SignPO.java

@@ -24,6 +24,6 @@ public class SignPO {
     /** 小程序/公众号 appId(领取金额红包微信转账时必传) */
     private String appId;
 
-    /** 来源:1=H5 2=小程序(金额红包微信转账时使用) */
+    /** 来源:1=H5 2=小程序 3=App(金额红包微信转账时使用) */
     private Integer source;
 }

+ 120 - 16
fs-user-app/src/main/java/com/fs/app/facade/impl/LiveFacadeServiceImpl.java

@@ -6,6 +6,8 @@ import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fs.app.facade.LiveFacadeService;
 import com.fs.common.constant.LiveKeysConstant;
 import com.fs.common.core.controller.BaseController;
@@ -13,13 +15,20 @@ import com.fs.common.core.domain.R;
 import com.fs.common.core.page.PageRequest;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.core.redis.RedisCache;
+import com.fs.common.exception.CustomException;
 import com.fs.common.utils.StringUtils;
+import com.fs.company.domain.Company;
 import com.fs.company.domain.CompanyUser;
+import com.fs.company.service.ICompanyService;
 import com.fs.company.service.ICompanyUserService;
+import com.fs.course.config.CourseConfig;
+import com.fs.course.param.FsCourseSendRewardUParam;
 import com.fs.his.domain.FsUser;
+import com.fs.his.domain.FsUserWx;
 import com.fs.his.param.WxSendRedPacketParam;
 import com.fs.his.service.IFsStorePaymentService;
 import com.fs.his.service.IFsUserService;
+import com.fs.his.service.IFsUserWxService;
 import com.fs.live.domain.*;
 import com.fs.framework.aspectj.lock.DistributeLock;
 import com.fs.live.param.CouponPO;
@@ -28,12 +37,14 @@ import com.fs.live.param.RedPO;
 import com.fs.live.param.SignPO;
 import com.fs.live.service.*;
 import com.fs.live.vo.*;
+import com.fs.system.service.ISysConfigService;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.temporal.ChronoUnit;
@@ -91,6 +102,15 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
     @Autowired
     private ICompanyUserService companyUserService;
 
+    @Autowired
+    private ICompanyService companyService;
+
+    @Autowired
+    private ISysConfigService configService;
+
+    @Autowired
+    private IFsUserWxService fsUserWxService;
+
     @Autowired
     private ILiveRewardRecordService liveRewardRecordService;
 
@@ -432,9 +452,14 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
         }
 
         boolean anySuccess = claimResults.stream().anyMatch(m -> Boolean.TRUE.equals(m.get("success")));
-        return R.ok(anySuccess ? "签到成功" : "签到成功,但奖励领取失败")
-                .put("signNo", signNo)
-                .put("rewards", claimResults);
+        // 有金额红包则返回其 one;否则只返回 msg
+        Map<String, Object> cashRed = claimResults.stream()
+                .filter(m -> Long.valueOf(6L).equals(m.get("rewardType")))
+                .findFirst().orElse(null);
+        if (cashRed != null) {
+            return R.ok(cashRed);
+        }
+        return R.ok(anySuccess ? "签到成功" : "签到成功,但奖励领取失败");
     }
 
     /**
@@ -444,7 +469,7 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
      */
     private R claimSignCashRed(Long liveId, Long userId, JSONObject item, SignPO sign) {
         BigDecimal amount = item.getBigDecimal("amount");
-        if (amount == null || amount.compareTo(java.math.BigDecimal.ZERO) <= 0) {
+        if (amount == null || amount.compareTo(BigDecimal.ZERO) <= 0) {
             return R.error("金额红包配置无效");
         }
         Live live = liveService.selectLiveByLiveId(liveId);
@@ -465,24 +490,28 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
             return R.error("绑定销售不存在或未归属公司,无法发放金额红包");
         }
         Long companyId = companyUser.getCompanyId();
-        String openId = null;
-        if (sign != null && sign.getSource() != null && sign.getSource() == 2
-                && StringUtils.isNotEmpty(user.getCourseMaOpenId())) {
-            openId = user.getCourseMaOpenId();
-        } else if (StringUtils.isNotEmpty(user.getMpOpenId())) {
-            openId = user.getMpOpenId();
-        } else if (StringUtils.isNotEmpty(user.getCourseMaOpenId())) {
-            openId = user.getCourseMaOpenId();
+        // 复用课程发奖 openId 解析逻辑:按 source 取 H5/小程序/App openId
+        FsCourseSendRewardUParam param = new FsCourseSendRewardUParam();
+        param.setUserId(userId);
+        param.setCompanyId(companyId);
+        param.setSource(3);
+        param.setAppId(sign != null ? sign.getAppId() : null);
+        String openId;
+        try {
+            openId = getOpenId(param, user);
+        } catch (CustomException e) {
+            return R.error(e.getMessage());
         }
+
         if (StringUtils.isEmpty(openId)) {
             return R.error("请使用微信登录后再领取金额红包");
         }
-        WxSendRedPacketParam packetParam = new com.fs.his.param.WxSendRedPacketParam();
+        WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
         packetParam.setOpenId(openId);
-        packetParam.setAmount(amount.setScale(1, java.math.RoundingMode.HALF_UP));
+        packetParam.setAmount(amount.setScale(1, RoundingMode.HALF_UP));
         packetParam.setCompanyId(companyId);
-        packetParam.setSource(sign != null && sign.getSource() != null ? sign.getSource() : 1);
-        packetParam.setAppId(sign != null ? sign.getAppId() : null);
+        packetParam.setSource(param.getSource());
+        packetParam.setAppId(param.getAppId());
         packetParam.setRedPacketMode(1);
         packetParam.setUser(user);
         try {
@@ -512,6 +541,81 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
         }
     }
 
+    /**
+     * 按来源获取用户 openId:1=H5 2=小程序 3=App
+     */
+    private String getOpenId(FsCourseSendRewardUParam param, FsUser user) {
+        Integer source = param.getSource() != null ? param.getSource() : 1;
+        Long userId = param.getUserId();
+        switch (source) {
+            case 1:
+                Company company = companyService.selectCompanyById(param.getCompanyId());
+                if (company == null) {
+                    throw new CustomException("公司不存在,无法获取openId");
+                }
+                String appId = company.getCourseMaAppId();
+
+                // 公司配置为空时获取默认配置
+                if (StringUtils.isBlank(appId)) {
+                    String json = configService.selectConfigByKey("course.config");
+                    CourseConfig config = JSON.parseObject(json, CourseConfig.class);
+                    if (config == null || StringUtils.isBlank(config.getMpAppId())) {
+                        throw new CustomException("未配置公众号appId,无法获取openId");
+                    }
+                    appId = config.getMpAppId();
+                }
+
+                // 查询openId
+                Wrapper<FsUserWx> queryWrapper = Wrappers.<FsUserWx>lambdaQuery()
+                        .eq(FsUserWx::getFsUserId, userId)
+                        .eq(FsUserWx::getAppId, appId);
+                FsUserWx fsUserWx = fsUserWxService.getOne(queryWrapper);
+                if (Objects.isNull(fsUserWx) || StringUtils.isBlank(fsUserWx.getOpenId())) {
+                    throw new CustomException("获取openId失败");
+                }
+                return fsUserWx.getOpenId();
+            case 2:
+                if (StringUtils.isBlank(param.getAppId())) {
+                    throw new CustomException("小程序appId不能为空");
+                }
+                FsUserWx userWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(), userId, 1);
+                if (Objects.nonNull(userWx) && StringUtils.isNotBlank(userWx.getOpenId())) {
+                    return userWx.getOpenId();
+                }
+
+                if (StringUtils.isNotBlank(user.getCourseMaOpenId())) {
+                    try {
+                        handleFsUserWx(user, param.getAppId());
+                    } catch (Exception e) {
+                        log.error("【更新或插入用户与小程序的绑定关系失败】:{}", userId, e);
+                    }
+                    return user.getCourseMaOpenId();
+                }
+                break;
+            case 3:
+                return user.getAppOpenId();
+            default:
+                break;
+        }
+        return null;
+    }
+
+    /**
+     * 更新或插入用户与小程序的绑定关系
+     */
+    private void handleFsUserWx(FsUser user, String appId) {
+        FsUserWx fsUserWx = new FsUserWx();
+        fsUserWx.setType(1);
+        fsUserWx.setFsUserId(user.getUserId());
+        fsUserWx.setAppId(appId);
+        fsUserWx.setOpenId(user.getCourseMaOpenId());
+        fsUserWx.setUnionId(user.getUnionId());
+        fsUserWx.setCreateTime(new Date());
+        fsUserWx.setUpdateTime(new Date());
+        fsUserWxService.saveOrUpdateByUniqueKey(fsUserWx);
+        log.info("【更新或插入用户与小程序{}的绑定关系】:{}", appId, user.getUserId());
+    }
+
     /**
      * 解析本次签到可领取奖励:优先读触发后 Redis 缓存(含 opLogId),否则回落已执行签到任务 content.rewards。
      */