KKSU
2025-01-08 5503695fd8f8651f849e48a16a2cec8ca359da68
refactor(mall): 优化订单服务中的优惠券和活动商品逻辑

- 移除了优惠券和商品 SKU 的交集计算逻辑
- 添加了活动商品的状态检查
- 删除了样品商品的相关逻辑
1 files modified
37 ■■■■ changed files
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java 37 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -87,6 +87,7 @@
    private final CouponGoodsMapper couponGoodsMapper;
    private final IMallVipConfigService mallVipConfigService;
    private final MallActivityMapper mallActivityMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -294,17 +295,7 @@
            return couponAmountMap;
        }
        Long couponId = mallMemberCoupon.getCouponId();//优惠卷ID
        List<Long> goodsIdsAll = couponGoodsMapper.selectByCouponId(couponId);
        List<MallGoodsSku> skusAll = mallGoodsSkuMapper.selectSkuIdsByGoodsId(goodsIdsAll);//获取该优惠卷绑定的全部商品sku
        Set<Long> skuIdsAll = skusAll.stream().map(MallGoodsSku::getId).collect(Collectors.toSet());//获取该优惠卷绑定的全部商品skuIDS
        Set<Long> skuIds = items.stream().map(AddOrderItemDto::getSkuId).collect(Collectors.toSet());//订单中的全部skuIds
        // 获取交集
        Set<Long> intersection = skuIds.stream()
                .filter(skuIdsAll::contains)
                .collect(Collectors.toSet());
        Set<Long> intersection = items.stream().map(AddOrderItemDto::getSkuId).collect(Collectors.toSet());//订单中的全部skuIds
        if (intersection.isEmpty()) {
            return couponAmountMap;
@@ -1017,22 +1008,6 @@
            if (sku == null) {
                return new FebsResponse().fail().message("购买商品或sku不存在");
            }
//            if("样品".equals(sku.getSample())){
//                List<MallOrderItem> mallOrderItems = mallOrderItemMapper.selectItemBySkuIdUnCancel(sku.getId(), member.getId());
//                if (CollUtil.isNotEmpty(mallOrderItems)) {
//                    return new FebsResponse().fail().message("样品只能购买一次");
//                }
//                Integer cnt = item.getCnt();
//                if(1 < cnt){
//                    return new FebsResponse().fail().message("样品只能购买一件");
//                }
//            }else{
//                //验证用户的等级
//                if(AgentLevelEnum.ZERO_LEVEL.name().equals(member.getLevel())){
//                    return new FebsResponse().fail().message("请先申请成为合伙人");
//                }
//            }
            if (sku.getStock() < item.getCnt()) {
                return new FebsResponse().fail().message(sku.getSkuName() + "库存不足");
            }
@@ -1041,6 +1016,14 @@
            if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
                return new FebsResponse().fail().message(mallGoods.getGoodsName() + "已下架");
            }
            if(GoodsTypeEnum.HUO_DONG.getValue() == mallGoods.getIsNormal()){
                //活动商品判断是否在活动进行中
                MallActivity mallActivity = mallActivityMapper.selectById(mallGoods.getActivityId());
                if(mallActivity == null || mallActivity.getState() != 2){
                    return new FebsResponse().fail().message("活动不在进行中");
                }
            }
        }
        return new FebsResponse().success();