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
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 | 30 | @Operation(summary = "获得满减送活动") |
| 31 | 31 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 32 | 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 | 36 | private List<Long> productScopeValues; |
| 37 | 37 | |
| 38 | 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 | 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 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 4 | 7 | import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO; |
| 5 | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityCreateReqVO; |
| 6 | 9 | import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityPageReqVO; |
| 7 | 10 | import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO; |
| 8 | 11 | import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; |
| 12 | +import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum; | |
| 9 | 13 | import jakarta.validation.Valid; |
| 10 | 14 | |
| 15 | +import java.util.ArrayList; | |
| 11 | 16 | import java.util.Collection; |
| 12 | 17 | import java.util.List; |
| 13 | 18 | |
| 19 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; | |
| 20 | + | |
| 14 | 21 | /** |
| 15 | 22 | * 满减送活动 Service 接口 |
| 16 | 23 | * |
| ... | ... | @@ -71,4 +78,28 @@ public interface RewardActivityService { |
| 71 | 78 | */ |
| 72 | 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 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 5 | -import cn.hutool.core.util.StrUtil; | |
| 6 | 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | -import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 9 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 10 | 8 | import cn.iocoder.yudao.module.product.api.category.ProductCategoryApi; |
| 11 | 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 | 15 | import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO; |
| 18 | 16 | import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; |
| 19 | 17 | import cn.iocoder.yudao.module.promotion.dal.mysql.reward.RewardActivityMapper; |
| 20 | -import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum; | |
| 21 | 18 | import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; |
| 22 | 19 | import jakarta.annotation.Resource; |
| 23 | 20 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -212,7 +209,8 @@ public class RewardActivityServiceImpl implements RewardActivityService { |
| 212 | 209 | } |
| 213 | 210 | |
| 214 | 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 | 214 | // 3.1 设置对应匹配的 spuIds |
| 217 | 215 | activityDTO.setSpuIds(new ArrayList<>()); |
| 218 | 216 | for (Long spuId : spuIds) { |
| ... | ... | @@ -231,25 +229,10 @@ public class RewardActivityServiceImpl implements RewardActivityService { |
| 231 | 229 | } |
| 232 | 230 | |
| 233 | 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 | 39 | @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 40 | 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 | 48 | @Schema(description = "营销编号", requiredMode = Schema.RequiredMode.REQUIRED) |
| 49 | 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 | 121 | List<ProductSkuRespDTO> skuList = spuIdAndSkuListMap.get(spuId); |
| 122 | 122 | List<AppTradeProductSettlementRespVO.Sku> skuVOList = convertList(skuList, sku -> { |
| 123 | 123 | AppTradeProductSettlementRespVO.Sku skuVO = new AppTradeProductSettlementRespVO.Sku() |
| 124 | - .setId(sku.getId()).setPayPrice(sku.getPrice()); | |
| 124 | + .setId(sku.getId()).setPromotionPrice(sku.getPrice()); | |
| 125 | 125 | TradePriceCalculateRespBO.OrderItem orderItem = new TradePriceCalculateRespBO.OrderItem() |
| 126 | 126 | .setPayPrice(sku.getPrice()).setCount(1); |
| 127 | 127 | // 计算限时折扣的优惠价格 |
| ... | ... | @@ -134,11 +134,11 @@ public class TradePriceServiceImpl implements TradePriceService { |
| 134 | 134 | } |
| 135 | 135 | // 选择一个大的优惠 |
| 136 | 136 | if (discountPrice > vipPrice) { |
| 137 | - return skuVO.setPayPrice(sku.getPrice() - discountPrice) | |
| 137 | + return skuVO.setPromotionPrice(sku.getPrice() - discountPrice) | |
| 138 | 138 | .setPromotionType(PromotionTypeEnum.DISCOUNT_ACTIVITY.getType()) |
| 139 | 139 | .setPromotionId(discountProduct.getId()).setPromotionEndTime(discountProduct.getActivityEndTime()); |
| 140 | 140 | } else { |
| 141 | - return skuVO.setPayPrice(sku.getPrice() - vipPrice) | |
| 141 | + return skuVO.setPromotionPrice(sku.getPrice() - vipPrice) | |
| 142 | 142 | .setPromotionType(PromotionTypeEnum.MEMBER_LEVEL.getType()); |
| 143 | 143 | } |
| 144 | 144 | }); | ... | ... |