lutong 2 месяцев назад
Родитель
Сommit
74ab97a1bf

+ 5 - 5
alien-entity/src/main/java/shop/alien/mapper/CommonRatingMapper.java

@@ -91,10 +91,10 @@ public interface CommonRatingMapper extends BaseMapper<CommonRating> {
     /**
      * 统计该用户在该店铺下已通过审核的好评次数(用于好评送券参与次数限制)
      * 注意:统计包括已删除的评论,防止用户删除评论后再次获得券
-     * 只统计活动开始时间之后创建的评论,活动开始前的评论不计入参与次数
+     * 审核成功之前的评论不计算在参与次数中(只统计审核成功时间在活动审核时间之后的评论)
      * @param userId 用户ID
      * @param storeId 店铺ID(business_id)
-     * @param activityStartTime 活动开始时间,为null时统计所有历史好评
+     * @param activityAuditTime 活动审核时间,为null时统计所有历史好评
      * @return 已通过的好评条数(business_type=1, audit_status=1, score>=4.5),包括已删除的评论
      */
     @Select("<script>" +
@@ -104,10 +104,10 @@ public interface CommonRatingMapper extends BaseMapper<CommonRating> {
             "AND user_id = #{userId} " +
             "AND audit_status = 1 " +
             "AND score >= 4.5 " +
-            "<if test='activityStartTime != null'>" +
-            "AND created_time >= #{activityStartTime} " +
+            "<if test='activityAuditTime != null'>" +
+            "AND updated_time >= #{activityAuditTime} " +
             "</if>" +
             "</script>")
-    int countPassedGoodRatingsByUserAndStore(@Param("userId") Long userId, @Param("storeId") Integer storeId, @Param("activityStartTime") Date activityStartTime);
+    int countPassedGoodRatingsByUserAndStore(@Param("userId") Long userId, @Param("storeId") Integer storeId, @Param("activityAuditTime") Date activityAuditTime);
 }
 

+ 3 - 5
alien-store/src/main/java/shop/alien/store/service/impl/CommonRatingServiceImpl.java

@@ -290,9 +290,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                     activityWrapper.eq(StoreOperationalActivity::getStoreId, businessId)
                             .eq(StoreOperationalActivity::getActivityType, "COMMENT")
                             .in(StoreOperationalActivity::getStatus, 5, 8)
-                            // 使用审核时间和开始时间中较晚的那个作为开始时间进行比较
-                            // GREATEST() 函数取两个值中的较大者,如果其中一个为 NULL,返回另一个;如果两个都为 NULL,返回 NULL(会被 WHERE 子句排除)
-                            .apply("GREATEST(audit_time, start_time) <= {0}", now)
+                            .le(StoreOperationalActivity::getStartTime, now)
                             .ge(StoreOperationalActivity::getEndTime, now)
                             .orderByDesc(StoreOperationalActivity::getId); // 按ID降序,优先处理最新创建的活动
                     List<StoreOperationalActivity> activities = storeOperationalActivityMapper.selectList(activityWrapper);
@@ -316,9 +314,9 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                         // 检查参与次数限制(每个活动单独计算)
                         Integer limit = activity.getParticipationLimit();
                         if (limit != null && limit > 0) {
-                            // 只统计活动开始时间之后的好评,活动开始前的评论不计入参与次数
+                            // 审核成功之前的评论不计算在参与次数中(只统计审核成功时间在活动审核时间之后的评论)
                             int passedCount = commonRatingMapper.countPassedGoodRatingsByUserAndStore(
-                                    commonRating.getUserId(), businessId, activity.getStartTime());
+                                    commonRating.getUserId(), businessId, activity.getAuditTime());
                             if (passedCount > limit) {
                                 log.info("CommonRatingService 好评送券跳过:超过运营活动参与次数 activityId={}, participation_limit={}, count={}, userId={}, storeId={}, activityStartTime={}",
                                         activity.getId(), limit, passedCount, commonRating.getUserId(), businessId, activity.getStartTime());