Просмотр исходного кода

手动/自动发app 课的领红包

三七 6 дней назад
Родитель
Сommit
0dd1f3e58b

+ 2 - 2
fs-service/src/main/java/com/fs/course/service/IFsUserCourseVideoService.java

@@ -288,7 +288,7 @@ public interface IFsUserCourseVideoService extends IService<FsUserCourseVideo> {
     R createAppFd(LuckyBagCollectRecord param);
 
     /**
-    * app发红包
+    * app发红包 1 自动发课 2 手动发课
     */
-    R withdrawal(FsCourseSendRewardUParam param);
+    R withdrawal(FsCourseSendRewardUParam param,Integer type);
 }

+ 22 - 5
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -1609,7 +1609,7 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
                 case 1:
                     if (param.getSource() == 3){
                         param.setWatchLogId(watchLog.getLogId());
-                        return withdrawal(param);
+                        return withdrawal(param,1);
                     } else {
                         return sendRedPacketReward(param, user, watchLog, video, config);
                     }
@@ -4897,7 +4897,7 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
      */
     @Override
     @Transactional
-    public R withdrawal(FsCourseSendRewardUParam param) {
+    public R withdrawal(FsCourseSendRewardUParam param,Integer type) {
         Long userId = param.getUserId();
         // 生成锁的key,基于用户ID和视频ID确保同一用户同一视频的请求被锁定
         String lockKey = "reward_red_lock:user:" + userId;
@@ -4912,7 +4912,7 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
             }
 
             logger.info("成功获取锁,开始处理奖励发放,用户ID:{}", userId);
-            return executeWithdrawal(param);
+            return executeWithdrawal(param,type);
 
         } catch (InterruptedException e) {
             Thread.currentThread().interrupt();
@@ -5034,7 +5034,7 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
     }
 
 
-    private R executeWithdrawal(FsCourseSendRewardUParam param) {
+    private R executeWithdrawal(FsCourseSendRewardUParam param, Integer type) {
         log.info("进入用户判断");
         FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
         if (user == null) {
@@ -5103,8 +5103,12 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
                 }
                 packetParam.setOpenId(openId);
                 BeanUtils.copyProperties(param, packetParam);
+                if (type==1){
+                    return sendAppRedPacketAuto(packetParam, log,video, config);
+                }else if (type==2){
+                    return sendAppRedPacket(packetParam, log,video, config);
+                }
 
-                return sendAppRedPacket(packetParam, log,video, config);
             // 积分奖励
             case 2:
                 return sendIntegralReward(param, user, log, config);
@@ -5340,6 +5344,9 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
     }
 
 
+    /**
+    * app手动看课的
+    */
     private R sendAppRedPacket(WxSendRedPacketParam packetParam,FsCourseWatchLog log,FsUserCourseVideo video,CourseConfig config) {
         FsUserCoursePeriodDays periodDays = new FsUserCoursePeriodDays();
         periodDays.setVideoId(log.getVideoId());
@@ -5353,6 +5360,14 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
             return R.error(403, "已超过领取红包时间");
         }
 
+        // 手动的就多一个查询手动营期的时间 ,所以这里直接复用
+        return sendAppRedPacketAuto(packetParam,log,video,config);
+    }
+
+    /**
+    * app自动看课的
+    */
+    private R sendAppRedPacketAuto(WxSendRedPacketParam packetParam,FsCourseWatchLog log,FsUserCourseVideo video,CourseConfig config) {
 
         // 确定红包金额
         BigDecimal amount = BigDecimal.ZERO;
@@ -5574,6 +5589,8 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
         }
     }
 
+
+
     /**
      * 获取用户openId
      */

+ 6 - 6
fs-user-app/src/main/java/com/fs/app/controller/course/CourseFsUserController.java

@@ -137,7 +137,7 @@ public class CourseFsUserController extends AppBaseController {
                     param.getQwUserId() != null ? String.valueOf(param.getQwUserId()) : null,
                     param.getQwExternalId()
                 );
-           
+
             } else {
                 fsCourseWatchLog = fsCourseWatchLogMapper.selectFsCourseWatchLogWithUCCV(param);
             }
@@ -145,7 +145,7 @@ public class CourseFsUserController extends AppBaseController {
             if (fsCourseWatchLog == null) {
                 return R.error("未查询到看课记录,暂无法提供倒计时完课功能!");
             }
-            
+
             // 如果已经完课,剩余时间为0
             if (fsCourseWatchLog.getLogType() != null && fsCourseWatchLog.getLogType() == 2) {
                 remainTime = 0;
@@ -159,15 +159,15 @@ public class CourseFsUserController extends AppBaseController {
                 } else if (fsCourseWatchLog != null && fsCourseWatchLog.getDuration() != null) {
                     watchedDuration = fsCourseWatchLog.getDuration();
                 }
-                
+
                 // 获取视频总时长(参照scheduleUpdateDurationToDatabase中的getFsUserVideoDuration方法)
                 Long videoDuration = getFsUserVideoDuration(param.getVideoId().longValue());
-                
+
                 if (videoDuration != null && videoDuration > 0 && config.getAnswerRate() != null) {
                     // 参照scheduleUpdateDurationToDatabase中的完课逻辑:percentage >= config.getAnswerRate()
                     // 计算需要观看的时长(秒)
                     long requiredDuration = videoDuration * config.getAnswerRate() / 100;
-                    
+
                     // 计算剩余时间(秒)
                     long remainTimeSeconds = requiredDuration - watchedDuration;
                     remainTime = (int) Math.max(0, remainTimeSeconds);
@@ -308,7 +308,7 @@ public class CourseFsUserController extends AppBaseController {
             return R.error("请先登录!");
         }
         param.setUserId(Long.parseLong(userId));
-        return R.ok(courseVideoService.withdrawal(param));
+        return R.ok(courseVideoService.withdrawal(param,2));
     }
 
 }