Ver código fonte

【BUG】修改结算页面选择电子券全部都是不可用的问题

痴货 7 meses atrás
pai
commit
085b94f0d0

+ 1 - 1
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<DiscountProductRespDTO> getMatchDiscountProductList(Collection<Long> skuIds) {
-        return DiscountActivityConvert.INSTANCE.convertList02(discountActivityService.getMatchDiscountProductList(skuIds));
+        return discountActivityService.getMatchDiscountProductList(skuIds);
     }
 
 }

+ 2 - 2
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<List<AppCouponMatchRespVO>> getMatchCouponList(AppCouponMatchReqVO matchReqVO) {
         // todo: 优化:优惠金额倒序
-        List<CouponDO> list = couponService.getMatchCouponList(getLoginUserId(), matchReqVO);
-        return success(BeanUtils.toBean(list, AppCouponMatchRespVO.class));
+        List<AppCouponMatchRespVO> list = couponService.getMatchCouponList(getLoginUserId(), matchReqVO);
+        return success(list);
     }
 
     @GetMapping("/page")

+ 2 - 0
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())

+ 4 - 11
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> {
     }
 
     default List<CouponDO> selectListByUserIdAndStatusAndUsePriceLeAndProductScope(
-            Long userId, Integer status, Integer usePrice, List<Long> spuIds, List<Long> categoryIds) {
-        Function<List<Long>, String> productScopeValuesFindInSetFunc = ids -> ids.stream()
-                .map(id -> StrUtil.format("FIND_IN_SET({}, product_scope_values) ", id))
-                .collect(Collectors.joining(" OR "));
-        return selectList(new LambdaQueryWrapperX<CouponDO>()
+            Long userId, Integer status) {
+        List<CouponDO> couponDOS = selectList(new LambdaQueryWrapperX<CouponDO>()
                 .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<CouponDO> selectListByStatusAndValidEndTimeLe(Integer status, LocalDateTime validEndTime) {

+ 2 - 1
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<CouponDO> getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO);
+    List<AppCouponMatchRespVO> getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO);
 
     /**
      * 获取用户是否可以领取优惠券

+ 40 - 6
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<CouponDO> getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO) {
+    public List<AppCouponMatchRespVO> getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO) {
+        List<AppCouponMatchRespVO> couponMatchist = new ArrayList<>();
         List<CouponDO> 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<Long> 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

+ 1 - 2
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);