Просмотр исходного кода

feat(goods): 添加商品热度功能

- 新增 addGoodsHot接口,用于增加商品热度- 热度数量通过更新 likeCount 字段实现
- 添加参数校验和商品存在性检查
- 返回成功或失败的响应消息
wxd 3 месяцев назад
Родитель
Сommit
617b42ea77

+ 29 - 0
alien-second/src/main/java/shop/alien/second/controller/SecondGoodsController.java

@@ -174,6 +174,35 @@ public class SecondGoodsController {
     }
 
     /**
+     * 商品热度添加接口
+     */
+    @PostMapping("/addGoodsHot")
+    @ApiOperation("商品热度添加,热度数量加1")
+    public R<Void> addGoodsHot(@ApiParam("商品ID") @RequestParam Integer goodsId) {
+        log.info("SecondGoodsController.addGoodsHot?goodsId={}", goodsId);
+        if (goodsId == null) {
+            return R.fail("商品ID不能为空");
+        }
+        
+        SecondGoods goods = secondGoodsService.getById(goodsId);
+        if (goods == null) {
+            return R.fail("商品不存在");
+        }
+        
+        // 热度数量加1(使用likeCount字段表示热度)
+        SecondGoods updateGoods = new SecondGoods();
+        updateGoods.setId(goodsId);
+        updateGoods.setLikeCount(goods.getLikeCount() == null ? 1 : goods.getLikeCount() + 1);
+        boolean result = secondGoodsService.updateById(updateGoods);
+        
+        if (result) {
+            return R.success("热度添加成功");
+        } else {
+            return R.fail("热度添加失败");
+        }
+    }
+
+    /**
      * 文本审核接口 - 商品发布场景
      */
     @GetMapping("/textModeration/productPublish")