|  | @@ -246,6 +246,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  |       * 查询课堂视频
 |  |       * 查询课堂视频
 | 
											
												
													
														|  |       *
 |  |       *
 | 
											
										
											
												
													
														|  | @@ -1075,72 +1076,93 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 | 
											
												
													
														|  |  //        if (isWithin10Minutes){
 |  |  //        if (isWithin10Minutes){
 | 
											
												
													
														|  |  //            return R.error("非有效期内,不允许领取!");
 |  |  //            return R.error("非有效期内,不允许领取!");
 | 
											
												
													
														|  |  //        }
 |  |  //        }
 | 
											
												
													
														|  | -        // 获取用户信息
 |  | 
 | 
											
												
													
														|  | -        FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        RLock lock = redissonClient.getLock("sendReward");
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        try{
 | 
											
												
													
														|  | 
 |  | +            boolean getLock = lock.tryLock(100,10000, TimeUnit.MILLISECONDS);
 | 
											
												
													
														|  | 
 |  | +            if (!getLock) {
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                return R.error("服务器繁忙,请稍候再试!");
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            // 获取用户信息
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
 | 
											
												
													
														|  |  //        if (StringUtils.isEmpty(user.getMpOpenId())){
 |  |  //        if (StringUtils.isEmpty(user.getMpOpenId())){
 | 
											
												
													
														|  |  //            return R.error("未识别到领取信息");
 |  |  //            return R.error("未识别到领取信息");
 | 
											
												
													
														|  |  //        }
 |  |  //        }
 | 
											
												
													
														|  | -        log.info("查询会员信息:{}", user);
 |  | 
 | 
											
												
													
														|  | -        if (user.getStatus()==0){
 |  | 
 | 
											
												
													
														|  | -            return R.error("会员被停用,无权限,请联系客服!");
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        FsCourseWatchLog watchLog = new FsCourseWatchLog();
 |  | 
 | 
											
												
													
														|  | 
 |  | +            log.info("查询会员信息:{}", user);
 | 
											
												
													
														|  | 
 |  | +            if (user.getStatus()==0){
 | 
											
												
													
														|  | 
 |  | +                return R.error("会员被停用,无权限,请联系客服!");
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            FsCourseWatchLog watchLog = new FsCourseWatchLog();
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        // 根据链接类型判断是否已发放奖励
 |  | 
 | 
											
												
													
														|  | -        watchLog = courseWatchLogMapper.getWatchCourseVideo(param.getUserId(), param.getVideoId(), param.getQwUserId(), param.getQwExternalId());
 |  | 
 | 
											
												
													
														|  | -        log.info("看课记录:{}", watchLog);
 |  | 
 | 
											
												
													
														|  | -        if (watchLog == null) {
 |  | 
 | 
											
												
													
														|  | -            return R.error("无记录");
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        if (watchLog.getLogType() != 2) {
 |  | 
 | 
											
												
													
														|  | -            return R.error("未完课");
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        if (watchLog.getRewardType() != null) {
 |  | 
 | 
											
												
													
														|  | -            FsCourseRedPacketLog packetLog = redPacketLogMapper.selectFsCourseRedPacketLogByTemporary(param.getVideoId(), param.getUserId());
 |  | 
 | 
											
												
													
														|  | -            log.info("课程红包:{}", packetLog);
 |  | 
 | 
											
												
													
														|  | -            if(packetLog != null && packetLog.getStatus() == 1) {
 |  | 
 | 
											
												
													
														|  | -                return R.error("已领取该课程奖励,不可重复领取!");
 |  | 
 | 
											
												
													
														|  | 
 |  | +            // 根据链接类型判断是否已发放奖励
 | 
											
												
													
														|  | 
 |  | +            watchLog = courseWatchLogMapper.getWatchCourseVideo(param.getUserId(), param.getVideoId(), param.getQwUserId(), param.getQwExternalId());
 | 
											
												
													
														|  | 
 |  | +            log.info("看课记录:{}", watchLog);
 | 
											
												
													
														|  | 
 |  | +            if (watchLog == null) {
 | 
											
												
													
														|  | 
 |  | +                return R.error("无记录");
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -            if(packetLog != null && packetLog.getStatus() == 0) {
 |  | 
 | 
											
												
													
														|  | -                log.info("判断领取记录");
 |  | 
 | 
											
												
													
														|  | -                if(StringUtils.isNotEmpty(packetLog.getResult())){
 |  | 
 | 
											
												
													
														|  | -                    log.info("是否有结果");
 |  | 
 | 
											
												
													
														|  | -                    R r = JSON.parseObject(packetLog.getResult(), R.class);
 |  | 
 | 
											
												
													
														|  | -                    return r;
 |  | 
 | 
											
												
													
														|  | -                } else {
 |  | 
 | 
											
												
													
														|  | -                    return R.error("操作频繁,请稍后再试!");
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (watchLog.getLogType() != 2) {
 | 
											
												
													
														|  | 
 |  | +                return R.error("未完课");
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            if (watchLog.getRewardType() != null) {
 | 
											
												
													
														|  | 
 |  | +                FsCourseRedPacketLog packetLog = redPacketLogMapper.selectFsCourseRedPacketLogByTemporary(param.getVideoId(), param.getUserId());
 | 
											
												
													
														|  | 
 |  | +                log.info("课程红包:{}", packetLog);
 | 
											
												
													
														|  | 
 |  | +                if(packetLog != null && packetLog.getStatus() == 1) {
 | 
											
												
													
														|  | 
 |  | +                    return R.error("已领取该课程奖励,不可重复领取!");
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  | 
 |  | +                if(packetLog != null && packetLog.getStatus() == 0) {
 | 
											
												
													
														|  | 
 |  | +                    log.info("判断领取记录");
 | 
											
												
													
														|  | 
 |  | +                    if(StringUtils.isNotEmpty(packetLog.getResult())){
 | 
											
												
													
														|  | 
 |  | +                        log.info("是否有结果");
 | 
											
												
													
														|  | 
 |  | +                        R r = JSON.parseObject(packetLog.getResult(), R.class);
 | 
											
												
													
														|  | 
 |  | +                        return r;
 | 
											
												
													
														|  | 
 |  | +                    } else {
 | 
											
												
													
														|  | 
 |  | +                        return R.error("操作频繁,请稍后再试!");
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                if(packetLog != null && packetLog.getStatus() == 2) {
 | 
											
												
													
														|  | 
 |  | +                    return R.error("请联系客服补发");
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                return R.error("奖励已发放");
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -            if(packetLog != null && packetLog.getStatus() == 2) {
 |  | 
 | 
											
												
													
														|  | -                return R.error("请联系客服补发");
 |  | 
 | 
											
												
													
														|  | 
 |  | +            // 获取视频信息
 | 
											
												
													
														|  | 
 |  | +            FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            // 获取配置信息
 | 
											
												
													
														|  | 
 |  | +            String json = configService.selectConfigByKey("course.config");
 | 
											
												
													
														|  | 
 |  | +            CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
 | 
											
												
													
														|  | 
 |  | +            log.info("奖励类型:{}", config.getRewardType());
 | 
											
												
													
														|  | 
 |  | +            // 根据奖励类型发放不同奖励
 | 
											
												
													
														|  | 
 |  | +            switch (config.getRewardType()) {
 | 
											
												
													
														|  | 
 |  | +                // 红包奖励
 | 
											
												
													
														|  | 
 |  | +                case 1:
 | 
											
												
													
														|  | 
 |  | +                    return sendRedPacketReward(param, user, watchLog, video, config);
 | 
											
												
													
														|  | 
 |  | +                // 积分奖励
 | 
											
												
													
														|  | 
 |  | +                case 2:
 | 
											
												
													
														|  | 
 |  | +                    return sendIntegralReward(param,user, watchLog, config);
 | 
											
												
													
														|  | 
 |  | +                // 红包+积分
 | 
											
												
													
														|  | 
 |  | +                case 3:
 | 
											
												
													
														|  | 
 |  | +                    R sendRed = sendRedPacketReward(param, user, watchLog, video, config);
 | 
											
												
													
														|  | 
 |  | +                    if (!Objects.equals(sendRed.get("code"), 200)) {
 | 
											
												
													
														|  | 
 |  | +                        return sendRed;
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                    return sendIntegralReward(param,user, watchLog, config);
 | 
											
												
													
														|  | 
 |  | +                default:
 | 
											
												
													
														|  | 
 |  | +                    return R.error("参数错误!");
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -            return R.error("奖励已发放");
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        // 获取视频信息
 |  | 
 | 
											
												
													
														|  | -        FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        // 获取配置信息
 |  | 
 | 
											
												
													
														|  | -        String json = configService.selectConfigByKey("course.config");
 |  | 
 | 
											
												
													
														|  | -        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
 |  | 
 | 
											
												
													
														|  | -        log.info("奖励类型:{}", config.getRewardType());
 |  | 
 | 
											
												
													
														|  | -        // 根据奖励类型发放不同奖励
 |  | 
 | 
											
												
													
														|  | -        switch (config.getRewardType()) {
 |  | 
 | 
											
												
													
														|  | -            // 红包奖励
 |  | 
 | 
											
												
													
														|  | -            case 1:
 |  | 
 | 
											
												
													
														|  | -                return sendRedPacketReward(param, user, watchLog, video, config);
 |  | 
 | 
											
												
													
														|  | -            // 积分奖励
 |  | 
 | 
											
												
													
														|  | -            case 2:
 |  | 
 | 
											
												
													
														|  | -                return sendIntegralReward(param,user, watchLog, config);
 |  | 
 | 
											
												
													
														|  | -            // 红包+积分
 |  | 
 | 
											
												
													
														|  | -            case 3:
 |  | 
 | 
											
												
													
														|  | -                R sendRed = sendRedPacketReward(param, user, watchLog, video, config);
 |  | 
 | 
											
												
													
														|  | -                if (!Objects.equals(sendRed.get("code"), 200)) {
 |  | 
 | 
											
												
													
														|  | -                    return sendRed;
 |  | 
 | 
											
												
													
														|  | -                }
 |  | 
 | 
											
												
													
														|  | -                return sendIntegralReward(param,user, watchLog, config);
 |  | 
 | 
											
												
													
														|  | -            default:
 |  | 
 | 
											
												
													
														|  | -                return R.error("参数错误!");
 |  | 
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | 
 |  | +        catch (Exception e){
 | 
											
												
													
														|  | 
 |  | +            throw new CustomException(e.getMessage());
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        finally {
 | 
											
												
													
														|  | 
 |  | +            if(null != lock && lock.isLocked() && lock.isHeldByCurrentThread()){
 | 
											
												
													
														|  | 
 |  | +                lock.unlock();
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 |