Browse Source

feat:优化领取红包逻辑

caoliqin 1 day ago
parent
commit
24c7db978a

+ 3 - 0
fs-service-system/src/main/java/com/fs/course/mapper/FsCourseRedPacketLogMapper.java

@@ -157,4 +157,7 @@ public interface FsCourseRedPacketLogMapper
      */
     @Select("select ifnull(sum(fcrpl.amount), 0) from fs_course_red_packet_log fcrpl where fcrpl.company_user_id = #{companyUserId}")
     BigDecimal getSumByCompanyUserIdId(@Param("companyUserId") Long companyUserId);
+
+    @Select("select * from fs_course_red_packet_log where video_id = #{videoId} and user_id = #{userId} and period_id = #{periodId} limit 1")
+    FsCourseRedPacketLog selectUserFsCourseRedPacketLog(@Param("videoId") Long videoId, @Param("userId")Long userId, @Param("periodId")Long periodId);
 }

+ 13 - 6
fs-service-system/src/main/java/com/fs/course/service/impl/FsCourseQuestionBankServiceImpl.java

@@ -11,10 +11,7 @@ import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
 import com.fs.course.cache.FsUserCourseCategoryCacheService;
 import com.fs.course.config.CourseConfig;
-import com.fs.course.domain.FsCourseAnswerLogs;
-import com.fs.course.domain.FsCourseQuestionBank;
-import com.fs.course.domain.FsCourseWatchLog;
-import com.fs.course.domain.FsUserCourseCategory;
+import com.fs.course.domain.*;
 import com.fs.course.dto.FsCourseQuestionBankImportDTO;
 import com.fs.course.mapper.*;
 import com.fs.course.param.FsCourseQuestionAnswerUParam;
@@ -171,7 +168,11 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
         if (param.getLinkType()!=null&&param.getLinkType()==1){
             rightLog = courseAnswerLogsMapper.selectRightLogByCourseVideo(param.getVideoId(), param.getUserId(),null);
             if (rightLog!=null){
-                return R.error("该课程已答题完成,不可重复答题");
+                // 增加判断,去查询红包记录是否已发送成功,如果成功,则返回当前提示,否则返回答题成功(让其可以继续答题,直到红包领取完成)
+                FsCourseRedPacketLog fsCourseRedPacketLog = redPacketLogMapper.selectUserFsCourseRedPacketLog(param.getVideoId(), param.getUserId(),param.getPeriodId());
+                if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 1){
+                    return R.error("该课程已答题完成,不可重复答题");
+                }
             }
             errorCount = courseAnswerLogsMapper.selectErrorCountByCourseVideo(param.getVideoId(), param.getUserId(),null);
 
@@ -193,7 +194,13 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
             rightLog = courseAnswerLogsMapper.selectRightLogByCourseVideo(param.getVideoId(), param.getUserId(), param.getQwUserId());
             if (rightLog != null) {
                 if (log.getRewardType() != null) {
-                    return R.error("该课程已答题完成,不可重复答题");
+                    // 增加判断,去查询红包记录是否已发送成功,如果成功,则返回当前提示,否则返回答题成功(让其可以继续答题,直到红包领取完成)
+                    FsCourseRedPacketLog fsCourseRedPacketLog = redPacketLogMapper.selectUserFsCourseRedPacketLog(param.getVideoId(), param.getUserId(),param.getPeriodId());
+                    if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 1) {
+                        return R.error("该课程已答题完成,不可重复答题");
+                    } else {
+                        return R.ok("答题成功");
+                    }
                 } else {
                     return R.ok("答题成功");
                 }

+ 12 - 1
fs-service-system/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -737,7 +737,18 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
             return R.error("无记录");
         }
         if (log.getRewardType() != null) {
-            return R.error("奖励已发放");
+            FsCourseRedPacketLog fsCourseRedPacketLog = redPacketLogMapper.selectUserFsCourseRedPacketLog(param.getVideoId(), param.getUserId(),param.getPeriodId());
+            if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 1) {
+                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();
+                }
+            }
         }