|
@@ -4,6 +4,7 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fs.common.BeanCopyUtils;
|
|
|
import com.fs.common.core.domain.R;
|
|
@@ -214,28 +215,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
return fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public FsUserCourseVideoQVO selectFsUserCourseVideoByVideoIdVO(Long videoId,Long userId) {
|
|
|
- FsUserCourseVideoQVO fsUserCourseVideoQVO=new FsUserCourseVideoQVO();
|
|
|
- FsUserCourseVideo courseVideo = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoIdAndUserId(videoId,userId);
|
|
|
-
|
|
|
- BeanCopyUtils.copy(courseVideo,fsUserCourseVideoQVO);
|
|
|
- if (courseVideo.getRedPacketMoney()!=null){
|
|
|
- fsUserCourseVideoQVO.setRedPacketMoney(courseVideo.getRedPacketMoney().toString());
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(courseVideo.getQuestionBankId())){
|
|
|
- List<FsCourseQuestionBank> fsCourseQuestionBanks = courseQuestionBankMapper.selectFsCourseQuestionBankByIdVO(courseVideo.getQuestionBankId().split(","));
|
|
|
- fsUserCourseVideoQVO.setQuestionBankList(fsCourseQuestionBanks);
|
|
|
- }
|
|
|
- //返回课程关联的拍商品
|
|
|
- if(courseVideo.getIsProduct() != null && courseVideo.getIsProduct() == 1 && courseVideo.getProductId() != null){
|
|
|
- FsCourseProduct courseProduct = courseProductMapper.selectFsCourseProductById(courseVideo.getProductId());
|
|
|
- List<FsCourseProduct> courseProducts = Arrays.asList(courseProduct);
|
|
|
- fsUserCourseVideoQVO.setCourseProducts(courseProducts);
|
|
|
- }
|
|
|
- return fsUserCourseVideoQVO;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 查询课堂视频列表
|
|
|
*
|
|
@@ -428,7 +407,21 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
if (fsUser.getStatus()==0){
|
|
|
return R.error("会员被停用,无权限,请联系客服!");
|
|
|
}
|
|
|
-
|
|
|
+// if (param.getIsOpenCourse()!=null&¶m.getIsOpenCourse()==1){
|
|
|
+// FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByUserId(param.getUserId(), param.getVideoId());
|
|
|
+// if (log==null){
|
|
|
+// FsCourseWatchLog userLog = new FsCourseWatchLog();
|
|
|
+// BeanUtils.copyProperties(param,log);
|
|
|
+// userLog.setSendType(0);
|
|
|
+// userLog.setUserId(param.getUserId());
|
|
|
+// userLog.setVideoId(param.getVideoId());
|
|
|
+// userLog.setDuration(0L);
|
|
|
+// userLog.setCreateTime(new Date());
|
|
|
+// userLog.setLogType(3);
|
|
|
+// courseWatchLogMapper.insertFsCourseWatchLog(log);
|
|
|
+// }
|
|
|
+// return R.ok();
|
|
|
+// }
|
|
|
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>";
|
|
|
// try {
|
|
@@ -888,14 +881,14 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
if (log.getRewardType() != null) {
|
|
|
FsCourseRedPacketLog packetLog = redPacketLogMapper.selectFsCourseRedPacketLogByTemporary(param.getVideoId(), param.getUserId());
|
|
|
if(packetLog != null && packetLog.getStatus() == 1) {
|
|
|
- return R.error("奖励已发放");
|
|
|
+ return R.error("已领取该课程奖励,不可重复领取!");
|
|
|
}
|
|
|
if(packetLog != null && packetLog.getStatus() == 0) {
|
|
|
if(StringUtils.isNotEmpty(packetLog.getResult())){
|
|
|
R r = JSON.parseObject(packetLog.getResult(), R.class);
|
|
|
return r;
|
|
|
} else {
|
|
|
- return R.error("奖励已发放");
|
|
|
+ return R.error("操作频繁,请稍后再试!");
|
|
|
}
|
|
|
}
|
|
|
if(packetLog != null && packetLog.getStatus() == 2) {
|
|
@@ -936,14 +929,14 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
if (log.getRewardType() != null) {
|
|
|
FsCourseRedPacketLog fsCourseRedPacketLog = redPacketLogMapper.selectUserFsCourseRedPacketLog(param.getVideoId(), param.getUserId(),param.getPeriodId());
|
|
|
if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 1) {
|
|
|
- return R.error("奖励已发放");
|
|
|
+ return R.error("已领取该课程奖励,不可重复领取!");
|
|
|
}
|
|
|
if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 0) {
|
|
|
if(StringUtils.isNotEmpty(fsCourseRedPacketLog.getResult())){
|
|
|
R r = JSON.parseObject(fsCourseRedPacketLog.getResult(), R.class);
|
|
|
return r;
|
|
|
} else {
|
|
|
- return R.error();
|
|
|
+ return R.error("操作频繁,请稍后再试!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -998,8 +991,12 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
if (param.getSource() == 2) {
|
|
|
//处理多小程序问题
|
|
|
FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1);
|
|
|
- if (fsUserWx ==null || fsUserWx.getOpenId()==null){
|
|
|
- packetParam.setOpenId(user.getCourseMaOpenId());
|
|
|
+ if (fsUserWx ==null){
|
|
|
+ try {
|
|
|
+ handleFsUserWx(user,param.getAppId());
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.error("zyp \n 【更新或插入用户与小程序的绑定关系失败】:{}", user.getUserId());
|
|
|
+ }
|
|
|
}else {
|
|
|
packetParam.setOpenId(fsUserWx.getOpenId());
|
|
|
}
|
|
@@ -1108,6 +1105,31 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private void handleFsUserWx(FsUser user, String appId) {
|
|
|
+ // 尝试更新
|
|
|
+ boolean updated = fsUserWxService.lambdaUpdate()
|
|
|
+ .eq(FsUserWx::getFsUserId, user.getUserId())
|
|
|
+ .eq(FsUserWx::getAppId,appId )
|
|
|
+ .eq(FsUserWx::getOpenId, user.getMaOpenId())
|
|
|
+// .set(FsUserWx::getUnionId, session.getUnionid() == null ? "" : session.getUnionid())
|
|
|
+ .set(FsUserWx::getUpdateTime, new Date())
|
|
|
+ .update();
|
|
|
+
|
|
|
+ // 如果更新失败(记录不存在),则插入
|
|
|
+ if (!updated) {
|
|
|
+ FsUserWx fsUserWx = new FsUserWx();
|
|
|
+ fsUserWx.setType(1);
|
|
|
+ fsUserWx.setFsUserId(user.getUserId());
|
|
|
+ fsUserWx.setAppId(appId);
|
|
|
+ fsUserWx.setOpenId(user.getMaOpenId());
|
|
|
+// fsUserWx.setUnionId(session.getUnionid() == null ? "" : session.getUnionid());
|
|
|
+ fsUserWx.setCreateTime(new Date());
|
|
|
+ fsUserWx.setUpdateTime(new Date());
|
|
|
+ fsUserWxService.save(fsUserWx);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发放红包奖励
|
|
|
*
|
|
@@ -1151,18 +1173,26 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
// 来源是小程序切换openId
|
|
|
if (param.getSource() == 2) {
|
|
|
//处理多小程序问题
|
|
|
- Company company = companyMapper.selectCompanyById(param.getCompanyId());
|
|
|
- if (company.getCourseMiniAppId()==null){
|
|
|
- return R.error("销售公司参数错误,未绑定小程序");
|
|
|
- }
|
|
|
- FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(company.getCourseMiniAppId(),user.getUserId(),1);
|
|
|
+// Company company = companyMapper.selectCompanyById(param.getCompanyId());
|
|
|
+// if (company.getCourseMiniAppId()==null){
|
|
|
+// return R.error("销售公司参数错误,未绑定小程序");
|
|
|
+// }
|
|
|
+ FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1);
|
|
|
if (fsUserWx ==null || fsUserWx.getOpenId()==null){
|
|
|
- return R.error("小程序openId参数缺失");
|
|
|
+ packetParam.setOpenId(user.getCourseMaOpenId());
|
|
|
+ try {
|
|
|
+ handleFsUserWx(user,param.getAppId());
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.error("zyp \n 【更新或插入用户与小程序的绑定关系失败】:{}", user.getUserId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }else {
|
|
|
+ packetParam.setOpenId(fsUserWx.getOpenId());
|
|
|
}
|
|
|
|
|
|
System.out.println("小程序id"+user.getCourseMaOpenId());
|
|
|
//查出公司绑定openid并赋值
|
|
|
- packetParam.setOpenId(fsUserWx.getOpenId());
|
|
|
+// packetParam.setOpenId(fsUserWx.getOpenId());
|
|
|
}
|
|
|
packetParam.setAmount(amount);
|
|
|
packetParam.setSource(param.getSource());
|
|
@@ -1171,6 +1201,9 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
System.out.println("红包金额"+amount);
|
|
|
System.out.println("红包商户号"+packetParam);
|
|
|
+ if (ObjectUtils.isNotEmpty(config.getIsNegative())&&config.getIsNegative() == 1) {
|
|
|
+ return processRedPacket(config, packetParam, param, amount, log);
|
|
|
+ }
|
|
|
//2025.6.19 红包金额为0的时候
|
|
|
if (amount.compareTo(BigDecimal.ZERO)>0){
|
|
|
|
|
@@ -1183,13 +1216,14 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
redPacketLog.setCompanyId(param.getCompanyId());
|
|
|
redPacketLog.setUserId(param.getUserId());
|
|
|
redPacketLog.setVideoId(param.getVideoId());
|
|
|
- redPacketLog.setStatus(2);
|
|
|
+ redPacketLog.setStatus(0);
|
|
|
redPacketLog.setQwUserId(param.getQwUserId() != null ? param.getQwUserId() : null);
|
|
|
redPacketLog.setCompanyUserId(param.getCompanyUserId());
|
|
|
redPacketLog.setCreateTime(new Date());
|
|
|
redPacketLog.setAmount(amount);
|
|
|
redPacketLog.setWatchLogId(log.getLogId() != null ? log.getLogId() : null);
|
|
|
redPacketLog.setPeriodId(param.getPeriodId());
|
|
|
+ redPacketLog.setAppId(param.getAppId());
|
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
return R.error("销售公司余额不足");
|
|
|
}
|
|
@@ -1218,6 +1252,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
redPacketLog.setAmount(amount);
|
|
|
redPacketLog.setWatchLogId(log.getLogId() != null ? log.getLogId() : null);
|
|
|
redPacketLog.setPeriodId(param.getPeriodId());
|
|
|
+ redPacketLog.setAppId(param.getAppId());
|
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
|
|
|
// 更新观看记录的奖励类型
|
|
@@ -1254,6 +1289,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
redPacketLog.setAmount(BigDecimal.ZERO);
|
|
|
redPacketLog.setWatchLogId(log.getLogId() != null ? log.getLogId() : null);
|
|
|
redPacketLog.setPeriodId(param.getPeriodId());
|
|
|
+ redPacketLog.setAppId(param.getAppId());
|
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
|
|
|
// 更新观看记录的奖励类型
|
|
@@ -1266,6 +1302,64 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 直接发送奖励
|
|
|
+ *
|
|
|
+ * @param config
|
|
|
+ * @param packetParam
|
|
|
+ * @param param
|
|
|
+ * @param amount
|
|
|
+ * @param log
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private R processRedPacket(CourseConfig config, WxSendRedPacketParam packetParam, FsCourseSendRewardUParam param, BigDecimal amount, FsCourseWatchLog log) {
|
|
|
+ R sendRedPacket = paymentService.sendRedPacket(packetParam);
|
|
|
+
|
|
|
+ if (!sendRedPacket.get("code").equals(200)) {
|
|
|
+ return R.error("奖励发送失败,请联系客服");
|
|
|
+ }
|
|
|
+
|
|
|
+ createRedPacketLog(sendRedPacket, param, amount, log);
|
|
|
+ updateWatchLogRewardType(log, config);
|
|
|
+
|
|
|
+ return sendRedPacket;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createRedPacketLog(R sendRedPacket, FsCourseSendRewardUParam param, BigDecimal amount, FsCourseWatchLog log) {
|
|
|
+ FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
+
|
|
|
+ // Set common fields
|
|
|
+ redPacketLog.setCourseId(param.getCourseId());
|
|
|
+ redPacketLog.setCompanyId(param.getCompanyId());
|
|
|
+ redPacketLog.setUserId(param.getUserId());
|
|
|
+ redPacketLog.setVideoId(param.getVideoId());
|
|
|
+ redPacketLog.setStatus(0);
|
|
|
+ redPacketLog.setQwUserId(param.getQwUserId());
|
|
|
+ redPacketLog.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ redPacketLog.setCreateTime(new Date());
|
|
|
+ redPacketLog.setAmount(amount);
|
|
|
+ redPacketLog.setWatchLogId(log != null ? log.getLogId() : null);
|
|
|
+ redPacketLog.setPeriodId(param.getPeriodId());
|
|
|
+ redPacketLog.setAppId(param.getAppId());
|
|
|
+
|
|
|
+ // Set batch number based on isNew flag
|
|
|
+ if (sendRedPacket.get("isNew").equals(1)) {
|
|
|
+ TransferBillsResult transferBillsResult = (TransferBillsResult) sendRedPacket.get("data");
|
|
|
+ redPacketLog.setResult(JSON.toJSONString(sendRedPacket));
|
|
|
+ redPacketLog.setOutBatchNo(transferBillsResult.getOutBillNo());
|
|
|
+ } else {
|
|
|
+ redPacketLog.setOutBatchNo(sendRedPacket.get("orderCode").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateWatchLogRewardType(FsCourseWatchLog log, CourseConfig config) {
|
|
|
+ if (log != null) {
|
|
|
+ log.setRewardType(config.getRewardType());
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 获取用户openId
|
|
|
*
|
|
@@ -1345,7 +1439,23 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
@Override
|
|
|
public List<FsUserCourseVideoPageListVO> pageListCourseVideo(UserCourseVideoPageParam param) {
|
|
|
- return fsUserCourseVideoMapper.selectFsUserCourseVideoPageList(param);
|
|
|
+ List<FsUserCourseVideoPageListVO> courseVideoPageListVOList = fsUserCourseVideoMapper.selectFsUserCourseVideoPageList(param);
|
|
|
+ if (courseVideoPageListVOList.isEmpty()) {
|
|
|
+ return new LinkedList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SysDictData> courseProject = dictDataMapper.selectDictDataByType("sys_course_project");
|
|
|
+ Map<String, String> projectMap = courseProject.stream()
|
|
|
+ .collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
|
|
|
+
|
|
|
+ courseVideoPageListVOList.forEach(vo -> {
|
|
|
+ if (vo.getProjectId() != null) {
|
|
|
+ String projectName = projectMap.get(vo.getProjectId().toString());
|
|
|
+ vo.setProjectName(projectName);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return courseVideoPageListVOList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -1425,7 +1535,29 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
if (fsUser == null){
|
|
|
return ResponseResult.fail(404,"当前用户信息不存在");
|
|
|
}
|
|
|
-
|
|
|
+ //公开课
|
|
|
+ if (param.getIsOpenCourse()!=null && param.getIsOpenCourse()==1){
|
|
|
+ FsCourseWatchLog watchCourseVideo = courseWatchLogMapper.getCourseWatchLogByUser(param.getUserId(), param.getVideoId());
|
|
|
+ //添加判断:该用户是否已经存在此课程的看课记录,并且看课记录的销售id不是传入的销售id
|
|
|
+ if(watchCourseVideo != null){
|
|
|
+ FsCourseWatchLog updateLog = new FsCourseWatchLog();
|
|
|
+ updateLog.setUpdateTime(new Date());
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(updateLog);
|
|
|
+ } else {
|
|
|
+ FsCourseWatchLog fsCourseWatchLog = new FsCourseWatchLog();
|
|
|
+ BeanUtils.copyProperties(param, fsCourseWatchLog);
|
|
|
+ fsCourseWatchLog.setSendType(1);
|
|
|
+ fsCourseWatchLog.setDuration(0L);
|
|
|
+ fsCourseWatchLog.setCreateTime(new Date());
|
|
|
+ fsCourseWatchLog.setLogType(1);
|
|
|
+ courseWatchLogMapper.insertFsCourseWatchLog(fsCourseWatchLog);
|
|
|
+ String redisKey = "h5wxuser:watch:heartbeat:" + param.getUserId() + ":" + param.getVideoId() + ":" + 0;
|
|
|
+ redisCache.setCacheObject(redisKey, LocalDateTime.now().toString());
|
|
|
+ // 设置 Redis 记录的过期时间(例如 5 分钟)
|
|
|
+ redisCache.expire(redisKey, 300, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+ return ResponseResult.ok(Boolean.TRUE);
|
|
|
+ }
|
|
|
//判断该销售是否存在
|
|
|
CompanyUser companyUser = companyUserMapper.selectCompanyUserById(param.getCompanyUserId());
|
|
|
if (companyUser == null){
|
|
@@ -1748,7 +1880,9 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
if (param.getLinkType() != null && param.getLinkType() == 1){
|
|
|
return R.ok();
|
|
|
}
|
|
|
-
|
|
|
+ if (param.getCompanyUserId()==null){
|
|
|
+ param.setCompanyUserId(0L);
|
|
|
+ }
|
|
|
// 从Redis中获取观看时长
|
|
|
String redisKey = "h5wxuser:watch:duration:" + param.getUserId() + ":" + param.getVideoId() + ":" + param.getCompanyUserId();
|
|
|
log.info("看课redis缓存key:{}", redisKey);
|