From 085b94f0d0067dc46a1d8d70a3dfee3d809b5691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=97=B4=E8=B4=A7?= <252048765@qq.com> Date: Sat, 14 Sep 2024 19:42:04 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90BUG=E3=80=91=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=BB=93=E7=AE=97=E9=A1=B5=E9=9D=A2=E9=80=89=E6=8B=A9=E7=94=B5?= =?UTF-8?q?=E5=AD=90=E5=88=B8=E5=85=A8=E9=83=A8=E9=83=BD=E6=98=AF=E4=B8=8D?= =?UTF-8?q?=E5=8F=AF=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/discount/DiscountActivityApiImpl.java | 2 +- .../app/coupon/AppCouponController.java | 4 +- .../convert/coupon/CouponConvert.java | 2 + .../dal/mysql/coupon/CouponMapper.java | 15 ++---- .../service/coupon/CouponService.java | 3 +- .../service/coupon/CouponServiceImpl.java | 46 ++++++++++++++++--- .../convert/aftersale/AfterSaleConvert.java | 3 +- 7 files changed, 52 insertions(+), 23 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/discount/DiscountActivityApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/discount/DiscountActivityApiImpl.java index 82b8516f9..9c9d760d0 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/discount/DiscountActivityApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/discount/DiscountActivityApiImpl.java @@ -24,7 +24,7 @@ public class DiscountActivityApiImpl implements DiscountActivityApi { @Override public List getMatchDiscountProductList(Collection skuIds) { - return DiscountActivityConvert.INSTANCE.convertList02(discountActivityService.getMatchDiscountProductList(skuIds)); + return discountActivityService.getMatchDiscountProductList(skuIds); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java index ed19d9141..f4235d9d6 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java @@ -60,8 +60,8 @@ public class AppCouponController { @Operation(summary = "获得匹配指定商品的优惠劵列表", description = "用于下单页,展示优惠劵列表") public CommonResult> getMatchCouponList(AppCouponMatchReqVO matchReqVO) { // todo: 优化:优惠金额倒序 - List list = couponService.getMatchCouponList(getLoginUserId(), matchReqVO); - return success(BeanUtils.toBean(list, AppCouponMatchRespVO.class)); + List list = couponService.getMatchCouponList(getLoginUserId(), matchReqVO); + return success(list); } @GetMapping("/page") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponConvert.java index 542a77e84..eb76395f6 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponConvert.java @@ -32,6 +32,8 @@ public interface CouponConvert { CouponRespDTO convert(CouponDO bean); + AppCouponMatchRespVO convert2(CouponDO bean); + default CouponDO convert(CouponTemplateDO template, Long userId) { CouponDO couponDO = new CouponDO() .setTemplateId(template.getId()) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java index e5f1daf6c..47341c2fa 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java @@ -85,19 +85,12 @@ public interface CouponMapper extends BaseMapperX { } default List selectListByUserIdAndStatusAndUsePriceLeAndProductScope( - Long userId, Integer status, Integer usePrice, List spuIds, List categoryIds) { - Function, String> productScopeValuesFindInSetFunc = ids -> ids.stream() - .map(id -> StrUtil.format("FIND_IN_SET({}, product_scope_values) ", id)) - .collect(Collectors.joining(" OR ")); - return selectList(new LambdaQueryWrapperX() + Long userId, Integer status) { + List couponDOS = selectList(new LambdaQueryWrapperX() .eq(CouponDO::getUserId, userId) .eq(CouponDO::getStatus, status) - .le(CouponDO::getUsePrice, usePrice) // 价格小于等于,满足价格使用条件 - .and(w -> w.eq(CouponDO::getProductScope, PromotionProductScopeEnum.ALL.getScope()) // 商品范围一:全部 - .or(ww -> ww.eq(CouponDO::getProductScope, PromotionProductScopeEnum.SPU.getScope()) // 商品范围二:满足指定商品 - .apply(productScopeValuesFindInSetFunc.apply(spuIds))) - .or(ww -> ww.eq(CouponDO::getProductScope, PromotionProductScopeEnum.CATEGORY.getScope()) // 商品范围三:满足指定分类 - .apply(productScopeValuesFindInSetFunc.apply(categoryIds))))); + ); + return couponDOS; } default List selectListByStatusAndValidEndTimeLe(Integer status, LocalDateTime validEndTime) { diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java index 5fdcd0669..27c392ba4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java @@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchRespVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; @@ -178,7 +179,7 @@ public interface CouponService { * @param matchReqVO 匹配参数 * @return 优惠券列表 */ - List getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO); + List getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO); /** * 获取用户是否可以领取优惠券 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java index 3945aa06b..9c7506d24 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java @@ -13,10 +13,12 @@ import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchRespVO; import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponMapper; +import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum; @@ -356,13 +358,45 @@ public class CouponServiceImpl implements CouponService { } @Override - public List getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO) { + public List getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO) { + List couponMatchist = new ArrayList<>(); List list = couponMapper.selectListByUserIdAndStatusAndUsePriceLeAndProductScope(userId, - CouponStatusEnum.UNUSED.getStatus(), - matchReqVO.getPrice(), matchReqVO.getSpuIds(), matchReqVO.getCategoryIds()); - // 兜底逻辑:如果 CouponExpireJob 未执行,status 未变成 EXPIRE ,但是 validEndTime 已经过期了,需要进行过滤 - list.removeIf(coupon -> !LocalDateTimeUtils.isBetween(coupon.getValidStartTime(), coupon.getValidEndTime())); - return list; + CouponStatusEnum.UNUSED.getStatus()); + for (CouponDO couponDO : list) { + AppCouponMatchRespVO appCouponMatchRespVO = CouponConvert.INSTANCE.convert2(couponDO); + Integer productScope = appCouponMatchRespVO.getProductScope(); + List productScopeValues = appCouponMatchRespVO.getProductScopeValues(); + Integer usePrice = appCouponMatchRespVO.getUsePrice(); + if(matchReqVO.getPrice() < usePrice){ + // 价格小于等于,满足价格使用条件 + appCouponMatchRespVO.setMatch(false); + appCouponMatchRespVO.setDescription("未达到使用门槛"); + }else if(!LocalDateTimeUtils.isBetween(appCouponMatchRespVO.getValidStartTime(), appCouponMatchRespVO.getValidEndTime())) { + //判断时间 + appCouponMatchRespVO.setMatch(false); + appCouponMatchRespVO.setDescription("使用时间未到"); + }else if (PromotionProductScopeEnum.ALL.getScope().equals(productScope)){ + appCouponMatchRespVO.setMatch(true); + }else if (PromotionProductScopeEnum.SPU.getScope().equals(productScope)){ + boolean spu = new HashSet<>(productScopeValues).containsAll(matchReqVO.getSpuIds()); + if(spu){ + appCouponMatchRespVO.setMatch(true); + }else { + appCouponMatchRespVO.setMatch(false); + appCouponMatchRespVO.setDescription("与商品不匹配"); + } + }else if (PromotionProductScopeEnum.CATEGORY.getScope().equals(productScope)){ + boolean category = new HashSet<>(productScopeValues).containsAll(matchReqVO.getCategoryIds()); + if(category){ + appCouponMatchRespVO.setMatch(true); + }else { + appCouponMatchRespVO.setMatch(false); + appCouponMatchRespVO.setDescription("与商品类型不匹配"); + } + } + couponMatchist.add(appCouponMatchRespVO); + } + return couponMatchist; } @Override diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/AfterSaleConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/AfterSaleConvert.java index 01676a6b8..b1f3b2782 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/AfterSaleConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/AfterSaleConvert.java @@ -43,8 +43,7 @@ public interface AfterSaleConvert { @Mapping(source = "afterSale.orderId", target = "merchantOrderId"), @Mapping(source = "afterSale.id", target = "merchantRefundId"), @Mapping(source = "afterSale.applyReason", target = "reason"), - @Mapping(source = "afterSale.refundPrice", target = "price"), - @Mapping(source = "orderProperties.payAppKey", target = "appKey") + @Mapping(source = "afterSale.refundPrice", target = "price") }) PayRefundCreateReqDTO convert(String userIp, AfterSaleDO afterSale);