luodangjia
2024-11-28 36ce1f3549df46609b4e3bc0bf0810bd0c85277e
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java
@@ -3,10 +3,14 @@
import cn.hutool.json.JSONArray;
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.common.security.service.TokenService;
import com.ruoyi.other.api.domain.Goods;
import com.ruoyi.other.api.domain.GoodsArea;
import com.ruoyi.other.api.domain.GoodsVip;
import com.ruoyi.other.api.domain.VipSetting;
import com.ruoyi.other.enums.GoodsStatus;
import com.ruoyi.other.mapper.GoodsAreaMapper;
@@ -19,6 +23,7 @@
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;
@@ -43,12 +48,14 @@
    private GoodsAreaMapper goodsAreaMapper;
    @Resource
    private GoodsVipService goodsVipService;
    @Resource
    private AppUserClient appUserClient;
    @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(Objects.nonNull(search.getGoodsCategoryId()), Goods::getGoodsCategoryId, search.getGoodsCategoryId())
                .like(StringUtils.isNotEmpty(search.getName()), Goods::getName, search.getName()));
        List<GoodsVO> result = new ArrayList<>();
@@ -62,27 +69,48 @@
    @Override
    public GoodsVO goodsDetail(Long goodsId) {
        // TODO 根据会员等级计算价格、积分
        if (goodsId == null || goodsId <= 0) {
            throw new NullPointerException("商品ID不能为空");
        }
        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
        VipSetting vipSetting = vipSettingService.getVipSettingByUserId(loginUserApplet.getUserid());
        // ...
        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);
        if (Objects.nonNull(goods)){
            GoodsVO goodsVO = new GoodsVO();
            BeanUtils.copyBeanProp(goodsVO, goods);
            return goodsVO;
        }
        return new GoodsVO();
        GoodsVO goodsVO = new GoodsVO();
        BeanUtils.copyBeanProp(goodsVO, goods);
        goodsVO.setSellingPrice(sellingPrice);
        goodsVO.setIntegral(integral);
        return goodsVO;
    }
    @Override
    public List<Goods> getGoodsListByShopId(Integer shopId) {
        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
        VipSetting vipSetting = vipSettingService.getVipSettingByUserId(loginUserApplet.getUserid());
        JSONArray array = new JSONArray();
        array.add(vipSetting.getId());
        return goodsMapper.selectListByShopId(shopId,array.toString());
        return goodsMapper.selectListByShopId(shopId, vipSetting.getId());
    }
}