Helius
2022-09-23 7c6f033b8754b07bf5c75ae8745a982d76f9abb4
src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
@@ -12,6 +12,7 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -109,6 +110,10 @@
        //新增商品
        MallGoods mallGoods = MallGoodsConversion.INSTANCE.dtoToEntity(addMallGoodsDto);
        mallGoods.setIsSale(MallGoods.ISSALE_STATUS_DISABLED);
        if (mallGoods.getHasCarriage() == 2) {
            mallGoods.setCarriage(BigDecimal.ZERO);
        }
        mallGoodsMapper.insert(mallGoods);
        String thumbs = addMallGoodsDto.getThumbs();
@@ -128,6 +133,27 @@
        }
        if (addMallGoodsDto.getGoodsType() == 2) {
            return new FebsResponse().success().message("添加成功");
        }
        // 单规格
        if (addMallGoodsDto.getIsSku() == 2) {
            MallGoodsStyle style = new MallGoodsStyle();
            style.setGoodsId(mallGoods.getId());
            style.setName(mallGoods.getGoodsName());
            mallGoodsStyleMapper.insert(style);
            MallGoodsSku sku = new MallGoodsSku();
            sku.setGoodsId(mallGoods.getId());
            sku.setSkuImage(mallGoods.getThumb());
            sku.setSkuName(mallGoods.getGoodsName());
            sku.setCostPrice(mallGoods.getCostPrice());
            sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice()));
            sku.setOriginalPrice(new BigDecimal(mallGoods.getOriginalPrice()));
            sku.setSkuVolume(mallGoods.getVolume());
            sku.setStock(mallGoods.getStock());
            sku.setStyleId(style.getId());
            mallGoodsSkuMapper.insert(sku);
            return new FebsResponse().success().message("添加成功");
        }
@@ -298,7 +324,7 @@
                        return new FebsResponse().fail().message("商品规格原价不能小于0");
                    }
                    BigDecimal presentPrice = addSku.getPresentPrice();
                    if (presentPrice.compareTo(BigDecimal.ZERO) <= 0) {
                    if (presentPrice.compareTo(BigDecimal.ZERO) < 0) {
                        return new FebsResponse().fail().message("商品规格现价不能小于0");
                    }
@@ -308,7 +334,18 @@
        //新增商品
        MallGoods mallGoods = mallGoodsMapper.selectById(mallGoodsUpdateDto.getId());
        // 若原来不为多规格或编辑后也不为多规格,则清空样式和规格
        if (mallGoods.getIsSku() == 2 || mallGoodsUpdateDto.getIsSku() == 2) {
            mallGoodsSkuMapper.deleteByGoodsId(mallGoods.getId());
            mallGoodsStyleMapper.deleteByGoodsId(mallGoods.getId());
        }
        BeanUtil.copyProperties(mallGoodsUpdateDto, mallGoods);
        if (mallGoods.getHasCarriage() == 2) {
            mallGoods.setCarriage(BigDecimal.ZERO);
        }
        mallGoodsMapper.updateById(mallGoods);
        mallGoodsImagesMapper.deleteByGoodsId(mallGoodsUpdateDto.getId());
@@ -331,6 +368,29 @@
        if (mallGoodsUpdateDto.getGoodsType() == 2) {
            return new FebsResponse().success().message("编辑成功");
        }
        // 单规格
        if (mallGoodsUpdateDto.getIsSku() == 2) {
            MallGoodsStyle style = new MallGoodsStyle();
            style.setGoodsId(mallGoods.getId());
            style.setName(mallGoods.getGoodsName());
            mallGoodsStyleMapper.insert(style);
            MallGoodsSku sku = new MallGoodsSku();
            sku.setGoodsId(mallGoods.getId());
            sku.setSkuImage(mallGoods.getThumb());
            sku.setSkuName(mallGoods.getGoodsName());
            sku.setCostPrice(mallGoods.getCostPrice());
            sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice()));
            sku.setOriginalPrice(new BigDecimal(mallGoods.getOriginalPrice()));
            sku.setSkuVolume(mallGoods.getVolume());
            sku.setStock(mallGoods.getStock());
            sku.setStyleId(style.getId());
            mallGoodsSkuMapper.insert(sku);
            return new FebsResponse().success().message("添加成功");
        }
        // 删除已存在sku
        List<Long> delSkuIds = mallGoodsUpdateDto.getDelSkuId();
@@ -414,5 +474,55 @@
        return mallGoodsMapper.getAllGoodsTree();
    }
    @Override
    public FebsResponse goodsHot(Long id) {
        MallGoods mallGoods = mallGoodsMapper.selectById(id);
        if (ObjectUtil.isEmpty(mallGoods)) {
            return new FebsResponse().fail().message("商品不存在,请刷新当前页面");
        }
        mallGoods.setIsHot(MallGoods.ISHOT_STATE_YES);
        mallGoodsMapper.updateById(mallGoods);
        return new FebsResponse().success();
    }
    @Override
    public FebsResponse goodsNotHot(Long id) {
        MallGoods mallGoods = mallGoodsMapper.selectById(id);
        if (ObjectUtil.isEmpty(mallGoods)) {
            return new FebsResponse().fail().message("商品不存在,请刷新当前页面");
        }
        mallGoods.setIsHot(MallGoods.ISHOT_STATE_NO);
        mallGoodsMapper.updateById(mallGoods);
        return new FebsResponse().success();
    }
    @Override
    public IPage<AdminHomeDeliverySettingVo> getDeliveryHomeListInPage(AdminHomeDeliverySettingVo adminHomeDeliverySetting, QueryRequest request) {
        Page<DataDictionaryCustom> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<DataDictionaryCustom> dataDictionaryCustomIPage = this.baseMapper.getDeliveryHomeListInPage(page, adminHomeDeliverySetting);
        List<DataDictionaryCustom> records = dataDictionaryCustomIPage.getRecords();
        List<AdminHomeDeliverySettingVo> adminHomeDeliverySettingVos = new ArrayList<>();
        if(CollUtil.isNotEmpty(records)){
            for(DataDictionaryCustom dataDictionaryCustom : records){
                AdminHomeDeliverySettingVo adminHomeDeliverySettingVo = JSONUtil.toBean(dataDictionaryCustom.getValue(), AdminHomeDeliverySettingVo.class);
                adminHomeDeliverySettingVo.setId(dataDictionaryCustom.getId());
                adminHomeDeliverySettingVos.add(adminHomeDeliverySettingVo);
            }
        }
        IPage<AdminHomeDeliverySettingVo> adminHomeDeliverySettingVoIPage = new Page<>();
        adminHomeDeliverySettingVoIPage.setRecords(adminHomeDeliverySettingVos);
        adminHomeDeliverySettingVoIPage.setTotal(dataDictionaryCustomIPage.getTotal());
        return adminHomeDeliverySettingVoIPage;
    }
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    @Override
    public FebsResponse deliveryHomeUpdate(AdminHomeDeliverySettingVo adminHomeDeliverySettingVo) {
        DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectById(adminHomeDeliverySettingVo.getId());
        adminHomeDeliverySettingVo.setId(null);
        dataDictionaryCustom.setValue(JSONUtil.toJsonStr(adminHomeDeliverySettingVo));
        dataDictionaryCustomMapper.updateById(dataDictionaryCustom);
        return new FebsResponse().success();
    }
}