Commit 085b94f0d0067dc46a1d8d70a3dfee3d809b5691
1 parent
1301eb1c
【BUG】修改结算页面选择电子券全部都是不可用的问题
Showing
7 changed files
with
52 additions
and
23 deletions
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 { | @@ -24,7 +24,7 @@ public class DiscountActivityApiImpl implements DiscountActivityApi { | ||
| 24 | 24 | ||
| 25 | @Override | 25 | @Override |
| 26 | public List<DiscountProductRespDTO> getMatchDiscountProductList(Collection<Long> skuIds) { | 26 | public List<DiscountProductRespDTO> getMatchDiscountProductList(Collection<Long> skuIds) { |
| 27 | - return DiscountActivityConvert.INSTANCE.convertList02(discountActivityService.getMatchDiscountProductList(skuIds)); | 27 | + return discountActivityService.getMatchDiscountProductList(skuIds); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | } | 30 | } |
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 { | @@ -60,8 +60,8 @@ public class AppCouponController { | ||
| 60 | @Operation(summary = "获得匹配指定商品的优惠劵列表", description = "用于下单页,展示优惠劵列表") | 60 | @Operation(summary = "获得匹配指定商品的优惠劵列表", description = "用于下单页,展示优惠劵列表") |
| 61 | public CommonResult<List<AppCouponMatchRespVO>> getMatchCouponList(AppCouponMatchReqVO matchReqVO) { | 61 | public CommonResult<List<AppCouponMatchRespVO>> getMatchCouponList(AppCouponMatchReqVO matchReqVO) { |
| 62 | // todo: 优化:优惠金额倒序 | 62 | // todo: 优化:优惠金额倒序 |
| 63 | - List<CouponDO> list = couponService.getMatchCouponList(getLoginUserId(), matchReqVO); | ||
| 64 | - return success(BeanUtils.toBean(list, AppCouponMatchRespVO.class)); | 63 | + List<AppCouponMatchRespVO> list = couponService.getMatchCouponList(getLoginUserId(), matchReqVO); |
| 64 | + return success(list); | ||
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | @GetMapping("/page") | 67 | @GetMapping("/page") |
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 { | @@ -32,6 +32,8 @@ public interface CouponConvert { | ||
| 32 | 32 | ||
| 33 | CouponRespDTO convert(CouponDO bean); | 33 | CouponRespDTO convert(CouponDO bean); |
| 34 | 34 | ||
| 35 | + AppCouponMatchRespVO convert2(CouponDO bean); | ||
| 36 | + | ||
| 35 | default CouponDO convert(CouponTemplateDO template, Long userId) { | 37 | default CouponDO convert(CouponTemplateDO template, Long userId) { |
| 36 | CouponDO couponDO = new CouponDO() | 38 | CouponDO couponDO = new CouponDO() |
| 37 | .setTemplateId(template.getId()) | 39 | .setTemplateId(template.getId()) |
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<CouponDO> { | @@ -85,19 +85,12 @@ public interface CouponMapper extends BaseMapperX<CouponDO> { | ||
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | default List<CouponDO> selectListByUserIdAndStatusAndUsePriceLeAndProductScope( | 87 | default List<CouponDO> selectListByUserIdAndStatusAndUsePriceLeAndProductScope( |
| 88 | - Long userId, Integer status, Integer usePrice, List<Long> spuIds, List<Long> categoryIds) { | ||
| 89 | - Function<List<Long>, String> productScopeValuesFindInSetFunc = ids -> ids.stream() | ||
| 90 | - .map(id -> StrUtil.format("FIND_IN_SET({}, product_scope_values) ", id)) | ||
| 91 | - .collect(Collectors.joining(" OR ")); | ||
| 92 | - return selectList(new LambdaQueryWrapperX<CouponDO>() | 88 | + Long userId, Integer status) { |
| 89 | + List<CouponDO> couponDOS = selectList(new LambdaQueryWrapperX<CouponDO>() | ||
| 93 | .eq(CouponDO::getUserId, userId) | 90 | .eq(CouponDO::getUserId, userId) |
| 94 | .eq(CouponDO::getStatus, status) | 91 | .eq(CouponDO::getStatus, status) |
| 95 | - .le(CouponDO::getUsePrice, usePrice) // 价格小于等于,满足价格使用条件 | ||
| 96 | - .and(w -> w.eq(CouponDO::getProductScope, PromotionProductScopeEnum.ALL.getScope()) // 商品范围一:全部 | ||
| 97 | - .or(ww -> ww.eq(CouponDO::getProductScope, PromotionProductScopeEnum.SPU.getScope()) // 商品范围二:满足指定商品 | ||
| 98 | - .apply(productScopeValuesFindInSetFunc.apply(spuIds))) | ||
| 99 | - .or(ww -> ww.eq(CouponDO::getProductScope, PromotionProductScopeEnum.CATEGORY.getScope()) // 商品范围三:满足指定分类 | ||
| 100 | - .apply(productScopeValuesFindInSetFunc.apply(categoryIds))))); | 92 | + ); |
| 93 | + return couponDOS; | ||
| 101 | } | 94 | } |
| 102 | 95 | ||
| 103 | default List<CouponDO> selectListByStatusAndValidEndTimeLe(Integer status, LocalDateTime validEndTime) { | 96 | default List<CouponDO> selectListByStatusAndValidEndTimeLe(Integer status, LocalDateTime validEndTime) { |
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; | @@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil; | ||
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; | 6 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; |
| 7 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchReqVO; | 7 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchReqVO; |
| 8 | +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchRespVO; | ||
| 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; |
| 10 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; | 11 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; |
| @@ -178,7 +179,7 @@ public interface CouponService { | @@ -178,7 +179,7 @@ public interface CouponService { | ||
| 178 | * @param matchReqVO 匹配参数 | 179 | * @param matchReqVO 匹配参数 |
| 179 | * @return 优惠券列表 | 180 | * @return 优惠券列表 |
| 180 | */ | 181 | */ |
| 181 | - List<CouponDO> getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO); | 182 | + List<AppCouponMatchRespVO> getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO); |
| 182 | 183 | ||
| 183 | /** | 184 | /** |
| 184 | * 获取用户是否可以领取优惠券 | 185 | * 获取用户是否可以领取优惠券 |
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; | @@ -13,10 +13,12 @@ import cn.iocoder.yudao.module.member.api.user.MemberUserApi; | ||
| 13 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | 13 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 14 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; | 14 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; |
| 15 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchReqVO; | 15 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchReqVO; |
| 16 | +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchRespVO; | ||
| 16 | import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert; | 17 | import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert; |
| 17 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; | 18 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 18 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | 19 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; |
| 19 | import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponMapper; | 20 | import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponMapper; |
| 21 | +import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; | ||
| 20 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; | 22 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; |
| 21 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; | 23 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; |
| 22 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum; | 24 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum; |
| @@ -356,13 +358,45 @@ public class CouponServiceImpl implements CouponService { | @@ -356,13 +358,45 @@ public class CouponServiceImpl implements CouponService { | ||
| 356 | } | 358 | } |
| 357 | 359 | ||
| 358 | @Override | 360 | @Override |
| 359 | - public List<CouponDO> getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO) { | 361 | + public List<AppCouponMatchRespVO> getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO) { |
| 362 | + List<AppCouponMatchRespVO> couponMatchist = new ArrayList<>(); | ||
| 360 | List<CouponDO> list = couponMapper.selectListByUserIdAndStatusAndUsePriceLeAndProductScope(userId, | 363 | List<CouponDO> list = couponMapper.selectListByUserIdAndStatusAndUsePriceLeAndProductScope(userId, |
| 361 | - CouponStatusEnum.UNUSED.getStatus(), | ||
| 362 | - matchReqVO.getPrice(), matchReqVO.getSpuIds(), matchReqVO.getCategoryIds()); | ||
| 363 | - // 兜底逻辑:如果 CouponExpireJob 未执行,status 未变成 EXPIRE ,但是 validEndTime 已经过期了,需要进行过滤 | ||
| 364 | - list.removeIf(coupon -> !LocalDateTimeUtils.isBetween(coupon.getValidStartTime(), coupon.getValidEndTime())); | ||
| 365 | - return list; | 364 | + CouponStatusEnum.UNUSED.getStatus()); |
| 365 | + for (CouponDO couponDO : list) { | ||
| 366 | + AppCouponMatchRespVO appCouponMatchRespVO = CouponConvert.INSTANCE.convert2(couponDO); | ||
| 367 | + Integer productScope = appCouponMatchRespVO.getProductScope(); | ||
| 368 | + List<Long> productScopeValues = appCouponMatchRespVO.getProductScopeValues(); | ||
| 369 | + Integer usePrice = appCouponMatchRespVO.getUsePrice(); | ||
| 370 | + if(matchReqVO.getPrice() < usePrice){ | ||
| 371 | + // 价格小于等于,满足价格使用条件 | ||
| 372 | + appCouponMatchRespVO.setMatch(false); | ||
| 373 | + appCouponMatchRespVO.setDescription("未达到使用门槛"); | ||
| 374 | + }else if(!LocalDateTimeUtils.isBetween(appCouponMatchRespVO.getValidStartTime(), appCouponMatchRespVO.getValidEndTime())) { | ||
| 375 | + //判断时间 | ||
| 376 | + appCouponMatchRespVO.setMatch(false); | ||
| 377 | + appCouponMatchRespVO.setDescription("使用时间未到"); | ||
| 378 | + }else if (PromotionProductScopeEnum.ALL.getScope().equals(productScope)){ | ||
| 379 | + appCouponMatchRespVO.setMatch(true); | ||
| 380 | + }else if (PromotionProductScopeEnum.SPU.getScope().equals(productScope)){ | ||
| 381 | + boolean spu = new HashSet<>(productScopeValues).containsAll(matchReqVO.getSpuIds()); | ||
| 382 | + if(spu){ | ||
| 383 | + appCouponMatchRespVO.setMatch(true); | ||
| 384 | + }else { | ||
| 385 | + appCouponMatchRespVO.setMatch(false); | ||
| 386 | + appCouponMatchRespVO.setDescription("与商品不匹配"); | ||
| 387 | + } | ||
| 388 | + }else if (PromotionProductScopeEnum.CATEGORY.getScope().equals(productScope)){ | ||
| 389 | + boolean category = new HashSet<>(productScopeValues).containsAll(matchReqVO.getCategoryIds()); | ||
| 390 | + if(category){ | ||
| 391 | + appCouponMatchRespVO.setMatch(true); | ||
| 392 | + }else { | ||
| 393 | + appCouponMatchRespVO.setMatch(false); | ||
| 394 | + appCouponMatchRespVO.setDescription("与商品类型不匹配"); | ||
| 395 | + } | ||
| 396 | + } | ||
| 397 | + couponMatchist.add(appCouponMatchRespVO); | ||
| 398 | + } | ||
| 399 | + return couponMatchist; | ||
| 366 | } | 400 | } |
| 367 | 401 | ||
| 368 | @Override | 402 | @Override |
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 { | @@ -43,8 +43,7 @@ public interface AfterSaleConvert { | ||
| 43 | @Mapping(source = "afterSale.orderId", target = "merchantOrderId"), | 43 | @Mapping(source = "afterSale.orderId", target = "merchantOrderId"), |
| 44 | @Mapping(source = "afterSale.id", target = "merchantRefundId"), | 44 | @Mapping(source = "afterSale.id", target = "merchantRefundId"), |
| 45 | @Mapping(source = "afterSale.applyReason", target = "reason"), | 45 | @Mapping(source = "afterSale.applyReason", target = "reason"), |
| 46 | - @Mapping(source = "afterSale.refundPrice", target = "price"), | ||
| 47 | - @Mapping(source = "orderProperties.payAppKey", target = "appKey") | 46 | + @Mapping(source = "afterSale.refundPrice", target = "price") |
| 48 | }) | 47 | }) |
| 49 | PayRefundCreateReqDTO convert(String userIp, AfterSaleDO afterSale); | 48 | PayRefundCreateReqDTO convert(String userIp, AfterSaleDO afterSale); |
| 50 | 49 |