|
|
@@ -6,22 +6,21 @@ import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
+import org.dromara.product.domain.ProductBrowsingHistory;
|
|
|
+import org.dromara.product.domain.ProductCollect;
|
|
|
+import org.dromara.product.domain.ProductFavorites;
|
|
|
import org.dromara.product.domain.ProductShoppingCart;
|
|
|
-import org.dromara.product.domain.bo.PcProductBo;
|
|
|
-import org.dromara.product.domain.bo.ProductBaseBo;
|
|
|
-import org.dromara.product.domain.bo.ProductShoppingCartBo;
|
|
|
+import org.dromara.product.domain.bo.*;
|
|
|
import org.dromara.product.domain.vo.PcProductVo;
|
|
|
import org.dromara.product.domain.vo.ProductBaseVo;
|
|
|
-import org.dromara.product.service.IProductBaseService;
|
|
|
-import org.dromara.product.service.IProductShoppingCartService;
|
|
|
+import org.dromara.product.service.*;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
- * 首页
|
|
|
+ * 小程序商品
|
|
|
*
|
|
|
* @author
|
|
|
* @date 2026/1/26 下午6:41
|
|
|
@@ -38,6 +37,16 @@ public class MiniProductController {
|
|
|
//购物车
|
|
|
private final IProductShoppingCartService productShoppingCartService;
|
|
|
|
|
|
+
|
|
|
+ //商品浏览记录
|
|
|
+ private final IProductBrowsingHistoryService productBrowsingHistoryService;
|
|
|
+
|
|
|
+
|
|
|
+ //商品收藏
|
|
|
+ private final IProductCollectService productCollectService;
|
|
|
+ //商品收藏夹
|
|
|
+ private final IProductFavoritesService productFavoritesService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取客户商品池的商品
|
|
|
*/
|
|
|
@@ -142,4 +151,108 @@ public class MiniProductController {
|
|
|
bo.setCustomerId(LoginHelper.getLoginUser().getCustomerId());
|
|
|
return productBaseService.getProtocolProductsPage(bo, pageQuery);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增商品浏览记录
|
|
|
+ */
|
|
|
+ @PostMapping("/addProductBrowsingHistory/{productId}")
|
|
|
+ public R addProductBrowsingHistory(@PathVariable Long productId) {
|
|
|
+ ProductBrowsingHistoryBo productBrowsingHistoryBo = new ProductBrowsingHistoryBo();
|
|
|
+ productBrowsingHistoryBo.setProductId(productId);
|
|
|
+ productBrowsingHistoryBo.setUserId(LoginHelper.getUserId());
|
|
|
+ productBrowsingHistoryBo.setCustomerId(LoginHelper.getLoginUser().getCustomerId());
|
|
|
+ productBrowsingHistoryService.insertByBo(productBrowsingHistoryBo);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除浏览记录
|
|
|
+ */
|
|
|
+ @DeleteMapping("/deleteProductBrowsingHistory/{ids}")
|
|
|
+ public R deleteProductBrowsingHistory(@PathVariable Long[] ids) {
|
|
|
+ productBrowsingHistoryService.remove(Wrappers.lambdaQuery(ProductBrowsingHistory.class)
|
|
|
+ .in(ProductBrowsingHistory::getProductId, ids)
|
|
|
+ .eq(ProductBrowsingHistory::getUserId, LoginHelper.getUserId())
|
|
|
+ );
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 浏览记录的商品
|
|
|
+ */
|
|
|
+ @GetMapping("/getProductBrowsingHistory")
|
|
|
+ public R<Map<String, List<PcProductVo>>> getProductBrowsingHistory(@RequestParam(required = false) Date startTime, @RequestParam(required = false) Date endTime) {
|
|
|
+ return R.ok(productBaseService.getProductBrowsingHistory(LoginHelper.getUserId(), startTime, endTime));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收藏商品
|
|
|
+ */
|
|
|
+ @PostMapping("/addProductCollect")
|
|
|
+ public R addProductCollect(@RequestBody ProductCollectBo bo) {
|
|
|
+ //如果未传收藏夹id,则查询有没有默认收藏夹,如果没有就新增收藏夹
|
|
|
+ if (bo.getFavoritesId() == null) {
|
|
|
+ ProductFavorites one = productFavoritesService.getOne(Wrappers.lambdaQuery(ProductFavorites.class)
|
|
|
+ .eq(ProductFavorites::getUserId, LoginHelper.getUserId())
|
|
|
+ .eq(ProductFavorites::getIsDefault, "0")
|
|
|
+ );
|
|
|
+ if (one == null) {
|
|
|
+ one = new ProductFavorites();
|
|
|
+ one.setUserId(LoginHelper.getUserId());
|
|
|
+ one.setCustomerId(LoginHelper.getLoginUser().getCustomerId());
|
|
|
+ one.setTitle("默认收藏夹");
|
|
|
+ one.setIsDefault("0");
|
|
|
+ productFavoritesService.save(one);
|
|
|
+ }
|
|
|
+ bo.setFavoritesId(one.getId());
|
|
|
+ }
|
|
|
+ bo.setUserId(LoginHelper.getUserId());
|
|
|
+ bo.setCustomerId(LoginHelper.getLoginUser().getCustomerId());
|
|
|
+ productCollectService.insertByBo(bo);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 取消收藏
|
|
|
+ */
|
|
|
+ @DeleteMapping("/cancelProductCollect")
|
|
|
+ public R cancelProductCollect(ProductCollectBo bo) {
|
|
|
+ productCollectService.remove(Wrappers.lambdaQuery(ProductCollect.class)
|
|
|
+ .eq(ProductCollect::getUserId, LoginHelper.getUserId())
|
|
|
+ .eq(ProductCollect::getProductId, bo.getProductId())
|
|
|
+ );
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收藏夹商品列表
|
|
|
+ */
|
|
|
+ @GetMapping("/getFavoritesProductPage")
|
|
|
+ public TableDataInfo<PcProductVo> getFavoritesProductPage(Long favoritesId, PageQuery pageQuery) {
|
|
|
+ return productBaseService.getFavoritesProductPage(favoritesId, LoginHelper.getUserId(), pageQuery);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询商品是否在默认收藏夹收藏
|
|
|
+ */
|
|
|
+ @GetMapping("/isProductInDefaultCollect/{productIds}")
|
|
|
+ public R isProductInDefaultCollect(@PathVariable Long[] productIds) {
|
|
|
+ //查询商品是否在默认收藏夹收藏
|
|
|
+ ProductFavorites one = productFavoritesService.getOne(Wrappers.lambdaQuery(ProductFavorites.class)
|
|
|
+ .eq(ProductFavorites::getUserId, LoginHelper.getUserId())
|
|
|
+ .eq(ProductFavorites::getIsDefault, "0")
|
|
|
+ );
|
|
|
+ if (one == null) {
|
|
|
+ one = new ProductFavorites();
|
|
|
+ one.setUserId(LoginHelper.getUserId());
|
|
|
+ one.setTitle("默认收藏夹");
|
|
|
+ one.setIsDefault("0");
|
|
|
+ productFavoritesService.save(one);
|
|
|
+ }
|
|
|
+ return R.ok(productCollectService.exists(Wrappers.lambdaQuery(ProductCollect.class)
|
|
|
+ .eq(ProductCollect::getUserId, LoginHelper.getUserId())
|
|
|
+ .eq(ProductCollect::getFavoritesId, one.getId())
|
|
|
+ .in(ProductCollect::getProductId, productIds)));
|
|
|
+ }
|
|
|
+
|
|
|
}
|