|
@@ -17,8 +17,10 @@ import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.utils.date.DateUtil;
|
|
|
import com.fs.company.domain.Company;
|
|
|
+import com.fs.company.domain.CompanyMoneyLogs;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
import com.fs.company.mapper.CompanyMapper;
|
|
|
+import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.*;
|
|
@@ -74,6 +76,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
@@ -100,7 +103,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
private static final String miniappRealLink = "/pages_course/video.html?course=";
|
|
|
private static final String REAL_LINK_PREFIX = "/courseH5/pages/course/learning?course=";
|
|
|
private static final String SHORT_LINK_PREFIX = "/courseH5/pages/course/learning?s=";
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private CompanyMoneyLogsMapper moneyLogsMapper;
|
|
|
@Autowired
|
|
|
private FsUserCourseVideoMapper fsUserCourseVideoMapper;
|
|
|
@Autowired
|
|
@@ -404,17 +408,17 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
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 {
|
|
|
- new Thread(() -> {
|
|
|
- try {
|
|
|
- rocketMQTemplate.syncSend("repeat-upload", JSON.toJSONString(RepeatUploadVo.builder().type(1).fsUserId(param.getUserId()).build()));
|
|
|
- }catch (Exception e){
|
|
|
- logger.error("看课重粉提交mq失败", e);
|
|
|
- }
|
|
|
- }).start();
|
|
|
- }catch (Exception e){
|
|
|
- logger.error("看课重粉提交mq失败", e);
|
|
|
- }
|
|
|
+// try {
|
|
|
+// new Thread(() -> {
|
|
|
+// try {
|
|
|
+// rocketMQTemplate.syncSend("repeat-upload", JSON.toJSONString(RepeatUploadVo.builder().type(1).fsUserId(param.getUserId()).build()));
|
|
|
+// }catch (Exception e){
|
|
|
+// logger.error("看课重粉提交mq失败", e);
|
|
|
+// }
|
|
|
+// }).start();
|
|
|
+// }catch (Exception e){
|
|
|
+// logger.error("看课重粉提交mq失败", e);
|
|
|
+// }
|
|
|
|
|
|
Integer isRoom = param.getIsRoom();
|
|
|
|
|
@@ -464,8 +468,10 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
// }
|
|
|
// return R.ok().put("qwExternalId",matchedContact.getId());
|
|
|
FsCourseLink courseLink = courseLinkMapper.selectFsCourseLinkByLink(param.getLink());
|
|
|
+ System.out.println("查询的链接参数"+courseLink);
|
|
|
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>";
|
|
|
+ System.out.println("企微传参:"+courseLink.getChatId()+"corpId:"+param.getCorpId());
|
|
|
QwGroupChatDetailsResult result = qwApiService.groupChatDetails(courseLink.getChatId(), param.getCorpId());
|
|
|
if(result.getErrCode() != 0){
|
|
|
return R.error("企微接口请求失败,请联系管理员:" +result.getErrMsg());
|
|
@@ -825,9 +831,20 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
// 根据链接类型判断是否已发放奖励
|
|
|
if (param.getLinkType() != null && param.getLinkType() == 1) {
|
|
|
FsCourseRedPacketLog packetLog = redPacketLogMapper.selectFsCourseRedPacketLogByTemporary(param.getVideoId(), param.getUserId());
|
|
|
- if (packetLog != null) {
|
|
|
+ if(packetLog != null && packetLog.getStatus() == 1) {
|
|
|
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("奖励已发放");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(packetLog != null && packetLog.getStatus() == 2) {
|
|
|
+ return R.error("请联系客服补发");
|
|
|
+ }
|
|
|
} else {
|
|
|
log = courseWatchLogMapper.getWatchCourseVideo(param.getUserId(), param.getVideoId(), param.getQwUserId(), param.getQwExternalId());
|
|
|
if (log == null) {
|
|
@@ -905,18 +922,22 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
*/
|
|
|
private R sendRedPacketReward(FsCourseSendRewardUParam param, FsUser user, FsCourseWatchLog log, FsUserCourseVideo video, CourseConfig config) {
|
|
|
// 判断是否属于领取红包时间(会员看课发放红包)
|
|
|
- FsUserCoursePeriodDays periodDays = new FsUserCoursePeriodDays();
|
|
|
- periodDays.setVideoId(param.getVideoId());
|
|
|
- periodDays.setPeriodId(param.getPeriodId());
|
|
|
- //正常情况是只能查询到一条,之前可能存在重复的脏数据,暂使用查询list的方式
|
|
|
- List<FsUserCoursePeriodDays> fsUserCoursePeriodDays = fsUserCoursePeriodDaysMapper.selectFsUserCoursePeriodDaysList(periodDays);
|
|
|
- if(fsUserCoursePeriodDays != null && !fsUserCoursePeriodDays.isEmpty()){
|
|
|
- periodDays = fsUserCoursePeriodDays.get(0);
|
|
|
+ if (param.getPeriodId()!=null && param.getPeriodId()>0) {
|
|
|
+ FsUserCoursePeriodDays periodDays = new FsUserCoursePeriodDays();
|
|
|
+ periodDays.setVideoId(param.getVideoId());
|
|
|
+ periodDays.setPeriodId(param.getPeriodId());
|
|
|
+ //正常情况是只能查询到一条,之前可能存在重复的脏数据,暂使用查询list的方式
|
|
|
+ List<FsUserCoursePeriodDays> fsUserCoursePeriodDays = fsUserCoursePeriodDaysMapper.selectFsUserCoursePeriodDaysList(periodDays);
|
|
|
+ if(fsUserCoursePeriodDays != null && !fsUserCoursePeriodDays.isEmpty()){
|
|
|
+ periodDays = fsUserCoursePeriodDays.get(0);
|
|
|
+ }
|
|
|
+ if(periodDays != null && periodDays.getLastJoinTime() !=null && LocalDateTime.now().isAfter(periodDays.getLastJoinTime())) {
|
|
|
+ return R.error(403,"已超过领取红包时间");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if(periodDays != null && periodDays.getLastJoinTime() !=null && LocalDateTime.now().isAfter(periodDays.getLastJoinTime())) {
|
|
|
- return R.error(403,"已超过领取红包时间");
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// 确定红包金额
|
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
@@ -946,6 +967,26 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
System.out.println("红包商户号"+packetParam);
|
|
|
//2025.6.19 红包金额为0的时候
|
|
|
if (amount.compareTo(BigDecimal.ZERO)>0){
|
|
|
+
|
|
|
+ Company company = companyMapper.selectCompanyByIdForUpdate(param.getCompanyId());
|
|
|
+ BigDecimal money = company.getMoney();
|
|
|
+ BigDecimal subtract = money.subtract(amount);
|
|
|
+ if (subtract.compareTo(BigDecimal.ZERO)<0){
|
|
|
+ FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
+ redPacketLog.setCourseId(param.getCourseId());
|
|
|
+ redPacketLog.setCompanyId(param.getCompanyId());
|
|
|
+ redPacketLog.setUserId(param.getUserId());
|
|
|
+ redPacketLog.setVideoId(param.getVideoId());
|
|
|
+ redPacketLog.setStatus(2);
|
|
|
+ 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());
|
|
|
+ redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
+ return R.error("销售公司余额不足");
|
|
|
+ }
|
|
|
// 发送红包
|
|
|
R sendRedPacket = paymentService.sendRedPacket(packetParam);
|
|
|
if (sendRedPacket.get("code").equals(200)) {
|
|
@@ -953,6 +994,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
TransferBillsResult transferBillsResult;
|
|
|
if (sendRedPacket.get("isNew").equals(1)){
|
|
|
transferBillsResult = (TransferBillsResult)sendRedPacket.get("data");
|
|
|
+ redPacketLog.setResult(JSON.toJSONString(sendRedPacket));
|
|
|
redPacketLog.setOutBatchNo(transferBillsResult.getOutBillNo());
|
|
|
}else {
|
|
|
redPacketLog.setOutBatchNo(sendRedPacket.get("orderCode").toString());
|
|
@@ -973,10 +1015,20 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
|
|
|
// 更新观看记录的奖励类型
|
|
|
-// if (param.getLinkType() == null || param.getLinkType() == 0) {
|
|
|
log.setRewardType(config.getRewardType());
|
|
|
courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
-// }
|
|
|
+ company.setMoney(subtract);
|
|
|
+ companyMapper.updateCompany(company);
|
|
|
+
|
|
|
+ CompanyMoneyLogs logs=new CompanyMoneyLogs();
|
|
|
+ logs.setCompanyId(company.getCompanyId());
|
|
|
+ logs.setRemark("扣除红包金额");
|
|
|
+ logs.setMoney(amount.multiply(new BigDecimal(-1)));
|
|
|
+ logs.setLogsType(15);
|
|
|
+ logs.setBalance(company.getMoney());
|
|
|
+ logs.setCreateTime(new Date());
|
|
|
+ moneyLogsMapper.insertCompanyMoneyLogs(logs);
|
|
|
+
|
|
|
return sendRedPacket;
|
|
|
} else {
|
|
|
return R.error("奖励发送失败,请联系客服");
|