wuchen 2 mesi fa
parent
commit
54844e8a83

+ 32 - 12
alien-store/src/main/java/shop/alien/store/service/impl/CommonRatingServiceImpl.java

@@ -21,10 +21,12 @@ import org.springframework.transaction.annotation.Transactional;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.*;
 import shop.alien.entity.store.vo.CommonCommentVo;
+import shop.alien.entity.storePlatform.StoreOperationalActivity;
 import shop.alien.entity.store.vo.CommonRatingVo;
 import shop.alien.entity.store.vo.StoreInfoScoreVo;
 import shop.alien.entity.store.vo.WebSocketVo;
 import shop.alien.mapper.*;
+import shop.alien.mapper.storePlantform.StoreOperationalActivityMapper;
 import shop.alien.store.config.WebSocketProcess;
 import shop.alien.store.service.CommonCommentService;
 import shop.alien.store.service.CommonRatingService;
@@ -81,6 +83,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
     private final ExecutorService commonVideoTaskExecutor;
     private final AiVideoModerationUtil aiVideoModerationUtil;
     private final LifeDiscountCouponStoreFriendService lifeDiscountCouponStoreFriendService;
+    private final StoreOperationalActivityMapper storeOperationalActivityMapper;
 
     public static final List<String> SERVICES_LIST = ImmutableList.of(
             TextReviewServiceEnum.COMMENT_DETECTION_PRO.getService(),
@@ -221,21 +224,38 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                 websocketVo.setText(JSONObject.from(lifeMessage).toJSONString());
                 webSocketProcess.sendMessage("store_" + storeUser.getPhone(), JSONObject.from(websocketVo).toJSONString());
             }
-            // 用户好评且 AI 审核通过后:按商家配置的参与次数限制,将优惠券/代金券发到用户券包,通知按优惠券/代金券分别发送
+            // 用户好评且 AI 审核通过后:按运营活动表(评论有礼)配置的 coupon_id/voucher_id 发放,参与次数以活动 participation_limit 为准,发放成功后扣减库存,按优惠券/代金券分别发通知
             if (score != null && score >= 4.5 && commonRating.getUserId() != null && commonRating.getBusinessId() != null) {
                 try {
-                    StoreInfo store = storeInfoMapper.selectById(businessId);
-                    Integer limit = (store != null && store.getGoodRatingParticipationLimit() != null)
-                            ? store.getGoodRatingParticipationLimit() : null;
-                    if (limit != null && limit <= 0) {
-                        limit = null; // 0 或负数视为不限制
+                    Date now = new Date();
+                    LambdaQueryWrapper<StoreOperationalActivity> activityWrapper = new LambdaQueryWrapper<>();
+                    activityWrapper.eq(StoreOperationalActivity::getStoreId, businessId)
+                            .eq(StoreOperationalActivity::getActivityType, "COMMENT")
+                            .in(StoreOperationalActivity::getStatus, 5, 8)
+                            .le(StoreOperationalActivity::getStartTime, now)
+                            .ge(StoreOperationalActivity::getEndTime, now);
+                    activityWrapper.last("LIMIT 1");
+                    StoreOperationalActivity activity = storeOperationalActivityMapper.selectOne(activityWrapper);
+                    if (activity == null) {
+                        log.debug("CommonRatingService 好评送券跳过:店铺无进行中的评论有礼活动 storeId={}", businessId);
+                        return;
                     }
-                    int passedCount = commonRatingMapper.countPassedGoodRatingsByUserAndStore(commonRating.getUserId(), businessId);
-                    if (limit == null || passedCount <= limit) {
-                        lifeDiscountCouponStoreFriendService.issueCouponForGoodRating(Math.toIntExact(commonRating.getUserId()), businessId);
-                    } else {
-                        log.info("CommonRatingService 好评送券跳过:已达商家指定参与次数上限 userId={}, storeId={}, limit={}, count={}",
-                                commonRating.getUserId(), businessId, limit, passedCount);
+                    Integer limit = activity.getParticipationLimit();
+                    if (limit != null && limit > 0) {
+                        int passedCount = commonRatingMapper.countPassedGoodRatingsByUserAndStore(commonRating.getUserId(), businessId);
+                        if (passedCount >= limit) {
+                            log.info("CommonRatingService 好评送券跳过:已达运营活动参与次数上限 userId={}, storeId={}, activityId={}, limit={}, count={}",
+                                    commonRating.getUserId(), businessId, activity.getId(), limit, passedCount);
+                            return;
+                        }
+                    }
+                    if (activity.getCouponId() != null || activity.getVoucherId() != null) {
+                        lifeDiscountCouponStoreFriendService.issueCouponForGoodRating(
+                                Math.toIntExact(commonRating.getUserId()),
+                                businessId,
+                                activity.getCouponId(),
+                                activity.getVoucherId(),
+                                activity.getCouponQuantity() != null ? activity.getCouponQuantity() : 1);
                     }
                 } catch (Exception ex) {
                     log.warn("CommonRatingService 好评送券异常 userId={}, storeId={}, msg={}", commonRating.getUserId(), businessId, ex.getMessage());