From 392b42c4891cf2e6beda57ab32c51598f290f4b7 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期五, 14 三月 2025 20:56:27 +0800
Subject: [PATCH] bug修改

---
 ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java |  145 +++++++++++++++++++++++++++--------------------
 1 files changed, 83 insertions(+), 62 deletions(-)

diff --git a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java
index 51e7216..0f5d0c5 100644
--- a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java
+++ b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java
@@ -8,8 +8,11 @@
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.ruoyi.common.core.constant.SecurityConstants;
-import com.ruoyi.common.core.domain.R;
-import com.ruoyi.common.core.enums.*;
+import com.ruoyi.common.core.enums.AuctionOrderTypeEnum;
+import com.ruoyi.common.core.enums.ListingStatusEnum;
+import com.ruoyi.common.core.enums.MemberVipClassifyEnum;
+import com.ruoyi.common.core.enums.OrderFromEnum;
+import com.ruoyi.common.core.enums.StartStatusEnum;
 import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.utils.page.BeanUtils;
@@ -33,7 +36,18 @@
 import com.ruoyi.goods.service.IGoodsInfoTitleValueService;
 import com.ruoyi.goods.service.IGoodsSkuService;
 import com.ruoyi.goods.service.IMemberGoodsCollectionService;
-import com.ruoyi.system.api.domain.*;
+import com.ruoyi.system.api.domain.AuctionGoods;
+import com.ruoyi.system.api.domain.AuctionSalesroom;
+import com.ruoyi.system.api.domain.AuctionSalesroomGoods;
+import com.ruoyi.system.api.domain.GoodsBrand;
+import com.ruoyi.system.api.domain.GoodsCategory;
+import com.ruoyi.system.api.domain.GoodsFlavorType;
+import com.ruoyi.system.api.domain.GoodsGroupPurchase;
+import com.ruoyi.system.api.domain.GoodsSeckill;
+import com.ruoyi.system.api.domain.GoodsSeries;
+import com.ruoyi.system.api.domain.GoodsSku;
+import com.ruoyi.system.api.domain.Member;
+import com.ruoyi.system.api.domain.Order;
 import com.ruoyi.system.api.domain.dto.GoodsStockUpdDTO;
 import com.ruoyi.system.api.domain.dto.HomeGoodsSkuDTO;
 import com.ruoyi.system.api.domain.dto.ListStatusDTO;
@@ -45,7 +59,7 @@
 import com.ruoyi.system.api.feignClient.GoodsSkuClient;
 import com.ruoyi.system.api.feignClient.MemberClient;
 import com.ruoyi.system.api.feignClient.OrderClient;
-
+import com.ruoyi.system.api.model.LoginUser;
 import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -340,56 +354,51 @@
 
     @Override
     public PageDTO<HomeGoodsSkuListVO> getHomeGoodsSkuVOList(HomeGoodsSkuDTO homeGoodsSkuDTO) {
-        Long userId = SecurityUtils.getUserId();
-        R<Member> memberR = memberClient.getMemberByUserId(userId, SecurityConstants.INNER);
-        Member member = memberR.getData();
-        Integer vipClassify = member.getVipClassify();
-
         Page<GoodsSku> page = new Page<>();
         page.setSize(homeGoodsSkuDTO.getPageSize());
         page.setCurrent(homeGoodsSkuDTO.getPageCurr());
 
-        LambdaQueryWrapper<GoodsSku> wrapper3= Wrappers.lambdaQuery();
-        wrapper3.eq(GoodsSku::getListingStatus,0);
+        LambdaQueryWrapper<GoodsSku> wrapper3 = Wrappers.lambdaQuery();
+        wrapper3.eq(GoodsSku::getListingStatus, 0);
         // if(homeGoodsSkuDTO.getId()!=null){
         //     List arr=new ArrayList<>();
         //     arr.add(homeGoodsSkuDTO.getId());
         //     wrapper3.notIn(GoodsSku::getId,arr);
         // }
-        if (homeGoodsSkuDTO.getSkuName()!=null&&homeGoodsSkuDTO.getSkuName()!=""){
-            wrapper3.like(GoodsSku::getSkuName,homeGoodsSkuDTO.getSkuName());
+        if (homeGoodsSkuDTO.getSkuName() != null && homeGoodsSkuDTO.getSkuName() != "") {
+            wrapper3.like(GoodsSku::getSkuName, homeGoodsSkuDTO.getSkuName());
         }
-        if (homeGoodsSkuDTO.getGoodsSkuId()!=null){
-            List<Long> id=new ArrayList<>();
+        if (homeGoodsSkuDTO.getGoodsSkuId() != null) {
+            List<Long> id = new ArrayList<>();
             id.add(homeGoodsSkuDTO.getGoodsSkuId());
-            wrapper3.notIn(GoodsSku::getId,id);
+            wrapper3.notIn(GoodsSku::getId, id);
         }
-        if (homeGoodsSkuDTO.getBrandId()!=null){
-            wrapper3.eq(GoodsSku::getBrandId,homeGoodsSkuDTO.getBrandId());
+        if (homeGoodsSkuDTO.getBrandId() != null) {
+            wrapper3.eq(GoodsSku::getBrandId, homeGoodsSkuDTO.getBrandId());
         }
-        if (homeGoodsSkuDTO.getCategoryId()!=null){
-            wrapper3.eq(GoodsSku::getCategoryId,homeGoodsSkuDTO.getCategoryId());
+        if (homeGoodsSkuDTO.getCategoryId() != null) {
+            wrapper3.eq(GoodsSku::getCategoryId, homeGoodsSkuDTO.getCategoryId());
         }
 
-        if (homeGoodsSkuDTO.getSeriesId()!=null){
-            wrapper3.eq(GoodsSku::getSeriesId,homeGoodsSkuDTO.getSeriesId());
+        if (homeGoodsSkuDTO.getSeriesId() != null) {
+            wrapper3.eq(GoodsSku::getSeriesId, homeGoodsSkuDTO.getSeriesId());
         }
-        if (homeGoodsSkuDTO.getFlavorTypeId()!=null){
-            wrapper3.eq(GoodsSku::getFlavorTypeId,homeGoodsSkuDTO.getFlavorTypeId());
+        if (homeGoodsSkuDTO.getFlavorTypeId() != null) {
+            wrapper3.eq(GoodsSku::getFlavorTypeId, homeGoodsSkuDTO.getFlavorTypeId());
         }
-        if (homeGoodsSkuDTO.getSort()==2){
+        if (homeGoodsSkuDTO.getSort() == 2) {
             wrapper3.orderByAsc(GoodsSku::getPrice);
         }
-        if (homeGoodsSkuDTO.getSort()==3){
+        if (homeGoodsSkuDTO.getSort() == 3) {
             wrapper3.orderByDesc(GoodsSku::getPrice);
         }
-        if (homeGoodsSkuDTO.getSort()==4){
+        if (homeGoodsSkuDTO.getSort() == 4) {
             wrapper3.orderByAsc(GoodsSku::getSoldQuantity);
         }
-        if (homeGoodsSkuDTO.getSort()==5){
+        if (homeGoodsSkuDTO.getSort() == 5) {
             wrapper3.orderByDesc(GoodsSku::getSoldQuantity);
         }
-        if(homeGoodsSkuDTO.getYear()==2){
+        if (homeGoodsSkuDTO.getYear() == 2) {
             LocalDateTime now = LocalDateTime.now();
             DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
             LocalDateTime newTime7 = now.minusYears(30);
@@ -397,7 +406,7 @@
             LocalDateTime parseTime7 = LocalDate.parse(formattedDate7).atStartOfDay();
             wrapper3.le(GoodsSku::getYears, DateUtil.format(parseTime7, "yyyy"));
         }
-        if(homeGoodsSkuDTO.getYear()==3){
+        if (homeGoodsSkuDTO.getYear() == 3) {
             LocalDateTime now = LocalDateTime.now();
             DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
             LocalDateTime newTime7 = now.minusYears(30);
@@ -406,12 +415,12 @@
 
             LocalDateTime newTime15 = now.minusYears(15);
             String formattedDate15 = newTime15.format(formatter);
-            LocalDateTime parseTime15= LocalDate.parse(formattedDate15).atStartOfDay();
+            LocalDateTime parseTime15 = LocalDate.parse(formattedDate15).atStartOfDay();
             wrapper3.le(GoodsSku::getYears, DateUtil.format(parseTime15, "yyyy"))
                     .gt(GoodsSku::getYears, DateUtil.format(parseTime7, "yyyy"));
         }
 
-        if(homeGoodsSkuDTO.getYear()==4){
+        if (homeGoodsSkuDTO.getYear() == 4) {
             LocalDateTime now = LocalDateTime.now();
             DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
             LocalDateTime newTime7 = now.minusYears(5);
@@ -420,12 +429,12 @@
 
             LocalDateTime newTime15 = now.minusYears(15);
             String formattedDate15 = newTime15.format(formatter);
-            LocalDateTime parseTime15= LocalDate.parse(formattedDate15).atStartOfDay();
+            LocalDateTime parseTime15 = LocalDate.parse(formattedDate15).atStartOfDay();
             wrapper3.le(GoodsSku::getYears, DateUtil.format(parseTime7, "yyyy"))
                     .gt(GoodsSku::getYears, DateUtil.format(parseTime15, "yyyy"));
         }
 
-        if(homeGoodsSkuDTO.getYear()==5){
+        if (homeGoodsSkuDTO.getYear() == 5) {
             LocalDateTime now = LocalDateTime.now();
             DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
             LocalDateTime newTime7 = now.minusYears(1);
@@ -433,21 +442,31 @@
             LocalDateTime parseTime7 = LocalDate.parse(formattedDate7).atStartOfDay();
             LocalDateTime newTime15 = now.minusYears(5);
             String formattedDate15 = newTime15.format(formatter);
-            LocalDateTime parseTime15= LocalDate.parse(formattedDate15).atStartOfDay();
+            LocalDateTime parseTime15 = LocalDate.parse(formattedDate15).atStartOfDay();
             wrapper3.le(GoodsSku::getYears, DateUtil.format(parseTime7, "yyyy"))
                     .ge(GoodsSku::getYears, DateUtil.format(parseTime15, "yyyy"));
         }
-        if (homeGoodsSkuDTO.getSort()==1){
+        if (homeGoodsSkuDTO.getSort() == 1) {
             wrapper3.last(" ORDER BY IF(isnull(sort_num),1,0), sort_num ASC,create_time DESC");
-        }else{
-            wrapper3.last(",IF(isnull(sort_num),1,0), sort_num DESC,create_time DESC" );
+        } else {
+            wrapper3.last(",IF(isnull(sort_num),1,0), sort_num DESC,create_time DESC");
         }
 
         Page<GoodsSku> page1 = this.page(page, wrapper3);
-        for (GoodsSku record : page1.getRecords()) {
-            // 获取会员价格
-            BigDecimal vipPrice = getVipPrice(record.getId());
-            record.setPrice(vipPrice);
+
+        if (SecurityUtils.isLogin()) {
+            LoginUser loginUser = SecurityUtils.getLoginUser();
+            Member member = memberClient.getMemberByUserId(loginUser.getUserid(),
+                    SecurityConstants.INNER).getData();
+            // 用户已登录 有会员等级 会员等级不为普通用户 则获取会员价格
+            if (Objects.nonNull(member.getVipClassify())
+                    && !member.getVipClassify().equals(MemberVipClassifyEnum.NORMAL.getCode())) {
+                for (GoodsSku record : page1.getRecords()) {
+                    // 获取会员价格
+                    BigDecimal vipPrice = getVipPrice(record.getId(), member.getVipClassify());
+                    record.setPrice(vipPrice);
+                }
+            }
         }
         return PageDTO.of(page1, HomeGoodsSkuListVO.class);
 
@@ -456,6 +475,9 @@
     @Override
     public HomeGoodsSkuInfoVO getHomeGoodsSkuInfo(HomeGoodsSkuDTO homeGoodsSkuDTO) {
         GoodsSku byId = this.getById(homeGoodsSkuDTO.getGoodsSkuId());
+        if (Objects.isNull(byId)) {
+            throw new ServiceException("当前商品已下架");
+        }
         HomeGoodsSkuInfoVO homeGoodsSkuInfoVO=new HomeGoodsSkuInfoVO();
         homeGoodsSkuInfoVO.setSkuName(byId.getSkuName());
         homeGoodsSkuInfoVO.setYears(String.valueOf(byId.getYears().getYear()));
@@ -484,7 +506,7 @@
         homeGoodsSkuInfoVO.setDescription(byId.getDescription());
         homeGoodsSkuInfoVO.setStock(byId.getStock());
         homeGoodsSkuInfoVO.setDetail(byId.getDetail());
-
+        homeGoodsSkuInfoVO.setPrice(byId.getPrice());
         if (StringUtils.isBlank(byId.getShareTitle())) {
             homeGoodsSkuInfoVO.setShareTitle(byId.getSkuName());
         } else {
@@ -520,8 +542,16 @@
             homeGoodsSkuInfoVO.setIsGoodsGroupPurchase(1);
         }
         // 获取会员价格
-        BigDecimal vipPrice = getVipPrice(byId.getId());
-        homeGoodsSkuInfoVO.setPrice(vipPrice);
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        Member member = memberClient.getMemberByUserId(loginUser.getUserid(),
+                SecurityConstants.INNER).getData();
+        // 用户已登录 有会员等级 会员等级不为普通用户 则获取会员价格
+        if (SecurityUtils.isLogin() && Objects.nonNull(member.getVipClassify())
+                && !member.getVipClassify().equals(MemberVipClassifyEnum.NORMAL.getCode())) {
+            // 获取会员价格
+            BigDecimal vipPrice = getVipPrice(byId.getId(), member.getVipClassify());
+            homeGoodsSkuInfoVO.setPrice(vipPrice);
+        }
 
         LambdaQueryWrapper<MemberGoodsCollection> wrapper3= Wrappers.lambdaQuery();
         wrapper3.eq(MemberGoodsCollection::getDelFlag,0);
@@ -566,24 +596,15 @@
         return homeGoodsSkuInfoVO;
     }
 
-    private BigDecimal getVipPrice(Long goodsSkuId){
-
-        if (SecurityUtils.isLogin()) {
-            Long userId = SecurityUtils.getUserId();
-            GoodsSku byId = getById(goodsSkuId);
-            Member member = memberClient.getMemberByUserId(userId, SecurityConstants.INNER).getData();
-            Integer vipClassify = member.getVipClassify();
-            if (MemberVipClassifyEnum.NORMAL.getCode().equals(vipClassify)) {
-                return byId.getPrice();
-            }else if (MemberVipClassifyEnum.VIP.getCode().equals(vipClassify)){
-                return byId.getVipPrice();
-            }else if (MemberVipClassifyEnum.SUPER_VIP.getCode().equals(vipClassify)){
-                return byId.getSuperVipPrice();
-            }
-        }else {
-            return getById(goodsSkuId).getPrice();
+    private BigDecimal getVipPrice(Long goodsSkuId, Integer vipClassify) {
+        GoodsSku byId = getById(goodsSkuId);
+        BigDecimal price = BigDecimal.ZERO;
+        if (MemberVipClassifyEnum.VIP.getCode().equals(vipClassify)) {
+            price = byId.getVipPrice();
+        } else if (MemberVipClassifyEnum.SUPER_VIP.getCode().equals(vipClassify)) {
+            price = byId.getSuperVipPrice();
         }
-        throw new ServiceException("会员等级错误");
+        return price;
     }
 
     @Override

--
Gitblit v1.7.1