Переглянути джерело

商品搜索相关接口修改

wxd 3 тижнів тому
батько
коміт
99afcc055e

+ 75 - 0
alien-entity/src/main/java/shop/alien/mapper/second/SecondGoodsMapper.java

@@ -111,4 +111,79 @@ public interface SecondGoodsMapper extends BaseMapper<SecondGoods> {
      * @return 屏蔽的商品列表
      */
     List<SecondGoods> getShieldedGoodsList( @Param("userId") Integer userId);
+
+    /**
+     * 获取用户收藏的商品列表
+     * @param page 分页参数
+     * @param queryWrapper 查询条件
+     * @return 收藏的商品列表
+     */
+    @Select("SELECT " +
+            "sg.*, " +
+            "sgc1.category_name as categoryOneName, " +
+            "sgc2.category_name as categoryTwoName " +
+            "FROM second_goods sg " +
+            "LEFT JOIN life_collect lc ON sg.id = lc.goods_id " +
+            "LEFT JOIN second_goods_category sgc1 " +
+            "on sg.category_one_id = sgc1.id " +
+            "LEFT JOIN second_goods_category sgc2 " +
+            "on sg.category_two_id = sgc2.id " +
+            "${ew.customSqlSegment}")
+    IPage<SecondGoodsVo> getCollectGoodsPage(IPage<SecondGoodsVo> page, QueryWrapper<SecondGoodsVo> queryWrapper);
+
+    /**
+     * 获取用户购买的商品列表
+     * @param page 分页参数
+     * @param queryWrapper 查询条件
+     * @return 购买的商品列表
+     */
+    @Select("SELECT " +
+            "sg.*, " +
+            "sgc1.category_name as categoryOneName, " +
+            "sgc2.category_name as categoryTwoName " +
+            "FROM second_goods sg " +
+            "LEFT JOIN second_trade_record str ON sg.id = str.goods_id " +
+            "LEFT JOIN second_goods_category sgc1 " +
+            "on sg.category_one_id = sgc1.id " +
+            "LEFT JOIN second_goods_category sgc2 " +
+            "on sg.category_two_id = sgc2.id " +
+            "${ew.customSqlSegment}")
+    IPage<SecondGoodsVo> getBuyGoodsPage(IPage<SecondGoodsVo> page, QueryWrapper<SecondGoodsVo> queryWrapper);
+
+    /**
+     * 获取用户出售的商品列表
+     * @param page 分页参数
+     * @param queryWrapper 查询条件
+     * @return 出售的商品列表
+     */
+    @Select("SELECT " +
+            "sg.*, " +
+            "sgc1.category_name as categoryOneName, " +
+            "sgc2.category_name as categoryTwoName " +
+            "FROM second_goods sg " +
+            "LEFT JOIN second_goods_category sgc1 " +
+            "on sg.category_one_id = sgc1.id " +
+            "LEFT JOIN second_goods_category sgc2 " +
+            "on sg.category_two_id = sgc2.id " +
+            "${ew.customSqlSegment}")
+    IPage<SecondGoodsVo> getSellGoodsPage(IPage<SecondGoodsVo> page, QueryWrapper<SecondGoodsVo> queryWrapper);
+
+    /**
+     * 获取用户商品列表
+     * @param page 分页参数
+     * @param queryWrapper 查询条件
+     * @return 商品列表
+     */
+    @Select("SELECT " +
+            "sg.*, " +
+            "sgc1.category_name as categoryOneName, " +
+            "sgc2.category_name as categoryTwoName, "+
+            "ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(',#{currentLongitude},' ',#{currentLatitude} , ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(sg.position, ',', ' '), ')' ))) / 1000, 2) AS distance "+
+            " FROM second_goods sg " +
+            "left JOIN second_goods_category sgc1 " +
+            "on sg.category_one_id = sgc1.id " +
+            "left JOIN second_goods_category sgc2 " +
+            "on sg.category_two_id = sgc2.id "+
+            "${ew.customSqlSegment}")
+    IPage<SecondGoodsVo> getUserGoodsPage(IPage<SecondGoodsVo> page, QueryWrapper<SecondGoodsVo> queryWrapper);
 }

+ 100 - 37
alien-second/src/main/java/shop/alien/second/controller/SecondGoodsController.java

@@ -1,6 +1,5 @@
 package shop.alien.second.controller;
 
-import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -43,41 +42,6 @@ public class SecondGoodsController {
     }
 
     /**
-     * 获取用户屏蔽的商品列表(分页)
-     */
-    @GetMapping("/getShieldedGoodsPage")
-    @ApiOperation("获取用户屏蔽的商品列表(分页)")
-    public R<IPage<SecondGoodsVo>> getShieldedGoodsPage(
-            @ApiParam("分页参数") @RequestBody SecondGoodsVo secondGoodsVo) {
-        R<IPage<SecondGoodsVo>> result = new R<>();
-        IPage<SecondGoodsVo> page = new Page<>(secondGoodsVo.getPageNum(), secondGoodsVo.getPageSize());
-        JSONObject data = JwtUtil.getCurrentUserInfo();
-        if (null != data) {
-            int userId = data.getInteger("userId");
-            result = R.data(secondGoodsService.getShieldedGoodsPage(page,userId));
-        }
-        return result;
-    }
-
-    /**
-     * 获取商品热卖排行榜(前10名)
-     */
-    @GetMapping("/getHotSellingRanking")
-    @ApiOperation("推荐 - 获取商品点赞热卖排行榜(前10名)")
-    public R<List<SecondGoods>> getHotSellingRanking() {
-        return R.data(secondGoodsService.getHotSellingRankingTop10(), "获取成功");
-    }
-
-    /**
-     * 大家都在看(前10名)
-     */
-    @GetMapping("/getCollectTop10")
-    @ApiOperation("大家都在看 - 获取商品收藏排行榜(前10名)")
-    public R<List<SecondGoods>> getCollectTop10() {
-        return R.data(secondGoodsService.getCollectTop10(), "获取成功");
-    }
-
-    /**
      * 添加二手商品
      */
     @PostMapping("/save")
@@ -99,7 +63,7 @@ public class SecondGoodsController {
     /**
      * 更新二手商品
      */
-    @PutMapping("/edit")
+    @PostMapping("/edit")
     @ApiOperation("更新二手商品")
     public R<Void> updateSecondGoods(@ApiParam("二手商品信息") @RequestBody SecondGoodsVo secondGoods) {
         if (!secondGoodsService.createBasicInfo(secondGoods)) {
@@ -147,4 +111,103 @@ public class SecondGoodsController {
         }
         return result;
     }
+
+    /**
+     * 获取商品热卖排行榜(前10名)
+     */
+    @GetMapping("/getHotSellingRanking")
+    @ApiOperation("推荐 - 获取商品点赞热卖排行榜(前10名)")
+    public R<List<SecondGoods>> getHotSellingRanking() {
+        return R.data(secondGoodsService.getHotSellingRankingTop10(), "获取成功");
+    }
+
+    /**
+     * 大家都在看(前10名)
+     */
+    @GetMapping("/getCollectTop10")
+    @ApiOperation("大家都在看 - 获取商品收藏排行榜(前10名)")
+    public R<List<SecondGoods>> getCollectTop10() {
+        return R.data(secondGoodsService.getCollectTop10(), "获取成功");
+    }
+
+    /**
+     * 获取用户屏蔽的商品列表(分页)
+     */
+    @GetMapping("/getShieldedGoodsPage")
+    @ApiOperation("获取用户屏蔽的商品列表(分页)")
+    public R<IPage<SecondGoodsVo>> getShieldedGoodsPage(
+            @ApiParam("分页参数") @RequestBody SecondGoodsVo secondGoodsVo) {
+        R<IPage<SecondGoodsVo>> result = new R<>();
+        IPage<SecondGoodsVo> page = new Page<>(secondGoodsVo.getPageNum(), secondGoodsVo.getPageSize());
+        JSONObject data = JwtUtil.getCurrentUserInfo();
+        if (null != data) {
+            int userId = data.getInteger("userId");
+            result = R.data(secondGoodsService.getShieldedGoodsPage(page,userId));
+        }
+        return result;
+    }
+
+    /**
+     * 我收藏的商品列表-分页
+     */
+    @GetMapping("/getCollectGoodsPage")
+    @ApiOperation("我收藏的商品列表-分页")
+    public R<IPage<SecondGoodsVo>> getCollectGoodsPage(
+            @ApiParam("分页参数") @RequestBody SecondGoodsVo secondGoodsVo) {
+        R<IPage<SecondGoodsVo>> result = new R<>();
+        IPage<SecondGoodsVo> page = new Page<>(secondGoodsVo.getPageNum(), secondGoodsVo.getPageSize());
+        JSONObject data = JwtUtil.getCurrentUserInfo();
+        if (null != data) {
+            int userId = data.getInteger("userId");
+            result = R.data(secondGoodsService.getCollectGoodsPage(page,userId));
+        }
+        return result;
+    }
+
+    /**
+     * 我卖出的商品列表-分页
+     */
+    @GetMapping("/getSellGoodsPage")
+    @ApiOperation("根据商品状态获取商品列表 - 0:草稿(我的草稿列表) 1:审核中 2:审核失败 3:已上架 4:已下架 5:已售出(我卖出的商品列表) -分页")
+    public R<IPage<SecondGoodsVo>> getSellGoodsPage(
+            @ApiParam("分页参数") @RequestBody SecondGoodsVo secondGoodsVo) {
+        R<IPage<SecondGoodsVo>> result = new R<>();
+        IPage<SecondGoodsVo> page = new Page<>(secondGoodsVo.getPageNum(), secondGoodsVo.getPageSize());
+        JSONObject data = JwtUtil.getCurrentUserInfo();
+        if (null != data) {
+            int userId = data.getInteger("userId");
+            result = R.data(secondGoodsService.getSellGoodsPage(page,secondGoodsVo,userId));
+        }
+        return result;
+    }
+
+    /**
+     * 我购买的商品列表-分页
+     */
+    @GetMapping("/getBuyGoodsPage")
+    @ApiOperation("我购买的商品列表-分页")
+    public R<IPage<SecondGoodsVo>> getBuyGoodsPage(
+            @ApiParam("分页参数") @RequestBody SecondGoodsVo secondGoodsVo) {
+        R<IPage<SecondGoodsVo>> result = new R<>();
+        IPage<SecondGoodsVo> page = new Page<>(secondGoodsVo.getPageNum(), secondGoodsVo.getPageSize());
+        JSONObject data = JwtUtil.getCurrentUserInfo();
+        if (null != data) {
+            int userId = data.getInteger("userId");
+            result = R.data(secondGoodsService.getBuyGoodsPage(page,userId));
+        }
+        return result;
+    }
+
+    /**
+     * 他的商品-个人主页用户发布的商品
+     */
+    @GetMapping("/getUserGoodsPage")
+    @ApiOperation("他的商品-个人主页用户发布的商品")
+    public R<IPage<SecondGoodsVo>> getUserGoodsPage(
+            @ApiParam("分页参数") @RequestBody SecondGoodsVo secondGoodsVo) {
+        IPage<SecondGoodsVo> page = new Page<>(secondGoodsVo.getPageNum(), secondGoodsVo.getPageSize());
+        return R.data(secondGoodsService.getUserGoodsPage(page,secondGoodsVo));
+    }
+
+
 }

+ 32 - 0
alien-second/src/main/java/shop/alien/second/service/SecondGoodsService.java

@@ -75,4 +75,36 @@ public interface SecondGoodsService extends IService<SecondGoods> {
      * @return 分页后的屏蔽商品列表
      */
     IPage<SecondGoodsVo>  getShieldedGoodsPage(IPage<SecondGoodsVo> page, Integer userId);
+
+    /**
+     * 获取我收藏的商品列表(分页)
+     * @param page 搜索条件
+     * @param userId 用户ID
+     * @return 分页后的收藏商品列表
+     */
+    IPage<SecondGoodsVo> getCollectGoodsPage(IPage<SecondGoodsVo> page, int userId);
+
+    /**
+     * 获取我购买的商品列表(分页)
+     * @param page 搜索条件
+     * @param userId 用户ID
+     * @return 分页后的购买商品列表
+     */
+    IPage<SecondGoodsVo> getBuyGoodsPage(IPage<SecondGoodsVo> page, int userId);
+
+    /**
+     * 获取我卖出的商品列表(分页)
+     * @param page 搜索条件
+     * @param userId 用户ID
+     * @return 分页后的卖出商品列表
+     */
+    IPage<SecondGoodsVo> getSellGoodsPage(IPage<SecondGoodsVo> page,SecondGoodsVo secondGoodsVo,int userId);
+
+    /**
+     * 获取个人主页用户发布的商品列表(分页)
+     * @param page 搜索条件
+     * @param secondGoodsVo 搜索条件
+     * @return 分页后的用户商品列表
+     */
+    IPage<SecondGoodsVo> getUserGoodsPage(IPage<SecondGoodsVo> page, SecondGoodsVo secondGoodsVo);
 }

+ 80 - 1
alien-second/src/main/java/shop/alien/second/service/impl/SecondGoodsServiceImpl.java

@@ -116,6 +116,10 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
         if (!saveStoreImages(savedGoodsId, goodsDTO.getImgUrl())) {
             return false;
         }
+        // 二手业务安全验证(调取阿里)
+        if (!checkSafety(goods)) {
+            return false;
+        }
 
         // 执行内容审核(图片和文本)
         if (!performContentReviews(goods, goodsDTO)) {
@@ -133,6 +137,15 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
     }
 
     /**
+     * 二手业务安全验证 (调取阿里)
+     * @param goods 商品信息
+     * @return 验证结果
+     */
+    private boolean checkSafety(SecondGoods goods) {
+        return true;
+    }
+
+    /**
      * 执行内容审核(图片和文本)
      * @param goods 商品信息
      * @param goodsDTO 商品DTO信息
@@ -378,10 +391,14 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
      * @param userId 用户ID(登录用户)
      */
     private void batchSetCollectStatus(IPage<SecondGoodsVo> searchGoodsList, Integer userId) {
+        // 获取用户信息
+        LifeUser lifeUser = lifeUserMapper.selectById(userId);
+        String phone = lifeUser.getUserPhone();
+        // 批量设置收藏状态
         searchGoodsList.getRecords().forEach(goods -> {
             if (userId != null) {
                 LambdaUpdateWrapper<LifeCollect> updateWrapper = new LambdaUpdateWrapper<>();
-                updateWrapper.eq(LifeCollect::getUserId, userId)
+                updateWrapper.eq(LifeCollect::getUserId, "user_"+phone)
                         .eq(LifeCollect::getGoodsId, goods.getId());
                         if (lifeCollectMapper.selectCount(updateWrapper) > 0) {
                             goods.setCollectStatus(1);
@@ -437,6 +454,68 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
     }
 
     /**
+     * 获取收藏商品列表
+     * @param page 分页参数
+     * @param userId 用户ID
+     * @return IPage<SecondGoodsVo> 收藏商品列表
+     */
+    @Override
+    public IPage<SecondGoodsVo> getCollectGoodsPage(IPage<SecondGoodsVo> page, int userId) {
+        QueryWrapper<SecondGoodsVo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("sg.delete_flag", 0)
+                .eq("lc.delete_flag", 0)
+                .eq("lc.user_id", userId);
+        return secondGoodsMapper.getCollectGoodsPage(page, queryWrapper);
+    }
+
+    /**
+     * 获取购买商品列表
+     * @param page 分页参数
+     * @param userId 用户ID
+     * @return IPage<SecondGoodsVo> 购买商品列表
+     */
+    @Override
+    public IPage<SecondGoodsVo> getBuyGoodsPage(IPage<SecondGoodsVo> page, int userId) {
+        QueryWrapper<SecondGoodsVo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("sg.delete_flag", 0)
+                .eq("str.delete_flag", 0)
+                .eq("str.buyer_id", userId) // 买家ID
+                .eq("str.trade_status", 1); // 1-交易成功
+        return secondGoodsMapper.getBuyGoodsPage(page, queryWrapper);
+    }
+
+    /**
+     * 根据商品状态获取商品列表 - 0:草稿 1:审核中 2:审核失败 3:已上架 4:已下架 5:已售出
+     * @param page 分页参数
+     * @param userId 用户ID
+     * @return IPage<SecondGoodsVo> 出售商品列表
+     */
+    @Override
+    public IPage<SecondGoodsVo> getSellGoodsPage(IPage<SecondGoodsVo> page, SecondGoodsVo secondGoodsVo,int userId) {
+        QueryWrapper<SecondGoodsVo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("sg.delete_flag", 0)
+                .eq("sg.user_id", userId)
+                .eq("sg.goods_status", secondGoodsVo.getGoodsStatus()); // 5-已售出 ,0-草稿
+        return secondGoodsMapper.getSellGoodsPage(page, queryWrapper);
+    }
+
+    /**
+     * 获取用户商品列表
+     * @param page 分页参数
+     * @param secondGoodsVo 查询参数
+     * @return IPage<SecondGoodsVo> 用户商品列表
+     */
+    @Override
+    public IPage<SecondGoodsVo> getUserGoodsPage(IPage<SecondGoodsVo> page, SecondGoodsVo secondGoodsVo) {
+        QueryWrapper<SecondGoodsVo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("sg.delete_flag", 0)
+                .eq("sg.user_id", secondGoodsVo.getUserId()) // 主页用户ID
+                .in("sg.goods_status",3,5) // 3-上架 5-已售出
+                .orderByAsc("distance");
+        return secondGoodsMapper.getUserGoodsPage(page, queryWrapper);
+    }
+
+    /**
      * 查询搜索结果
      * @param page 分页参数
      * @param secondGoodsVo 查询参数