|
@@ -4,6 +4,7 @@ import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
@@ -39,6 +40,7 @@ import com.fs.live.param.CouponPO;
|
|
|
import com.fs.live.param.LiveRedPacketParam;
|
|
import com.fs.live.param.LiveRedPacketParam;
|
|
|
import com.fs.live.mapper.LiveMapper;
|
|
import com.fs.live.mapper.LiveMapper;
|
|
|
import com.fs.live.service.*;
|
|
import com.fs.live.service.*;
|
|
|
|
|
+import com.fs.live.vo.LiveCompletionAnswerRecordListVO;
|
|
|
import com.fs.live.vo.RecordTimeRangeVO;
|
|
import com.fs.live.vo.RecordTimeRangeVO;
|
|
|
import com.fs.voice.utils.StringUtil;
|
|
import com.fs.voice.utils.StringUtil;
|
|
|
import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult;
|
|
import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult;
|
|
@@ -127,6 +129,9 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FsCourseCouponUserMapper courseCouponUserMapper;
|
|
private FsCourseCouponUserMapper courseCouponUserMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ILiveCompletionAnswerRecordService liveCompletionAnswerRecordService;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 查询直播红包 记录
|
|
* 查询直播红包 记录
|
|
@@ -272,6 +277,10 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
|
|
|
if (watchUser==null){
|
|
if (watchUser==null){
|
|
|
return R.error("您没有观看过该课程,无奖励发放!");
|
|
return R.error("您没有观看过该课程,无奖励发放!");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (watchUser.getSendType() != null){
|
|
|
|
|
+ return R.error("奖励已发放!请勿重复领取");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
//直播不空 那要存一下录播
|
|
//直播不空 那要存一下录播
|
|
|
else {
|
|
else {
|
|
@@ -280,28 +289,46 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (watchUser.getSendType() != null || (replayUser != null && replayUser.getSendType() != null)){
|
|
|
|
|
+ return R.error("奖励已发放!请勿重复领取");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- //是否以及领取了奖励 看直播或者录播 俩者只要有一个领取了奖励 就返回
|
|
|
|
|
- if (watchUser.getRewardType() != null || (replayUser != null && replayUser.getRewardType() != null)) {
|
|
|
|
|
-
|
|
|
|
|
- LiveRedPacketLog liveRedPacketLog = redPacketLogMapper.selectLiveRedPacketLogByTemporary(param.getLiveId(), param.getUserId());
|
|
|
|
|
|
|
+ // 查是否有领取记录
|
|
|
|
|
+ LiveRedPacketLog liveRedPacketLog = redPacketLogMapper.selectLiveRedPacketLogByTemporary(param.getLiveId(), param.getUserId());
|
|
|
|
|
|
|
|
- log.info("直播课程红包:{}", liveRedPacketLog);
|
|
|
|
|
- if (liveRedPacketLog != null && liveRedPacketLog.getStatus() == 1) {
|
|
|
|
|
- return R.error("已领取该直播课程奖励,不可重复领取!");
|
|
|
|
|
- }
|
|
|
|
|
- if (liveRedPacketLog != null && liveRedPacketLog.getStatus() == 0) {
|
|
|
|
|
- if (StringUtils.isNotEmpty(liveRedPacketLog.getResult())) {
|
|
|
|
|
- R r = JSON.parseObject(liveRedPacketLog.getResult(), R.class);
|
|
|
|
|
- return r;
|
|
|
|
|
- } else {
|
|
|
|
|
- return R.error("操作频繁,请稍后再试!");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (liveRedPacketLog != null && liveRedPacketLog.getStatus() == 2) {
|
|
|
|
|
- return R.error("请联系客服补发");
|
|
|
|
|
|
|
+ log.info("直播课程红包:{}", liveRedPacketLog);
|
|
|
|
|
+ if (liveRedPacketLog != null && liveRedPacketLog.getStatus() == 1) {
|
|
|
|
|
+ //已领确定领取
|
|
|
|
|
+ watchUser.setRewardType(1);
|
|
|
|
|
+ watchUser.setSendType(1);
|
|
|
|
|
+ watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
+ return R.error("已领取该直播课程奖励,不可重复领取!");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (liveRedPacketLog != null && liveRedPacketLog.getStatus() == 0) {
|
|
|
|
|
+ //已跳转但是没点确定领取
|
|
|
|
|
+ watchUser.setRewardType(1);
|
|
|
|
|
+ watchUser.setSendType(1);
|
|
|
|
|
+ watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
+
|
|
|
|
|
+ if (!StringUtil.strIsNullOrEmpty(liveRedPacketLog.getResult())) {
|
|
|
|
|
+ R r = JSON.parseObject(liveRedPacketLog.getResult(), R.class);
|
|
|
|
|
+ return r;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return R.error("操作频繁,请稍后再试!");
|
|
|
}
|
|
}
|
|
|
- return R.error("奖励已发放");
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ if (liveRedPacketLog != null && liveRedPacketLog.getStatus() == 2) {
|
|
|
|
|
+ return R.error("请联系客服补发");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //已经有领取记录了 但是 奖励状态没变更 给它改了
|
|
|
|
|
+ if (liveRedPacketLog!=null && (watchUser.getRewardType() != null || (replayUser != null && replayUser.getRewardType() != null))) {
|
|
|
|
|
+ //已跳转但是没点确定领取
|
|
|
|
|
+ watchUser.setRewardType(98);
|
|
|
|
|
+ watchUser.setSendType(1);
|
|
|
|
|
+ watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
+
|
|
|
|
|
+ return R.error("奖励已发放!请勿重复领取");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//判断直播数据 是否满足 完课/如果有录播数据 再判断录播是否满足完课
|
|
//判断直播数据 是否满足 完课/如果有录播数据 再判断录播是否满足完课
|
|
@@ -353,6 +380,22 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //没设置题目直接发 设置了题目 判断答得对不 对也发 不对不发
|
|
|
|
|
+ if (!StringUtil.strIsNullOrEmpty(config.getFinishQuestionIds())){
|
|
|
|
|
+ LiveCompletionAnswerRecordListVO answerRecordListVO = liveCompletionAnswerRecordService.selectLiveCompletionAnswerRecordByLiveUserId(param.getLiveId(), param.getUserId());
|
|
|
|
|
+ //没有答对的 直接红包OK 答对了走下面的 红包
|
|
|
|
|
+ if (answerRecordListVO==null){
|
|
|
|
|
+
|
|
|
|
|
+ // 97 直播题目没答对且次数耗尽
|
|
|
|
|
+ watchUser.setRewardType(97);
|
|
|
|
|
+ watchUser.setSendType(1);
|
|
|
|
|
+
|
|
|
|
|
+ watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
|
|
|
|
|
|
if (StringUtil.strIsNullOrEmpty(user.getAppOpenId())){
|
|
if (StringUtil.strIsNullOrEmpty(user.getAppOpenId())){
|
|
@@ -451,9 +494,12 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
|
|
|
if (parts.length > 4 && !parts[4].isEmpty()) {
|
|
if (parts.length > 4 && !parts[4].isEmpty()) {
|
|
|
range.setScoreAmount(Long.valueOf(parts[4]));
|
|
range.setScoreAmount(Long.valueOf(parts[4]));
|
|
|
}
|
|
}
|
|
|
- // 核销卷ID
|
|
|
|
|
|
|
+ // 核销卷ID列表(~分隔)
|
|
|
if (parts.length > 5 && !parts[5].isEmpty()) {
|
|
if (parts.length > 5 && !parts[5].isEmpty()) {
|
|
|
- range.setCouponId(Long.valueOf(parts[5]));
|
|
|
|
|
|
|
+ range.setCouponIds(Arrays.stream(parts[5].split("~"))
|
|
|
|
|
+ .filter(s -> !s.isEmpty())
|
|
|
|
|
+ .map(Long::valueOf)
|
|
|
|
|
+ .collect(Collectors.toList()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
result.add(range);
|
|
result.add(range);
|
|
@@ -473,18 +519,45 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
|
|
|
|
|
|
|
|
// 红包
|
|
// 红包
|
|
|
if (matched.getRewardTypes() != null && matched.getRewardTypes().contains("1")) {
|
|
if (matched.getRewardTypes() != null && matched.getRewardTypes().contains("1")) {
|
|
|
- WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
|
|
|
- if (StringUtil.strIsNullOrEmpty(user.getAppOpenId())) {
|
|
|
|
|
- return R.error("请重新登录app");
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //没设置题目直接发 设置了题目 判断答得对不 对也发 不对不发
|
|
|
|
|
+ if (!StringUtil.strIsNullOrEmpty(config.getFinishQuestionIds())){
|
|
|
|
|
+ LiveCompletionAnswerRecordListVO answerRecordListVO = liveCompletionAnswerRecordService.selectLiveCompletionAnswerRecordByLiveUserId(param.getLiveId(), param.getUserId());
|
|
|
|
|
+ //没有答对的 直接红包OK 答对了走下面的 红包
|
|
|
|
|
+ if (answerRecordListVO==null){
|
|
|
|
|
+ hasReward = true;
|
|
|
|
|
+ combinedRewardType |= 1;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
|
|
|
+ if (StringUtil.strIsNullOrEmpty(user.getAppOpenId())) {
|
|
|
|
|
+ return R.error("请重新登录app");
|
|
|
|
|
+ }
|
|
|
|
|
+ String openId = user.getAppOpenId();
|
|
|
|
|
+ packetParam.setOpenId(openId);
|
|
|
|
|
+ BeanUtils.copyProperties(param, packetParam);
|
|
|
|
|
+ config.setRedPacketAmount(matched.getRedPacketAmount());
|
|
|
|
|
+ lastResult = sendAppLiveRedPacketAuto(packetParam, watchUser, config, param);
|
|
|
|
|
+
|
|
|
|
|
+ hasReward = true;
|
|
|
|
|
+ combinedRewardType |= 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }else {
|
|
|
|
|
+ WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
|
|
|
+ if (StringUtil.strIsNullOrEmpty(user.getAppOpenId())) {
|
|
|
|
|
+ return R.error("请重新登录app");
|
|
|
|
|
+ }
|
|
|
|
|
+ String openId = user.getAppOpenId();
|
|
|
|
|
+ packetParam.setOpenId(openId);
|
|
|
|
|
+ BeanUtils.copyProperties(param, packetParam);
|
|
|
|
|
+ config.setRedPacketAmount(matched.getRedPacketAmount());
|
|
|
|
|
+ lastResult = sendAppLiveRedPacketAuto(packetParam, watchUser, config, param);
|
|
|
|
|
+
|
|
|
|
|
+ hasReward = true;
|
|
|
|
|
+ combinedRewardType |= 1;
|
|
|
}
|
|
}
|
|
|
- String openId = user.getAppOpenId();
|
|
|
|
|
- packetParam.setOpenId(openId);
|
|
|
|
|
- BeanUtils.copyProperties(param, packetParam);
|
|
|
|
|
- config.setRedPacketAmount(matched.getRedPacketAmount());
|
|
|
|
|
- lastResult = sendAppLiveRedPacketAuto(packetParam, watchUser, config, param);
|
|
|
|
|
-// lastResult = R.ok();
|
|
|
|
|
- hasReward = true;
|
|
|
|
|
- combinedRewardType |= 1;
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
// 积分
|
|
// 积分
|
|
|
if (matched.getRewardTypes() != null && matched.getRewardTypes().contains("2")) {
|
|
if (matched.getRewardTypes() != null && matched.getRewardTypes().contains("2")) {
|
|
@@ -495,7 +568,23 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
|
|
|
}
|
|
}
|
|
|
// 课程优惠卷(核销卷)
|
|
// 课程优惠卷(核销卷)
|
|
|
if (matched.getRewardTypes() != null && matched.getRewardTypes().contains("3")) {
|
|
if (matched.getRewardTypes() != null && matched.getRewardTypes().contains("3")) {
|
|
|
- sendIssueCourseCoupon(param.getLiveId(),user.getUserId(),matched.getCouponId(),watchUser);
|
|
|
|
|
|
|
+ if (matched.getCouponIds() != null && !matched.getCouponIds().isEmpty()) {
|
|
|
|
|
+ List<String> failMsgs = new ArrayList<>();
|
|
|
|
|
+ for (Long couponId : matched.getCouponIds()) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ R couponResult = sendIssueCourseCoupon(param.getLiveId(), user.getUserId(), couponId);
|
|
|
|
|
+ if (couponResult.get("msg") != null) {
|
|
|
|
|
+ failMsgs.add("核销卷" + couponId + ":" + couponResult.get("msg"));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("发放核销卷异常,couponId:{}", couponId, e);
|
|
|
|
|
+ failMsgs.add("核销卷" + couponId + ":发放异常");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!failMsgs.isEmpty()) {
|
|
|
|
|
+ watchUser.setRemark(String.join("; ", failMsgs));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
hasReward = true;
|
|
hasReward = true;
|
|
|
combinedRewardType |= 4;
|
|
combinedRewardType |= 4;
|
|
|
}
|
|
}
|
|
@@ -611,35 +700,27 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
|
|
|
/**
|
|
/**
|
|
|
* 发放直播-课程优惠卷卷
|
|
* 发放直播-课程优惠卷卷
|
|
|
*/
|
|
*/
|
|
|
- public R sendIssueCourseCoupon(Long liveId, Long userId, Long couponId,LiveWatchUser watchUser) {
|
|
|
|
|
|
|
+ public R sendIssueCourseCoupon(Long liveId, Long userId, Long couponId) {
|
|
|
|
|
|
|
|
//优惠券
|
|
//优惠券
|
|
|
FsCourseCoupon fsCourseCoupon = fsCourseCouponMapper.selectFsCourseCouponById(couponId);
|
|
FsCourseCoupon fsCourseCoupon = fsCourseCouponMapper.selectFsCourseCouponById(couponId);
|
|
|
|
|
|
|
|
if (fsCourseCoupon == null) {
|
|
if (fsCourseCoupon == null) {
|
|
|
- watchUser.setRemark("核销卷不存在-发放失败");
|
|
|
|
|
- watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
- return R.ok();
|
|
|
|
|
|
|
+ return R.ok("不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (fsCourseCoupon.getStatus() != 1) {
|
|
if (fsCourseCoupon.getStatus() != 1) {
|
|
|
- watchUser.setRemark("核销卷已停用-发放失败");
|
|
|
|
|
- watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
- return R.ok();
|
|
|
|
|
|
|
+ return R.ok("已停用");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (fsCourseCoupon.getRemainNumber() <= 0) {
|
|
if (fsCourseCoupon.getRemainNumber() <= 0) {
|
|
|
- watchUser.setRemark("核销卷剩余数量不足-发放失败");
|
|
|
|
|
- watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
- return R.ok();
|
|
|
|
|
|
|
+ return R.ok("剩余数量不足");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//用户领取优惠券总数
|
|
//用户领取优惠券总数
|
|
|
Integer count = courseCouponUserMapper.selectCountByUserIdAndCouponId(userId, couponId);
|
|
Integer count = courseCouponUserMapper.selectCountByUserIdAndCouponId(userId, couponId);
|
|
|
if (count >= fsCourseCoupon.getLimitCount()) {
|
|
if (count >= fsCourseCoupon.getLimitCount()) {
|
|
|
- watchUser.setRemark("该核销卷领取达到上限,发放失败");
|
|
|
|
|
- watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
- return R.ok();
|
|
|
|
|
|
|
+ return R.ok("领取达到上限");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//发放优惠券
|
|
//发放优惠券
|
|
@@ -777,9 +858,10 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
|
|
|
if (sendRedPacket.get("code").equals(200)) {
|
|
if (sendRedPacket.get("code").equals(200)) {
|
|
|
|
|
|
|
|
// 更新观看记录的奖励类型
|
|
// 更新观看记录的奖励类型
|
|
|
-// watchUser.setRewardType(1);
|
|
|
|
|
-// watchUser.setSendType(1);
|
|
|
|
|
-// watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
|
|
+ watchUser.setRewardType(1);
|
|
|
|
|
+ watchUser.setSendType(1);
|
|
|
|
|
+ watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
LiveRedPacketLog liveRedPacketLog = new LiveRedPacketLog();
|
|
LiveRedPacketLog liveRedPacketLog = new LiveRedPacketLog();
|
|
|
TransferBillsResult transferBillsResult;
|
|
TransferBillsResult transferBillsResult;
|
|
@@ -833,9 +915,10 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
|
|
|
if (sendRedPacket.get("code").equals(200)) {
|
|
if (sendRedPacket.get("code").equals(200)) {
|
|
|
|
|
|
|
|
// 更新观看记录的奖励类型
|
|
// 更新观看记录的奖励类型
|
|
|
-// watchUser.setRewardType(1);
|
|
|
|
|
-// watchUser.setSendType(1);
|
|
|
|
|
-// watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
|
|
+ watchUser.setRewardType(1);
|
|
|
|
|
+ watchUser.setSendType(1);
|
|
|
|
|
+ watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
LiveRedPacketLog liveRedPacketLog = new LiveRedPacketLog();
|
|
LiveRedPacketLog liveRedPacketLog = new LiveRedPacketLog();
|
|
|
TransferBillsResult transferBillsResult;
|
|
TransferBillsResult transferBillsResult;
|
|
@@ -872,10 +955,11 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
|
|
-// // 更新直播观看记录的奖励类型
|
|
|
|
|
-// watchUser.setRewardType(1);
|
|
|
|
|
-// watchUser.setSendType(1);
|
|
|
|
|
-// watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
|
|
+ // 更新观看记录的奖励类型
|
|
|
|
|
+ watchUser.setRewardType(1);
|
|
|
|
|
+ watchUser.setSendType(1);
|
|
|
|
|
+ watchUserMapper.updateLiveWatchUser(watchUser);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
LiveRedPacketLog liveRedPacketLog = new LiveRedPacketLog();
|
|
LiveRedPacketLog liveRedPacketLog = new LiveRedPacketLog();
|
|
|
// 添加红包记录
|
|
// 添加红包记录
|