|
|
@@ -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: 今天过期或已过期;正数: 剩余天数
|
|
|
*/
|