commit
41decf1fa1
@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -189,12 +190,15 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
|
|||||||
//如果促销类型需要库存判定,则做对应处理
|
//如果促销类型需要库存判定,则做对应处理
|
||||||
orderItems.forEach(orderItem -> {
|
orderItems.forEach(orderItem -> {
|
||||||
if (orderItem.getPromotionType() != null) {
|
if (orderItem.getPromotionType() != null) {
|
||||||
|
String[] skuPromotions = orderItem.getPromotionType().split(",");
|
||||||
|
for (int i = 0; i < skuPromotions.length; i++) {
|
||||||
|
int currentIndex = i;
|
||||||
//如果此促销有库存概念,则计入
|
//如果此促销有库存概念,则计入
|
||||||
if (PromotionTypeEnum.haveStock(orderItem.getPromotionType())) {
|
Arrays.stream(PromotionTypeEnum.haveStockPromotion).filter(promotionTypeEnum -> promotionTypeEnum.name().equals(skuPromotions[currentIndex]))
|
||||||
|
.findFirst()
|
||||||
PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(orderItem.getPromotionType());
|
.ifPresent(promotionTypeEnum -> {
|
||||||
|
String promotionId = orderItem.getPromotionId().split(",")[currentIndex];
|
||||||
String cacheKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId());
|
String cacheKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, promotionId, orderItem.getSkuId());
|
||||||
|
|
||||||
switch (promotionTypeEnum) {
|
switch (promotionTypeEnum) {
|
||||||
case KANJIA:
|
case KANJIA:
|
||||||
@ -205,12 +209,14 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
|
|||||||
return;
|
return;
|
||||||
case SECKILL:
|
case SECKILL:
|
||||||
case PINTUAN:
|
case PINTUAN:
|
||||||
cache.put(cacheKey, promotionGoodsService.getPromotionGoodsStock(promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId()));
|
cache.put(cacheKey, promotionGoodsService.getPromotionGoodsStock(promotionTypeEnum, promotionId, orderItem.getSkuId()));
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -236,13 +242,17 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
|
|||||||
private void setPromotionStock(List<String> keys, List<String> values, OrderItem sku) {
|
private void setPromotionStock(List<String> keys, List<String> values, OrderItem sku) {
|
||||||
if (sku.getPromotionType() != null) {
|
if (sku.getPromotionType() != null) {
|
||||||
//如果此促销有库存概念,则计入
|
//如果此促销有库存概念,则计入
|
||||||
if (!PromotionTypeEnum.haveStock(sku.getPromotionType())) {
|
String[] skuPromotions = sku.getPromotionType().split(",");
|
||||||
return;
|
for (int i = 0; i < skuPromotions.length; i++) {
|
||||||
|
int currentIndex = i;
|
||||||
|
Arrays.stream(PromotionTypeEnum.haveStockPromotion).filter(promotionTypeEnum -> promotionTypeEnum.name().equals(skuPromotions[currentIndex]))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(promotionTypeEnum -> {
|
||||||
|
keys.add(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, sku.getPromotionId().split(",")[currentIndex], sku.getSkuId()));
|
||||||
|
int num = -sku.getNum();
|
||||||
|
values.add(Integer.toString(num));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(sku.getPromotionType());
|
|
||||||
keys.add(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, sku.getPromotionId(), sku.getSkuId()));
|
|
||||||
int i = -sku.getNum();
|
|
||||||
values.add(Integer.toString(i));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,41 +287,51 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
|
|||||||
goodsSku.setId(orderItem.getSkuId());
|
goodsSku.setId(orderItem.getSkuId());
|
||||||
goodsSku.setGoodsId(orderItem.getGoodsId());
|
goodsSku.setGoodsId(orderItem.getGoodsId());
|
||||||
//如果有促销信息
|
//如果有促销信息
|
||||||
if (null != orderItem.getPromotionType() && null != orderItem.getPromotionId() && PromotionTypeEnum.haveStock(orderItem.getPromotionType())) {
|
if (null != orderItem.getPromotionType() && null != orderItem.getPromotionId()) {
|
||||||
//如果促销有库存信息
|
//如果促销有库存信息
|
||||||
PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(orderItem.getPromotionType());
|
String[] skuPromotions = orderItem.getPromotionType().split(",");
|
||||||
|
for (int i = 0; i < skuPromotions.length; i++) {
|
||||||
|
int currentIndex = i;
|
||||||
|
Arrays.stream(PromotionTypeEnum.haveStockPromotion).filter(promotionTypeEnum -> promotionTypeEnum.name().equals(skuPromotions[currentIndex]))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(promotionTypeEnum -> {
|
||||||
|
//修改砍价商品库存
|
||||||
|
String promotionId = orderItem.getPromotionId().split(",")[currentIndex];
|
||||||
|
|
||||||
//修改砍价商品库存
|
//修改砍价商品库存
|
||||||
if (promotionTypeEnum.equals(PromotionTypeEnum.KANJIA)) {
|
if (promotionTypeEnum.equals(PromotionTypeEnum.KANJIA)) {
|
||||||
KanjiaActivity kanjiaActivity = kanjiaActivityService.getById(orderItem.getPromotionId());
|
KanjiaActivity kanjiaActivity = kanjiaActivityService.getById(promotionId);
|
||||||
KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO = kanjiaActivityGoodsService.getKanjiaGoodsDetail(kanjiaActivity.getKanjiaActivityGoodsId());
|
KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO = kanjiaActivityGoodsService.getKanjiaGoodsDetail(kanjiaActivity.getKanjiaActivityGoodsId());
|
||||||
|
|
||||||
Integer stock = Integer.parseInt(cache.get(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId())).toString());
|
Integer stock = Integer.parseInt(cache.get(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, promotionId, orderItem.getSkuId())).toString());
|
||||||
kanjiaActivityGoodsDTO.setStock(stock);
|
kanjiaActivityGoodsDTO.setStock(stock);
|
||||||
|
|
||||||
kanjiaActivityGoodsService.updateById(kanjiaActivityGoodsDTO);
|
kanjiaActivityGoodsService.updateById(kanjiaActivityGoodsDTO);
|
||||||
//修改积分商品库存
|
//修改积分商品库存
|
||||||
} else if (promotionTypeEnum.equals(PromotionTypeEnum.POINTS_GOODS)) {
|
} else if (promotionTypeEnum.equals(PromotionTypeEnum.POINTS_GOODS)) {
|
||||||
PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsDetail(orderItem.getPromotionId());
|
PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsDetail(promotionId);
|
||||||
Integer stock = Integer.parseInt(cache.get(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId())).toString());
|
Integer stock = Integer.parseInt(cache.get(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, promotionId, orderItem.getSkuId())).toString());
|
||||||
pointsGoodsVO.setActiveStock(stock);
|
pointsGoodsVO.setActiveStock(stock);
|
||||||
pointsGoodsService.updateById(pointsGoodsVO);
|
pointsGoodsService.updateById(pointsGoodsVO);
|
||||||
} else {
|
} else {
|
||||||
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
|
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
|
||||||
searchParams.setPromotionType(promotionTypeEnum.name());
|
searchParams.setPromotionType(promotionTypeEnum.name());
|
||||||
searchParams.setPromotionId(orderItem.getPromotionId());
|
searchParams.setPromotionId(promotionId);
|
||||||
searchParams.setSkuId(orderItem.getSkuId());
|
searchParams.setSkuId(orderItem.getSkuId());
|
||||||
PromotionGoods pGoods = promotionGoodsService.getPromotionsGoods(searchParams);
|
PromotionGoods pGoods = promotionGoodsService.getPromotionsGoods(searchParams);
|
||||||
//记录需要更新的促销库存信息
|
//记录需要更新的促销库存信息
|
||||||
promotionKey.add(
|
promotionKey.add(
|
||||||
PromotionGoodsService.getPromotionGoodsStockCacheKey(
|
PromotionGoodsService.getPromotionGoodsStockCacheKey(
|
||||||
promotionTypeEnum,
|
promotionTypeEnum,
|
||||||
orderItem.getPromotionId(), orderItem.getSkuId())
|
promotionId, orderItem.getSkuId())
|
||||||
);
|
);
|
||||||
if (pGoods != null) {
|
if (pGoods != null) {
|
||||||
promotionGoods.add(pGoods);
|
promotionGoods.add(pGoods);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
goodsSkus.add(goodsSku);
|
goodsSkus.add(goodsSku);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public enum PromotionTypeEnum {
|
|||||||
/**
|
/**
|
||||||
* 有促销库存的活动类型
|
* 有促销库存的活动类型
|
||||||
*/
|
*/
|
||||||
static final PromotionTypeEnum[] haveStockPromotion = new PromotionTypeEnum[]{PINTUAN, SECKILL, KANJIA, POINTS_GOODS};
|
public static final PromotionTypeEnum[] haveStockPromotion = new PromotionTypeEnum[]{PINTUAN, SECKILL, KANJIA, POINTS_GOODS};
|
||||||
|
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|
||||||
|
@ -328,7 +328,11 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (goodsSkuDetail.getGoodsGalleryList() == null || goodsSkuDetail.getGoodsGalleryList().isEmpty()) {
|
||||||
|
goodsSkuDetail.setGoodsGalleryList(goodsVO.getGoodsGalleryList());
|
||||||
|
} else {
|
||||||
goodsSkuDetail.getGoodsGalleryList().addAll(goodsVO.getGoodsGalleryList());
|
goodsSkuDetail.getGoodsGalleryList().addAll(goodsVO.getGoodsGalleryList());
|
||||||
|
}
|
||||||
map.put("data", goodsSkuDetail);
|
map.put("data", goodsSkuDetail);
|
||||||
|
|
||||||
//获取分类
|
//获取分类
|
||||||
|
@ -399,6 +399,8 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
|
|||||||
Object quantity = cache.get(promotionGoodsStockCacheKey);
|
Object quantity = cache.get(promotionGoodsStockCacheKey);
|
||||||
if (quantity != null) {
|
if (quantity != null) {
|
||||||
goodsVO.setQuantity((Integer) quantity);
|
goodsVO.setQuantity((Integer) quantity);
|
||||||
|
} else {
|
||||||
|
cache.put(promotionGoodsStockCacheKey, seckillApply.getQuantity());
|
||||||
}
|
}
|
||||||
seckillGoodsVoS.add(goodsVO);
|
seckillGoodsVoS.add(goodsVO);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user