From eb5d7885fa9e4bd20c0827eec9b4cdd48c47b509 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期二, 07 一月 2025 09:11:20 +0800 Subject: [PATCH] 修改bug --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java | 215 +++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 175 insertions(+), 40 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 d647b1d..387c300 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,6 +2,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -18,6 +19,8 @@ import com.ruoyi.order.feignClient.RemoteOrderGoodsClient; import com.ruoyi.order.vo.Price; import com.ruoyi.other.api.domain.*; +import com.ruoyi.other.api.vo.GetGoodsBargainPrice; +import com.ruoyi.other.api.vo.GetSeckillActivityInfo; import com.ruoyi.other.enums.GoodsStatus; import com.ruoyi.other.mapper.GoodsAreaMapper; import com.ruoyi.other.mapper.GoodsMapper; @@ -71,25 +74,39 @@ private GoodsAreaService goodsAreaService; @Resource private RemoteOrderGoodsClient remoteOrderGoodsClient; + @Resource + private SeckillActivityInfoService seckillActivityInfoService; + @Resource + private GoodsSeckillService goodsSeckillService; + @Resource + private GoodsBargainPriceService goodsBargainPriceService; + @Resource + private GoodsBargainPriceDetailService goodsBargainPriceDetailService; + + @Override 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; + Integer vipId = 0; + String provinceCode = null; + String cityCode = null; + String districtCode = null; String token = SecurityUtils.getToken(ServletUtils.getRequest()); if(StringUtils.isNotEmpty(token)){ - userId = tokenService.getLoginUserApplet().getUserid(); + Long userid = tokenService.getLoginUserApplet().getUserid(); + AppUser appUser = appUserClient.getAppUserById(userid); + vipId = appUser.getVipId(); + provinceCode = appUser.getProvinceCode(); + cityCode = appUser.getCityCode(); + districtCode = appUser.getDistrictCode(); } + List<GoodsVO> list = this.baseMapper.goodsList(pageInfo, search.getGoodsCategoryId(), search.getName(), vipId); 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()); - } + Price price = getPrice(vipId, goods.getGoodsId(), 1, null, provinceCode, cityCode, districtCode); + if(null != price){ + goods.setSellingPrice(price.getCash()); + goods.setIntegral(price.getPoint()); } } return pageInfo.setRecords(list); @@ -101,30 +118,18 @@ throw new NullPointerException("商品ID不能为空"); } - LoginUser loginUserApplet = tokenService.getLoginUserApplet(); - AppUser appUser = appUserClient.getAppUserById(loginUserApplet.getUserid()); - BigDecimal sellingPrice = BigDecimal.ZERO; - Integer integral = 0; - - GoodsArea goodsArea = goodsAreaMapper.selectOne(new LambdaQueryWrapper<GoodsArea>() - .eq(GoodsArea::getGoodsId, goodsId) - .eq(GoodsArea::getVip, appUser.getVipId()) - .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)); - if(null != goodsVip){ - sellingPrice = goodsVip.getSellingPrice(); - integral = goodsVip.getIntegral(); - } + Integer vipId = 0; + String provinceCode = null; + String cityCode = null; + String districtCode = null; + String token = SecurityUtils.getToken(ServletUtils.getRequest()); + if(StringUtils.isNotEmpty(token)){ + Long userid = tokenService.getLoginUserApplet().getUserid(); + AppUser appUser = appUserClient.getAppUserById(userid); + vipId = appUser.getVipId(); + provinceCode = appUser.getProvinceCode(); + cityCode = appUser.getCityCode(); + districtCode = appUser.getDistrictCode(); } Goods goods = this.getById(goodsId); @@ -132,8 +137,11 @@ BeanUtils.copyBeanProp(goodsVO, goods); goodsVO.setGoodsId(goods.getId()); goodsVO.setGoodsName(goods.getName()); - goodsVO.setSellingPrice(sellingPrice); - goodsVO.setIntegral(integral); + Price price = getPrice(vipId, goods.getId(), 1, null, provinceCode, cityCode, districtCode); + if(null != price){ + goodsVO.setSellingPrice(price.getCash()); + goodsVO.setIntegral(price.getPoint()); + } if(goods.getType() == 1){ if(goods.getAppointStore() == 2){ @@ -161,9 +169,28 @@ @Override public List<Goods> getGoodsListByShopId(PageInfo<Goods> pageInfo, Integer shopId) { - LoginUser loginUserApplet = tokenService.getLoginUserApplet(); - VipSetting vipSetting = vipSettingService.getVipSettingByUserId(loginUserApplet.getUserid()); - return goodsMapper.selectListByShopId(pageInfo, shopId, vipSetting.getId()); + Integer vipId = 0; + String provinceCode = null; + String cityCode = null; + String districtCode = null; + String token = SecurityUtils.getToken(ServletUtils.getRequest()); + if(StringUtils.isNotEmpty(token)){ + Long userid = tokenService.getLoginUserApplet().getUserid(); + AppUser appUser = appUserClient.getAppUserById(userid); + vipId = appUser.getVipId(); + provinceCode = appUser.getProvinceCode(); + cityCode = appUser.getCityCode(); + districtCode = appUser.getDistrictCode(); + } + List<Goods> goods = goodsMapper.selectListByShopId(pageInfo, shopId, vipId); + for (Goods good : goods) { + Price price = getPrice(vipId, good.getId(), 1, shopId, provinceCode, cityCode, districtCode); + if(null != price){ + good.setSellingPrice(price.getCash()); + good.setIntegral(price.getPoint()); + } + } + return goods; } @Override @@ -376,4 +403,112 @@ goodsArea1.setGoodsAreaList(goodsAreas); return goodsArea1; } + + + /** + * 根据商品的价格配置体系获取商品当前的价格 + * @param vip + * @param goodsId + * @param type 1普通商品,2秒杀商品 + * @param shopId + * @param provinceCode + * @param cityCode + * @param districtCode + * @return + */ + public Price getPrice(Integer vip, Integer goodsId, Integer shopId, Integer type, String provinceCode, String cityCode, String districtCode){ + //获取支付价格 + //秒杀活动>门店特价>地区价格>会员价格 + //判断是否有秒杀活动 + Price price = new Price(); + SeckillActivityInfo one = seckillActivityInfoService.getOne(new LambdaQueryWrapper<SeckillActivityInfo>().eq(SeckillActivityInfo::getGoodId, goodsId) + .eq(SeckillActivityInfo::getIsShelves, 1).eq(SeckillActivityInfo::getDelFlag, 0) + .last(" and now() between start_time and end_time and FIND_IN_SET(" + vip + ", vip_ids) order by create_time desc limit 0, 1")); + GoodsSeckill goodsSeckill = null; + if(null != one){ + goodsSeckill = goodsSeckillService.getOne(new LambdaQueryWrapper<GoodsSeckill>().eq(GoodsSeckill::getSeckillActivityInfoId, one.getId()).eq(GoodsSeckill::getVip, vip)); + } + //没有秒杀活动或者添加的普通商品则不使用秒杀活动价格 + if(null == goodsSeckill || type == 1){ + //没有秒杀价,则判断门店特价 + GoodsBargainPriceDetail bargainPriceDetail = null; + if (shopId != null){ + GoodsBargainPrice priceServiceOne = goodsBargainPriceService.getOne(new LambdaQueryWrapper<GoodsBargainPrice>().eq(GoodsBargainPrice::getGoodsId, goodsId).eq(GoodsBargainPrice::getShopId, shopId) + .eq(GoodsBargainPrice::getDelFlag, 0).eq(GoodsBargainPrice::getAuditStatus, 1).last(" order by create_time desc limit 0, 1")); + if(null != priceServiceOne){ + bargainPriceDetail = goodsBargainPriceDetailService.getOne(new LambdaQueryWrapper<GoodsBargainPriceDetail>().eq(GoodsBargainPriceDetail::getGoodsBargainPriceId, priceServiceOne.getId()).eq(GoodsBargainPriceDetail::getVip, vip)); + } + } + if(null == bargainPriceDetail){ + //没有门店特价,判断地区价格配置 + LambdaQueryWrapper<GoodsArea> queryWrapper = new LambdaQueryWrapper<GoodsArea>().eq(GoodsArea::getGoodsId, goodsId).eq(GoodsArea::getVip, vip); + if(StringUtils.isNotEmpty(districtCode)){ + queryWrapper.eq(GoodsArea::getDistrictsCode, districtCode); + } + if(StringUtils.isNotEmpty(cityCode)){ + queryWrapper.eq(GoodsArea::getCityCode, cityCode); + } + if(StringUtils.isNotEmpty(provinceCode)){ + queryWrapper.eq(GoodsArea::getProvinceCode, provinceCode); + } + GoodsArea goodsArea = goodsAreaService.getOne(queryWrapper); + if(null == goodsArea){ + //没有地区价格,则使用会员价格 + GoodsVip goodsVip = goodsVipService.getOne(new LambdaQueryWrapper<GoodsVip>().eq(GoodsVip::getGoodsId, goodsId).eq(GoodsVip::getVip, vip)); + if(null == goodsVip){ + //没有配置价格,直接使用原始基础价格 + return null; + }else{ + //构建价格数据 + if(goodsVip.getCashPayment() == 1 && goodsVip.getPointPayment() == 1){ + price.setCash(goodsVip.getSellingPrice()); + price.setPoint(goodsVip.getIntegral()); + } + if(goodsVip.getCashPayment() == 1 && goodsVip.getPointPayment() == 0){ + price.setCash(goodsVip.getSellingPrice()); + } + if(goodsVip.getCashPayment() == 0 && goodsVip.getPointPayment() == 1){ + price.setPoint(goodsVip.getIntegral()); + } + price.setCashPayment(goodsVip.getCashPayment() == 1); + price.setPointPayment(goodsVip.getPointPayment() == 1); + } + }else{ + //构建价格数据 + if(goodsArea.getCashPayment() == 1 && goodsArea.getPointPayment() == 1){ + price.setCash(goodsArea.getSellingPrice()); + price.setPoint(goodsArea.getIntegral()); + } + if(goodsArea.getCashPayment() == 1 && goodsArea.getPointPayment() == 0){ + price.setCash(goodsArea.getSellingPrice()); + } + if(goodsArea.getCashPayment() == 0 && goodsArea.getPointPayment() == 1){ + price.setPoint(goodsArea.getIntegral()); + } + price.setCashPayment(goodsArea.getCashPayment() == 1); + price.setPointPayment(goodsArea.getPointPayment() == 1); + } + }else{ + price.setCash(bargainPriceDetail.getSellingPrice()); + price.setPoint(bargainPriceDetail.getIntegral()); + price.setCashPayment(bargainPriceDetail.getSellingPrice() != null); + price.setPointPayment(bargainPriceDetail.getIntegral() != null); + } + }else{ + //构建价格数据 + if(goodsSeckill.getCashPayment() == 1 && goodsSeckill.getPointPayment() == 1){ + price.setCash(goodsSeckill.getSellingPrice()); + price.setPoint(goodsSeckill.getIntegral()); + } + if(goodsSeckill.getCashPayment() == 1 && goodsSeckill.getPointPayment() == 0){ + price.setCash(goodsSeckill.getSellingPrice()); + } + if(goodsSeckill.getCashPayment() == 0 && goodsSeckill.getPointPayment() == 1){ + price.setPoint(goodsSeckill.getIntegral()); + } + price.setCashPayment(goodsSeckill.getCashPayment() == 1); + price.setPointPayment(goodsSeckill.getPointPayment() == 1); + } + return price; + } } -- Gitblit v1.7.1