Merge branch 'master' of gitee.com:beijing_hongye_huicheng/lilishop
This commit is contained in:
commit
ca352ca341
@ -358,6 +358,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
|
||||
skuKeys.add(GoodsSkuService.getStockCacheKey(orderItem.getSkuId()));
|
||||
GoodsSku goodsSku = new GoodsSku();
|
||||
goodsSku.setId(orderItem.getSkuId());
|
||||
goodsSku.setGoodsId(orderItem.getGoodsId());
|
||||
goodsSkus.add(goodsSku);
|
||||
}
|
||||
//批量获取商品库存
|
||||
|
@ -506,18 +506,14 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateGoodsStuck(List<GoodsSku> goodsSkus) {
|
||||
//商品id集合 hashset 去重复
|
||||
Set<String> goodsIds = new HashSet<>();
|
||||
for (GoodsSku sku : goodsSkus) {
|
||||
goodsIds.add(sku.getGoodsId());
|
||||
}
|
||||
Map<String, List<GoodsSku>> groupByGoodsIds = goodsSkus.stream().collect(Collectors.groupingBy(GoodsSku::getGoodsId));
|
||||
//获取相关的sku集合
|
||||
LambdaQueryWrapper<GoodsSku> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.in(GoodsSku::getGoodsId, goodsIds);
|
||||
lambdaQueryWrapper.in(GoodsSku::getGoodsId, groupByGoodsIds.keySet());
|
||||
List<GoodsSku> goodsSkuList = this.list(lambdaQueryWrapper);
|
||||
|
||||
//统计每个商品的库存
|
||||
for (String goodsId : goodsIds) {
|
||||
for (String goodsId : groupByGoodsIds.keySet()) {
|
||||
//库存
|
||||
Integer quantity = 0;
|
||||
for (GoodsSku goodsSku : goodsSkuList) {
|
||||
|
@ -117,4 +117,8 @@ public class CartSkuVO extends CartBase implements Serializable {
|
||||
public Map<String, Object> getPromotionMap() {
|
||||
return PromotionTools.filterInvalidPromotionsMap(this.promotionMap);
|
||||
}
|
||||
|
||||
public Map<String, Object> getNotFilterPromotionMap() {
|
||||
return this.promotionMap;
|
||||
}
|
||||
}
|
||||
|
@ -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.PointsGoods;
|
||||
import cn.lili.modules.promotion.entity.vos.CouponVO;
|
||||
import cn.lili.modules.promotion.service.PromotionGoodsService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -63,6 +64,11 @@ public class CheckDataRender implements CartRenderStep {
|
||||
@Autowired
|
||||
private WholesaleService wholesaleService;
|
||||
|
||||
/**
|
||||
* 商品索引
|
||||
*/
|
||||
@Autowired
|
||||
private PromotionGoodsService promotionGoodsService;
|
||||
|
||||
@Override
|
||||
public RenderStepEnums step() {
|
||||
@ -127,6 +133,17 @@ public class CheckDataRender implements CartRenderStep {
|
||||
//设置失效消息
|
||||
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()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.GoodsSalesModeEnum;
|
||||
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.GoodsSkuService;
|
||||
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.promotion.entity.dos.KanjiaActivity;
|
||||
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.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.MemberCouponStatusEnum;
|
||||
import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum;
|
||||
@ -139,7 +136,7 @@ public class CartServiceImpl implements CartService {
|
||||
}
|
||||
CartTypeEnum cartTypeEnum = getCartType(cartType);
|
||||
GoodsSku dataSku = checkGoods(skuId);
|
||||
Map<String, Object> promotionMap = this.getCurrentGoodsPromotion(dataSku, cartType);
|
||||
Map<String, Object> promotionMap = promotionGoodsService.getCurrentGoodsPromotion(dataSku, cartType);
|
||||
|
||||
try {
|
||||
//购物车方式购买需要保存之前的选择,其他方式购买,则直接抹除掉之前的记录
|
||||
@ -554,39 +551,6 @@ public class CartServiceImpl implements CartService {
|
||||
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()));
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import cn.lili.modules.order.order.entity.enums.OrderComplaintStatusEnum;
|
||||
import cn.lili.modules.order.order.entity.enums.OrderItemAfterSaleStatusEnum;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 子订单VO
|
||||
@ -13,6 +14,7 @@ import lombok.Data;
|
||||
* @since 2020-08-17 20:28
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class OrderItemVO {
|
||||
|
||||
@ApiModelProperty(value = "编号")
|
||||
@ -55,17 +57,39 @@ public class OrderItemVO {
|
||||
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.goodsId = goodsId;
|
||||
}
|
||||
|
||||
public void setSkuId(String skuId) {
|
||||
this.skuId = skuId;
|
||||
}
|
||||
|
||||
public void setNum(String num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
this.afterSaleStatus = afterSaleStatus;
|
||||
this.complainStatus = complainStatus;
|
||||
this.commentStatus = commentStatus;
|
||||
}
|
||||
|
||||
public void setGoodsPrice(Double 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;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
package cn.lili.modules.order.order.entity.vo;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
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 io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
@ -135,28 +134,54 @@ public class OrderSimpleVO {
|
||||
private String deliverStatus;
|
||||
|
||||
public List<OrderItemVO> getOrderItems() {
|
||||
if (StringUtils.isEmpty(groupGoodsId)) {
|
||||
if (CharSequenceUtil.isEmpty(groupGoodsId)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<OrderItemVO> orderItemVOS = new ArrayList<>();
|
||||
String[] orderItemsSn = groupOrderItemsSn.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++) {
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化自身状态
|
||||
*/
|
||||
|
@ -3,6 +3,7 @@ package cn.lili.modules.promotion.service;
|
||||
import cn.lili.cache.CachePrefix;
|
||||
import cn.lili.common.enums.PromotionTypeEnum;
|
||||
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.dto.search.PromotionGoodsSearchParams;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 促销商品业务层
|
||||
@ -35,7 +37,7 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
|
||||
/**
|
||||
* 获取某sku所有有效活动
|
||||
*
|
||||
* @param skuId 商品skuId
|
||||
* @param skuId 商品skuId
|
||||
* @param storeIds 店铺id
|
||||
* @return 促销商品集合
|
||||
*/
|
||||
@ -70,7 +72,7 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
|
||||
/**
|
||||
* 获取当前有效时间特定促销类型的促销商品信息
|
||||
*
|
||||
* @param skuId skuId
|
||||
* @param skuId skuId
|
||||
* @param promotionTypes 特定促销类型
|
||||
* @return 促销商品信息
|
||||
*/
|
||||
@ -79,7 +81,7 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
|
||||
/**
|
||||
* 获取当前有效时间特定促销类型的促销商品价格
|
||||
*
|
||||
* @param skuId skuId
|
||||
* @param skuId skuId
|
||||
* @param promotionTypes 特定促销类型
|
||||
* @return 促销商品价格
|
||||
*/
|
||||
@ -154,4 +156,13 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
|
||||
*/
|
||||
void deletePromotionGoods(PromotionGoodsSearchParams searchParams);
|
||||
|
||||
/**
|
||||
* 获取当前商品促销信息
|
||||
*
|
||||
* @param dataSku 商品sku信息
|
||||
* @param cartType 购物车类型
|
||||
* @return 当前商品促销信息
|
||||
*/
|
||||
Map<String, Object> getCurrentGoodsPromotion(GoodsSku dataSku, String cartType);
|
||||
|
||||
}
|
@ -2,10 +2,15 @@ package cn.lili.modules.promotion.serviceimpl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
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.vo.PageVO;
|
||||
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.order.cart.entity.enums.CartTypeEnum;
|
||||
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
|
||||
import cn.lili.modules.promotion.entity.dos.SeckillApply;
|
||||
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.SeckillApplyService;
|
||||
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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 促销商品业务层实现
|
||||
@ -59,6 +63,12 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
@Autowired
|
||||
private GoodsSkuService goodsSkuService;
|
||||
|
||||
@Autowired
|
||||
private GoodsService goodsService;
|
||||
|
||||
@Autowired
|
||||
private EsGoodsIndexService goodsIndexService;
|
||||
|
||||
@Override
|
||||
public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) {
|
||||
|
||||
@ -267,8 +277,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
*/
|
||||
@Override
|
||||
public void deletePromotionGoods(List<String> promotionIds) {
|
||||
LambdaQueryWrapper<PromotionGoods> queryWrapper = new LambdaQueryWrapper<PromotionGoods>()
|
||||
.in(PromotionGoods::getPromotionId, promotionIds);
|
||||
LambdaQueryWrapper<PromotionGoods> queryWrapper = new LambdaQueryWrapper<PromotionGoods>().in(PromotionGoods::getPromotionId, promotionIds);
|
||||
this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
@ -282,4 +291,41 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -44,4 +44,7 @@ public class EsGoodsSearchDTO {
|
||||
@ApiModelProperty(hidden = true)
|
||||
private Map<String, List<String>> notShowCol = new HashMap<>();
|
||||
|
||||
@ApiModelProperty("当前商品skuId,根据当前浏览的商品信息来给用户推荐可能喜欢的商品")
|
||||
private String currentGoodsId;
|
||||
|
||||
}
|
||||
|
@ -363,6 +363,9 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
//对查询条件进行处理
|
||||
this.commonSearch(filterBuilder, searchDTO);
|
||||
|
||||
//智能推荐
|
||||
this.recommended(filterBuilder,searchDTO);
|
||||
|
||||
//未上架的商品不显示
|
||||
filterBuilder.must(QueryBuilders.matchQuery("marketEnable", GoodsStatusEnum.UPPER.name()));
|
||||
//待审核和审核不通过的商品不显示
|
||||
@ -401,6 +404,36 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
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+"*"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询属性处理
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user