Procházet zdrojové kódy

完善查询店铺是屏蔽黑名单 开发通过手机号查询店铺详情接口

lutong před 2 měsíci
rodič
revize
61226930b8

+ 11 - 0
alien-entity/src/main/java/shop/alien/mapper/StoreTrackEventMapper.java

@@ -137,4 +137,15 @@ public interface StoreTrackEventMapper extends BaseMapper<StoreTrackEvent> {
             "GROUP BY event_type")
     List<Map<String, Object>> calculateServiceStatistics(@Param("storeId") Integer storeId,
                                                           @Param("endDate") Date endDate);
+    
+    /**
+     * 统计店铺当前总浏览量(所有历史数据)
+     */
+    @Select("SELECT COUNT(*) as viewCount " +
+            "FROM store_track_event " +
+            "WHERE store_id = #{storeId} " +
+            "AND delete_flag = 0 " +
+            "AND event_category = 'TRAFFIC' " +
+            "AND event_type = 'VIEW'")
+    Long countStoreViewCount(@Param("storeId") Integer storeId);
 }

+ 59 - 12
alien-store/src/main/java/shop/alien/store/controller/StoreInfoController.java

@@ -28,6 +28,9 @@ import shop.alien.store.annotation.TrackEvent;
 import shop.alien.store.config.BaseRedisService;
 import shop.alien.store.service.StoreInfoService;
 import shop.alien.store.service.StoreQualificationService;
+import shop.alien.entity.store.UserLoginInfo;
+import shop.alien.util.common.TokenInfo;
+import springfox.documentation.annotations.ApiIgnore;
 
 import java.io.IOException;
 import java.util.*;
@@ -212,6 +215,37 @@ public class StoreInfoController {
         return R.data(storeInfoService.getDetail(id));
     }
 
+    @ApiOperation(value = "门店详细信息(通过商家手机号)")
+    @ApiOperationSupport(order = 6)
+    @ApiImplicitParams({@ApiImplicitParam(name = "phone", value = "商家手机号", dataType = "String", paramType = "query", required = true)})
+    @GetMapping("/getDetailByPhone")
+    public R<StoreMainInfoVo> getDetailByPhone(@RequestParam("phone") String phone) {
+        log.info("StoreInfoController.getDetailByPhone?phone={}", phone);
+        try {
+            // 根据手机号查询 store_user
+            LambdaQueryWrapper<StoreUser> userWrapper = new LambdaQueryWrapper<>();
+            userWrapper.eq(StoreUser::getPhone, phone)
+                      .eq(StoreUser::getDeleteFlag, 0);
+            StoreUser storeUser = storeUserMapper.selectOne(userWrapper);
+            
+            if (storeUser == null) {
+                log.warn("未找到手机号对应的商家用户: phone={}", phone);
+                return R.fail("未找到该手机号对应的商家");
+            }
+            
+            // 如果 store_id 不为空,则使用该 store_id 查询门店详细信息
+            if (storeUser.getStoreId() != null && storeUser.getStoreId() > 0) {
+                return R.data(storeInfoService.getDetail(storeUser.getStoreId()));
+            } else {
+                log.warn("商家用户的 store_id 为空: phone={}, userId={}", phone, storeUser.getId());
+                return R.fail("该商家未关联门店");
+            }
+        } catch (Exception e) {
+            log.error("根据手机号查询门店详细信息失败: phone={}", phone, e);
+            return R.fail("查询失败: " + e.getMessage());
+        }
+    }
+
     @ApiOperation(value = "门店信息-修改后展示")
     @ApiOperationSupport(order = 6)
     @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "门店id", dataType = "Long", paramType = "query", required = true)})
@@ -1481,6 +1515,7 @@ public class StoreInfoController {
     })
     @GetMapping("/getRandomPage")
     public R<IPage<StoreInfoWithHeadImg>> getRandomPage(
+            @ApiIgnore @TokenInfo UserLoginInfo userLoginInfo,
             @RequestParam(defaultValue = "1") int page,
             @RequestParam(defaultValue = "10") int size) {
         log.info("StoreInfoController.getRandomPage - page={}, size={}", page, size);
@@ -1489,20 +1524,32 @@ public class StoreInfoController {
             int pageNum = page > 0 ? page : 1;
             int pageSize = size > 0 ? size : 10;
             
-            // 查询所有被拉黑的店铺ID
-            LambdaQueryWrapper<LifeBlacklist> blacklistWrapper = new LambdaQueryWrapper<>();
-            blacklistWrapper.eq(LifeBlacklist::getBlockedType, "1") // 1表示商户
-                           .eq(LifeBlacklist::getDeleteFlag, 0);
-            List<LifeBlacklist> blacklist = lifeBlacklistMapper.selectList(blacklistWrapper);
+            // 查询当前登录用户拉黑的店铺ID
             List<Integer> blacklistedStoreIds = new ArrayList<>();
-            if (!CollectionUtils.isEmpty(blacklist)) {
-                for (LifeBlacklist item : blacklist) {
-                    try {
-                        if (item.getBlockedId() != null && !item.getBlockedId().trim().isEmpty()) {
-                            blacklistedStoreIds.add(Integer.parseInt(item.getBlockedId()));
+            if (userLoginInfo != null && userLoginInfo.getUserId() > 0) {
+                // 获取当前登录用户的类型和ID
+                String blockerType = userLoginInfo.getType(); // "user" 或 "store"
+                String blockerId = String.valueOf(userLoginInfo.getUserId());
+                
+                // 根据用户类型设置拉黑方类型(1:商户,2:用户)
+                String blockerTypeValue = "user".equals(blockerType) ? "2" : "1";
+                
+                LambdaQueryWrapper<LifeBlacklist> blacklistWrapper = new LambdaQueryWrapper<>();
+                blacklistWrapper.eq(LifeBlacklist::getBlockerType, blockerTypeValue) // 拉黑方类型
+                               .eq(LifeBlacklist::getBlockerId, blockerId) // 拉黑方ID(当前登录用户)
+                               .eq(LifeBlacklist::getBlockedType, "1") // 1表示商户
+                               .eq(LifeBlacklist::getDeleteFlag, 0);
+                List<LifeBlacklist> blacklist = lifeBlacklistMapper.selectList(blacklistWrapper);
+                
+                if (!CollectionUtils.isEmpty(blacklist)) {
+                    for (LifeBlacklist item : blacklist) {
+                        try {
+                            if (item.getBlockedId() != null && !item.getBlockedId().trim().isEmpty()) {
+                                blacklistedStoreIds.add(Integer.parseInt(item.getBlockedId()));
+                            }
+                        } catch (NumberFormatException e) {
+                            log.warn("拉黑记录中的店铺ID格式错误: {}", item.getBlockedId());
                         }
-                    } catch (NumberFormatException e) {
-                        log.warn("拉黑记录中的店铺ID格式错误: {}", item.getBlockedId());
                     }
                 }
             }

+ 23 - 0
alien-store/src/main/java/shop/alien/store/controller/TrackEventController.java

@@ -112,6 +112,27 @@ public class TrackEventController {
         }
     }
 
+    @ApiOperation("统计店铺浏览量")
+    @ApiOperationSupport(order = 3)
+    @GetMapping("/statistics/viewCount")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "storeId", value = "店铺ID", dataType = "Integer", paramType = "query", required = true)
+    })
+    public R<Long> getStoreViewCount(@RequestParam("storeId") Integer storeId) {
+        try {
+            if (storeId == null || storeId <= 0) {
+                return R.fail("店铺ID不能为空且必须大于0");
+            }
+            
+            Long viewCount = trackEventService.getStoreViewCount(storeId);
+            log.info("查询店铺浏览量: storeId={}, viewCount={}", storeId, viewCount);
+            return R.data(viewCount);
+        } catch (Exception e) {
+            log.error("统计店铺浏览量失败: storeId={}", storeId, e);
+            return R.fail("统计店铺浏览量失败: " + e.getMessage());
+        }
+    }
+
     /**
      * 获取客户端IP地址
      */
@@ -138,4 +159,6 @@ public class TrackEventController {
         }
         return ip;
     }
+
+
 }

+ 8 - 0
alien-store/src/main/java/shop/alien/store/service/TrackEventService.java

@@ -35,4 +35,12 @@ public interface TrackEventService {
      * @param weekly          统计类型(DAILY/WEEKLY/MONTHLY)
      */
     void calculateAndSaveStatistics(Integer id, Date lastWeekMonday, String weekly);
+    
+    /**
+     * 统计店铺当前总浏览量
+     *
+     * @param storeId 店铺ID
+     * @return 浏览量
+     */
+    Long getStoreViewCount(Integer storeId);
 }

+ 17 - 0
alien-store/src/main/java/shop/alien/store/service/impl/TrackEventServiceImpl.java

@@ -1003,4 +1003,21 @@ public class TrackEventServiceImpl extends ServiceImpl<StoreTrackEventMapper, St
         }
     }
 
+    @Override
+    public Long getStoreViewCount(Integer storeId) {
+        try {
+            if (storeId == null || storeId <= 0) {
+                log.warn("店铺ID无效: storeId={}", storeId);
+                return 0L;
+            }
+            
+            StoreTrackEventMapper mapper = this.getBaseMapper();
+            Long viewCount = mapper.countStoreViewCount(storeId);
+            return viewCount != null ? viewCount : 0L;
+        } catch (Exception e) {
+            log.error("统计店铺浏览量失败: storeId={}", storeId, e);
+            return 0L;
+        }
+    }
+
 }