Merge branch 'master' of gitee.com:beijing_hongye_huicheng/lilishop

This commit is contained in:
Chopper 2022-06-07 09:37:25 +08:00
commit ca352ca341
12 changed files with 198 additions and 110 deletions

View File

@ -358,6 +358,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
skuKeys.add(GoodsSkuService.getStockCacheKey(orderItem.getSkuId())); skuKeys.add(GoodsSkuService.getStockCacheKey(orderItem.getSkuId()));
GoodsSku goodsSku = new GoodsSku(); GoodsSku goodsSku = new GoodsSku();
goodsSku.setId(orderItem.getSkuId()); goodsSku.setId(orderItem.getSkuId());
goodsSku.setGoodsId(orderItem.getGoodsId());
goodsSkus.add(goodsSku); goodsSkus.add(goodsSku);
} }
//批量获取商品库存 //批量获取商品库存

View File

@ -506,18 +506,14 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateGoodsStuck(List<GoodsSku> goodsSkus) { public void updateGoodsStuck(List<GoodsSku> goodsSkus) {
//商品id集合 hashset 去重复 Map<String, List<GoodsSku>> groupByGoodsIds = goodsSkus.stream().collect(Collectors.groupingBy(GoodsSku::getGoodsId));
Set<String> goodsIds = new HashSet<>();
for (GoodsSku sku : goodsSkus) {
goodsIds.add(sku.getGoodsId());
}
//获取相关的sku集合 //获取相关的sku集合
LambdaQueryWrapper<GoodsSku> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<GoodsSku> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.in(GoodsSku::getGoodsId, goodsIds); lambdaQueryWrapper.in(GoodsSku::getGoodsId, groupByGoodsIds.keySet());
List<GoodsSku> goodsSkuList = this.list(lambdaQueryWrapper); List<GoodsSku> goodsSkuList = this.list(lambdaQueryWrapper);
//统计每个商品的库存 //统计每个商品的库存
for (String goodsId : goodsIds) { for (String goodsId : groupByGoodsIds.keySet()) {
//库存 //库存
Integer quantity = 0; Integer quantity = 0;
for (GoodsSku goodsSku : goodsSkuList) { for (GoodsSku goodsSku : goodsSkuList) {

View File

@ -117,4 +117,8 @@ public class CartSkuVO extends CartBase implements Serializable {
public Map<String, Object> getPromotionMap() { public Map<String, Object> getPromotionMap() {
return PromotionTools.filterInvalidPromotionsMap(this.promotionMap); return PromotionTools.filterInvalidPromotionsMap(this.promotionMap);
} }
public Map<String, Object> getNotFilterPromotionMap() {
return this.promotionMap;
}
} }

View File

@ -31,6 +31,7 @@ import cn.lili.modules.promotion.entity.dos.Coupon;
import cn.lili.modules.promotion.entity.dos.Pintuan; import cn.lili.modules.promotion.entity.dos.Pintuan;
import cn.lili.modules.promotion.entity.dos.PointsGoods; import cn.lili.modules.promotion.entity.dos.PointsGoods;
import cn.lili.modules.promotion.entity.vos.CouponVO; import cn.lili.modules.promotion.entity.vos.CouponVO;
import cn.lili.modules.promotion.service.PromotionGoodsService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -63,6 +64,11 @@ public class CheckDataRender implements CartRenderStep {
@Autowired @Autowired
private WholesaleService wholesaleService; private WholesaleService wholesaleService;
/**
* 商品索引
*/
@Autowired
private PromotionGoodsService promotionGoodsService;
@Override @Override
public RenderStepEnums step() { public RenderStepEnums step() {
@ -127,6 +133,17 @@ public class CheckDataRender implements CartRenderStep {
//设置失效消息 //设置失效消息
cartSkuVO.setErrorMessage("商品库存不足,现有库存数量[" + dataSku.getQuantity() + "]"); cartSkuVO.setErrorMessage("商品库存不足,现有库存数量[" + dataSku.getQuantity() + "]");
} }
//如果存在商品促销活动则判定商品促销状态
if (CollUtil.isNotEmpty(cartSkuVO.getNotFilterPromotionMap()) || Boolean.TRUE.equals(cartSkuVO.getGoodsSku().getPromotionFlag())) {
//获取当前最新的促销信息
cartSkuVO.setPromotionMap(this.promotionGoodsService.getCurrentGoodsPromotion(cartSkuVO.getGoodsSku(), tradeDTO.getCartTypeEnum().name()));
//设定商品价格
Double goodsPrice = cartSkuVO.getGoodsSku().getPromotionFlag() != null && cartSkuVO.getGoodsSku().getPromotionFlag() ? cartSkuVO.getGoodsSku().getPromotionPrice() : cartSkuVO.getGoodsSku().getPrice();
cartSkuVO.setPurchasePrice(goodsPrice);
cartSkuVO.setUtilPrice(goodsPrice);
cartSkuVO.setSubTotal(CurrencyUtil.mul(cartSkuVO.getPurchasePrice(), cartSkuVO.getNum()));
}
} }
} }

View File

@ -16,7 +16,6 @@ import cn.lili.modules.goods.entity.dos.Wholesale;
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
import cn.lili.modules.goods.entity.enums.GoodsSalesModeEnum; import cn.lili.modules.goods.entity.enums.GoodsSalesModeEnum;
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
import cn.lili.modules.goods.entity.vos.GoodsVO;
import cn.lili.modules.goods.service.GoodsService; import cn.lili.modules.goods.service.GoodsService;
import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.goods.service.GoodsSkuService;
import cn.lili.modules.goods.service.WholesaleService; import cn.lili.modules.goods.service.WholesaleService;
@ -36,10 +35,8 @@ import cn.lili.modules.order.order.entity.dos.Trade;
import cn.lili.modules.order.order.entity.vo.ReceiptVO; import cn.lili.modules.order.order.entity.vo.ReceiptVO;
import cn.lili.modules.promotion.entity.dos.KanjiaActivity; import cn.lili.modules.promotion.entity.dos.KanjiaActivity;
import cn.lili.modules.promotion.entity.dos.MemberCoupon; import cn.lili.modules.promotion.entity.dos.MemberCoupon;
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
import cn.lili.modules.promotion.entity.dto.search.KanjiaActivitySearchParams; import cn.lili.modules.promotion.entity.dto.search.KanjiaActivitySearchParams;
import cn.lili.modules.promotion.entity.dto.search.MemberCouponSearchParams; import cn.lili.modules.promotion.entity.dto.search.MemberCouponSearchParams;
import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams;
import cn.lili.modules.promotion.entity.enums.KanJiaStatusEnum; import cn.lili.modules.promotion.entity.enums.KanJiaStatusEnum;
import cn.lili.modules.promotion.entity.enums.MemberCouponStatusEnum; import cn.lili.modules.promotion.entity.enums.MemberCouponStatusEnum;
import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum;
@ -139,7 +136,7 @@ public class CartServiceImpl implements CartService {
} }
CartTypeEnum cartTypeEnum = getCartType(cartType); CartTypeEnum cartTypeEnum = getCartType(cartType);
GoodsSku dataSku = checkGoods(skuId); GoodsSku dataSku = checkGoods(skuId);
Map<String, Object> promotionMap = this.getCurrentGoodsPromotion(dataSku, cartType); Map<String, Object> promotionMap = promotionGoodsService.getCurrentGoodsPromotion(dataSku, cartType);
try { try {
//购物车方式购买需要保存之前的选择其他方式购买则直接抹除掉之前的记录 //购物车方式购买需要保存之前的选择其他方式购买则直接抹除掉之前的记录
@ -554,39 +551,6 @@ public class CartServiceImpl implements CartService {
return trade; return trade;
} }
private Map<String, Object> getCurrentGoodsPromotion(GoodsSku dataSku, String cartType) {
Map<String, Object> promotionMap;
EsGoodsIndex goodsIndex = goodsIndexService.findById(dataSku.getId());
if (goodsIndex == null) {
GoodsVO goodsVO = this.goodsService.getGoodsVO(dataSku.getGoodsId());
goodsIndex = goodsIndexService.getResetEsGoodsIndex(dataSku, goodsVO.getGoodsParamsDTOList());
}
if (goodsIndex.getPromotionMap() != null && !goodsIndex.getPromotionMap().isEmpty()) {
if (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.SECKILL.name())) || (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.PINTUAN.name())) && CartTypeEnum.PINTUAN.name().equals(cartType))) {
Optional<Map.Entry<String, Object>> containsPromotion = goodsIndex.getPromotionMap().entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())).findFirst();
if (containsPromotion.isPresent()) {
JSONObject promotionsObj = JSONUtil.parseObj(containsPromotion.get().getValue());
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
searchParams.setSkuId(dataSku.getId());
searchParams.setPromotionId(promotionsObj.get("id").toString());
PromotionGoods promotionsGoods = promotionGoodsService.getPromotionsGoods(searchParams);
if (promotionsGoods != null && promotionsGoods.getPrice() != null) {
dataSku.setPromotionFlag(true);
dataSku.setPromotionPrice(promotionsGoods.getPrice());
} else {
dataSku.setPromotionFlag(false);
dataSku.setPromotionPrice(null);
}
}
}
promotionMap = goodsIndex.getPromotionMap();
} else {
promotionMap = null;
}
return promotionMap;
}
/** /**
* 获取购物车类型 * 获取购物车类型
@ -640,6 +604,9 @@ public class CartServiceImpl implements CartService {
cartPrice = CurrencyUtil.add(cartPrice, CurrencyUtil.mul(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getNum())); cartPrice = CurrencyUtil.add(cartPrice, CurrencyUtil.mul(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getNum()));
skuPrice.put(cartSkuVO.getGoodsSku().getId(), CurrencyUtil.mul(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getNum())); skuPrice.put(cartSkuVO.getGoodsSku().getId(), CurrencyUtil.mul(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getNum()));
} }
} else {
cartPrice = CurrencyUtil.add(cartPrice, CurrencyUtil.mul(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getNum()));
skuPrice.put(cartSkuVO.getGoodsSku().getId(), CurrencyUtil.mul(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getNum()));
} }
} }

View File

@ -5,6 +5,7 @@ import cn.lili.modules.order.order.entity.enums.OrderComplaintStatusEnum;
import cn.lili.modules.order.order.entity.enums.OrderItemAfterSaleStatusEnum; import cn.lili.modules.order.order.entity.enums.OrderItemAfterSaleStatusEnum;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
/** /**
* 子订单VO * 子订单VO
@ -13,6 +14,7 @@ import lombok.Data;
* @since 2020-08-17 20:28 * @since 2020-08-17 20:28
*/ */
@Data @Data
@NoArgsConstructor
public class OrderItemVO { public class OrderItemVO {
@ApiModelProperty(value = "编号") @ApiModelProperty(value = "编号")
@ -55,17 +57,39 @@ public class OrderItemVO {
private String commentStatus; private String commentStatus;
public OrderItemVO(String sn, String goodsId, String skuId, String num, String image, String name, String afterSaleStatus, String complainStatus, String commentStatus, Double goodsPrice) { public void setSn(String sn) {
this.sn = sn; this.sn = sn;
this.goodsId = goodsId; }
public void setSkuId(String skuId) {
this.skuId = skuId; this.skuId = skuId;
}
public void setNum(String num) {
this.num = num; this.num = num;
}
public void setImage(String image) {
this.image = image; this.image = image;
}
public void setName(String name) {
this.name = name; this.name = name;
this.afterSaleStatus = afterSaleStatus; }
this.complainStatus = complainStatus;
this.commentStatus = commentStatus; public void setGoodsPrice(Double goodsPrice) {
this.goodsPrice = goodsPrice; this.goodsPrice = goodsPrice;
} }
public void setAfterSaleStatus(String afterSaleStatus) {
this.afterSaleStatus = afterSaleStatus;
}
public void setComplainStatus(String complainStatus) {
this.complainStatus = complainStatus;
}
public void setCommentStatus(String commentStatus) {
this.commentStatus = commentStatus;
}
} }

View File

@ -1,8 +1,7 @@
package cn.lili.modules.order.order.entity.vo; package cn.lili.modules.order.order.entity.vo;
import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.enums.ClientTypeEnum; import cn.lili.common.enums.ClientTypeEnum;
import cn.lili.common.utils.StringUtils;
import cn.lili.modules.order.order.entity.enums.*;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -135,28 +134,54 @@ public class OrderSimpleVO {
private String deliverStatus; private String deliverStatus;
public List<OrderItemVO> getOrderItems() { public List<OrderItemVO> getOrderItems() {
if (StringUtils.isEmpty(groupGoodsId)) { if (CharSequenceUtil.isEmpty(groupGoodsId)) {
return new ArrayList<>(); return new ArrayList<>();
} }
List<OrderItemVO> orderItemVOS = new ArrayList<>(); List<OrderItemVO> orderItemVOS = new ArrayList<>();
String[] orderItemsSn = groupOrderItemsSn.split(",");
String[] goodsId = groupGoodsId.split(","); String[] goodsId = groupGoodsId.split(",");
String[] skuId = groupSkuId.split(",");
String[] num = groupNum.split(",");
String[] image = groupImages.split(",");
String[] name = groupName.split(",");
String[] afterSaleStatus = groupAfterSaleStatus.split(",");
String[] complainStatus = groupComplainStatus.split(",");
String[] commentStatus = groupCommentStatus.split(",");
String[] goodsPrice = groupGoodsPrice.split(",");
for (int i = 0; i < goodsId.length; i++) { for (int i = 0; i < goodsId.length; i++) {
orderItemVOS.add(new OrderItemVO(orderItemsSn[i], goodsId[i], skuId[i], num[i], image[i], name[i], afterSaleStatus[i], complainStatus[i], commentStatus[i], Double.parseDouble(goodsPrice[i]))); orderItemVOS.add(this.getOrderItemVO(i));
} }
return orderItemVOS; return orderItemVOS;
} }
private OrderItemVO getOrderItemVO(int i) {
OrderItemVO orderItemVO = new OrderItemVO();
orderItemVO.setGoodsId(groupGoodsId.split(",")[i]);
if (CharSequenceUtil.isNotEmpty(groupOrderItemsSn)) {
orderItemVO.setSn(groupOrderItemsSn.split(",")[i]);
}
if (CharSequenceUtil.isNotEmpty(groupSkuId)) {
orderItemVO.setSkuId(groupSkuId.split(",")[i]);
}
if (CharSequenceUtil.isNotEmpty(groupName)) {
orderItemVO.setName(groupName.split(",")[i]);
}
if (CharSequenceUtil.isNotEmpty(groupNum) && groupNum.split(",").length == groupGoodsId.split(",").length) {
orderItemVO.setNum(groupNum.split(",")[i]);
}
if (CharSequenceUtil.isNotEmpty(groupImages) && groupImages.split(",").length == groupGoodsId.split(",").length) {
orderItemVO.setImage(groupImages.split(",")[i]);
}
if (CharSequenceUtil.isNotEmpty(groupAfterSaleStatus) && groupAfterSaleStatus.split(",").length == groupGoodsId.split(",").length) {
orderItemVO.setAfterSaleStatus(groupAfterSaleStatus.split(",")[i]);
}
if (CharSequenceUtil.isNotEmpty(groupComplainStatus) && groupComplainStatus.split(",").length == groupGoodsId.split(",").length) {
orderItemVO.setComplainStatus(groupComplainStatus.split(",")[i]);
}
if (CharSequenceUtil.isNotEmpty(groupCommentStatus) && groupCommentStatus.split(",").length == groupGoodsId.split(",").length) {
orderItemVO.setCommentStatus(groupCommentStatus.split(",")[i]);
}
if (CharSequenceUtil.isNotEmpty(groupGoodsPrice) && groupGoodsPrice.split(",").length == groupGoodsId.split(",").length) {
orderItemVO.setGoodsPrice(Double.parseDouble(groupGoodsPrice.split(",")[i]));
}
return orderItemVO;
}
/** /**
* 初始化自身状态 * 初始化自身状态
*/ */

View File

@ -3,6 +3,7 @@ package cn.lili.modules.promotion.service;
import cn.lili.cache.CachePrefix; import cn.lili.cache.CachePrefix;
import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.vo.PageVO; import cn.lili.common.vo.PageVO;
import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dos.PromotionGoods;
import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams; import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -10,6 +11,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 促销商品业务层 * 促销商品业务层
@ -154,4 +156,13 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
*/ */
void deletePromotionGoods(PromotionGoodsSearchParams searchParams); void deletePromotionGoods(PromotionGoodsSearchParams searchParams);
/**
* 获取当前商品促销信息
*
* @param dataSku 商品sku信息
* @param cartType 购物车类型
* @return 当前商品促销信息
*/
Map<String, Object> getCurrentGoodsPromotion(GoodsSku dataSku, String cartType);
} }

View File

@ -2,10 +2,15 @@ package cn.lili.modules.promotion.serviceimpl;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.vo.PageVO; import cn.lili.common.vo.PageVO;
import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.entity.vos.GoodsVO;
import cn.lili.modules.goods.service.GoodsService;
import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.goods.service.GoodsSkuService;
import cn.lili.modules.order.cart.entity.enums.CartTypeEnum;
import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dos.PromotionGoods;
import cn.lili.modules.promotion.entity.dos.SeckillApply; import cn.lili.modules.promotion.entity.dos.SeckillApply;
import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams; import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams;
@ -16,6 +21,8 @@ import cn.lili.modules.promotion.mapper.PromotionGoodsMapper;
import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.service.PromotionGoodsService;
import cn.lili.modules.promotion.service.SeckillApplyService; import cn.lili.modules.promotion.service.SeckillApplyService;
import cn.lili.modules.promotion.tools.PromotionTools; import cn.lili.modules.promotion.tools.PromotionTools;
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
import cn.lili.modules.search.service.EsGoodsIndexService;
import cn.lili.mybatis.util.PageUtil; import cn.lili.mybatis.util.PageUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -27,10 +34,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/** /**
* 促销商品业务层实现 * 促销商品业务层实现
@ -59,6 +63,12 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
@Autowired @Autowired
private GoodsSkuService goodsSkuService; private GoodsSkuService goodsSkuService;
@Autowired
private GoodsService goodsService;
@Autowired
private EsGoodsIndexService goodsIndexService;
@Override @Override
public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) { public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) {
@ -267,8 +277,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
*/ */
@Override @Override
public void deletePromotionGoods(List<String> promotionIds) { public void deletePromotionGoods(List<String> promotionIds) {
LambdaQueryWrapper<PromotionGoods> queryWrapper = new LambdaQueryWrapper<PromotionGoods>() LambdaQueryWrapper<PromotionGoods> queryWrapper = new LambdaQueryWrapper<PromotionGoods>().in(PromotionGoods::getPromotionId, promotionIds);
.in(PromotionGoods::getPromotionId, promotionIds);
this.remove(queryWrapper); this.remove(queryWrapper);
} }
@ -282,4 +291,41 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
this.remove(searchParams.queryWrapper()); this.remove(searchParams.queryWrapper());
} }
@Override
public Map<String, Object> getCurrentGoodsPromotion(GoodsSku dataSku, String cartType) {
Map<String, Object> promotionMap;
EsGoodsIndex goodsIndex = goodsIndexService.findById(dataSku.getId());
if (goodsIndex == null) {
GoodsVO goodsVO = this.goodsService.getGoodsVO(dataSku.getGoodsId());
goodsIndex = goodsIndexService.getResetEsGoodsIndex(dataSku, goodsVO.getGoodsParamsDTOList());
}
if (goodsIndex.getPromotionMap() != null && !goodsIndex.getPromotionMap().isEmpty()) {
if (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.SECKILL.name())) || (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.PINTUAN.name())) && CartTypeEnum.PINTUAN.name().equals(cartType))) {
Optional<Map.Entry<String, Object>> containsPromotion = goodsIndex.getPromotionMap().entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())).findFirst();
containsPromotion.ifPresent(stringObjectEntry -> this.setGoodsPromotionInfo(dataSku, stringObjectEntry));
}
promotionMap = goodsIndex.getPromotionMap();
} else {
promotionMap = null;
dataSku.setPromotionFlag(false);
dataSku.setPromotionPrice(null);
}
return promotionMap;
}
private void setGoodsPromotionInfo(GoodsSku dataSku, Map.Entry<String, Object> promotionInfo) {
JSONObject promotionsObj = JSONUtil.parseObj(promotionInfo);
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
searchParams.setSkuId(dataSku.getId());
searchParams.setPromotionId(promotionsObj.get("id").toString());
PromotionGoods promotionsGoods = this.getPromotionsGoods(searchParams);
if (promotionsGoods != null && promotionsGoods.getPrice() != null) {
dataSku.setPromotionFlag(true);
dataSku.setPromotionPrice(promotionsGoods.getPrice());
} else {
dataSku.setPromotionFlag(false);
dataSku.setPromotionPrice(null);
}
}
} }

View File

@ -1,39 +0,0 @@
package cn.lili.modules.promotion.tools;
import cn.lili.cache.CachePrefix;
/**
* 满额活动缓存Key
* @author paulG
* @since 2020/10/12
**/
public class PromotionCacheKeys {
/**
* 读取满优惠redis key
* @param activityId 活动ID
* @return 满优惠redis key
*/
public static String getFullDiscountKey(String activityId){
return CachePrefix.STORE_ID_FULL_DISCOUNT + "::" + activityId;
}
/**
* 读取满优惠redis key
* @param id id
* @return 满优惠redis key
*/
public static String getPromotionGoodsKey(String id){
return CachePrefix.PROMOTION_GOODS + "::" + id;
}
/**
* 读取秒杀活动redis key
* @param timeStr 时间字符串格式为 yyyyMMdd
* @return 满优惠redis key
*/
public static String getSeckillTimelineKey(String timeStr){
return CachePrefix.STORE_ID_SECKILL + "::" + timeStr;
}
}

View File

@ -44,4 +44,7 @@ public class EsGoodsSearchDTO {
@ApiModelProperty(hidden = true) @ApiModelProperty(hidden = true)
private Map<String, List<String>> notShowCol = new HashMap<>(); private Map<String, List<String>> notShowCol = new HashMap<>();
@ApiModelProperty("当前商品skuId,根据当前浏览的商品信息来给用户推荐可能喜欢的商品")
private String currentGoodsId;
} }

View File

@ -363,6 +363,9 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
//对查询条件进行处理 //对查询条件进行处理
this.commonSearch(filterBuilder, searchDTO); this.commonSearch(filterBuilder, searchDTO);
//智能推荐
this.recommended(filterBuilder,searchDTO);
//未上架的商品不显示 //未上架的商品不显示
filterBuilder.must(QueryBuilders.matchQuery("marketEnable", GoodsStatusEnum.UPPER.name())); filterBuilder.must(QueryBuilders.matchQuery("marketEnable", GoodsStatusEnum.UPPER.name()));
//待审核和审核不通过的商品不显示 //待审核和审核不通过的商品不显示
@ -401,6 +404,36 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
return nativeSearchQueryBuilder; return nativeSearchQueryBuilder;
} }
/**
* 商品推荐
* @param filterBuilder
* @param searchDTO
*/
private void recommended(BoolQueryBuilder filterBuilder, EsGoodsSearchDTO searchDTO) {
String currentGoodsId = searchDTO.getCurrentGoodsId();
if(CharSequenceUtil.isEmpty(currentGoodsId)) {
return;
}
//排除当前商品
filterBuilder.mustNot(QueryBuilders.matchQuery("id",currentGoodsId));
//查询当前浏览商品的索引信息
EsGoodsIndex esGoodsIndex = restTemplate.get(currentGoodsId, EsGoodsIndex.class);
if(esGoodsIndex==null) {
return;
}
//推荐与当前浏览商品相同一个二级分类下的商品
String categoryPath = esGoodsIndex.getCategoryPath();
if(CharSequenceUtil.isNotEmpty(categoryPath)){
//匹配二级分类
String substring = categoryPath.substring(0, categoryPath.lastIndexOf(","));
filterBuilder.must(QueryBuilders.wildcardQuery("categoryPath",substring+"*"));
}
}
/** /**
* 查询属性处理 * 查询属性处理
* *