Skip to content

Commit

Permalink
fix: 修复商品模版/商品草稿,保存批发规则无效问题
Browse files Browse the repository at this point in the history
  • Loading branch information
LeiGaoRobot committed Oct 14, 2022
1 parent 4ea6660 commit b9d7e07
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import cn.lili.modules.goods.entity.dos.*;
import cn.lili.modules.goods.entity.dto.DraftGoodsDTO;
import cn.lili.modules.goods.entity.dto.DraftGoodsSearchParams;
import cn.lili.modules.goods.entity.dto.GoodsOperationDTO;
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
import cn.lili.modules.goods.entity.dto.*;
import cn.lili.modules.goods.entity.vos.DraftGoodsVO;
import cn.lili.modules.goods.mapper.DraftGoodsMapper;
import cn.lili.modules.goods.service.*;
import cn.lili.modules.goods.sku.GoodsSkuBuilder;
import cn.lili.mybatis.util.PageUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -75,13 +73,23 @@ public void saveGoodsDraft(DraftGoodsDTO draftGoods) {
draftGoods.setSmall(goodsGallery.getSmall());
draftGoods.setThumbnail(goodsGallery.getThumbnail());
}
// 商品图片
draftGoods.setGoodsGalleryListJson(JSONUtil.toJsonStr(draftGoods.getGoodsGalleryList()));
// 检查是否需要生成索引
List<GoodsSku> goodsSkus = GoodsSkuBuilder.buildBatch(new Goods(draftGoods), draftGoods.getSkuList());
goodsSkuService.renderGoodsSkuList(goodsSkus, GoodsOperationDTO.builder().goodsTemplateFlag(true).wholesaleList(draftGoods.getWholesaleList()).salesModel(draftGoods.getSalesModel()).build());
draftGoods.setSkuListJson(JSONUtil.toJsonStr(goodsSkus));
// 商品参数
draftGoods.setGoodsParamsListJson(JSONUtil.toJsonStr(draftGoods.getGoodsParamsDTOList()));
this.saveOrUpdate(draftGoods);
boolean result = this.saveOrUpdate(draftGoods);
if (result) {
// 商品sku
List<GoodsSku> goodsSkus = GoodsSkuBuilder.buildBatch(new Goods(draftGoods), draftGoods.getSkuList());
for (WholesaleDTO wholesaleDTO : draftGoods.getWholesaleList()) {
wholesaleDTO.setTemplateId(draftGoods.getId());
}
goodsSkuService.renderGoodsSkuList(goodsSkus, GoodsOperationDTO.builder().goodsTemplateFlag(true).wholesaleList(draftGoods.getWholesaleList()).salesModel(draftGoods.getSalesModel()).build());
LambdaUpdateWrapper<DraftGoods> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(DraftGoods::getId, draftGoods.getId());
updateWrapper.set(DraftGoods::getSkuListJson, JSONUtil.toJsonStr(goodsSkus));
this.update(updateWrapper);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public void renderBatch(List<GoodsSku> goodsSkus, GoodsOperationDTO goodsOperati
skus.setPrice(collect.get(0).getPrice());
skus.setCost(collect.get(0).getPrice());
}
if (Boolean.FALSE.equals(goodsOperationDTO.getGoodsTemplateFlag())) {
if (Boolean.TRUE.equals(goodsOperationDTO.getGoodsTemplateFlag())) {
wholesaleService.removeByTemplateId(goodsSkus.get(0).getGoodsId());
} else {
wholesaleService.removeByGoodsId(goodsSkus.get(0).getGoodsId());
}
wholesaleService.saveOrUpdateBatch(collect);
Expand Down

0 comments on commit b9d7e07

Please sign in to comment.