|  | @@ -321,13 +321,61 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 | 
	
		
			
				|  |  |          FsUser fsUser = fsUserMapper.selectFsUserByUserId(param.getUserId());
 | 
	
		
			
				|  |  |          //用户不存在唤起重新授权
 | 
	
		
			
				|  |  |          if (fsUser==null){
 | 
	
		
			
				|  |  | -            return R.error(504,"");
 | 
	
		
			
				|  |  | +            return R.error(504,"未授权");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        String nickName = "微信用户";
 | 
	
		
			
				|  |  | -        if (fsUser.getNickname() != null && fsUser.getNickname().contains(nickName)) {
 | 
	
		
			
				|  |  | -            return R.error(504,"");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String msg = "<div style=\"color: red;margin-bottom: 15px;font-weight: bold;\">本课程为会员独享<br>请长按二维码</div>\n" +
 | 
	
		
			
				|  |  | +                "\t\t\t\t\t<div style=\"color: #999;font-size: 14px;font-weight: bold;\">添加伴学助手免费领取会员权限</div>";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Integer isRoom = param.getIsRoom();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 处理逻辑
 | 
	
		
			
				|  |  | +        if (isRoom == null || isRoom == 0) {
 | 
	
		
			
				|  |  | +            // 当 isRoom 为 null 或 0 时走 handleExt
 | 
	
		
			
				|  |  | +            return handleExt(param,msg);
 | 
	
		
			
				|  |  | +        } else if (isRoom == 1) {
 | 
	
		
			
				|  |  | +            // 当 isRoom 为 1 时走 handleRoom
 | 
	
		
			
				|  |  | +            return handleRoom(param,fsUser);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            // 非法参数
 | 
	
		
			
				|  |  | +            logger.warn("非法参数 isRoom: {}", isRoom);
 | 
	
		
			
				|  |  | +            return R.error("参数错误!");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private R handleRoom(FsUserCourseVideoAddKfUParam param,FsUser user) {
 | 
	
		
			
				|  |  | +        if (user.getQwExtId()==null){
 | 
	
		
			
				|  |  | +            return R.error("未注册");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        param.setQwExternalId(user.getQwExtId());
 | 
	
		
			
				|  |  | +        //查询是否有添加客服
 | 
	
		
			
				|  |  | +        QwExternalContact externalContact = qwExternalContactMapper.selectQwExternalContactById(param.getQwExternalId());
 | 
	
		
			
				|  |  | +        if (externalContact==null){
 | 
	
		
			
				|  |  | +            return R.error("客户不存在!");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (!externalContact.getQwUserId().equals(param.getUserId())){
 | 
	
		
			
				|  |  | +            return R.error("无权限观看,添加群主非本群主");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByExt(param.getQwExternalId(), param.getVideoId(),param.getQwUserId());
 | 
	
		
			
				|  |  | +        if (log==null){
 | 
	
		
			
				|  |  | +            createWatchLog(param);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        return R.ok();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void createWatchLog(FsUserCourseVideoAddKfUParam param) {
 | 
	
		
			
				|  |  | +        FsCourseWatchLog log = new FsCourseWatchLog();
 | 
	
		
			
				|  |  | +        BeanUtils.copyProperties(param,log);
 | 
	
		
			
				|  |  | +        log.setQwExternalContactId(param.getQwExternalId());
 | 
	
		
			
				|  |  | +        log.setSendType(2);
 | 
	
		
			
				|  |  | +        log.setDuration(0L);
 | 
	
		
			
				|  |  | +        log.setCreateTime(new Date());
 | 
	
		
			
				|  |  | +        log.setLogType(0);
 | 
	
		
			
				|  |  | +        courseWatchLogMapper.insertFsCourseWatchLog(log);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private R handleExt(FsUserCourseVideoAddKfUParam param,String msg){
 | 
	
		
			
				|  |  |          if (param.getLinkType()!=null&¶m.getLinkType()==1){
 | 
	
		
			
				|  |  |              if (param.getLinkId()!=null){
 | 
	
		
			
				|  |  |                  // 从数据库中查找短链对应的真实链接
 | 
	
	
		
			
				|  | @@ -350,12 +398,10 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 | 
	
		
			
				|  |  |              return R.error("链接过期");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        String msg = "<div style=\"color: red;margin-bottom: 15px;font-weight: bold;\">本课程为会员独享<br>请长按二维码</div>\n" +
 | 
	
		
			
				|  |  | -                "\t\t\t\t\t<div style=\"color: #999;font-size: 14px;font-weight: bold;\">添加伴学助手免费领取会员权限</div>";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByExt(param.getQwExternalId(), param.getVideoId(),param.getQwUserId());
 | 
	
		
			
				|  |  |          if (log==null ){
 | 
	
		
			
				|  |  | -            logger.info("");
 | 
	
		
			
				|  |  |              return addCustomerService(param.getQwUserId(),msg);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -371,12 +417,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 | 
	
		
			
				|  |  |              return addCustomerService(param.getQwUserId(),msg);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        //如果客户状态为正常或流失且无接替记录,才生成可以看课,不然加好友
 | 
	
		
			
				|  |  | -//        if (externalContact.getStatus() != 0 && externalContact.getStatus() != 2 && externalContact.getStatus() != 3){
 | 
	
		
			
				|  |  | -//        if (externalContact.getStatus()==4){
 | 
	
		
			
				|  |  | -//            return addCustomerService(param.getQwUserId(),msg);
 | 
	
		
			
				|  |  | -//        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          //判断外部联系人有没有绑定userId
 | 
	
		
			
				|  |  |          if (externalContact.getFsUserId()!=null){
 | 
	
		
			
				|  |  |              //有客户有小程序id  但 登录的小程序id和根据外部联系人id查出来的小程序id不一致
 | 
	
	
		
			
				|  | @@ -389,13 +429,9 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              //看课记录中userId为0绑定userId
 | 
	
		
			
				|  |  | -            if (log.getUserId()==null||log.getUserId().equals(0L)){
 | 
	
		
			
				|  |  | +            if (log.getUserId()==null||log.getUserId().equals(0L) || !log.getUserId().equals(param.getUserId())){
 | 
	
		
			
				|  |  |                  log.setUserId(param.getUserId());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            //看课记录不为已完课时 改为看课中
 | 
	
		
			
				|  |  | -//            if (log.getLogType()!=2){
 | 
	
		
			
				|  |  | -//                log.setLogType(1);
 | 
	
		
			
				|  |  | -//            }
 | 
	
		
			
				|  |  |              log.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |              courseWatchLogMapper.updateFsCourseWatchLog(log);
 | 
	
		
			
				|  |  |              return R.ok();
 | 
	
	
		
			
				|  | @@ -407,26 +443,20 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 | 
	
		
			
				|  |  |              contact.setFsUserId(param.getUserId());
 | 
	
		
			
				|  |  |              qwExternalContactMapper.updateQwExternalContact(contact);
 | 
	
		
			
				|  |  |              FsUser user = new FsUser();
 | 
	
		
			
				|  |  | -            user.setUserId(fsUser.getUserId());
 | 
	
		
			
				|  |  | +            user.setUserId(param.getUserId());
 | 
	
		
			
				|  |  |              user.setIsAddQw(1);
 | 
	
		
			
				|  |  |              fsUserMapper.updateFsUser(user);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              //绑定上之后 更新观看记录
 | 
	
		
			
				|  |  |              //看课记录中userId为0绑定userId
 | 
	
		
			
				|  |  | -            if (log.getUserId()==null||log.getUserId().equals(0L)){
 | 
	
		
			
				|  |  | +            if (log.getUserId()==null||log.getUserId().equals(0L) || !log.getUserId().equals(param.getUserId())){
 | 
	
		
			
				|  |  |                  log.setUserId(param.getUserId());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            //看课记录不为已完课时 改为看课中
 | 
	
		
			
				|  |  | -//            if (log.getLogType()!=2){
 | 
	
		
			
				|  |  | -//                log.setLogType(1);
 | 
	
		
			
				|  |  | -//            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              log.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |              courseWatchLogMapper.updateFsCourseWatchLog(log);
 | 
	
		
			
				|  |  |              return R.ok();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private R addCustomerService(String qwUserById,String msg){
 | 
	
	
		
			
				|  | @@ -775,7 +805,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 | 
	
		
			
				|  |  |          QwExternalContact qw = new QwExternalContact();
 | 
	
		
			
				|  |  |          qw.setFsUserId(fsUser.getUserId());
 | 
	
		
			
				|  |  |          qw.setId(qwExternalContact.getId());
 | 
	
		
			
				|  |  | -        qwExternalContactMapper.updateQwExternalContactByExternalUserId(qw);
 | 
	
		
			
				|  |  | +        qwExternalContactMapper.updateById(qw);
 | 
	
		
			
				|  |  |          List<String> list= sopUserLogsInfoMapper.selectSopUserLogsInfoByExtId(qwExternalContact.getId());
 | 
	
		
			
				|  |  |          if (list!=null&& !list.isEmpty()){
 | 
	
		
			
				|  |  |              sopUserLogsInfoMapper.updateSopUserLogsInfoFsUserIdById(list,param.getUserId());
 |