| 
					
				 | 
			
			
				@@ -3,6 +3,7 @@ package com.fs.course.service.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.core.util.NumberUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.json.JSONUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.common.BeanCopyUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.common.core.domain.R; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.common.core.domain.ResponseResult; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -39,6 +40,7 @@ import com.fs.qwApi.Result.QwAddContactWayResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.qwApi.param.QwAddContactWayParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.qwApi.service.QwApiService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.sop.mapper.QwSopLogsMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.fs.store.service.cache.IFsUserCourseCacheService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.system.service.ISysConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.slf4j.Logger; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -321,13 +323,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 +400,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 +419,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 +431,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 +445,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){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -471,6 +503,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private IFsUserCourseCacheService fsUserCourseCacheService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public R getInternetTraffic(FsUserCourseVideoFinishUParam param) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -496,6 +530,12 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (StringUtils.isNotEmpty(trafficLog.getUuId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 // 直接插入或更新 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //                logger.error("zyp \n【插入或更新流量】:{}",trafficLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(ObjectUtils.isNotNull(trafficLog.getCourseId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    FsUserCourse course = fsUserCourseCacheService.selectFsUserCourseByCourseId(trafficLog.getCourseId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if(ObjectUtils.isNotNull(course)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        trafficLog.setProject(course.getProject()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 fsCourseTrafficLogMapper.insertOrUpdateTrafficLog(trafficLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } catch (Exception e) { 
			 |