From 47133a6b0d4e6e805b32486593e242cb722e7795 Mon Sep 17 00:00:00 2001 From: wyn <1074145239@qq.com> Date: Thu, 23 Jul 2026 09:27:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E5=AD=90=E4=B9=A6vip=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E6=96=B0=E8=A7=84=E5=88=99=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/peanut/common/utils/MailUtil.java | 2 +- .../book/controller/BuyOrderController.java | 13 +- .../book/service/ShopProductService.java | 5 +- .../service/impl/ShopProductServiceImpl.java | 184 +++++++++++++++++- .../bookAbroad/controller/HomeController.java | 169 +++++++++++++++- .../modules/common/entity/ShopProduct.java | 9 + .../common/service/UserEbookVipService.java | 6 + .../service/impl/UserEbookVipServiceImpl.java | 20 ++ .../service/impl/CourseServiceImpl.java | 142 +++++++------- 9 files changed, 451 insertions(+), 99 deletions(-) diff --git a/src/main/java/com/peanut/common/utils/MailUtil.java b/src/main/java/com/peanut/common/utils/MailUtil.java index cd6f557..f294fc7 100644 --- a/src/main/java/com/peanut/common/utils/MailUtil.java +++ b/src/main/java/com/peanut/common/utils/MailUtil.java @@ -12,7 +12,7 @@ import java.util.Properties; public class MailUtil { private final static String mailName = "AmazingLimited@163.com"; - private final static String mailToken = "ZMbHwKZF2Vr8V7xs"; + private final static String mailToken = "DLTVBxdWpPdvvvFP"; public static R sendMail(String content,String receiveAddress){ try { diff --git a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java index ba1ac10..8ea0d7a 100644 --- a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java +++ b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java @@ -259,12 +259,11 @@ public class BuyOrderController { @RequestMapping("/getVipDiscountAmount") public R getVipDiscountAmount(@RequestBody BuyOrder buyOrder){ BigDecimal b = new BigDecimal(0); - if (userVipService.isVip()){ - List buyOrderProductList = buyOrder.getProductList(); - for (BuyOrderProduct buyOrderProduct : buyOrderProductList) { - BigDecimal pvda = shopProductService.getVipDiscountAmount(shopProductService.getById(buyOrderProduct.getProductId())); - b = b.add(pvda.multiply(new BigDecimal(buyOrderProduct.getQuantity()))); - } + + List buyOrderProductList = buyOrder.getProductList(); + for (BuyOrderProduct buyOrderProduct : buyOrderProductList) { + BigDecimal pvda = shopProductService.getCourseOrBookVipDiscountAmount(shopProductService.getById(buyOrderProduct.getProductId())); + b = b.add(pvda.multiply(new BigDecimal(buyOrderProduct.getQuantity()))); } return R.ok().put("discountAmount",b); } @@ -277,7 +276,7 @@ public class BuyOrderController { for (BuyOrderProduct buyOrderProduct : buyOrderProductList) { ShopProduct shopProduct = shopProductService.getById(buyOrderProduct.getProductId()); if (userVipService.isVip()){ - BigDecimal pvda = shopProductService.getVipDiscountAmount(shopProductService.getById(buyOrderProduct.getProductId())); + BigDecimal pvda = shopProductService.getCourseOrBookVipDiscountAmount(shopProductService.getById(buyOrderProduct.getProductId())); if (pvda.compareTo(BigDecimal.ZERO)>0){ continue; } diff --git a/src/main/java/com/peanut/modules/book/service/ShopProductService.java b/src/main/java/com/peanut/modules/book/service/ShopProductService.java index 25f5fed..522995c 100644 --- a/src/main/java/com/peanut/modules/book/service/ShopProductService.java +++ b/src/main/java/com/peanut/modules/book/service/ShopProductService.java @@ -23,6 +23,8 @@ public interface ShopProductService extends IService { List appGetCategoryList(Integer catId); + BigDecimal getCourseOrBookVipDiscountAmount(ShopProduct shopProduct); + BigDecimal getVipDiscountAmount(ShopProduct shopProduct); BigDecimal getVipPrice(ShopProduct shopProduct); @@ -36,8 +38,5 @@ public interface ShopProductService extends IService { PageUtils queryPageactivityprice(Map params); List getProductListForBook(Integer bookId); - - - } diff --git a/src/main/java/com/peanut/modules/book/service/impl/ShopProductServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/ShopProductServiceImpl.java index fe38c78..d4eb70d 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/ShopProductServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/ShopProductServiceImpl.java @@ -1,9 +1,13 @@ package com.peanut.modules.book.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.peanut.common.utils.ExcludeEmptyQueryWrapper; import com.peanut.common.utils.ShiroUtils; +import com.peanut.modules.common.dao.BookDao; import com.peanut.modules.common.dao.ShopProductBookDao; +import com.peanut.modules.common.entity.BookEntity; import com.peanut.modules.common.entity.ShopProductBookEntity; +import com.peanut.modules.common.service.UserEbookVipService; import com.peanut.modules.common.service.UserVipService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -28,6 +32,10 @@ public class ShopProductServiceImpl extends ServiceImpl params) { @@ -55,7 +63,6 @@ public class ShopProductServiceImpl extends ServiceImpl list = this.getBaseMapper().appGetCategoryList(catId); return list; } - @Override public BigDecimal getVipDiscountAmount(ShopProduct shopProduct) { BigDecimal p = new BigDecimal(0); @@ -75,6 +82,98 @@ public class ShopProductServiceImpl extends ServiceImpl 0 + && vipPrice.compareTo(shopProduct.getActivityPrice()) >= 0) { + return BigDecimal.ZERO; + } + return shopProduct.getPrice().subtract(vipPrice).setScale(2, BigDecimal.ROUND_HALF_UP); + } + // isVip=2:付费折扣 + if (bookIsVip != null && bookIsVip == 2 && shopProduct.getIsVipPrice() == 1) { + BigDecimal courseVipPrice = BigDecimal.ZERO; + if (userVipService.isVip()) { + if (userVipService.is4569SVip(ShiroUtils.getUId()) || userVipService.is78SVip(ShiroUtils.getUId())) { + courseVipPrice = shopProduct.getPrice().multiply(new BigDecimal(0.8)); + } else if (userVipService.isVip()) { + courseVipPrice = shopProduct.getPrice().multiply(new BigDecimal(0.9)); + } + } + BigDecimal bookVipPrice = BigDecimal.ZERO; + if (userEbookVipService.isBookVip()) { + bookVipPrice = shopProduct.getPrice().multiply(new BigDecimal(0.8)); + } + // 取非0且更小的vip价 + BigDecimal vipPrice = BigDecimal.ZERO; + if (courseVipPrice.compareTo(BigDecimal.ZERO) > 0) { + vipPrice = courseVipPrice; + } + if (bookVipPrice.compareTo(BigDecimal.ZERO) > 0 + && (vipPrice.compareTo(BigDecimal.ZERO) == 0 || bookVipPrice.compareTo(vipPrice) < 0)) { + vipPrice = bookVipPrice; + } + if (vipPrice.compareTo(BigDecimal.ZERO) <= 0) { + return p; + } + // vip折后价不低于活动价,直接返回0 + if (shopProduct.getActivityPrice().compareTo(new BigDecimal(0)) > 0 + && vipPrice.compareTo(shopProduct.getActivityPrice()) >= 0) { + return BigDecimal.ZERO; + } + return shopProduct.getPrice().subtract(vipPrice).setScale(2, BigDecimal.ROUND_HALF_UP); + } + } + if (userVipService.isVip()&&shopProduct.getIsVipPrice()==1){ + if (userVipService.is4569SVip(ShiroUtils.getUId())||userVipService.is78SVip(ShiroUtils.getUId())){ + p = shopProduct.getPrice().multiply(new BigDecimal(0.8)); + }else if (userVipService.isVip()){ + p = shopProduct.getPrice().multiply(new BigDecimal(0.9)); + } + // vip折后价不低于活动价,直接返回0 + if (shopProduct.getActivityPrice().compareTo(new BigDecimal(0))>0 + &&p.compareTo(shopProduct.getActivityPrice())>=0){ + return BigDecimal.ZERO; + } + return shopProduct.getPrice().subtract(p).setScale(2,BigDecimal.ROUND_HALF_UP); + } + return p; + } + + /** + * 根据商品关联图书获取isVip + */ + private Integer getRelatedBookIsVip(Integer productId) { + List productBooks = shopProductBookDao.selectList(new LambdaQueryWrapper() + .eq(ShopProductBookEntity::getProductId, productId) + .eq(ShopProductBookEntity::getDelFlag, 0) + .last("limit 1")); + if (productBooks == null || productBooks.isEmpty()) { + return null; + } + BookEntity book = bookDao.selectById(productBooks.get(0).getBookId()); + return book == null ? null : book.getIsVip(); + } @Override public BigDecimal getVipPrice(ShopProduct shopProduct) { @@ -89,12 +188,11 @@ public class ShopProductServiceImpl extends ServiceImpl0 - &&b.compareTo(shopProduct.getActivityPrice())>0){ + &&b.compareTo(shopProduct.getActivityPrice())>=0){ b = new BigDecimal(0); } return b; } - @Override public PageUtils getNewBook(Map params) { IPage page = this.page( @@ -145,8 +243,86 @@ public class ShopProductServiceImpl extends ServiceImpl shopProducts = shopProductBookDao.selectJoinList(ShopProduct.class, wrapper); + BookEntity book = bookDao.selectById(bookId); + Integer isVip = book == null ? null : book.getIsVip(); + boolean courseVip = userVipService.isVip(); + boolean bookVip = userEbookVipService.isBookVip(); + for (ShopProduct shopProduct : shopProducts) { + BigDecimal minPrice = BigDecimal.ZERO; + int discountType = 0; + BigDecimal price = shopProduct.getPrice(); + if (price != null && price.compareTo(BigDecimal.ZERO) > 0) { + minPrice = price; + } + BigDecimal activityPrice = shopProduct.getActivityPrice(); + if (activityPrice != null && activityPrice.compareTo(BigDecimal.ZERO) > 0 + && minPrice.compareTo(activityPrice) > 0) { + discountType = 1; + minPrice = activityPrice; + } + + // isVip=1:电子书vip免费,课程vip打对应折扣 + if (isVip != null && isVip == 1) { + if (bookVip) { + shopProduct.setVipPrice(BigDecimal.ZERO); + discountType = 2; + minPrice = BigDecimal.ZERO; + } else if (courseVip && shopProduct.getIsVipPrice() != null && shopProduct.getIsVipPrice() == 1) { + BigDecimal courseVipPrice = this.getVipPrice(shopProduct); + shopProduct.setVipPrice(courseVipPrice); + if (courseVipPrice.compareTo(BigDecimal.ZERO) > 0 && minPrice.compareTo(courseVipPrice) > 0) { + discountType = 2; + minPrice = courseVipPrice; + } + } + // isVip=2:付费,电子书vip八折,课程vip打对应折扣 + } else if (isVip != null && isVip == 2 && shopProduct.getIsVipPrice() != null && shopProduct.getIsVipPrice() == 1 + && minPrice.compareTo(BigDecimal.ZERO) > 0 + && (courseVip || bookVip)) { + BigDecimal vipPrice = BigDecimal.ZERO; + BigDecimal courseVipPrice = BigDecimal.ZERO; + if (courseVip) { + courseVipPrice = this.getVipPrice(shopProduct); + } + BigDecimal bookVipPrice = BigDecimal.ZERO; + if (bookVip) { + bookVipPrice = userEbookVipService.getBookVipPrice(shopProduct); + } + if (courseVipPrice.compareTo(BigDecimal.ZERO) > 0) { + vipPrice = courseVipPrice; + shopProduct.setVipPrice(vipPrice); + } + if (bookVipPrice.compareTo(BigDecimal.ZERO) > 0 + && (vipPrice.compareTo(BigDecimal.ZERO) == 0 || bookVipPrice.compareTo(vipPrice) < 0)) { + vipPrice = bookVipPrice; + shopProduct.setVipPrice(bookVipPrice); + } + // minPrice 更大才用 vip 替换,否则不替换 + if (vipPrice.compareTo(BigDecimal.ZERO) > 0 && minPrice.compareTo(vipPrice) > 0) { + discountType = 2; + minPrice = vipPrice; + } + } + shopProduct.setIsVip(isVip); + shopProduct.setDiscountType(discountType); + shopProduct.setMinPrice(minPrice); + } return shopProducts; } - + /** + * 课程vip原始折后价(不与活动价比较,由调用方与 minPrice 比较) + */ + private BigDecimal calcCourseVipRawPrice(ShopProduct shopProduct) { + if (shopProduct.getPrice() == null) { + return BigDecimal.ZERO; + } + if (userVipService.is4569SVip(ShiroUtils.getUId()) || userVipService.is78SVip(ShiroUtils.getUId())) { + return shopProduct.getPrice().multiply(new BigDecimal(0.8)).setScale(2, BigDecimal.ROUND_HALF_UP); + } + if (userVipService.isVip()) { + return shopProduct.getPrice().multiply(new BigDecimal(0.9)).setScale(2, BigDecimal.ROUND_HALF_UP); + } + return BigDecimal.ZERO; + } } \ No newline at end of file diff --git a/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java b/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java index cae95df..cc46c47 100644 --- a/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java +++ b/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java @@ -80,6 +80,101 @@ public class HomeController { wrapper.like(BookEntity::getName,params.get("title")); wrapper.orderByAsc(BookAbroadToLable::getSort); List> list = toLableService.listMaps(wrapper); + for (Map map : list) { + //查询最低价格 + List shopProducts = shopProductService.list(new MPJLambdaWrapper() + .leftJoin(ShopProductBookEntity.class,ShopProductBookEntity::getProductId,ShopProduct::getProductId) + .selectAll(ShopProduct.class) + .eq(ShopProduct::getGoodsType,"02") + .eq(ShopProductBookEntity::getBookId,map.get("bookId"))); + map.put("minPrice",0); + map.put("discountType",0); + List> priceList = new ArrayList<>(); + for (ShopProduct shopProduct : shopProducts) { + BigDecimal price = shopProduct.getPrice(); + if (price.compareTo(BigDecimal.ZERO)>0){ + Map priceMap = new HashMap<>(); + priceMap.put("discountType",BigDecimal.ZERO); + priceMap.put("price",price); + priceList.add(priceMap); + } + BigDecimal activityPrice = shopProduct.getActivityPrice(); + if (activityPrice.compareTo(BigDecimal.ZERO)>0){ + Map priceMap = new HashMap<>(); + priceMap.put("discountType",new BigDecimal(1)); + priceMap.put("price",activityPrice); + priceList.add(priceMap); + } + BigDecimal vipPrice = BigDecimal.ZERO; + if(Integer.parseInt(map.get("isVip").toString())==0){ + Map priceMap = new HashMap<>(); + priceMap.put("discountType",new BigDecimal(0)); + priceMap.put("price",BigDecimal.ZERO); + priceList.add(priceMap); + }else if(Integer.parseInt(map.get("isVip").toString())==1 ){ + boolean courseVip = userVipService.isVip(); + boolean bookVip = userEbookVipService.isBookVip(); + if(bookVip){ + Map priceMap = new HashMap<>(); + priceMap.put("discountType",new BigDecimal(2)); + priceMap.put("price",BigDecimal.ZERO); + priceList.add(priceMap); + }else if(courseVip){ + BigDecimal courseVipPrice = shopProductService.getVipPrice(shopProduct); + if (courseVipPrice.compareTo(BigDecimal.ZERO) > 0) { + Map priceMap = new HashMap<>(); + priceMap.put("discountType",new BigDecimal(2)); + priceMap.put("price",courseVipPrice); + priceList.add(priceMap); + } + } + }else if(Integer.parseInt(map.get("isVip").toString())==2 && shopProduct.getIsVipPrice()==1){ + boolean courseVip = userVipService.isVip(); + boolean bookVip = userEbookVipService.isBookVip(); + BigDecimal courseVipPrice = BigDecimal.ZERO; + if(courseVip){ + courseVipPrice = shopProductService.getVipPrice(shopProduct); + } + BigDecimal bookVipPrice = BigDecimal.ZERO; + if(bookVip){ + bookVipPrice = userEbookVipService.getBookVipPrice(shopProduct); + } + if (courseVipPrice.compareTo(BigDecimal.ZERO) > 0) { + vipPrice = courseVipPrice; + } + if (bookVipPrice.compareTo(BigDecimal.ZERO) > 0 + && (vipPrice.compareTo(BigDecimal.ZERO) == 0 || bookVipPrice.compareTo(vipPrice) < 0)) { + vipPrice = bookVipPrice; + } + // 非vip用户vipPrice为0,不加入比价,避免minPrice被写成0且discountType=2 + if (vipPrice.compareTo(BigDecimal.ZERO) > 0) { + Map priceMap = new HashMap<>(); + priceMap.put("discountType",new BigDecimal(2)); + priceMap.put("price",vipPrice); + priceList.add(priceMap); + } + } + } + if (priceList.size()>0){ + priceList=priceList.stream().sorted((b1,b2)->{ + return b1.get("price").compareTo(b2.get("price")); + }).collect(Collectors.toList()); + Map minPriceMap = priceList.get(0); + map.put("minPrice", minPriceMap.get("price")); + map.put("discountType", minPriceMap.get("discountType").intValue()); + } + map.put("isBuy",false); + long count = userEbookBuyService.count(new LambdaQueryWrapper() + .eq(UserEbookBuyEntity::getUserId,ShiroUtils.getUId()) + .eq(UserEbookBuyEntity::getBookId,map.get("bookId"))); + if (count > 0) { + map.put("isBuy",true); + } + } + + + + // for (Map map : list) { // long readCount = bookReadRateService.count(new LambdaQueryWrapper() // .eq(BookReadRateEntity::getBookId,map.get("bookId"))); @@ -263,29 +358,85 @@ public class HomeController { .eq(ShopProduct::getGoodsType,"02") .eq(ShopProductBookEntity::getBookId,map.get("bookId"))); map.put("minPrice",0); - List priceList = new ArrayList<>(); + map.put("discountType",0); + List> priceList = new ArrayList<>(); for (ShopProduct shopProduct : shopProducts) { BigDecimal price = shopProduct.getPrice(); if (price.compareTo(BigDecimal.ZERO)>0){ - priceList.add(price); + Map priceMap = new HashMap<>(); + priceMap.put("discountType",BigDecimal.ZERO); + priceMap.put("price",price); + priceList.add(priceMap); } BigDecimal activityPrice = shopProduct.getActivityPrice(); if (activityPrice.compareTo(BigDecimal.ZERO)>0){ - priceList.add(activityPrice); + Map priceMap = new HashMap<>(); + priceMap.put("discountType",new BigDecimal(1)); + priceMap.put("price",activityPrice); + priceList.add(priceMap); } BigDecimal vipPrice = BigDecimal.ZERO; - if (userVipService.isVip()&&shopProduct.getIsVipPrice()==1){ - vipPrice = shopProductService.getVipPrice(shopProduct); - if (vipPrice.compareTo(BigDecimal.ZERO)>0){ - priceList.add(vipPrice); + + if(Integer.parseInt(map.get("isVip").toString())==0){ + Map priceMap = new HashMap<>(); + priceMap.put("discountType",new BigDecimal(0)); + priceMap.put("price",BigDecimal.ZERO); + priceList.add(priceMap); + }else if(Integer.parseInt(map.get("isVip").toString())==1 ){ + boolean courseVip = userVipService.isVip(); + boolean bookVip = userEbookVipService.isBookVip(); + if(bookVip){ + Map priceMap = new HashMap<>(); + priceMap.put("discountType",new BigDecimal(2)); + priceMap.put("price",BigDecimal.ZERO); + priceList.add(priceMap); + }else if(courseVip){ + BigDecimal courseVipPrice = shopProductService.getVipPrice(shopProduct); + if (courseVipPrice.compareTo(BigDecimal.ZERO) > 0) { + Map priceMap = new HashMap<>(); + priceMap.put("discountType",new BigDecimal(2)); + priceMap.put("price",courseVipPrice); + priceList.add(priceMap); + } } + }else if(Integer.parseInt(map.get("isVip").toString())==2 && shopProduct.getIsVipPrice()==1){ + boolean courseVip = userVipService.isVip(); + boolean bookVip = userEbookVipService.isBookVip(); + if(courseVip||bookVip){ + BigDecimal courseVipPrice = BigDecimal.ZERO; + if(courseVip){ + courseVipPrice = shopProductService.getVipPrice(shopProduct); + } + BigDecimal bookVipPrice = BigDecimal.ZERO; + if(bookVip){ + bookVipPrice = userEbookVipService.getBookVipPrice(shopProduct); + } + if (courseVipPrice.compareTo(BigDecimal.ZERO) > 0) { + vipPrice = courseVipPrice; + } + if (bookVipPrice.compareTo(BigDecimal.ZERO) > 0 + && (vipPrice.compareTo(BigDecimal.ZERO) == 0 || bookVipPrice.compareTo(vipPrice) < 0)) { + vipPrice = bookVipPrice; + } + // 非vip用户vipPrice为0,不加入比价,避免minPrice被写成0且discountType=2 + if (vipPrice.compareTo(BigDecimal.ZERO) > 0) { + Map priceMap = new HashMap<>(); + priceMap.put("discountType",new BigDecimal(2)); + priceMap.put("price",vipPrice); + priceList.add(priceMap); + } + } + + } } if (priceList.size()>0){ priceList=priceList.stream().sorted((b1,b2)->{ - return b1.compareTo(b2); + return b1.get("price").compareTo(b2.get("price")); }).collect(Collectors.toList()); - map.put("minPrice",priceList.get(0)); + Map minPriceMap = priceList.get(0); + map.put("minPrice", minPriceMap.get("price")); + map.put("discountType", minPriceMap.get("discountType").intValue()); } map.put("isBuy",false); long count = userEbookBuyService.count(new LambdaQueryWrapper() diff --git a/src/main/java/com/peanut/modules/common/entity/ShopProduct.java b/src/main/java/com/peanut/modules/common/entity/ShopProduct.java index a0ffe49..db87a79 100644 --- a/src/main/java/com/peanut/modules/common/entity/ShopProduct.java +++ b/src/main/java/com/peanut/modules/common/entity/ShopProduct.java @@ -194,4 +194,13 @@ public class ShopProduct implements Serializable { //vip价格 @TableField(exist = false) private BigDecimal vipPrice; + + @TableField(exist = false) + private BigDecimal minPrice; + + @TableField(exist = false) + private int discountType; + + @TableField(exist = false) + private Integer isVip; } diff --git a/src/main/java/com/peanut/modules/common/service/UserEbookVipService.java b/src/main/java/com/peanut/modules/common/service/UserEbookVipService.java index 0a5eabb..44ec731 100644 --- a/src/main/java/com/peanut/modules/common/service/UserEbookVipService.java +++ b/src/main/java/com/peanut/modules/common/service/UserEbookVipService.java @@ -1,7 +1,13 @@ package com.peanut.modules.common.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.peanut.modules.common.entity.ShopProduct; import com.peanut.modules.common.entity.UserEbookVip; +import java.math.BigDecimal; + public interface UserEbookVipService extends IService { + BigDecimal getBookVipPrice(ShopProduct shopProduct); + + Boolean isBookVip(); } diff --git a/src/main/java/com/peanut/modules/common/service/impl/UserEbookVipServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/UserEbookVipServiceImpl.java index 5361aee..1bdb456 100644 --- a/src/main/java/com/peanut/modules/common/service/impl/UserEbookVipServiceImpl.java +++ b/src/main/java/com/peanut/modules/common/service/impl/UserEbookVipServiceImpl.java @@ -1,13 +1,33 @@ package com.peanut.modules.common.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.peanut.common.utils.ShiroUtils; import com.peanut.modules.common.dao.UserEbookVipDao; +import com.peanut.modules.common.entity.ShopProduct; import com.peanut.modules.common.entity.UserEbookVip; import com.peanut.modules.common.service.UserEbookVipService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.util.Date; + @Slf4j @Service("commonUserEbookVipService") public class UserEbookVipServiceImpl extends ServiceImpl implements UserEbookVipService { + @Override + public BigDecimal getBookVipPrice(ShopProduct shopProduct) { + return shopProduct.getPrice().multiply(new BigDecimal(0.8)).setScale(2, BigDecimal.ROUND_HALF_UP); + } + @Override + public Boolean isBookVip() { + UserEbookVip vip = this.getOne(new LambdaQueryWrapper() + .eq(UserEbookVip::getUserId, ShiroUtils.getUId()) + .and(w -> w.isNull(UserEbookVip::getEndTime) + .or() + .gt(UserEbookVip::getEndTime, new Date())) + .last("limit 1")); + return vip != null; + } } diff --git a/src/main/java/com/peanut/modules/medical/service/impl/CourseServiceImpl.java b/src/main/java/com/peanut/modules/medical/service/impl/CourseServiceImpl.java index 53a6a03..690e953 100644 --- a/src/main/java/com/peanut/modules/medical/service/impl/CourseServiceImpl.java +++ b/src/main/java/com/peanut/modules/medical/service/impl/CourseServiceImpl.java @@ -187,43 +187,77 @@ public class CourseServiceImpl extends ServiceImpl impl .stream().map(UserCourseBuyEntity::getCourseId).collect(Collectors.toList()); if (list.size()>0&&buyList.size()>0){ wrapper.and(t->t.in(CourseToMedicine::getMedicalId,list).or().in(CourseToMedicine::getCourseId,buyList)); - }else if (list.size()>0){ - wrapper.in(CourseToMedicine::getMedicalId,list); - }else if (buyList.size()>0){ - wrapper.in(CourseToMedicine::getCourseId,buyList); - } - long page = Long.parseLong(param.get("page").toString()); - int limit = Integer.parseInt(param.get("limit").toString()); - Page courseEntityPage; - List courseEntities; - if (list.size()>0||buyList.size()>0){ - if (StringUtils.isNotEmpty(param.get("medicalId").toString())){ - wrapper.eq(CourseToMedicine::getMedicalId,param.get("medicalId")); - } - if (StringUtils.isNotEmpty(param.get("title").toString())){ - wrapper.like(CourseEntity::getTitle,param.get("title")); - } - wrapper.distinct(); - wrapper.selectAll(CourseEntity.class); - wrapper.orderByAsc(CourseEntity::getSort); - courseEntityPage = this.getBaseMapper().selectJoinPage(new Page<>(page, limit), CourseEntity.class, wrapper); - courseEntities = courseEntityPage.getRecords(); }else { - courseEntityPage = new Page<>(page, limit); - courseEntities = new ArrayList<>(); - } - if(courseEntities.size() sociologyParam = new HashMap<>(param); - if (list.size()==0&&buyList.size()==0){ - //无医学课程,直接查国学分页 + if (list.size()>0){ + wrapper.in(CourseToMedicine::getMedicalId,list); + }else if (buyList.size()>0){ + wrapper.in(CourseToMedicine::getCourseId,buyList); }else { - sociologyParam.put("page", 1); - sociologyParam.put("limit", limit - courseEntities.size()); - sociologyParam.put("excludeIds", courseEntities.stream().map(CourseEntity::getId).collect(Collectors.toList())); + return new Page<>(); } - courseEntities.addAll(getUserSociologyCourse(sociologyParam)); - courseEntityPage.setRecords(courseEntities); } + if (StringUtils.isNotEmpty(param.get("medicalId").toString())){ + wrapper.eq(CourseToMedicine::getMedicalId,param.get("medicalId")); + } + if (StringUtils.isNotEmpty(param.get("title").toString())){ + wrapper.like(CourseEntity::getTitle,param.get("title")); + } + wrapper.distinct(); + wrapper.selectAll(CourseEntity.class); + wrapper.orderByAsc(CourseEntity::getSort); + Page courseEntityPage = this.getBaseMapper().selectJoinPage(new Page<>(Long.parseLong(param.get("page").toString()), Long.parseLong(param.get("limit").toString())), CourseEntity.class, wrapper); + List courseEntities = courseEntityPage.getRecords(); + System.out.println(courseEntities); + + MPJLambdaWrapper wrapper2 = new MPJLambdaWrapper<>(); + wrapper2.rightJoin(CourseToSociologyEntity.class,CourseToSociologyEntity::getCourseId,CourseEntity::getId); + //开通的会员下的课程 + List list2 = new ArrayList<>();//通过顶级标签获取最下层标签 +// if (userVipService.isMedicalVip(ShiroUtils.getUId())){ +// userVipService.bottomLabel(1,list); +// } +// if (userVipService.isChineseWesternVip(ShiroUtils.getUId())){ +// userVipService.bottomLabel(74,list); +// } +// if (userVipService.isAcupunctureVip(ShiroUtils.getUId())){ +// userVipService.bottomLabel(2,list); +// } +// if (userVipService.istumorVip(ShiroUtils.getUId())){ +// userVipService.bottomLabel(5,list); +// } +// if (userVipService.isPsycheVip(ShiroUtils.getUId())){ +// userVipService.bottomLabel(4,list); +// } + System.out.println("==============9999"+buyList.size()); + System.out.println(buyList); + if (list2.size()>0&&buyList.size()>0){ + wrapper2.and(t->t.in(CourseToSociologyEntity::getSociologyId,list2).or().in(CourseToSociologyEntity::getCourseId,buyList)); + }else { + if (list2.size()>0){ + wrapper2.in(CourseToSociologyEntity::getSociologyId,list2); + }else if (buyList.size()>0){ + wrapper2.in(CourseToSociologyEntity::getCourseId,buyList); + }else { + return new Page<>(); + } + } + if (StringUtils.isNotEmpty(param.get("medicalId").toString())){ + wrapper2.eq(CourseToSociologyEntity::getSociologyId,param.get("medicalId")); + } + if (StringUtils.isNotEmpty(param.get("title").toString())){ + wrapper2.like(CourseEntity::getTitle,param.get("title")); + } + wrapper2.distinct(); + wrapper2.selectAll(CourseEntity.class); + wrapper2.orderByAsc(CourseEntity::getSort); + Page courseEntityPage2 = this.getBaseMapper().selectJoinPage(new Page<>(Long.parseLong(param.get("page").toString()), Long.parseLong(param.get("limit").toString())), CourseEntity.class, wrapper2); + List courseEntities2 = courseEntityPage2.getRecords(); + if(courseEntities.size()>0){ + courseEntities.addAll(courseEntities2); + }else{ + courseEntities = courseEntities2; + } + for (CourseEntity co:courseEntities){ int i = studyingDao.selectCount(new LambdaQueryWrapper() .eq(UserCourseStudying::getCourseId,co.getId()) @@ -262,49 +296,7 @@ public class CourseServiceImpl extends ServiceImpl impl } return courseEntityPage; } - public List getUserSociologyCourse(Map param){ - log.info("=======getUserSociologyCourse===in====",param); - MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); - wrapper.rightJoin(CourseToSociologyEntity.class,CourseToSociologyEntity::getCourseId,CourseEntity::getId); - //开通的会员下的课程 - List list = new ArrayList<>();//通过顶级标签获取最下层标签 - if (userVipService.isSociologyVip(ShiroUtils.getUId())){ - userVipService.bottomLabel(7,list); - } - //购买的课程 - List buyList = userCourseBuyDao.selectList(new LambdaQueryWrapper() - .eq(UserCourseBuyEntity::getUserId,ShiroUtils.getUId())) - .stream().map(UserCourseBuyEntity::getCourseId).collect(Collectors.toList()); - if (list.size()>0&&buyList.size()>0){ - wrapper.and(t->t.in(CourseToSociologyEntity::getSociologyId,list).or().in(CourseToSociologyEntity::getCourseId,buyList)); - }else { - if (list.size()>0){ - wrapper.in(CourseToSociologyEntity::getSociologyId,list); - }else if (buyList.size()>0){ - wrapper.in(CourseToSociologyEntity::getCourseId,buyList); - }else { - return new ArrayList<>(); - } - } - if (StringUtils.isNotEmpty(param.get("medicalId").toString())){ - wrapper.eq(CourseToSociologyEntity::getSociologyId,param.get("medicalId")); - } - if (StringUtils.isNotEmpty(param.get("title").toString())){ - wrapper.like(CourseEntity::getTitle,param.get("title")); - } - if (param.get("excludeIds") != null){ - List excludeIds = (List) param.get("excludeIds"); - if (excludeIds.size()>0){ - wrapper.notIn(CourseEntity::getId,excludeIds); - } - } - wrapper.distinct(); - wrapper.selectAll(CourseEntity.class); - wrapper.orderByAsc(CourseEntity::getSort); - Page courseEntityPage = this.getBaseMapper().selectJoinPage(new Page<>(Long.parseLong(param.get("page").toString()), Long.parseLong(param.get("limit").toString())), CourseEntity.class, wrapper); - return courseEntityPage.getRecords(); - } @Override public List getCourseExpire(Map param) { MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>();