Ver código fonte

益寿缘app-优化看课奖励弹窗展示逻辑

cgp 1 semana atrás
pai
commit
463a680b0f

+ 7 - 0
fs-service/src/main/java/com/fs/course/mapper/FsCourseWatchLogMapper.java

@@ -584,4 +584,11 @@ public interface FsCourseWatchLogMapper extends BaseMapper<FsCourseWatchLog> {
     long countOldData(@Param("cutoffTime") LocalDateTime cutoffTime);
 
     int deleteOldDataDirectly(@Param("cutoffTime") LocalDateTime cutoffTime);
+
+    /**
+     * 根据用户ID和今天的日期查询完课记录
+     * @param userId 用户ID
+     * @return 完课记录列表
+     */
+    List<FsCourseWatchLog> selectTodayFinishedLogsByUserId(@Param("userId") Long userId);
 }

+ 9 - 3
fs-service/src/main/java/com/fs/his/mapper/FsUserRewardsMapper.java

@@ -23,13 +23,12 @@ public interface FsUserRewardsMapper {
     public FsUserRewards selectFsUserRewardsById(Long id);
     
     /**
-     * 根据用户ID和活动类型查询
+     * 根据用户ID和首次登录注册标识查询
      *
      * @param fsUserId 用户ID
-     * @param activityType 活动类型
      * @return 用户活动奖品信息
      */
-    public FsUserRewards selectByUserIdAndActivityType(@Param("fsUserId") Long fsUserId, @Param("activityType") String activityType);
+    public FsUserRewards selectByUserIdAndFirstLoginType(@Param("fsUserId") Long fsUserId);
 
     /**
      * 根据用户ID和奖品id查询
@@ -116,4 +115,11 @@ public interface FsUserRewardsMapper {
      * @return 结果
      */
     public int deleteFsUserRewardsByIds(Long[] ids);
+
+    /**
+     * 根据用户ID和活动类型查询今日数据
+     * @param fsUserId 用户ID
+     * @param activityType 活动类型
+     * */
+    List<FsUserRewards> selectTodayListDataByUserIdAndActivityType(Long fsUserId, String activityType);
 }

+ 57 - 25
fs-service/src/main/java/com/fs/his/service/impl/AppUserRewardServiceImpl.java

@@ -4,6 +4,8 @@ import com.fs.app.domain.FsAppRole;
 import com.fs.app.mapper.FsAppRoleMapper;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
+import com.fs.course.domain.FsCourseWatchLog;
+import com.fs.course.mapper.FsCourseWatchLogMapper;
 import com.fs.his.domain.FsUser;
 import com.fs.his.domain.FsUserRewards;
 import com.fs.his.dto.ClaimRewardsAddDTO;
@@ -40,6 +42,9 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
     @Autowired
     private FsAppRoleMapper appRoleMapper;
 
+    @Autowired
+    private FsCourseWatchLogMapper watchLogMapper;
+
     @Autowired
     private ObjectMapper objectMapper;
 
@@ -287,10 +292,8 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
             log.info("用户:{}已注册登录过,非首次登录", fsUserId);
             return false;
         }
-
         // 2. 查奖品表判断是否已发放奖励
-        String activityType = ActivityTypeEnum.FIRST_LOGIN.getCode();
-        FsUserRewards queryReward = rewardsMapper.selectByUserIdAndActivityType(fsUserId, activityType);
+        FsUserRewards queryReward = rewardsMapper.selectByUserIdAndFirstLoginType(fsUserId);
         if (queryReward != null) {
             log.info("用户:{}已下发过首次注册奖励, status={}", fsUserId, queryReward.getStatus());
             return false;
@@ -309,8 +312,7 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
         }
 
         // 2. 查奖品表判断是否已发放奖励
-        String activityType = ActivityTypeEnum.FIRST_LOGIN.getCode();
-        FsUserRewards queryReward = rewardsMapper.selectByUserIdAndActivityType(fsUserId, activityType);
+        FsUserRewards queryReward = rewardsMapper.selectByUserIdAndFirstLoginType(fsUserId);
         if (queryReward == null) {
             //查询当前用户对应的角色配置返回红包、积分、商品弹窗信息
             fsAppRole = getAppRoleConfig(fsUserId);
@@ -321,19 +323,60 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
 
     @Override
     public FsAppRole showWatchCourseRewardWindows(Long fsUserId) {
-        FsAppRole fsAppRole =new FsAppRole();
+        FsAppRole noShowWindow = new FsAppRole();
+
+        // 获取用户和配置
         FsUser fsUser = fsUserMapper.selectFsUserById(fsUserId);
-        // 2. 查奖品表判断是否已发放奖励
-        String activityType = ActivityTypeEnum.FIRST_LOGIN.getCode();
-        FsUserRewards queryReward = rewardsMapper.selectByUserIdAndActivityType(fsUserId, activityType);
-        if (queryReward == null) {
-            //TODO 查询当前用户对应的角色配置返回红包、积分、商品弹窗信息(还需要判断当前用户是否满足看课奖励)
-            fsAppRole = getAppRoleConfig(fsUserId);
-            return fsAppRole;
+        FsAppRole defaultConfig = getAppRoleConfig(fsUserId);
+        if (defaultConfig == null) {
+            return noShowWindow;
+        }
+        String activityType = ActivityTypeEnum.WATCH_COURSE.getCode();
+        List<FsUserRewards> todayRewards = rewardsMapper.selectTodayListDataByUserIdAndActivityType(fsUserId, activityType);
+        // 实物商品逻辑
+        if (defaultConfig.getCourseRewardType() == 3) {
+            Long courseNeedDay = defaultConfig.getCourseNeedDay();// 看课商品领取所需天数
+            Integer courseDay = fsUser.getAppRewardsViewedDays();// 客户实际累计看课天数
+
+            // 不满足累计天数 → 不展示
+            if (courseNeedDay == null || courseNeedDay <= 0 || courseDay < courseNeedDay) {
+                return noShowWindow;
+            }
+            // 今天已领过 → 不展示
+            if (CollectionUtils.isNotEmpty(todayRewards)) {
+                return noShowWindow;
+            }
+            // 满足条件 → 展示
+            return defaultConfig;
+        }
+
+        // 积分/红包逻辑
+        List<FsCourseWatchLog> finishedLogs = watchLogMapper.selectTodayFinishedLogsByUserId(fsUserId);
+        // 今日没有完课 → 不展示
+        if (CollectionUtils.isEmpty(finishedLogs)) {
+            return noShowWindow;
+        }
+        // 今天已领过 → 不展示
+        if (CollectionUtils.isNotEmpty(todayRewards)) {
+            return noShowWindow;
         }
+        // 满足条件 → 展示
+        return defaultConfig;
+    }
+
+    //根据用户id、角色id获取配置的奖品信息(实物商品包含商品名称和图片)
+    private FsAppRole getAppRoleConfig(Long fsUserId){
+        //获取当前用户最高权重角色, "false"表示查询等级数字最小的权重角色
+        FsAppRole fsAppRole = appRoleMapper.selectHighestLevelAppRoleByUserId(fsUserId,"false");
+        if (fsAppRole==null){
+            log.info("未找到用户:{}对应的角色配置", fsUserId);
+            return null;
+        }
+        fsAppRole.setShow(true);//显示弹窗
         return fsAppRole;
     }
 
+
     /**
      * 积分、商品是否过期的判断方法(红包需要另外方法计算)
      * @param reward: 奖品
@@ -373,19 +416,8 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
         return expirationDate.before(currentDate);
     }
 
-    //根据用户id、角色id获取配置的奖品信息
-    private FsAppRole getAppRoleConfig(Long fsUserId){
-        //获取当前用户最高权重角色, "false"表示查询等级数字最小的权重角色
-        FsAppRole fsAppRole = appRoleMapper.selectHighestLevelAppRoleByUserId(fsUserId,"false");
-        if (fsAppRole==null){
-            log.info("未找到用户:{}对应的角色配置", fsUserId);
-            return null;
-        }
-        fsAppRole.setShow(true);//弹窗显示
-        return fsAppRole;
-    }
     /**
-     * 计算单个奖品的剩余过期天数
+     * 用于计算奖品列表里面的单个奖品的剩余过期天数
      * @param reward 奖品实体
      * @return 剩余天数。null: 表示无有效期或查询失败;0: 今天过期或已过期;正数: 剩余天数
      */

+ 6 - 0
fs-service/src/main/resources/mapper/course/FsCourseWatchLogMapper.xml

@@ -1054,6 +1054,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         DATE(o.create_time)
         ) AS t
     </select>
+    <select id="selectTodayFinishedLogsByUserId" parameterType="long" resultMap="FsCourseWatchLogResult">
+        <include refid="selectFsCourseWatchLogVo"/>
+        WHERE user_id = #{userId}
+        AND finish_time &gt;= CURDATE() and finish_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY) <!-- finish_time的日期部分等于今天 -->
+        AND log_type = 2
+    </select>
 
     <delete id="deleteOldDataDirectly">
         DELETE FROM fs_course_watch_log

+ 7 - 3
fs-service/src/main/resources/mapper/his/FsUserRewardsMapper.xml

@@ -37,10 +37,10 @@
         where id = #{id}
     </select>
 
-    <!-- 根据用户ID和活动类型查询 -->
-    <select id="selectByUserIdAndActivityType" resultMap="FsUserRewardsResult">
+    <!-- 根据用户ID和首次登录注册标识查询 -->
+    <select id="selectByUserIdAndFirstLoginType" resultMap="FsUserRewardsResult">
         <include refid="selectFsUserRewardsVo"/>
-        where fs_user_id = #{fsUserId} and activity_type = #{activityType}
+        where fs_user_id = #{fsUserId} and activity_type = "FIRST_LOGIN"
     </select>
 
     <!-- 根据用户ID和奖品id查询 -->
@@ -92,6 +92,10 @@
         </where>
         order by create_time desc
     </select>
+    <select id="selectTodayListDataByUserIdAndActivityType" resultMap="FsUserRewardsResult">
+        <include refid="selectFsUserRewardsVo"/>
+        where fs_user_id = #{fsUserId} and activity_type = #{activityType} and create_time &gt;= CURDATE() and create_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY)
+    </select>
 
     <!-- 新增记录 -->
     <insert id="insertFsUserRewards" parameterType="com.fs.his.domain.FsUserRewards" useGeneratedKeys="true" keyProperty="id">