修改游客模式商品详情

This commit is contained in:
wuchunlei
2025-04-03 11:14:00 +08:00
parent 4ace069730
commit d4cfd54ed3
3 changed files with 60 additions and 4 deletions

View File

@@ -15,4 +15,6 @@ public interface ShopProductService extends IService<ShopProduct> {
List<ShopProduct> getProductListForCourse(Integer CatalogueId);
Map<String,Object> getProductDetail(Integer productId);
Map<String,Object> getProductDetailVistor(Integer productId);
}

View File

@@ -70,8 +70,6 @@ public class ShopProductServiceImpl extends ServiceImpl<ShopProductDao, ShopProd
HashMap<String, Object> flag = new HashMap<>();
if (userVipService.isVip(ShiroUtils.getUId())&&product.getIsVipPrice()==1){
product.setVipPrice(shopProductService.getVipPrice(product));
}else {
product.setVipPrice(BigDecimal.ZERO);
}
flag.put("detail",product);//基础信息
//查询包含的书
@@ -127,7 +125,6 @@ public class ShopProductServiceImpl extends ServiceImpl<ShopProductDao, ShopProd
List<ShopProduct> shopProducts = (List)flag.get("GLProducts");
if (shopProducts.size()>0){
for (ShopProduct shopProduct : shopProducts) {
shopProduct.setVipPrice(BigDecimal.ZERO);
if (userVipService.isVip(ShiroUtils.getUId())&&shopProduct.getIsVipPrice()==1){
shopProduct.setVipPrice(shopProductService.getVipPrice(shopProduct));
}
@@ -136,4 +133,61 @@ public class ShopProductServiceImpl extends ServiceImpl<ShopProductDao, ShopProd
}
return flag;
}
@Override
public Map<String, Object> getProductDetailVistor(Integer productId) {
ShopProduct product = this.getById(productId);
HashMap<String, Object> flag = new HashMap<>();
flag.put("detail",product);//基础信息
//查询包含的书
MPJLambdaWrapper<ShopProductBookEntity> shopProductBookEntityMPJLambdaWrapper = new MPJLambdaWrapper<>();
shopProductBookEntityMPJLambdaWrapper.selectAll(BookEntity.class);
shopProductBookEntityMPJLambdaWrapper.leftJoin(BookEntity.class,BookEntity::getId,ShopProductBookEntity::getBookId);
shopProductBookEntityMPJLambdaWrapper.eq(ShopProductBookEntity::getProductId,productId);
List<BookEntity> bookEntities = shopProductBookDao.selectJoinList(BookEntity.class, shopProductBookEntityMPJLambdaWrapper);
flag.put("books",bookEntities);
//查询包含的课
MPJLambdaWrapper<ShopProductCourseEntity> shopProductCourseEntityMPJLambdaWrapper = new MPJLambdaWrapper<>();
shopProductCourseEntityMPJLambdaWrapper.selectAll(CourseEntity.class);
shopProductCourseEntityMPJLambdaWrapper.leftJoin(CourseEntity.class,CourseEntity::getId,ShopProductCourseEntity::getCourseId);
shopProductCourseEntityMPJLambdaWrapper.eq(ShopProductCourseEntity::getProductId,productId);
List<CourseEntity> courseEntities = shopProductCourseDao.selectJoinList(CourseEntity.class, shopProductCourseEntityMPJLambdaWrapper);
flag.put("courses",courseEntities);
//查询包含此商品的所有商品的列表
List<Integer> book_product_ids = new ArrayList<>();
if(bookEntities.size()>0){
List<Integer> collect = bookEntities.stream().map(BookEntity::getId).collect(Collectors.toList());
LambdaQueryWrapper<ShopProductBookEntity> shopProductBookEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
shopProductBookEntityLambdaQueryWrapper.in(ShopProductBookEntity::getBookId,collect);
shopProductBookEntityLambdaQueryWrapper.groupBy(ShopProductBookEntity::getProductId);
shopProductBookEntityLambdaQueryWrapper.having("count(product_id)>="+collect.size());
List<ShopProductBookEntity> shopProductBookEntities = shopProductBookDao.selectList(shopProductBookEntityLambdaQueryWrapper);
book_product_ids = shopProductBookEntities.stream().map(ShopProductBookEntity::getProductId).collect(Collectors.toList());
}
List<Integer> course_product_ids = new ArrayList<>();
if(courseEntities.size()>0){
List<Integer> collect = courseEntities.stream().map(CourseEntity::getId).collect(Collectors.toList());
LambdaQueryWrapper<ShopProductCourseEntity> shopProductCourseEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
shopProductCourseEntityLambdaQueryWrapper.in(ShopProductCourseEntity::getCourseId,collect);
shopProductCourseEntityLambdaQueryWrapper.groupBy(ShopProductCourseEntity::getProductId);
shopProductCourseEntityLambdaQueryWrapper.having("count(product_id)>="+collect.size());
List<ShopProductCourseEntity> shopProductCourseEntities = shopProductCourseDao.selectList(shopProductCourseEntityLambdaQueryWrapper);
course_product_ids = shopProductCourseEntities.stream().map(ShopProductCourseEntity::getProductId).collect(Collectors.toList());
}
if(book_product_ids.size()==0&&course_product_ids.size()==0){
List<ShopProduct> shopProducts = new ArrayList<>();
shopProducts.add(product);
flag.put("GLProducts",shopProducts);
} else if (book_product_ids.size()>0&&course_product_ids.size()>0) {
List<Integer> intersection = new ArrayList<>(book_product_ids);
intersection.retainAll(course_product_ids);
List<ShopProduct> shopProducts = this.getBaseMapper().selectList(new LambdaQueryWrapper<ShopProduct>().in(ShopProduct::getProductId, intersection));
flag.put("GLProducts",shopProducts);
} else {
List<Integer> is = new ArrayList<>(CollectionUtils.union(book_product_ids, course_product_ids));
List<ShopProduct> shopProducts = this.getBaseMapper().selectList(new LambdaQueryWrapper<ShopProduct>().in(ShopProduct::getProductId, is));
flag.put("GLProducts",shopProducts);
}
return flag;
}
}

View File

@@ -251,7 +251,7 @@ public class VisitorController {
//商品详情
@RequestMapping("/getProductDetail")
public R getProductDetail(@RequestBody Map<String,Integer> map){
Map<String, Object> detail = medicineShopProductService.getProductDetail(map.get("productId"));
Map<String, Object> detail = medicineShopProductService.getProductDetailVistor(map.get("productId"));
return R.ok().put("data",detail);
}