From c8ea2d96f5b0522a09f3203ae98fe796084d2d15 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期六, 04 一月 2025 09:34:21 +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 |   91 ++++++++++++++++++++++++---------------------
 1 files changed, 49 insertions(+), 42 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 4a11ead..d647b1d 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
@@ -1,15 +1,20 @@
 package com.ruoyi.other.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 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.constant.TokenConstants;
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.utils.ServletUtils;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.utils.bean.BeanUtils;
+import com.ruoyi.common.core.web.page.PageInfo;
 import com.ruoyi.common.security.service.TokenService;
+import com.ruoyi.common.security.utils.SecurityUtils;
 import com.ruoyi.order.feignClient.RemoteOrderGoodsClient;
 import com.ruoyi.order.vo.Price;
 import com.ruoyi.other.api.domain.*;
@@ -28,10 +33,7 @@
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -71,29 +73,26 @@
     private RemoteOrderGoodsClient remoteOrderGoodsClient;
 
     @Override
-    public List<GoodsVO> goodsList(Goods search) {
-        List<Goods> goodsList = this.list(new LambdaQueryWrapper<Goods>()
-                .eq(Goods::getStatus, GoodsStatus.UP.getCode())
-                .eq(Goods::getDelFlag, 0)
-                .eq(Objects.nonNull(search.getGoodsCategoryId()), Goods::getGoodsCategoryId, search.getGoodsCategoryId())
-                .like(StringUtils.isNotEmpty(search.getName()), Goods::getName, search.getName()));
-
-        List<GoodsVO> result = new ArrayList<>();
-        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
-        for (Goods goods : goodsList) {
-            GoodsVO goodsVO = new GoodsVO();
-            BeanUtils.copyBeanProp(goodsVO, goods);
-            goodsVO.setGoodsId(goods.getId());
-            goodsVO.setGoodsName(goods.getName());
-            R<Price> r = remoteOrderGoodsClient.getGoodsPrice(loginUserApplet.getUserid(), goods.getId(), null);
-            if (null != r.getData()){
-                Price price = r.getData();
-                goodsVO.setSellingPrice(price.getCash());
-                goodsVO.setIntegral(price.getPoint());
-            }
-            result.add(goodsVO);
+    public PageInfo<GoodsVO> goodsList(Goods search) {
+        PageInfo<GoodsVO> pageInfo = new PageInfo(search.getPageCurr(), search.getPageSize());
+        List<GoodsVO> list = this.baseMapper.goodsList(pageInfo, search.getGoodsCategoryId(), search.getName());
+        Long userId = null;
+        String token = SecurityUtils.getToken(ServletUtils.getRequest());
+        if(StringUtils.isNotEmpty(token)){
+            userId = tokenService.getLoginUserApplet().getUserid();
         }
-        return result;
+        for (GoodsVO goods : list) {
+            //游客展示基础售价
+            if(null != userId){
+                R<Price> r = remoteOrderGoodsClient.getGoodsPrice(userId, goods.getGoodsId(), null);
+                if (null != r.getData()){
+                    Price price = r.getData();
+                    goods.setSellingPrice(price.getCash());
+                    goods.setIntegral(price.getPoint());
+                }
+            }
+        }
+        return pageInfo.setRecords(list);
     }
 
     @Override
@@ -136,29 +135,35 @@
         goodsVO.setSellingPrice(sellingPrice);
         goodsVO.setIntegral(integral);
 
-        if(goods.getAppointStore() == 2){
+        if(goods.getType() == 1){
+            if(goods.getAppointStore() == 2){
+                List<Shop> shopList = shopMapper.selectList(new LambdaQueryWrapper<Shop>()
+                        .in(Shop::getDelFlag, 0));
+                goodsVO.setShopList(shopList);
+            }else{
+                List<GoodsShop> goodsShopList = goodsShopMapper.selectList(new LambdaQueryWrapper<GoodsShop>()
+                        .eq(GoodsShop::getGoodsId, goodsId));
+                if (!CollectionUtils.isEmpty(goodsShopList)){
+                    List<Integer> shopIds = goodsShopList.stream().map(GoodsShop::getShopId).collect(Collectors.toList());
+                    List<Shop> shopList = shopMapper.selectList(new LambdaQueryWrapper<Shop>()
+                            .in(Shop::getId, shopIds));
+                    goodsVO.setShopList(shopList);
+                }
+            }
+        }else{
             List<Shop> shopList = shopMapper.selectList(new LambdaQueryWrapper<Shop>()
                     .in(Shop::getDelFlag, 0));
             goodsVO.setShopList(shopList);
-        }else{
-            List<GoodsShop> goodsShopList = goodsShopMapper.selectList(new LambdaQueryWrapper<GoodsShop>()
-                    .eq(GoodsShop::getGoodsId, goodsId));
-            if (!CollectionUtils.isEmpty(goodsShopList)){
-                List<Integer> shopIds = goodsShopList.stream().map(GoodsShop::getShopId).collect(Collectors.toList());
-                List<Shop> shopList = shopMapper.selectList(new LambdaQueryWrapper<Shop>()
-                        .in(Shop::getId, shopIds));
-                goodsVO.setShopList(shopList);
-            }
         }
         return goodsVO;
     }
 
 
     @Override
-    public List<Goods> getGoodsListByShopId(Integer shopId) {
+    public List<Goods> getGoodsListByShopId(PageInfo<Goods> pageInfo, Integer shopId) {
         LoginUser loginUserApplet = tokenService.getLoginUserApplet();
         VipSetting vipSetting = vipSettingService.getVipSettingByUserId(loginUserApplet.getUserid());
-        return goodsMapper.selectListByShopId(shopId, vipSetting.getId());
+        return goodsMapper.selectListByShopId(pageInfo, shopId, vipSetting.getId());
     }
 
     @Override
@@ -288,10 +293,12 @@
 
         for (GoodsShop goodsShop : goodsShops) {
             Shop shop = shopMapper.selectById(goodsShop.getShopId());
-            goodsShop.setShopName(shop.getName());
-            goodsShop.setOwnerName(shop.getShopManager());
-            goodsShop.setPhone(shop.getPhone());
-            goodsShop.setAddress(shop.getAddress());
+            if(null != shop){
+                goodsShop.setShopName(shop.getName());
+                goodsShop.setOwnerName(shop.getShopManager());
+                goodsShop.setPhone(shop.getPhone());
+                goodsShop.setAddress(shop.getAddress());
+            }
         }
         goods.setGoodsShopList(goodsShops);
 

--
Gitblit v1.7.1