From 609d91e1e62b1e8932b34b15b09baf02e7f09a93 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期一, 09 十二月 2024 10:36:47 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/qijisheng

---
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java |   88 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 77 insertions(+), 11 deletions(-)

diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java
index b1de54c..a299b54 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java
@@ -2,19 +2,30 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.account.api.feignClient.AppUserClient;
+import com.ruoyi.account.api.model.AppUser;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.utils.bean.BeanUtils;
-import com.ruoyi.other.api.domain.Goods;
+import com.ruoyi.common.security.service.TokenService;
+import com.ruoyi.other.api.domain.*;
 import com.ruoyi.other.enums.GoodsStatus;
+import com.ruoyi.other.mapper.GoodsAreaMapper;
 import com.ruoyi.other.mapper.GoodsMapper;
+import com.ruoyi.other.mapper.GoodsShopMapper;
+import com.ruoyi.other.mapper.ShopMapper;
 import com.ruoyi.other.service.GoodsService;
+import com.ruoyi.other.service.GoodsVipService;
+import com.ruoyi.other.service.VipSettingService;
 import com.ruoyi.other.vo.GoodsVO;
+import com.ruoyi.system.api.model.LoginUser;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -28,18 +39,34 @@
 public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {
     @Resource
     private GoodsMapper goodsMapper;
+    @Resource
+    private TokenService tokenService;
+    @Resource
+    private VipSettingService vipSettingService;
+    @Resource
+    private GoodsAreaMapper goodsAreaMapper;
+    @Resource
+    private GoodsVipService goodsVipService;
+    @Resource
+    private AppUserClient appUserClient;
+    @Resource
+    private GoodsShopMapper goodsShopMapper;
+    @Resource
+    private ShopMapper shopMapper;
 
     @Override
     public List<GoodsVO> goodsList(Goods search) {
         List<Goods> goodsList = this.list(new LambdaQueryWrapper<Goods>()
-                .eq(Goods::getStatus, GoodsStatus.UP)
-                .eq(Objects.nonNull(search.getGoodsCategoryId()) ,Goods::getGoodsCategoryId, search.getGoodsCategoryId())
+                .eq(Goods::getStatus, GoodsStatus.UP.getCode())
+                .eq(Objects.nonNull(search.getGoodsCategoryId()), Goods::getGoodsCategoryId, search.getGoodsCategoryId())
                 .like(StringUtils.isNotEmpty(search.getName()), Goods::getName, search.getName()));
 
         List<GoodsVO> result = new ArrayList<>();
         for (Goods goods : goodsList) {
             GoodsVO goodsVO = new GoodsVO();
             BeanUtils.copyBeanProp(goodsVO, goods);
+            goodsVO.setGoodsId(goods.getId());
+            goodsVO.setGoodsName(goods.getName());
             result.add(goodsVO);
         }
         return result;
@@ -47,18 +74,57 @@
 
     @Override
     public GoodsVO goodsDetail(Long goodsId) {
-        // TODO 根据会员等级展示价格
-        Goods goods = this.getById(goodsId);
-        if (Objects.nonNull(goods)){
-            GoodsVO goodsVO = new GoodsVO();
-            BeanUtils.copyBeanProp(goodsVO, goods);
-            return goodsVO;
+        if (goodsId == null || goodsId <= 0) {
+            throw new NullPointerException("商品ID不能为空");
         }
-        return new GoodsVO();
+
+        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
+        AppUser appUser = appUserClient.getAppUserById(loginUserApplet.getUserid());
+        BigDecimal sellingPrice;
+        Integer integral;
+
+        GoodsArea goodsArea = goodsAreaMapper.selectOne(new LambdaQueryWrapper<GoodsArea>()
+                .eq(GoodsArea::getGoodsId, goodsId)
+                .eq(GoodsArea::getProvinceCode, appUser.getProvinceCode())
+                .eq(StringUtils.isNotEmpty(appUser.getCityCode()), GoodsArea::getCityCode, appUser.getCityCode())
+                .eq(StringUtils.isNotEmpty(appUser.getDistrictCode()), GoodsArea::getDistrictsCode, appUser.getDistrictCode()));
+
+        if (Objects.nonNull(goodsArea)){
+            sellingPrice = goodsArea.getSellingPrice();
+            integral = goodsArea.getIntegral();
+        }else {
+            VipSetting vipSetting = vipSettingService.getVipSettingByUserId(loginUserApplet.getUserid());
+            GoodsVip goodsVip = goodsVipService.getOne(new LambdaQueryWrapper<GoodsVip>()
+                    .eq(GoodsVip::getVip, vipSetting.getId())
+                    .eq(GoodsVip::getGoodsId, goodsId));
+
+            sellingPrice = goodsVip.getSellingPrice();
+            integral = goodsVip.getIntegral();
+        }
+
+        Goods goods = this.getById(goodsId);
+
+        List<GoodsShop> goodsShopList = goodsShopMapper.selectList(new LambdaQueryWrapper<GoodsShop>()
+                .eq(GoodsShop::getGoodsId, goodsId));
+        List<Integer> shopIds = goodsShopList.stream().map(GoodsShop::getShopId).collect(Collectors.toList());
+        List<Shop> shopList = shopMapper.selectList(new LambdaQueryWrapper<Shop>()
+                .in(Shop::getId, shopIds));
+        GoodsVO goodsVO = new GoodsVO();
+        goodsVO.setShopList(shopList);
+        BeanUtils.copyBeanProp(goodsVO, goods);
+        goodsVO.setGoodsId(goods.getId());
+        goodsVO.setGoodsName(goods.getName());
+        goodsVO.setSellingPrice(sellingPrice);
+        goodsVO.setIntegral(integral);
+        return goodsVO;
     }
+
 
     @Override
     public List<Goods> getGoodsListByShopId(Integer shopId) {
-        return goodsMapper.selectListByShopId(shopId);
+        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
+        VipSetting vipSetting = vipSettingService.getVipSettingByUserId(loginUserApplet.getUserid());
+        return goodsMapper.selectListByShopId(shopId, vipSetting.getId());
     }
+
 }

--
Gitblit v1.7.1