Commit ce9f00edef1f9909288641140b0e8e386146860b
1 parent
6f740fab
【功能完善】商城:App 满减送活动的详情,增加 description 规则描述
Showing
7 changed files
with
67 additions
and
33 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/vo/RewardActivityBaseVO.java
| @@ -88,6 +88,7 @@ public class RewardActivityBaseVO { | @@ -88,6 +88,7 @@ public class RewardActivityBaseVO { | ||
| 88 | return point == null || point >= 0; | 88 | return point == null || point >= 0; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | + | ||
| 91 | } | 92 | } |
| 92 | 93 | ||
| 93 | @AssertTrue(message = "商品范围编号的数组不能为空") | 94 | @AssertTrue(message = "商品范围编号的数组不能为空") |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/reward/AppRewardActivityController.java
| @@ -30,8 +30,18 @@ public class AppRewardActivityController { | @@ -30,8 +30,18 @@ public class AppRewardActivityController { | ||
| 30 | @Operation(summary = "获得满减送活动") | 30 | @Operation(summary = "获得满减送活动") |
| 31 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 31 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 32 | public CommonResult<AppRewardActivityRespVO> getRewardActivity(@RequestParam("id") Long id) { | 32 | public CommonResult<AppRewardActivityRespVO> getRewardActivity(@RequestParam("id") Long id) { |
| 33 | - RewardActivityDO rewardActivity = rewardActivityService.getRewardActivity(id); | ||
| 34 | - return success(BeanUtils.toBean(rewardActivity, AppRewardActivityRespVO.class)); | 33 | + RewardActivityDO activity = rewardActivityService.getRewardActivity(id); |
| 34 | + if (activity == null) { | ||
| 35 | + return success(null); | ||
| 36 | + } | ||
| 37 | + // 拼接 Rule 描述 | ||
| 38 | + AppRewardActivityRespVO activityVO = BeanUtils.toBean(activity, AppRewardActivityRespVO.class); | ||
| 39 | + for (int i = 0; i < activityVO.getRules().size(); i++) { | ||
| 40 | + AppRewardActivityRespVO.Rule ruleVO = activityVO.getRules().get(i); | ||
| 41 | + RewardActivityDO.Rule rule = activity.getRules().get(i); | ||
| 42 | + ruleVO.setDescription(rewardActivityService.getRewardActivityRuleDescription(activity.getConditionType(), rule)); | ||
| 43 | + } | ||
| 44 | + return success(activityVO); | ||
| 35 | } | 45 | } |
| 36 | 46 | ||
| 37 | } | 47 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/reward/vo/AppRewardActivityRespVO.java
| @@ -36,6 +36,15 @@ public class AppRewardActivityRespVO { | @@ -36,6 +36,15 @@ public class AppRewardActivityRespVO { | ||
| 36 | private List<Long> productScopeValues; | 36 | private List<Long> productScopeValues; |
| 37 | 37 | ||
| 38 | @Schema(description = "优惠规则的数组") | 38 | @Schema(description = "优惠规则的数组") |
| 39 | - private List<RewardActivityBaseVO.Rule> rules; | 39 | + private List<Rule> rules; |
| 40 | + | ||
| 41 | + @Schema(description = "优惠规则") | ||
| 42 | + @Data | ||
| 43 | + public static class Rule extends RewardActivityBaseVO.Rule { | ||
| 44 | + | ||
| 45 | + @Schema(description = "规则描述") | ||
| 46 | + private String description; // 通过 {@link #limit}、{@link #discountPrice} 等字段进行拼接 | ||
| 47 | + | ||
| 48 | + } | ||
| 40 | 49 | ||
| 41 | } | 50 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityService.java
| 1 | package cn.iocoder.yudao.module.promotion.service.reward; | 1 | package cn.iocoder.yudao.module.promotion.service.reward; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.hutool.core.util.StrUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | ||
| 4 | import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO; | 7 | import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO; |
| 5 | import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityCreateReqVO; | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityCreateReqVO; |
| 6 | import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityPageReqVO; | 9 | import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityPageReqVO; |
| 7 | import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO; | 10 | import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO; |
| 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | 11 | import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; |
| 12 | +import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum; | ||
| 9 | import jakarta.validation.Valid; | 13 | import jakarta.validation.Valid; |
| 10 | 14 | ||
| 15 | +import java.util.ArrayList; | ||
| 11 | import java.util.Collection; | 16 | import java.util.Collection; |
| 12 | import java.util.List; | 17 | import java.util.List; |
| 13 | 18 | ||
| 19 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; | ||
| 20 | + | ||
| 14 | /** | 21 | /** |
| 15 | * 满减送活动 Service 接口 | 22 | * 满减送活动 Service 接口 |
| 16 | * | 23 | * |
| @@ -71,4 +78,28 @@ public interface RewardActivityService { | @@ -71,4 +78,28 @@ public interface RewardActivityService { | ||
| 71 | */ | 78 | */ |
| 72 | List<RewardActivityMatchRespDTO> getMatchRewardActivityListBySpuIds(Collection<Long> spuIds); | 79 | List<RewardActivityMatchRespDTO> getMatchRewardActivityListBySpuIds(Collection<Long> spuIds); |
| 73 | 80 | ||
| 81 | + default String getRewardActivityRuleDescription(Integer conditionType, RewardActivityDO.Rule rule) { | ||
| 82 | + String description = ""; | ||
| 83 | + if (PromotionConditionTypeEnum.PRICE.getType().equals(conditionType)) { | ||
| 84 | + description += StrUtil.format("满 {} 元", MoneyUtils.fenToYuanStr(rule.getLimit())); | ||
| 85 | + } else { | ||
| 86 | + description += StrUtil.format("满 {} 件", rule.getLimit()); | ||
| 87 | + } | ||
| 88 | + List<String> tips = new ArrayList<>(10); | ||
| 89 | + if (rule.getDiscountPrice() != null) { | ||
| 90 | + tips.add(StrUtil.format("减 {}", MoneyUtils.fenToYuanStr(rule.getDiscountPrice()))); | ||
| 91 | + } | ||
| 92 | + if (Boolean.TRUE.equals(rule.getFreeDelivery())) { | ||
| 93 | + tips.add("包邮"); | ||
| 94 | + } | ||
| 95 | + if (rule.getPoint() != null && rule.getPoint() > 0) { | ||
| 96 | + tips.add(StrUtil.format("送 {} 积分", rule.getPoint())); | ||
| 97 | + } | ||
| 98 | + if (CollUtil.isNotEmpty(rule.getGiveCouponTemplateCounts())) { | ||
| 99 | + tips.add(StrUtil.format("送 {} 张优惠券", | ||
| 100 | + getSumValue(rule.getGiveCouponTemplateCounts().values(), count -> count, Integer::sum))); | ||
| 101 | + } | ||
| 102 | + return description + StrUtil.join("、", tips); | ||
| 103 | + } | ||
| 104 | + | ||
| 74 | } | 105 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java
| @@ -2,10 +2,8 @@ package cn.iocoder.yudao.module.promotion.service.reward; | @@ -2,10 +2,8 @@ package cn.iocoder.yudao.module.promotion.service.reward; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.date.LocalDateTimeUtil; | 4 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 5 | -import cn.hutool.core.util.StrUtil; | ||
| 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | -import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | ||
| 9 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 10 | import cn.iocoder.yudao.module.product.api.category.ProductCategoryApi; | 8 | import cn.iocoder.yudao.module.product.api.category.ProductCategoryApi; |
| 11 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; | 9 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; |
| @@ -17,7 +15,6 @@ import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivi | @@ -17,7 +15,6 @@ import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivi | ||
| 17 | import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO; | 15 | import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO; |
| 18 | import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | 16 | import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; |
| 19 | import cn.iocoder.yudao.module.promotion.dal.mysql.reward.RewardActivityMapper; | 17 | import cn.iocoder.yudao.module.promotion.dal.mysql.reward.RewardActivityMapper; |
| 20 | -import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum; | ||
| 21 | import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; | 18 | import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; |
| 22 | import jakarta.annotation.Resource; | 19 | import jakarta.annotation.Resource; |
| 23 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
| @@ -212,7 +209,8 @@ public class RewardActivityServiceImpl implements RewardActivityService { | @@ -212,7 +209,8 @@ public class RewardActivityServiceImpl implements RewardActivityService { | ||
| 212 | } | 209 | } |
| 213 | 210 | ||
| 214 | // 3. 转换成 Response DTO | 211 | // 3. 转换成 Response DTO |
| 215 | - return BeanUtils.toBean(activityList, RewardActivityMatchRespDTO.class, activityDTO -> { | 212 | + return convertList(activityList, activity -> { |
| 213 | + RewardActivityMatchRespDTO activityDTO = BeanUtils.toBean(activity, RewardActivityMatchRespDTO.class); | ||
| 216 | // 3.1 设置对应匹配的 spuIds | 214 | // 3.1 设置对应匹配的 spuIds |
| 217 | activityDTO.setSpuIds(new ArrayList<>()); | 215 | activityDTO.setSpuIds(new ArrayList<>()); |
| 218 | for (Long spuId : spuIds) { | 216 | for (Long spuId : spuIds) { |
| @@ -231,25 +229,10 @@ public class RewardActivityServiceImpl implements RewardActivityService { | @@ -231,25 +229,10 @@ public class RewardActivityServiceImpl implements RewardActivityService { | ||
| 231 | } | 229 | } |
| 232 | 230 | ||
| 233 | // 3.2 设置每个 Rule 的描述 | 231 | // 3.2 设置每个 Rule 的描述 |
| 234 | - activityDTO.getRules().forEach(rule -> { | ||
| 235 | - String description = ""; | ||
| 236 | - if (PromotionConditionTypeEnum.PRICE.getType().equals(activityDTO.getConditionType())) { | ||
| 237 | - description += StrUtil.format("满 {} 元", MoneyUtils.fenToYuanStr(rule.getLimit())); | ||
| 238 | - } else { | ||
| 239 | - description += StrUtil.format("满 {} 件", rule.getLimit()); | ||
| 240 | - } | ||
| 241 | - if (rule.getDiscountPrice() != null) { | ||
| 242 | - description += StrUtil.format("减 {}", MoneyUtils.fenToYuanStr(rule.getDiscountPrice())); | ||
| 243 | - } else if (Boolean.TRUE.equals(rule.getFreeDelivery())) { | ||
| 244 | - description += "包邮"; | ||
| 245 | - } else if (rule.getPoint() != null && rule.getPoint() > 0) { | ||
| 246 | - description += StrUtil.format("增 {} 积分", rule.getPoint()); | ||
| 247 | - } else if (CollUtil.isNotEmpty(rule.getGiveCouponTemplateCounts())) { | ||
| 248 | - description += StrUtil.format("送 {} 张优惠券", | ||
| 249 | - getSumValue(rule.getGiveCouponTemplateCounts().values(), count -> count, Integer::sum)); | ||
| 250 | - } | ||
| 251 | - rule.setDescription(description); | ||
| 252 | - }); | 232 | + activityDTO.setRules(convertList(activity.getRules(), rule -> |
| 233 | + BeanUtils.toBean(rule, RewardActivityMatchRespDTO.Rule.class) | ||
| 234 | + .setDescription(getRewardActivityRuleDescription(activityDTO.getConditionType(), rule)))); | ||
| 235 | + return activityDTO; | ||
| 253 | }); | 236 | }); |
| 254 | } | 237 | } |
| 255 | 238 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeProductSettlementRespVO.java
| @@ -39,11 +39,11 @@ public class AppTradeProductSettlementRespVO { | @@ -39,11 +39,11 @@ public class AppTradeProductSettlementRespVO { | ||
| 39 | @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | 39 | @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 40 | private Long id; | 40 | private Long id; |
| 41 | 41 | ||
| 42 | - @Schema(description = "支付价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 43 | - private Integer payPrice; // 优惠后价格 | 42 | + @Schema(description = "优惠后价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") |
| 43 | + private Integer promotionPrice; | ||
| 44 | 44 | ||
| 45 | - @Schema(description = "营销类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 46 | - private Integer promotionType; // 对应 PromotionTypeEnum 枚举 | 45 | + @Schema(description = "营销类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "4") |
| 46 | + private Integer promotionType; // 对应 PromotionTypeEnum 枚举,目前只有 4 和 6 两种 | ||
| 47 | 47 | ||
| 48 | @Schema(description = "营销编号", requiredMode = Schema.RequiredMode.REQUIRED) | 48 | @Schema(description = "营销编号", requiredMode = Schema.RequiredMode.REQUIRED) |
| 49 | private Long promotionId; // 目前只有限时折扣活动的编号 | 49 | private Long promotionId; // 目前只有限时折扣活动的编号 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java
| @@ -121,7 +121,7 @@ public class TradePriceServiceImpl implements TradePriceService { | @@ -121,7 +121,7 @@ public class TradePriceServiceImpl implements TradePriceService { | ||
| 121 | List<ProductSkuRespDTO> skuList = spuIdAndSkuListMap.get(spuId); | 121 | List<ProductSkuRespDTO> skuList = spuIdAndSkuListMap.get(spuId); |
| 122 | List<AppTradeProductSettlementRespVO.Sku> skuVOList = convertList(skuList, sku -> { | 122 | List<AppTradeProductSettlementRespVO.Sku> skuVOList = convertList(skuList, sku -> { |
| 123 | AppTradeProductSettlementRespVO.Sku skuVO = new AppTradeProductSettlementRespVO.Sku() | 123 | AppTradeProductSettlementRespVO.Sku skuVO = new AppTradeProductSettlementRespVO.Sku() |
| 124 | - .setId(sku.getId()).setPayPrice(sku.getPrice()); | 124 | + .setId(sku.getId()).setPromotionPrice(sku.getPrice()); |
| 125 | TradePriceCalculateRespBO.OrderItem orderItem = new TradePriceCalculateRespBO.OrderItem() | 125 | TradePriceCalculateRespBO.OrderItem orderItem = new TradePriceCalculateRespBO.OrderItem() |
| 126 | .setPayPrice(sku.getPrice()).setCount(1); | 126 | .setPayPrice(sku.getPrice()).setCount(1); |
| 127 | // 计算限时折扣的优惠价格 | 127 | // 计算限时折扣的优惠价格 |
| @@ -134,11 +134,11 @@ public class TradePriceServiceImpl implements TradePriceService { | @@ -134,11 +134,11 @@ public class TradePriceServiceImpl implements TradePriceService { | ||
| 134 | } | 134 | } |
| 135 | // 选择一个大的优惠 | 135 | // 选择一个大的优惠 |
| 136 | if (discountPrice > vipPrice) { | 136 | if (discountPrice > vipPrice) { |
| 137 | - return skuVO.setPayPrice(sku.getPrice() - discountPrice) | 137 | + return skuVO.setPromotionPrice(sku.getPrice() - discountPrice) |
| 138 | .setPromotionType(PromotionTypeEnum.DISCOUNT_ACTIVITY.getType()) | 138 | .setPromotionType(PromotionTypeEnum.DISCOUNT_ACTIVITY.getType()) |
| 139 | .setPromotionId(discountProduct.getId()).setPromotionEndTime(discountProduct.getActivityEndTime()); | 139 | .setPromotionId(discountProduct.getId()).setPromotionEndTime(discountProduct.getActivityEndTime()); |
| 140 | } else { | 140 | } else { |
| 141 | - return skuVO.setPayPrice(sku.getPrice() - vipPrice) | 141 | + return skuVO.setPromotionPrice(sku.getPrice() - vipPrice) |
| 142 | .setPromotionType(PromotionTypeEnum.MEMBER_LEVEL.getType()); | 142 | .setPromotionType(PromotionTypeEnum.MEMBER_LEVEL.getType()); |
| 143 | } | 143 | } |
| 144 | }); | 144 | }); |