瀏覽代碼

商家好评发送券

wuchen 2 月之前
父節點
當前提交
e94a15ae65

+ 5 - 0
alien-entity/src/main/java/shop/alien/entity/store/StoreInfo.java

@@ -359,4 +359,9 @@ public class StoreInfo {
     @TableField("tableware_fee")
     private Integer tablewareFee;
 
+    /** 好评送券活动:每用户可参与次数,0或null表示不限制(需表 store_info 存在列 good_rating_participation_limit) */
+    @ApiModelProperty(value = "好评送券活动每用户可参与次数,0或null不限制")
+    @TableField("good_rating_participation_limit")
+    private Integer goodRatingParticipationLimit;
+
 }

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

@@ -86,5 +86,14 @@ public interface CommonRatingMapper extends BaseMapper<CommonRating> {
      * @return 分页结果
      */
     Integer getRatingWithNoReply( @Param(Constants.WRAPPER) Wrapper<CommonRating> wrapper);
+
+    /**
+     * 统计该用户在该店铺下已通过审核的好评次数(用于好评送券参与次数限制)
+     * @param userId 用户ID
+     * @param storeId 店铺ID(business_id)
+     * @return 已通过的好评条数(business_type=1, audit_status=1, score>=4.5)
+     */
+    @Select("SELECT COUNT(*) FROM common_rating WHERE business_type = 1 AND business_id = #{storeId} AND user_id = #{userId} AND audit_status = 1 AND score >= 4.5 AND delete_flag = 0")
+    int countPassedGoodRatingsByUserAndStore(@Param("userId") Long userId, @Param("storeId") Integer storeId);
 }
 

+ 21 - 10
alien-store/src/main/java/shop/alien/store/service/impl/CommonRatingServiceImpl.java

@@ -105,16 +105,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                 commonRating.setScoreThree(parse.getDouble("scoreThree"));
             }
             int i = this.save(commonRating) ? 0 : 1;
-            if (i == 0 && commonRating.getBusinessType() != null && commonRating.getBusinessType() == RatingBusinessTypeEnum.STORE_RATING.getBusinessType()) {
-                Double score = commonRating.getScore();
-                if (score != null && score >= 4.5 && commonRating.getUserId() != null && commonRating.getBusinessId() != null) {
-                    try {
-                        lifeDiscountCouponStoreFriendService.issueCouponForGoodRating(Math.toIntExact(commonRating.getUserId()), commonRating.getBusinessId());
-                    } catch (Exception ex) {
-                        log.warn("CommonRatingService.saveCommonRating 好评送券异常 userId={}, storeId={}, msg={}", commonRating.getUserId(), commonRating.getBusinessId(), ex.getMessage());
-                    }
-                }
-            }
+            // 好评发券改为仅在 AI 审核通过后执行,见 doBusinessWithType 中逻辑
             // 一次遍历完成分类,避免多次流式处理
             Map<String, List<String>> urlCategoryMap = StoreRenovationRequirementServiceImpl.classifyUrls(Arrays.asList(commonRating.getImageUrls().split(",")));
             AiContentModerationUtil.AuditResult auditResult = new AiContentModerationUtil.AuditResult(true, "");
@@ -230,6 +221,26 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                 websocketVo.setText(JSONObject.from(lifeMessage).toJSONString());
                 webSocketProcess.sendMessage("store_" + storeUser.getPhone(), JSONObject.from(websocketVo).toJSONString());
             }
+            // 用户好评且 AI 审核通过后:按商家配置的参与次数限制,将优惠券/代金券发到用户券包,通知按优惠券/代金券分别发送
+            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 或负数视为不限制
+                    }
+                    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);
+                    }
+                } catch (Exception ex) {
+                    log.warn("CommonRatingService 好评送券异常 userId={}, storeId={}, msg={}", commonRating.getUserId(), businessId, ex.getMessage());
+                }
+            }
         }
 
     }