Explorar el Código

二手收藏BUG 修改

lutong hace 1 día
padre
commit
5c9e23c099

+ 1 - 1
alien-second/src/main/java/shop/alien/second/controller/SecondRecommendController.java

@@ -75,7 +75,7 @@ public class SecondRecommendController {
         return R.data(service.querySecondGoodsDetail(goodsId, longitude + "," + latitude), "查询成功");
     }
 
-    @ApiOperation("搜索商品详情")
+    @ApiOperation(value = "商品详情(匿名/带手机号)", notes = "需传当前用户 phoneId(可为裸手机号或 user_ 前缀),与 collect/addCollect 写入的 life_collect.user_id 一致;响应 collectStatus:0=未收藏,1=已收藏")
     @PostMapping("/querySecondGoodsDetailWithOutJWT")
     public R<SecondGoodsRecommendVo> querySecondGoodsDetailWithOutJWT(
             @RequestParam(value = "phoneId", required = false) String phoneId,

+ 22 - 4
alien-second/src/main/java/shop/alien/second/service/impl/SecondRecommendServiceImpl.java

@@ -191,7 +191,8 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
             if (StringUtil.isBlank(phoneId)) {
                 return null;
             }
-            SecondGoodsRecommendVo item = mapper.querySecondGoodsDetail(goodsId, "user_" + phoneId, position);
+            String collectUserId = toLifeCollectUserId(phoneId);
+            SecondGoodsRecommendVo item = mapper.querySecondGoodsDetail(goodsId, collectUserId, position);
             applySecondGoodsDetailEnrichment(item, phoneId, goodsId);
             return item;
         } catch (Exception e) {
@@ -206,7 +207,8 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
             if (StringUtil.isBlank(phoneId)) {
                 return null;
             }
-            SecondGoodsRecommendVo item = mapper.querySecondGoodsDetail(goodsId, "user_" + phoneId, position);
+            String collectUserId = toLifeCollectUserId(phoneId);
+            SecondGoodsRecommendVo item = mapper.querySecondGoodsDetail(goodsId, collectUserId, position);
             applySecondGoodsDetailEnrichment(item, phoneId, goodsId);
             return item;
         } catch (Exception e) {
@@ -216,7 +218,20 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
     }
 
     /**
-     * 二手商品详情公共填充:图片列表(含视频排序)、关注状态、距离文案、价格展示
+     * 与 {@code alienStore/collect/addCollect}、表 {@code life_collect.user_id} 一致:普通用户收藏键为 {@code user_手机号}。
+     *
+     * @param phoneOrUserId 裸手机号或已带 {@code user_} 的前端入参
+     */
+    static String toLifeCollectUserId(String phoneOrUserId) {
+        if (StringUtil.isBlank(phoneOrUserId)) {
+            return "";
+        }
+        String t = phoneOrUserId.trim();
+        return t.startsWith("user_") ? t : "user_" + t;
+    }
+
+    /**
+     * 二手商品详情公共填充:图片列表(含视频排序)、关注状态、距离文案、价格展示;收藏状态由 SQL 已带出,此处补默认「未收藏」。
      */
     private void applySecondGoodsDetailEnrichment(SecondGoodsRecommendVo item, String phoneId, Integer goodsId) {
         if (item == null) {
@@ -246,7 +261,7 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
         query1.lambda()
                 .eq(LifeFans::getFollowedId, item.getUserPhone())
                 .eq(LifeFans::getDeleteFlag, 0)
-                .eq(LifeFans::getFansId, "user_" + phoneId);
+                .eq(LifeFans::getFansId, toLifeCollectUserId(phoneId));
         List<LifeFans> lifeFans = lifeFansMapper.selectList(query1);
         if (lifeFans.size() > 0) {
             item.setFansStatus(1);
@@ -256,6 +271,9 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
             item.setPosition("距离" + item.getDist() + "km");
         }
         item.setPrice(item.getAmount() != null ? item.getAmount().setScale(2, BigDecimal.ROUND_HALF_UP).toString() : null);
+        if (StringUtil.isBlank(item.getCollectStatus())) {
+            item.setCollectStatus("0");
+        }
     }
 
     public static void main(String[] args) {