소스 검색

1、查询完播答题后的奖励领取记录(红包/积分、核销券、优惠券三类整合)

yys 5 일 전
부모
커밋
1ff7d8166e

+ 6 - 0
fs-service/src/main/java/com/fs/live/mapper/LiveCompletionPointsRecordMapper.java

@@ -60,6 +60,12 @@ public interface LiveCompletionPointsRecordMapper {
     List<LiveCompletionPointsRecord> selectRecordsByUser(@Param("liveId") Long liveId, 
                                                           @Param("userId") Long userId);
 
+    /**
+     * 查询用户在指定直播间的已领取完课积分记录
+     */
+    List<LiveCompletionPointsRecord> selectReceivedByLiveAndUser(@Param("liveId") Long liveId,
+                                                                  @Param("userId") Long userId);
+
     /**
      * 根据ID查询
      */

+ 7 - 0
fs-service/src/main/java/com/fs/live/service/ILiveCompletionCouponService.java

@@ -9,6 +9,7 @@ import com.fs.live.vo.LiveCompletionCouponConfigVO;
 import com.fs.live.vo.LiveCompletionCouponNotifyResult;
 import com.fs.live.vo.LiveCompletionCouponStatusVO;
 import com.fs.live.vo.LiveCompletionQuestionVO;
+import com.fs.live.vo.LiveCompletionAnswerClaimRecordsVo;
 
 import java.util.List;
 
@@ -41,4 +42,10 @@ public interface ILiveCompletionCouponService {
      * <p>支持 finishCoupons 多选及每券张数;返回全部发放明细</p>
      */
     LiveCompletionCouponClaimResult claimCompletionCoupon(LiveCompletionCouponClaimParam param, Long userId);
+
+    /**
+     * 查询用户在指定直播间「完播答题后」的奖励领取记录(三类整合)
+     * <p>仅在存在答题全对记录时返回:完课积分、核销券、优惠券</p>
+     */
+    LiveCompletionAnswerClaimRecordsVo getAnswerClaimRecords(Long liveId, Long userId);
 }

+ 124 - 0
fs-service/src/main/java/com/fs/live/service/impl/LiveCompletionCouponServiceImpl.java

@@ -4,15 +4,20 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.exception.base.BaseException;
+import com.fs.common.utils.DictUtils;
 import com.fs.common.utils.StringUtils;
 import com.fs.live.domain.*;
+import com.fs.live.mapper.LiveCompletionPointsRecordMapper;
 import com.fs.live.mapper.LiveQuestionBankMapper;
+import com.fs.live.param.LiveCompletionAnswerRecordParam;
 import com.fs.live.param.LiveCompletionCouponAnswerItem;
 import com.fs.live.param.LiveCompletionCouponAnswerParam;
 import com.fs.live.param.LiveCompletionCouponClaimParam;
 import com.fs.live.service.*;
 import com.fs.live.utils.LiveCompletionConfigUtils;
+import com.fs.live.vo.LiveCompletionAnswerClaimRecordsVo;
 import com.fs.live.vo.LiveCompletionAnswerDetailVO;
+import com.fs.live.vo.LiveCompletionAnswerRecordListVO;
 import com.fs.live.vo.LiveCompletionCouponAnswerResult;
 import com.fs.live.vo.LiveCompletionCouponClaimItemVO;
 import com.fs.live.vo.LiveCompletionCouponClaimResult;
@@ -22,6 +27,7 @@ import com.fs.live.vo.LiveCompletionCouponNotifyResult;
 import com.fs.live.vo.LiveCompletionCouponStatusVO;
 import com.fs.live.vo.LiveCompletionQuestionVO;
 import com.fs.live.vo.LiveRewardCouponItem;
+import com.fs.live.vo.LiveUserClaimRecordVo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -81,6 +87,9 @@ public class LiveCompletionCouponServiceImpl implements ILiveCompletionCouponSer
     @Autowired
     private ILiveCompletionAnswerRecordService liveCompletionAnswerRecordService;
 
+    @Autowired
+    private LiveCompletionPointsRecordMapper liveCompletionPointsRecordMapper;
+
     @Override
     public LiveCompletionCouponConfigVO parseCompletionCouponConfig(Live live) {
         LiveCompletionCouponConfigVO vo = new LiveCompletionCouponConfigVO();
@@ -1045,4 +1054,119 @@ public class LiveCompletionCouponServiceImpl implements ILiveCompletionCouponSer
             return details;
         }
     }
+
+    /**
+     * 完播答题后奖励领取记录:红包/积分、核销券、优惠券三类整合。
+     * <p>无答题全对记录时三类均为空;券类仅取完课优惠券留存(opType=8),并按券模板区分核销券/普通优惠券。</p>
+     */
+    @Override
+    public LiveCompletionAnswerClaimRecordsVo getAnswerClaimRecords(Long liveId, Long userId) {
+        LiveCompletionAnswerClaimRecordsVo result = new LiveCompletionAnswerClaimRecordsVo();
+        result.setAnswered(false);
+        result.setAnswerRecordId(null);
+        result.setRedPointsList(new ArrayList<>());
+        result.setVerifyCouponList(new ArrayList<>());
+        result.setCouponList(new ArrayList<>());
+        if (liveId == null || userId == null) {
+            return result;
+        }
+
+        LiveCompletionAnswerRecordParam answerParam = new LiveCompletionAnswerRecordParam();
+        answerParam.setLiveId(liveId);
+        answerParam.setUserId(userId);
+        answerParam.setIsRight(1);
+        List<LiveCompletionAnswerRecordListVO> answerList =
+                liveCompletionAnswerRecordService.selectLiveCompletionAnswerRecordList(answerParam);
+        if (answerList == null || answerList.isEmpty()) {
+            return result;
+        }
+        result.setAnswered(true);
+        result.setAnswerRecordId(answerList.get(0).getId());
+
+        // 1) 红包/积分:本场已领取完课积分
+        List<LiveCompletionPointsRecord> pointsRecords =
+                liveCompletionPointsRecordMapper.selectReceivedByLiveAndUser(liveId, userId);
+        if (pointsRecords != null) {
+            for (LiveCompletionPointsRecord pointsRecord : pointsRecords) {
+                result.getRedPointsList().add(buildPointsClaimRow(pointsRecord));
+            }
+        }
+
+        // 2) 核销券 / 优惠券:完课优惠券留存(opType=8)已领取明细
+        List<LiveUserClaimRecordVo> claimRecords = liveConsoleOpLogService.listUserClaimRecords(liveId, userId);
+        if (claimRecords == null || claimRecords.isEmpty()) {
+            return result;
+        }
+        Map<Long, LiveCoupon> couponCache = new HashMap<>();
+        for (LiveUserClaimRecordVo claim : claimRecords) {
+            if (claim == null || claim.getOpType() == null) {
+                continue;
+            }
+            if (claim.getOpType() != LiveConsoleOpLog.OP_COMPLETION_COUPON) {
+                continue;
+            }
+            if (isVerifyCouponClaim(claim, couponCache)) {
+                result.getVerifyCouponList().add(claim);
+            } else {
+                result.getCouponList().add(claim);
+            }
+        }
+        return result;
+    }
+
+    private LiveUserClaimRecordVo buildPointsClaimRow(LiveCompletionPointsRecord pointsRecord) {
+        LiveUserClaimRecordVo vo = new LiveUserClaimRecordVo();
+        vo.setOpLogId(null);
+        vo.setOpType(LiveConsoleOpLog.OP_COMPLETION_POINTS);
+        vo.setOpTypeName(LiveUserClaimRecordVo.resolveOpTypeName(LiveConsoleOpLog.OP_COMPLETION_POINTS));
+        vo.setBizId(pointsRecord.getId());
+        Integer points = pointsRecord.getPointsAwarded();
+        vo.setBizName(points == null ? "完课积分" : ("完课积分+" + points));
+        vo.setCreateTime(pointsRecord.getReceiveTime() != null
+                ? pointsRecord.getReceiveTime() : pointsRecord.getCreateTime());
+        vo.setCouponCount(1);
+        return vo;
+    }
+
+    private boolean isVerifyCouponClaim(LiveUserClaimRecordVo claim, Map<Long, LiveCoupon> couponCache) {
+        Long couponId = resolveCouponIdFromClaim(claim);
+        if (couponId == null) {
+            return false;
+        }
+        LiveCoupon coupon = couponCache.get(couponId);
+        if (coupon == null) {
+            coupon = liveCouponService.selectLiveCouponById(couponId);
+            if (coupon != null) {
+                couponCache.put(couponId, coupon);
+            }
+        }
+        return isVerifyCouponType(coupon);
+    }
+
+    private Long resolveCouponIdFromClaim(LiveUserClaimRecordVo claim) {
+        if (claim == null) {
+            return null;
+        }
+        if (claim.getCouponUserId() != null) {
+            LiveCouponUser couponUser = liveCouponUserService.selectLiveCouponUserById(claim.getCouponUserId());
+            if (couponUser != null && couponUser.getCouponId() != null) {
+                return couponUser.getCouponId();
+            }
+        }
+        // 完课优惠券留存 bizId 即为 couponId
+        return claim.getBizId();
+    }
+
+    /** 核销券/无门槛券:type=3,或字典标签含核销/代金券 */
+    private boolean isVerifyCouponType(LiveCoupon coupon) {
+        if (coupon == null || coupon.getType() == null) {
+            return false;
+        }
+        if (coupon.getType() == 3L) {
+            return true;
+        }
+        String typeLabel = DictUtils.getDictLabel("store_coupon_type", String.valueOf(coupon.getType()));
+        return StringUtils.isNotEmpty(typeLabel)
+                && (typeLabel.contains("核销") || typeLabel.contains("代金券"));
+    }
 }

+ 29 - 0
fs-service/src/main/java/com/fs/live/vo/LiveCompletionAnswerClaimRecordsVo.java

@@ -0,0 +1,29 @@
+package com.fs.live.vo;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 完播答题后奖励领取记录(三类整合)
+ * <p>仅包含用户在该直播间答题全对后,完播奖励相关的已领取数据。</p>
+ */
+@Data
+public class LiveCompletionAnswerClaimRecordsVo {
+
+    /** 是否已答题全对 */
+    private Boolean answered;
+
+    /** 最新全对答题记录ID */
+    private Long answerRecordId;
+
+    /** 红包/积分(完课积分) */
+    private List<LiveUserClaimRecordVo> redPointsList = new ArrayList<>();
+
+    /** 核销券(完播答题后领取) */
+    private List<LiveUserClaimRecordVo> verifyCouponList = new ArrayList<>();
+
+    /** 优惠券(完播答题后领取) */
+    private List<LiveUserClaimRecordVo> couponList = new ArrayList<>();
+}

+ 9 - 0
fs-service/src/main/resources/mapper/live/LiveCompletionPointsRecordMapper.xml

@@ -130,6 +130,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ORDER BY current_completion_date DESC
     </select>
 
+    <!-- 查询用户在指定直播间的已领取完课积分记录 -->
+    <select id="selectReceivedByLiveAndUser" resultMap="LiveCompletionPointsRecordResult">
+        SELECT * FROM live_completion_points_record
+        WHERE live_id = #{liveId}
+          AND user_id = #{userId}
+          AND receive_status = 1
+        ORDER BY current_completion_date DESC, id DESC
+    </select>
+
     <!-- 根据ID查询 -->
     <select id="selectById" resultMap="LiveCompletionPointsRecordResult">
         SELECT * FROM live_completion_points_record

+ 13 - 0
fs-user-app/src/main/java/com/fs/app/controller/live/LiveCompletionCouponController.java

@@ -74,4 +74,17 @@ public class LiveCompletionCouponController extends AppBaseController {
                 // 兼容:旧逻辑 data 直接是 LiveCouponUser
                 .put("couponUser", result.getCouponUser());
     }
+
+    /**
+     * 查询完播答题后的奖励领取记录(红包/积分、核销券、优惠券三类整合)
+     * <p>
+     * 入参:liveId、userId(须为当前登录用户)。
+     * 仅在该直播间存在答题全对记录时返回已领取的完播奖励数据。
+     * </p>
+     */
+    @GetMapping("/claimRecords")
+    public R claimRecords(@RequestParam Long liveId) {
+        Long userId = Long.parseLong(getUserId());
+        return R.ok().put("data", completionCouponService.getAnswerClaimRecords(liveId, userId));
+    }
 }