!277 fix & improve

Merge pull request !277 from OceansDeep/pg
This commit is contained in:
OceansDeep 2023-04-10 10:13:06 +00:00 committed by Gitee
commit 7f202506b5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
18 changed files with 230 additions and 133 deletions

View File

@ -68,6 +68,8 @@ public class MemberAddressBuyerController {
@ApiOperation(value = "修改会员收件地址")
@PutMapping
public ResultMessage<MemberAddress> editShippingAddress(@Valid MemberAddress shippingAddress) {
OperationalJudgment.judgment(memberAddressService.getById(shippingAddress.getId()));
shippingAddress.setMemberId(Objects.requireNonNull(UserContext.getCurrentUser()).getId());
return ResultUtil.data(memberAddressService.updateMemberAddress(shippingAddress));
}

View File

@ -82,6 +82,7 @@ public enum ResultCode {
HAVE_INVALID_SALES_MODEL(11023, "批发规则存在小于等于0的无效数据"),
MUST_HAVE_GOODS_SKU_VALUE(11024, "规格值不能为空!"),
DO_NOT_MATCH_WHOLESALE(11025, "批发商品购买数量不能低于起拍量!"),
GOODS_NOT_ERROR(11026, "商品不存在"),
GOODS_PARAMS_ERROR(11013, "商品参数错误,刷新后重试"),
PHYSICAL_GOODS_NEED_TEMP(11014, "实物商品需选择配送模板"),

View File

@ -12,6 +12,7 @@ import cn.lili.common.enums.ResultCode;
import cn.lili.common.event.TransactionCommitSendMQEvent;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.properties.RocketmqCustomProperties;
import cn.lili.common.security.AuthUser;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.utils.SnowFlake;
import cn.lili.modules.goods.entity.dos.Goods;
@ -29,16 +30,22 @@ import cn.lili.modules.goods.entity.vos.GoodsSkuVO;
import cn.lili.modules.goods.entity.vos.GoodsVO;
import cn.lili.modules.goods.entity.vos.SpecValueVO;
import cn.lili.modules.goods.mapper.GoodsSkuMapper;
import cn.lili.modules.goods.service.*;
import cn.lili.modules.goods.service.GoodsGalleryService;
import cn.lili.modules.goods.service.GoodsService;
import cn.lili.modules.goods.service.GoodsSkuService;
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.member.entity.dos.FootPrint;
import cn.lili.modules.member.entity.dto.EvaluationQueryParams;
import cn.lili.modules.member.entity.enums.EvaluationGradeEnum;
import cn.lili.modules.member.service.MemberEvaluationService;
import cn.lili.modules.promotion.entity.dos.Coupon;
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams;
import cn.lili.modules.promotion.entity.enums.CouponGetEnum;
import cn.lili.modules.promotion.service.CouponService;
import cn.lili.modules.promotion.service.MemberCouponService;
import cn.lili.modules.promotion.service.PromotionGoodsService;
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
import cn.lili.modules.search.service.EsGoodsIndexService;
@ -80,7 +87,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
* 分类
*/
@Autowired
private CategoryService categoryService;
private MemberCouponService memberCouponService;
/**
* 商品相册
*/
@ -121,6 +128,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
@Autowired
private WholesaleService wholesaleService;
@Autowired
private CouponService couponService;
@Autowired
private List<SalesModelRender> salesModelRenders;
@ -166,7 +176,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
//发送mq消息
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.SKU_DELETE.name();
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(oldSkuIds), RocketmqSendCallbackBuilder.commonCallback());
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(oldSkuIds),
RocketmqSendCallbackBuilder.commonCallback());
} else {
skuList = new ArrayList<>();
for (Map<String, Object> map : goodsOperationDTO.getSkuList()) {
@ -176,14 +187,15 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
//如果商品状态值不对则es索引移除
if (goods.getAuthFlag().equals(GoodsAuthEnum.PASS.name()) && goods.getMarketEnable().equals(GoodsStatusEnum.UPPER.name())) {
goodsIndexService.deleteIndexById(sku.getId());
this.clearCache(sku.getId());
}
this.clearCache(sku.getId());
}
}
if (!skuList.isEmpty()) {
LambdaQueryWrapper<GoodsSku> unnecessarySkuIdsQuery = new LambdaQueryWrapper<>();
unnecessarySkuIdsQuery.eq(GoodsSku::getGoodsId, goods.getId());
unnecessarySkuIdsQuery.notIn(GoodsSku::getId, skuList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
unnecessarySkuIdsQuery.notIn(GoodsSku::getId,
skuList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
this.remove(unnecessarySkuIdsQuery);
this.saveOrUpdateBatch(skuList);
this.updateStock(skuList);
@ -263,14 +275,16 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
if (goodsVO == null || goodsSku == null) {
//发送mq消息
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name();
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsId)), RocketmqSendCallbackBuilder.commonCallback());
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsId)),
RocketmqSendCallbackBuilder.commonCallback());
throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
}
//商品下架||商品未审核通过||商品删除则提示商品已下架
if (GoodsStatusEnum.DOWN.name().equals(goodsVO.getMarketEnable()) || !GoodsAuthEnum.PASS.name().equals(goodsVO.getAuthFlag()) || Boolean.TRUE.equals(goodsVO.getDeleteFlag())) {
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name();
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsId)), RocketmqSendCallbackBuilder.commonCallback());
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsId)),
RocketmqSendCallbackBuilder.commonCallback());
throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
}
@ -284,15 +298,31 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
GoodsSkuVO goodsSkuDetail = this.getGoodsSkuVO(goodsSku);
Map<String, Object> promotionMap = goodsIndex.getPromotionMap();
AuthUser currentUser = UserContext.getCurrentUser();
//设置当前商品的促销价格
if (promotionMap != null && !promotionMap.isEmpty()) {
promotionMap = promotionMap.entrySet().stream().parallel().filter(i -> {
JSONObject jsonObject = JSONUtil.parseObj(i.getValue());
if (i.getKey().contains(PromotionTypeEnum.COUPON.name()) && currentUser != null) {
Integer couponLimitNum = jsonObject.getInt("couponLimitNum");
Coupon coupon = couponService.getById(jsonObject.getStr("id"));
if (coupon == null || (coupon.getPublishNum() != 0 && coupon.getReceivedNum() >= coupon.getPublishNum())) {
return false;
}
if (couponLimitNum > 0) {
Long count = memberCouponService.getMemberCouponNum(currentUser.getId(), jsonObject.getStr(
"id"));
if (count >= couponLimitNum) {
return false;
}
}
}
// 过滤活动赠送优惠券和无效时间的活动
return (jsonObject.get("getType") == null || jsonObject.get("getType", String.class).equals(CouponGetEnum.FREE.name())) && (jsonObject.get("startTime") != null && jsonObject.get("startTime", Date.class).getTime() <= System.currentTimeMillis()) && (jsonObject.get("endTime") == null || jsonObject.get("endTime", Date.class).getTime() >= System.currentTimeMillis());
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Optional<Map.Entry<String, Object>> containsPromotion = promotionMap.entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())).findFirst();
Optional<Map.Entry<String, Object>> containsPromotion =
promotionMap.entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())).findFirst();
if (containsPromotion.isPresent()) {
JSONObject jsonObject = JSONUtil.parseObj(containsPromotion.get().getValue());
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
@ -312,8 +342,10 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
map.put("data", goodsSkuDetail);
//获取分类
map.put("wholesaleList", GoodsSalesModeEnum.WHOLESALE.name().equals(goodsVO.getSalesModel()) ? wholesaleService.findByGoodsId(goodsSkuDetail.getGoodsId()) : Collections.emptyList());
map.put("categoryName", CharSequenceUtil.isNotEmpty(goodsIndex.getCategoryNamePath()) ? goodsIndex.getCategoryNamePath().split(",") : null);
map.put("wholesaleList", GoodsSalesModeEnum.WHOLESALE.name().equals(goodsVO.getSalesModel()) ?
wholesaleService.findByGoodsId(goodsSkuDetail.getGoodsId()) : Collections.emptyList());
map.put("categoryName", CharSequenceUtil.isNotEmpty(goodsIndex.getCategoryNamePath()) ?
goodsIndex.getCategoryNamePath().split(",") : null);
//获取规格信息
map.put("specs", this.groupBySkuAndSpec(goodsVO.getSkuList()));
@ -325,8 +357,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
}
//记录用户足迹
if (UserContext.getCurrentUser() != null) {
FootPrint footPrint = new FootPrint(UserContext.getCurrentUser().getId(), goodsIndex.getStoreId(), goodsId, skuId);
if (currentUser != null) {
FootPrint footPrint = new FootPrint(currentUser.getId(), goodsIndex.getStoreId(), goodsId, skuId);
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.VIEW_GOODS.name();
rocketMQTemplate.asyncSend(destination, footPrint, RocketmqSendCallbackBuilder.commonCallback());
}
@ -374,10 +406,13 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
boolean update = this.update(updateWrapper);
if (Boolean.TRUE.equals(update)) {
if (GoodsStatusEnum.UPPER.name().equals(marketEnable)) {
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("生成店铺商品", rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.GENERATOR_STORE_GOODS_INDEX.name(), storeId));
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("生成店铺商品",
rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.GENERATOR_STORE_GOODS_INDEX.name(),
storeId));
} else if (GoodsStatusEnum.DOWN.name().equals(marketEnable)) {
cache.vagueDel(CachePrefix.GOODS_SKU.getPrefix());
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("删除店铺商品", rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.STORE_GOODS_DELETE.name(), storeId));
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("删除店铺商品",
rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.STORE_GOODS_DELETE.name(), storeId));
}
}
}
@ -443,9 +478,11 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
if ("images".equals(entry.getKey())) {
specValueVO.setSpecName(entry.getKey());
if (entry.getValue().toString().contains("url")) {
List<SpecValueVO.SpecImages> specImages = JSONUtil.toList(JSONUtil.parseArray(entry.getValue()), SpecValueVO.SpecImages.class);
List<SpecValueVO.SpecImages> specImages = JSONUtil.toList(JSONUtil.parseArray(entry.getValue()),
SpecValueVO.SpecImages.class);
specValueVO.setSpecImage(specImages);
goodsGalleryList = specImages.stream().map(SpecValueVO.SpecImages::getUrl).collect(Collectors.toList());
goodsGalleryList =
specImages.stream().map(SpecValueVO.SpecImages::getUrl).collect(Collectors.toList());
}
} else {
specValueVO.setSpecName(entry.getKey());
@ -496,7 +533,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
goodsIndexService.deleteIndexById(goodsSku.getId());
}
goodsSku.setQuantity(quantity);
boolean update = this.update(new LambdaUpdateWrapper<GoodsSku>().eq(GoodsSku::getId, skuId).set(GoodsSku::getQuantity, quantity));
boolean update =
this.update(new LambdaUpdateWrapper<GoodsSku>().eq(GoodsSku::getId, skuId).set(GoodsSku::getQuantity, quantity));
if (update) {
cache.remove(CachePrefix.GOODS.getPrefix() + goodsSku.getGoodsId());
}
@ -527,7 +565,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
@Override
@Transactional(rollbackFor = Exception.class)
public void updateGoodsStuck(List<GoodsSku> goodsSkus) {
Map<String, List<GoodsSku>> groupByGoodsIds = goodsSkus.stream().collect(Collectors.groupingBy(GoodsSku::getGoodsId));
Map<String, List<GoodsSku>> groupByGoodsIds =
goodsSkus.stream().collect(Collectors.groupingBy(GoodsSku::getGoodsId));
//获取相关的sku集合
LambdaQueryWrapper<GoodsSku> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.in(GoodsSku::getGoodsId, groupByGoodsIds.keySet());
@ -572,9 +611,14 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
//修改规格索引,发送mq消息
Map<String, Object> updateIndexFieldsMap = EsIndexUtil.getUpdateIndexFieldsMap(MapUtil.builder(new HashMap<String, Object>()).put("id", goodsSku.getId()).build(), MapUtil.builder(new HashMap<String, Object>()).put("commentNum", goodsSku.getCommentNum()).put("highPraiseNum", highPraiseNum).put("grade", grade).build());
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name();
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(updateIndexFieldsMap), RocketmqSendCallbackBuilder.commonCallback());
Map<String, Object> updateIndexFieldsMap =
EsIndexUtil.getUpdateIndexFieldsMap(MapUtil.builder(new HashMap<String, Object>()).put("id",
goodsSku.getId()).build(), MapUtil.builder(new HashMap<String, Object>()).put("commentNum",
goodsSku.getCommentNum()).put("highPraiseNum", highPraiseNum).put("grade", grade).build());
String destination =
rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name();
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(updateIndexFieldsMap),
RocketmqSendCallbackBuilder.commonCallback());
//修改商品的评价数量
goodsService.updateGoodsCommentNum(goodsSku.getGoodsId());
@ -608,11 +652,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
public Long countSkuNum(String storeId) {
LambdaQueryWrapper<GoodsSku> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.eq(GoodsSku::getStoreId, storeId)
.eq(GoodsSku::getDeleteFlag, Boolean.FALSE)
.eq(GoodsSku::getAuthFlag, GoodsAuthEnum.PASS.name())
.eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name());
queryWrapper.eq(GoodsSku::getStoreId, storeId).eq(GoodsSku::getDeleteFlag, Boolean.FALSE).eq(GoodsSku::getAuthFlag, GoodsAuthEnum.PASS.name()).eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name());
return this.count(queryWrapper);
}

View File

@ -69,9 +69,7 @@ public class MemberAddressServiceImpl extends ServiceImpl<MemberAddressMapper, M
@Transactional(rollbackFor = Exception.class)
public MemberAddress updateMemberAddress(MemberAddress memberAddress) {
MemberAddress originalMemberAddress = this.getMemberAddress(memberAddress.getId());
if (originalMemberAddress != null &&
originalMemberAddress.getMemberId().equals(Objects.requireNonNull(UserContext.getCurrentUser()).getId())) {
if (originalMemberAddress != null) {
if (memberAddress.getIsDefault() == null) {
memberAddress.setIsDefault(false);
}

View File

@ -120,6 +120,9 @@ public class CheckDataRender implements CartRenderStep {
if (checkGoodsStatus || checkGoodsValid) {
if (checkGoodsValid) {
cartSkuVO.rebuildBySku(dataSku);
}
if (checkGoodsStatus) {
//设置购物车未选中
cartSkuVO.setChecked(false);
@ -127,10 +130,9 @@ public class CheckDataRender implements CartRenderStep {
cartSkuVO.setInvalid(true);
//设置失效消息
cartSkuVO.setErrorMessage("商品已下架");
continue;
}
if (checkGoodsValid) {
cartSkuVO.rebuildBySku(dataSku);
}
}
//商品库存判定

View File

@ -128,4 +128,11 @@ public interface AbstractPromotionsService<T extends BasePromotions> extends ISe
*/
PromotionTypeEnum getPromotionType();
/**
* 是否允许同一时间内存在相同的促销
*
* @return 是否允许同一时间内存在相同的促销
*/
boolean allowExistSame();
}

View File

@ -165,4 +165,9 @@ public interface MemberCouponService extends IService<MemberCoupon> {
*/
Page<MemberCouponVO> getMemberCouponsPage(Page<MemberCoupon> page, MemberCouponSearchParams param);
/**
* 获取会员领取过的优惠券数量
*/
long getMemberCouponNum(String memberId, String couponId);
}

View File

@ -192,6 +192,9 @@ public abstract class AbstractPromotionsServiceImpl<M extends BaseMapper<T>, T e
@Override
public void checkPromotions(T promotions) {
PromotionTools.checkPromotionTime(promotions.getStartTime(), promotions.getEndTime());
if (!this.allowExistSame()) {
this.checkSamePromotions(promotions);
}
}
/**
@ -264,4 +267,21 @@ public abstract class AbstractPromotionsServiceImpl<M extends BaseMapper<T>, T e
}
}
@Override
public boolean allowExistSame() {
return false;
}
public void checkSamePromotions(T promotions) {
if (promotions.getStartTime() == null || promotions.getEndTime() == null) {
return;
}
QueryWrapper<T> queryWrapper = PromotionTools.checkActiveTime(promotions.getStartTime(), promotions.getEndTime(), this.getPromotionType(), promotions.getStoreId(), promotions.getId());
long sameNum = this.count(queryWrapper);
//当前时间段是否存在同类活动
if (sameNum > 0) {
throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST);
}
}
}

View File

@ -310,11 +310,11 @@ public class CouponServiceImpl extends AbstractPromotionsServiceImpl<CouponMappe
*/
private void checkCouponPortionGoods(CouponVO coupon) {
String[] split = coupon.getScopeId().split(",");
if (split.length <= 0) {
if (split.length == 0) {
throw new ServiceException(ResultCode.COUPON_SCOPE_ERROR);
}
for (String id : split) {
GoodsSku goodsSku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(id);
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(id);
if (goodsSku == null) {
throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
}

View File

@ -23,7 +23,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
/**
@ -95,8 +94,6 @@ public class FullDiscountServiceImpl extends AbstractPromotionsServiceImpl<FullD
PromotionTools.checkPromotionTime(fullDiscountVO.getStartTime(), fullDiscountVO.getEndTime());
}
//当前时间段是否存在同类活动
this.checkSameActiveExist(promotions.getStartTime(), promotions.getEndTime(), promotions.getStoreId(), promotions.getId());
//检查满减参数
this.checkFullDiscount(promotions);
@ -112,11 +109,11 @@ public class FullDiscountServiceImpl extends AbstractPromotionsServiceImpl<FullD
@Transactional(rollbackFor = {Exception.class})
public boolean updatePromotionsGoods(FullDiscount promotions) {
boolean result = super.updatePromotionsGoods(promotions);
if (!PromotionsStatusEnum.CLOSE.name().equals(promotions.getPromotionStatus())
&& PromotionsScopeTypeEnum.PORTION_GOODS.name().equals(promotions.getScopeType())
&& promotions instanceof FullDiscountVO) {
if (!PromotionsStatusEnum.CLOSE.name().equals(promotions.getPromotionStatus()) && PromotionsScopeTypeEnum.PORTION_GOODS.name().equals(promotions.getScopeType()) && promotions instanceof FullDiscountVO) {
FullDiscountVO fullDiscountVO = (FullDiscountVO) promotions;
List<PromotionGoods> promotionGoodsList = PromotionTools.promotionGoodsInit(fullDiscountVO.getPromotionGoodsList(), fullDiscountVO, PromotionTypeEnum.FULL_DISCOUNT);
List<PromotionGoods> promotionGoodsList =
PromotionTools.promotionGoodsInit(fullDiscountVO.getPromotionGoodsList(), fullDiscountVO,
PromotionTypeEnum.FULL_DISCOUNT);
this.promotionGoodsService.deletePromotionGoods(Collections.singletonList(promotions.getId()));
//促销活动商品更新
result = this.promotionGoodsService.saveBatch(promotionGoodsList);
@ -166,8 +163,7 @@ public class FullDiscountServiceImpl extends AbstractPromotionsServiceImpl<FullD
* @param fullDiscount 满减参数信息
*/
private void checkFullDiscount(FullDiscount fullDiscount) {
if (fullDiscount.getFullMinusFlag() == null && fullDiscount.getCouponFlag() == null && fullDiscount.getGiftFlag() == null
&& fullDiscount.getPointFlag() == null && fullDiscount.getFullRateFlag() == null) {
if (fullDiscount.getFullMinusFlag() == null && fullDiscount.getCouponFlag() == null && fullDiscount.getGiftFlag() == null && fullDiscount.getPointFlag() == null && fullDiscount.getFullRateFlag() == null) {
throw new ServiceException(ResultCode.FULL_DISCOUNT_WAY_ERROR);
}
//如果优惠方式是满减
@ -199,23 +195,6 @@ public class FullDiscountServiceImpl extends AbstractPromotionsServiceImpl<FullD
}
/**
* 检查同一时间段内不能存在相同的活动数量
*
* @param statTime 开始时间
* @param endTime 结束时间
* @param storeId 店铺id
* @param id 满优惠活动ID
*/
private void checkSameActiveExist(Date statTime, Date endTime, String storeId, String id) {
//同一时间段内相同的活动
QueryWrapper<FullDiscount> queryWrapper = PromotionTools.checkActiveTime(statTime, endTime, PromotionTypeEnum.FULL_DISCOUNT, storeId, id);
long sameNum = this.count(queryWrapper);
if (sameNum > 0) {
throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST);
}
}
/**
* 检查优惠券信息
*

View File

@ -327,6 +327,14 @@ public class MemberCouponServiceImpl extends ServiceImpl<MemberCouponMapper, Mem
return this.baseMapper.getMemberCoupons(page, queryWrapper);
}
@Override
public long getMemberCouponNum(String memberId, String couponId) {
LambdaQueryWrapper<MemberCoupon> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MemberCoupon::getMemberId, memberId);
queryWrapper.eq(MemberCoupon::getCouponId, couponId);
return this.count(queryWrapper);
}
/**
* 清除无效的会员优惠券
*

View File

@ -31,12 +31,10 @@ import cn.lili.trigger.interfaces.TimeTrigger;
import cn.lili.trigger.model.TimeExecuteConstant;
import cn.lili.trigger.model.TimeTriggerMsg;
import cn.lili.trigger.util.DelayQueueTools;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@ -156,48 +154,6 @@ public class PintuanServiceImpl extends AbstractPromotionsServiceImpl<PintuanMap
return pintuanShareVO;
}
/**
* 更新促销状态
* 如果要更新促销状态为关闭startTime和endTime置为空即可
*
* @param ids 促销id集合
* @param startTime 开始时间
* @param endTime 结束时间
* @return 是否更新成功
*/
@Override
public boolean updateStatus(List<String> ids, Long startTime, Long endTime) {
if (startTime != null && endTime != null) {
for (String id : ids) {
Pintuan pintuan = this.getById(id);
QueryWrapper<Pintuan> queryWrapper = PromotionTools.checkActiveTime(new Date(startTime), new Date(endTime), PromotionTypeEnum.PINTUAN, pintuan.getStoreId(), id);
long sameNum = this.count(queryWrapper);
//当前时间段是否存在同类活动
if (sameNum > 0) {
throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST);
}
}
}
return super.updateStatus(ids, startTime, endTime);
}
/**
* 检查促销参数
*
* @param promotions 促销实体
*/
@Override
public void checkPromotions(Pintuan promotions) {
QueryWrapper<Pintuan> queryWrapper = PromotionTools.checkActiveTime(promotions.getStartTime(), promotions.getEndTime(), PromotionTypeEnum.PINTUAN, promotions.getStoreId(), promotions.getId());
long sameNum = this.count(queryWrapper);
//当前时间段是否存在同类活动
if (sameNum > 0) {
throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST);
}
super.checkPromotions(promotions);
}
/**
* 更新促销商品信息
*

View File

@ -74,7 +74,8 @@ public class PointsGoodsServiceImpl extends AbstractPromotionsServiceImpl<Points
if (this.checkSkuDuplicate(pointsGoods.getSkuId(), null) == null) {
pointsGoods.setPromotionName("积分商品活动");
} else {
throw new ServiceException("商品id为" + pointsGoods.getSkuId() + "的商品已参加积分商品活动!");
throw new ServiceException(ResultCode.PROMOTION_LOG_EXIST, "商品id为" + pointsGoods.getSkuId() +
"的商品已参加积分商品活动!");
}
GoodsSku goodsSku = this.checkSkuExist(pointsGoods.getSkuId());
pointsGoods.setStoreId(goodsSku.getStoreId());

View File

@ -262,17 +262,6 @@ public class SeckillServiceImpl extends AbstractPromotionsServiceImpl<SeckillMap
promotions.setStartTime(DateUtil.parse(startTimeStr, DatePattern.NORM_DATETIME_MINUTE_PATTERN));
promotions.setEndTime(DateUtil.endOfDay(promotions.getStartTime()));
}
if (promotions.getStartTime() != null && promotions.getEndTime() != null) {
//同一时间段内相同的活动
QueryWrapper<Seckill> queryWrapper = PromotionTools.checkActiveTime(promotions.getStartTime(), promotions.getEndTime(), PromotionTypeEnum.SECKILL, null, promotions.getId());
long sameNum = this.count(queryWrapper);
//当前时间段是否存在同类活动
if (sameNum > 0) {
throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST);
}
}
}
/**

View File

@ -34,6 +34,10 @@ public class PromotionTools {
public static final String PLATFORM_ID = "0";
public static final String PLATFORM_NAME = "platform";
private PromotionTools() {
throw new IllegalStateException("Utility class");
}
/**
* 参数验证
* 1活动起始时间必须大于当前时间
@ -87,13 +91,43 @@ public class PromotionTools {
} else {
queryWrapper.ge(START_TIME_COLUMN, DateUtil.beginOfDay(startTime)).le(END_TIME_COLUMN, DateUtil.endOfDay(endTime));
}
queryWrapper.eq(CharSequenceUtil.isNotEmpty(storeId), "store_id", storeId);
queryWrapper.ne(CharSequenceUtil.isNotEmpty(activityId), "id", activityId);
if (storeId != null) {
queryWrapper.eq("store_id", storeId);
}
if (activityId != null) {
queryWrapper.ne("id", activityId);
}
queryWrapper.and(i -> i.or(queryPromotionStatus(PromotionsStatusEnum.NEW)).or(queryPromotionStatus(PromotionsStatusEnum.START)));
queryWrapper.eq("delete_flag", false);
return queryWrapper;
}
/**
* 检查商品是否重复参加同类型活动
*
* @param exceptType 排除的促销活动类型可同时参加的活动类型
* @param skuIds 商品skuId
* @param activityId 当前活动id
* @return mybatis plus query wrapper对象
*/
public static QueryWrapper<PromotionGoods> checkSkuDuplicate(List<PromotionTypeEnum> exceptType, List<String> skuIds, String activityId) {
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
if (skuIds != null && !skuIds.isEmpty()) {
queryWrapper.in("sku_id", skuIds);
}
if (CharSequenceUtil.isNotEmpty(activityId)) {
queryWrapper.ne("id", activityId);
}
queryWrapper.and(i -> i.or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)).or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.NEW)));
if (exceptType != null) {
queryWrapper.notIn(!exceptType.isEmpty(), "promotion_type", exceptType.stream().map(PromotionTypeEnum::name).collect(Collectors.toList()));
}
queryWrapper.eq("delete_flag", false);
return queryWrapper;
}
public static <T> Consumer<QueryWrapper<T>> queryPromotionStatus(PromotionsStatusEnum promotionsStatusEnum) {
switch (promotionsStatusEnum) {
@ -158,6 +192,12 @@ public class PromotionTools {
return nextHour;
}
/**
* 过滤无效促销活动
*
* @param map 促销活动map
* @return 过滤后的促销活动map
*/
public static Map<String, Object> filterInvalidPromotionsMap(Map<String, Object> map) {
if (CollUtil.isEmpty(map)) {
return new HashMap<>();
@ -173,9 +213,22 @@ public class PromotionTools {
return i.getValue() != null;
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> newValue));
} catch (Exception e) {
log.error("过滤无效促销活动出现异常。异常促销信息:{},异常信息{} ", map, e);
log.error("过滤无效促销活动出现异常。异常促销信息:{},异常信息 ", map, e);
return new HashMap<>();
}
}
/**
* 是否为需要检查的促销活动类型(用于判定部分类型的商品不能参与活动的条件)
* 内容为不需要检查的促销活动类型
*
* @param key 促销key
* @return 当前促销key是否存在
*/
public static boolean isPromotionsTypeNeedsToChecked(String key) {
return !CharSequenceUtil.containsAny(key,
PromotionTypeEnum.COUPON.name(),
PromotionTypeEnum.FULL_DISCOUNT.name());
}
}

View File

@ -58,6 +58,24 @@ public class EsGoodsSearchDTO {
@ApiModelProperty(value = "促销活动id")
private String promotionsId;
/**
* @see cn.lili.modules.goods.entity.enums.GoodsTypeEnum
*/
@ApiModelProperty(value = "商品类型")
private String goodsType;
@ApiModelProperty("销售模式")
private String salesModel;
/**
* @see cn.lili.modules.goods.entity.enums.GoodsTypeEnum
*/
@ApiModelProperty(value = "除了当前商品类型之外")
private String neGoodsType;
@ApiModelProperty("除了销售模式当前销售模式之外")
private String neSalesModel;
//过滤搜索关键字
public String getKeyword() {
if (CharSequenceUtil.isNotEmpty(keyword)) {

View File

@ -22,6 +22,7 @@ import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
import cn.lili.modules.goods.entity.dto.GoodsSkuDTO;
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.service.BrandService;
import cn.lili.modules.goods.service.CategoryService;
@ -542,6 +543,10 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
public UpdateRequest updateEsGoodsIndexPromotions(String id, BasePromotions promotion, String key) {
EsGoodsIndex goodsIndex = findById(id);
if (goodsIndex != null) {
// 批发商品不参与促销除优惠券和满减
if (PromotionTools.isPromotionsTypeNeedsToChecked(key) && GoodsSalesModeEnum.WHOLESALE.name().equals(goodsIndex.getSalesModel())) {
return null;
}
//更新索引
return this.updateGoodsIndexPromotion(goodsIndex, key, promotion);
} else {
@ -610,24 +615,23 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
private void executeUpdateEsGoodsIndexAll(BasePromotions promotion, String key) {
for (int i = 0; ; i++) {
List<String> skuIds;
PageVO pageVO = new PageVO();
pageVO.setPageNumber(i);
pageVO.setPageSize(1000);
EsGoodsSearchDTO searchDTO = new EsGoodsSearchDTO();
if (PromotionTools.isPromotionsTypeNeedsToChecked(key)) {
searchDTO.setSalesModel(GoodsSalesModeEnum.RETAIL.name());
}
//如果storeId不为空则表示是店铺活动
if (promotion.getStoreId() != null && !promotion.getStoreId().equals(PromotionTools.PLATFORM_ID)) {
PageVO pageVO = new PageVO();
pageVO.setPageNumber(i);
pageVO.setPageSize(1000);
EsGoodsSearchDTO searchDTO = new EsGoodsSearchDTO();
searchDTO.setStoreId(promotion.getStoreId());
//查询出店铺商品
SearchPage<EsGoodsIndex> esGoodsIndices = goodsSearchService.searchGoods(searchDTO, pageVO);
skuIds = esGoodsIndices.isEmpty() ? new ArrayList<>() : esGoodsIndices.getContent().stream().map(SearchHit::getId).collect(Collectors.toList());
} else {
//否则是平台活动
org.springframework.data.domain.Page<EsGoodsIndex> all = goodsIndexRepository.findAll(PageRequest.of(i, 1000));
//查询出全部商品
skuIds = all.isEmpty() ? new ArrayList<>() : all.toList().stream().map(EsGoodsIndex::getId).collect(Collectors.toList());
}
//查询出店铺商品
SearchPage<EsGoodsIndex> esGoodsIndices = goodsSearchService.searchGoods(searchDTO, pageVO);
skuIds = esGoodsIndices.isEmpty() ? new ArrayList<>() :
esGoodsIndices.getContent().stream().map(SearchHit::getId).collect(Collectors.toList());
if (skuIds.isEmpty()) {
break;
}

View File

@ -466,6 +466,20 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
if (searchDTO.getRecommend() != null) {
filterBuilder.filter(QueryBuilders.termQuery("recommend", searchDTO.getRecommend()));
}
// 商品类型判定
if (CharSequenceUtil.isNotEmpty(searchDTO.getGoodsType())) {
filterBuilder.filter(QueryBuilders.termQuery("goodsType", searchDTO.getGoodsType()));
}
if (CharSequenceUtil.isNotEmpty(searchDTO.getNeGoodsType())) {
filterBuilder.mustNot(QueryBuilders.termQuery("goodsType", searchDTO.getNeGoodsType()));
}
// 销售类型判定
if (CharSequenceUtil.isNotEmpty(searchDTO.getSalesModel())) {
filterBuilder.filter(QueryBuilders.termQuery("salesModel", searchDTO.getSalesModel()));
}
if (CharSequenceUtil.isNotEmpty(searchDTO.getNeSalesModel())) {
filterBuilder.mustNot(QueryBuilders.termQuery("salesModel", searchDTO.getNeSalesModel()));
}
//规格项判定
if (searchDTO.getNameIds() != null && !searchDTO.getNameIds().isEmpty()) {
filterBuilder.must(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.termsQuery("attrList.nameId", searchDTO.getNameIds()), ScoreMode.None));