huliguo
2025-04-11 f103ac7bc4f2fbb20a0f2dd3ed97b0ac7fc5f46d
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java
@@ -18,6 +18,7 @@
import com.ruoyi.order.feignClient.RemoteOrderGoodsClient;
import com.ruoyi.order.vo.Price;
import com.ruoyi.other.api.domain.*;
import com.ruoyi.other.dto.AddGoodsDTO;
import com.ruoyi.other.enums.GoodsStatus;
import com.ruoyi.other.mapper.GoodsMapper;
import com.ruoyi.other.mapper.GoodsShopMapper;
@@ -28,12 +29,15 @@
import com.ruoyi.other.vo.NearbyShopVO;
import com.ruoyi.system.api.domain.SysConfig;
import com.ruoyi.system.api.feignClient.SysConfigClient;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
@@ -89,16 +93,23 @@
        }
        //查找满足条件的商品  分类、名称、附近十家店
        List<GoodsVO> list = this.baseMapper.goodsList(search.getGoodsCategoryId(), search.getName(),shopIds);
        //去重
        Map<Integer, GoodsVO> uniqueGoodsMap = new LinkedHashMap<>();
        for (GoodsVO goods : list) {
            uniqueGoodsMap.putIfAbsent(goods.getGoodsId(), goods);
        }
        list = new ArrayList<>(uniqueGoodsMap.values());
        for (GoodsVO goods : list) {
            //计算所需价格和积分
            Price price = getPrice( goods.getGoodsId(), 1);
            Price price = getPrice( goods.getGoodsId());
            if(null != price){
                //秒杀活动
                goods.setSellingPrice(price.getCash());
                goods.setIntegral(price.getPoint());
                goods.setStartTime(price.getStartTime());
                goods.setEndTime(price.getEndTime());
                goods.setPurchaseLimit(price.getPurchaseLimit());
            }
            //已售数量
            Integer data = orderClient.getGoodsSaleNum(goods.getGoodsId(), 1).getData();
@@ -198,13 +209,14 @@
        goodsVO.setGoodsName(goods.getName());
        //计算所需价格和积分
        Price price = getPrice( goods.getId(), 1);
        Price price = getPrice( goods.getId());
        if(null != price){
            //秒杀活动
            goodsVO.setSellingPrice(price.getCash());
            goodsVO.setIntegral(price.getPoint());
            goodsVO.setStartTime(price.getStartTime());
            goodsVO.setEndTime(price.getEndTime());
            goodsVO.setPurchaseLimit(price.getPurchaseLimit());
        }
        //已售数量
        Integer data = orderClient.getGoodsSaleNum(goods.getId(), 1).getData();
@@ -231,11 +243,12 @@
        List<GoodsVO> goods = goodsMapper.selectListByShopId(pageInfo, shopId);
        for (GoodsVO good : goods) {
            //价格
            Price price = getPrice( good.getGoodsId(), 1);
            Price price = getPrice( good.getGoodsId());
            if(null != price){
                //秒杀活动
                good.setSellingPrice(price.getCash());
                good.setIntegral(price.getPoint());
                good.setPurchaseLimit(price.getPurchaseLimit());
                good.setStartTime(price.getStartTime());
                good.setEndTime(price.getEndTime());
            }
@@ -258,7 +271,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addGoods(Goods goods) {
       /* goods.setSaleNum(0);
      /*  goods.setSaleNum(0);
        goods.setStatus(GoodsStatus.DOWN.getCode());
        goodsMapper.insert(goods);
@@ -328,13 +341,11 @@
    /**
     * 根据商品的价格配置体系获取商品当前的价格
     * @param goodsId
     * @param type          1普通商品,2秒杀商品
     * @return
     * 获取商品当前的价格,就是判断是否在秒杀活动中
     */
    public Price getPrice( Integer goodsId, Integer type){
    public Price getPrice( Integer goodsId ){
        //判断是否有在秒杀活动时间中
        Price price = new Price();
        SeckillActivityInfo one = seckillActivityInfoService.getOne(new LambdaQueryWrapper<SeckillActivityInfo>().eq(SeckillActivityInfo::getGoodId, goodsId)
@@ -346,7 +357,7 @@
            goodsSeckill = goodsSeckillService.getOne(new LambdaQueryWrapper<GoodsSeckill>().eq(GoodsSeckill::getSeckillActivityInfoId, one.getId()));
        }
        //没有秒杀活动或者添加的普通商品则使用秒杀活动价格
        if(null == goodsSeckill || type == 1){
        if(null == goodsSeckill ){
           return null;
        }
        //秒杀活动价格
@@ -355,6 +366,7 @@
        price.setPoint(getPoint(price.getCash()));
        price.setStartTime(one.getStartTime());
        price.setEndTime(one.getEndTime());
        price.setPurchaseLimit(one.getMaxNum());
        return price;
    }