| | |
| | | import cn.lili.modules.goods.service.WholesaleService; |
| | | import cn.lili.modules.goods.sku.GoodsSkuBuilder; |
| | | import cn.lili.modules.goods.sku.render.SalesModelRender; |
| | | import cn.lili.modules.lmk.domain.entity.PriceChange; |
| | | import cn.lili.modules.lmk.enums.general.ChangePriceAudioStatusEnum; |
| | | import cn.lili.modules.lmk.enums.general.ChangePriceOperationTypeEnum; |
| | | import cn.lili.modules.lmk.enums.general.ViewTypeEnum; |
| | | import cn.lili.modules.lmk.service.PriceChangeService; |
| | | import cn.lili.modules.member.entity.dos.FootPrint; |
| | | import cn.lili.modules.promotion.entity.dos.Coupon; |
| | | import cn.lili.modules.promotion.entity.dos.PromotionGoods; |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.poi.ss.usermodel.*; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | private List<SalesModelRender> salesModelRenders; |
| | | |
| | | @Autowired |
| | | private PriceChangeService priceChangeService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void add(Goods goods, GoodsOperationDTO goodsOperationDTO) { |
| | |
| | | if (!goodsSkus.isEmpty()) { |
| | | this.saveOrUpdateBatch(goodsSkus); |
| | | this.updateGoodsStock(goodsSkus); |
| | | //记录价格变动 |
| | | List<PriceChange> priceChangeList = goodsSkus.stream().map(item -> { |
| | | PriceChange priceChange = new PriceChange(); |
| | | priceChange.setCurrentPrice(BigDecimal.valueOf(item.getPrice())); |
| | | priceChange.setSkuId(item.getId()); |
| | | priceChange.setGoodsId(item.getGoodsId()); |
| | | priceChange.setPreviousPrice(BigDecimal.ZERO); |
| | | priceChange.setPreviousCommission(BigDecimal.ZERO); |
| | | priceChange.setCurrentCommission(goods.getCommission()); |
| | | priceChange.setOperatorType(ChangePriceOperationTypeEnum.STORE.name()); |
| | | priceChange.setExamineStatus(ChangePriceAudioStatusEnum.APPLY.name()); |
| | | priceChange.setOperatorId(UserContext.getCurrentUser().getId()); |
| | | priceChange.setOperatorName(UserContext.getCurrentUser().getNickName()); |
| | | priceChange.setStoreId(item.getStoreId()); |
| | | return priceChange; |
| | | }).collect(Collectors.toList()); |
| | | priceChangeService.saveBatch(priceChangeList); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(Goods goods, GoodsOperationDTO goodsOperationDTO) { |
| | | public void update(Goods goods, GoodsOperationDTO goodsOperationDTO,Goods previousGoods) { |
| | | // 是否存在规格 |
| | | if (goodsOperationDTO.getSkuList() == null || goodsOperationDTO.getSkuList().isEmpty()) { |
| | | throw new ServiceException(ResultCode.MUST_HAVE_GOODS_SKU); |
| | |
| | | unnecessarySkuIdsQuery.eq(GoodsSku::getGoodsId, goods.getId()); |
| | | unnecessarySkuIdsQuery.notIn(GoodsSku::getId, |
| | | skuList.stream().map(BaseEntity::getId).collect(Collectors.toList())); |
| | | LambdaQueryWrapper<GoodsSku> skuIdsQuery = new LambdaQueryWrapper<>(); |
| | | skuIdsQuery.eq(GoodsSku::getGoodsId, goods.getId()); |
| | | skuIdsQuery.in(GoodsSku::getId, |
| | | skuList.stream().map(BaseEntity::getId).collect(Collectors.toList())); |
| | | Map<String, GoodsSku> skuMap = this.list(skuIdsQuery).stream().collect(Collectors.toMap(GoodsSku::getId, Function.identity())); |
| | | this.remove(unnecessarySkuIdsQuery); |
| | | this.saveOrUpdateBatch(skuList); |
| | | this.updateGoodsStock(skuList); |
| | | //记录价格变动 |
| | | //删除当前审核状态为申请的改价的商品 店铺id一致商品id一致且为申请状态的移除 |
| | | LambdaQueryWrapper<PriceChange> needRemove = Wrappers.<PriceChange>lambdaQuery() |
| | | .eq(PriceChange::getGoodsId, goods.getId()) |
| | | .eq(PriceChange::getStoreId, goods.getStoreId()) |
| | | .eq(PriceChange::getExamineStatus, ChangePriceAudioStatusEnum.APPLY.name()); |
| | | priceChangeService.remove(needRemove); |
| | | //重新添加改价商品 |
| | | List<PriceChange> priceChangeList = skuList.stream().map(item -> { |
| | | PriceChange priceChange = new PriceChange(); |
| | | priceChange.setCurrentPrice(BigDecimal.valueOf(item.getPrice())); |
| | | GoodsSku goodsSku = skuMap.get(item.getId()); |
| | | priceChange.setSkuId(item.getId()); |
| | | priceChange.setGoodsId(item.getGoodsId()); |
| | | if (Objects.nonNull(goodsSku)) { |
| | | priceChange.setPreviousPrice(BigDecimal.valueOf(goodsSku.getPrice())); |
| | | } |
| | | priceChange.setPreviousCommission(previousGoods.getCommission()); |
| | | priceChange.setCurrentCommission(goods.getCommission()); |
| | | priceChange.setOperatorType(ChangePriceOperationTypeEnum.STORE.name()); |
| | | priceChange.setExamineStatus(ChangePriceAudioStatusEnum.APPLY.name()); |
| | | priceChange.setOperatorId(UserContext.getCurrentUser().getId()); |
| | | priceChange.setOperatorName(UserContext.getCurrentUser().getNickName()); |
| | | priceChange.setStoreId(item.getStoreId()); |
| | | return priceChange; |
| | | }).collect(Collectors.toList()); |
| | | priceChangeService.saveBatch(priceChangeList); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | //记录用户足迹 |
| | | if (currentUser != null) { |
| | | FootPrint footPrint = new FootPrint(currentUser.getId(), goodsIndex.getStoreId(), goodsId, skuId, ViewTypeEnum.GOODS.getValue(), null); |
| | | FootPrint footPrint = new FootPrint(currentUser.getId(), goodsIndex.getStoreId(), goodsId, skuId, ViewTypeEnum.GOODS.getValue(), null, null); |
| | | String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.VIEW_GOODS.name(); |
| | | rocketMQTemplate.asyncSend(destination, footPrint, RocketmqSendCallbackBuilder.commonCallback()); |
| | | } |
| | |
| | | updateWrapper.set(GoodsSku::getDeleteFlag, goods.getDeleteFlag()); |
| | | boolean update = this.update(updateWrapper); |
| | | if (Boolean.TRUE.equals(update)) { |
| | | //修改订单改价状态为通过或者失败 |
| | | LambdaUpdateWrapper<PriceChange> updatePriceChange = Wrappers.<PriceChange>lambdaUpdate() |
| | | .eq(PriceChange::getGoodsId, goods.getId()) |
| | | .eq(PriceChange::getStoreId, goods.getStoreId()) |
| | | .eq(PriceChange::getExamineStatus, ChangePriceAudioStatusEnum.APPLY.name()); |
| | | if (GoodsAuthEnum.PASS.name().equals(goods.getAuthFlag())) { |
| | | updatePriceChange.set(PriceChange::getExamineStatus, ChangePriceAudioStatusEnum.PASS.name()); |
| | | }else { |
| | | updatePriceChange.set(PriceChange::getExamineStatus, ChangePriceAudioStatusEnum.REFUSE.name()); |
| | | } |
| | | priceChangeService.update(updatePriceChange); |
| | | List<GoodsSku> goodsSkus = this.getGoodsSkuListByGoodsId(goods.getId()); |
| | | for (GoodsSku sku : goodsSkus) { |
| | | cache.remove(GoodsSkuService.getCacheKeys(sku.getId())); |