From ce9f00edef1f9909288641140b0e8e386146860b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 16 Sep 2024 18:15:49 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E3=80=91=E5=95=86=E5=9F=8E=EF=BC=9AApp=20=E6=BB=A1=E5=87=8F?= =?UTF-8?q?=E9=80=81=E6=B4=BB=E5=8A=A8=E7=9A=84=E8=AF=A6=E6=83=85=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20description=20=E8=A7=84=E5=88=99=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/reward/vo/RewardActivityBaseVO.java | 1 + .../reward/AppRewardActivityController.java | 14 +++++++-- .../reward/vo/AppRewardActivityRespVO.java | 11 ++++++- .../service/reward/RewardActivityService.java | 31 +++++++++++++++++++ .../reward/RewardActivityServiceImpl.java | 29 ++++------------- .../vo/AppTradeProductSettlementRespVO.java | 8 ++--- .../service/price/TradePriceServiceImpl.java | 6 ++-- 7 files changed, 67 insertions(+), 33 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/vo/RewardActivityBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/vo/RewardActivityBaseVO.java index 590e9a7f2..b581ee47f 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/vo/RewardActivityBaseVO.java +++ b/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 { return point == null || point >= 0; } + } @AssertTrue(message = "商品范围编号的数组不能为空") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/reward/AppRewardActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/reward/AppRewardActivityController.java index 88cdcd8af..87a03d01a 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/reward/AppRewardActivityController.java +++ b/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 { @Operation(summary = "获得满减送活动") @Parameter(name = "id", description = "编号", required = true, example = "1024") public CommonResult getRewardActivity(@RequestParam("id") Long id) { - RewardActivityDO rewardActivity = rewardActivityService.getRewardActivity(id); - return success(BeanUtils.toBean(rewardActivity, AppRewardActivityRespVO.class)); + RewardActivityDO activity = rewardActivityService.getRewardActivity(id); + if (activity == null) { + return success(null); + } + // 拼接 Rule 描述 + AppRewardActivityRespVO activityVO = BeanUtils.toBean(activity, AppRewardActivityRespVO.class); + for (int i = 0; i < activityVO.getRules().size(); i++) { + AppRewardActivityRespVO.Rule ruleVO = activityVO.getRules().get(i); + RewardActivityDO.Rule rule = activity.getRules().get(i); + ruleVO.setDescription(rewardActivityService.getRewardActivityRuleDescription(activity.getConditionType(), rule)); + } + return success(activityVO); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/reward/vo/AppRewardActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/reward/vo/AppRewardActivityRespVO.java index 37f77ba86..063d159f5 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/reward/vo/AppRewardActivityRespVO.java +++ b/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 { private List productScopeValues; @Schema(description = "优惠规则的数组") - private List rules; + private List rules; + + @Schema(description = "优惠规则") + @Data + public static class Rule extends RewardActivityBaseVO.Rule { + + @Schema(description = "规则描述") + private String description; // 通过 {@link #limit}、{@link #discountPrice} 等字段进行拼接 + + } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityService.java index 7db588b1e..896209086 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityService.java @@ -1,16 +1,23 @@ package cn.iocoder.yudao.module.promotion.service.reward; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; +import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum; import jakarta.validation.Valid; +import java.util.ArrayList; import java.util.Collection; import java.util.List; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; + /** * 满减送活动 Service 接口 * @@ -71,4 +78,28 @@ public interface RewardActivityService { */ List getMatchRewardActivityListBySpuIds(Collection spuIds); + default String getRewardActivityRuleDescription(Integer conditionType, RewardActivityDO.Rule rule) { + String description = ""; + if (PromotionConditionTypeEnum.PRICE.getType().equals(conditionType)) { + description += StrUtil.format("满 {} 元", MoneyUtils.fenToYuanStr(rule.getLimit())); + } else { + description += StrUtil.format("满 {} 件", rule.getLimit()); + } + List tips = new ArrayList<>(10); + if (rule.getDiscountPrice() != null) { + tips.add(StrUtil.format("减 {}", MoneyUtils.fenToYuanStr(rule.getDiscountPrice()))); + } + if (Boolean.TRUE.equals(rule.getFreeDelivery())) { + tips.add("包邮"); + } + if (rule.getPoint() != null && rule.getPoint() > 0) { + tips.add(StrUtil.format("送 {} 积分", rule.getPoint())); + } + if (CollUtil.isNotEmpty(rule.getGiveCouponTemplateCounts())) { + tips.add(StrUtil.format("送 {} 张优惠券", + getSumValue(rule.getGiveCouponTemplateCounts().values(), count -> count, Integer::sum))); + } + return description + StrUtil.join("、", tips); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java index 55b9eaa1e..b8c0341c9 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java +++ b/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; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.LocalDateTimeUtil; -import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.product.api.category.ProductCategoryApi; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; @@ -17,7 +15,6 @@ import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivi import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; import cn.iocoder.yudao.module.promotion.dal.mysql.reward.RewardActivityMapper; -import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; @@ -212,7 +209,8 @@ public class RewardActivityServiceImpl implements RewardActivityService { } // 3. 转换成 Response DTO - return BeanUtils.toBean(activityList, RewardActivityMatchRespDTO.class, activityDTO -> { + return convertList(activityList, activity -> { + RewardActivityMatchRespDTO activityDTO = BeanUtils.toBean(activity, RewardActivityMatchRespDTO.class); // 3.1 设置对应匹配的 spuIds activityDTO.setSpuIds(new ArrayList<>()); for (Long spuId : spuIds) { @@ -231,25 +229,10 @@ public class RewardActivityServiceImpl implements RewardActivityService { } // 3.2 设置每个 Rule 的描述 - activityDTO.getRules().forEach(rule -> { - String description = ""; - if (PromotionConditionTypeEnum.PRICE.getType().equals(activityDTO.getConditionType())) { - description += StrUtil.format("满 {} 元", MoneyUtils.fenToYuanStr(rule.getLimit())); - } else { - description += StrUtil.format("满 {} 件", rule.getLimit()); - } - if (rule.getDiscountPrice() != null) { - description += StrUtil.format("减 {}", MoneyUtils.fenToYuanStr(rule.getDiscountPrice())); - } else if (Boolean.TRUE.equals(rule.getFreeDelivery())) { - description += "包邮"; - } else if (rule.getPoint() != null && rule.getPoint() > 0) { - description += StrUtil.format("增 {} 积分", rule.getPoint()); - } else if (CollUtil.isNotEmpty(rule.getGiveCouponTemplateCounts())) { - description += StrUtil.format("送 {} 张优惠券", - getSumValue(rule.getGiveCouponTemplateCounts().values(), count -> count, Integer::sum)); - } - rule.setDescription(description); - }); + activityDTO.setRules(convertList(activity.getRules(), rule -> + BeanUtils.toBean(rule, RewardActivityMatchRespDTO.Rule.class) + .setDescription(getRewardActivityRuleDescription(activityDTO.getConditionType(), rule)))); + return activityDTO; }); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeProductSettlementRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeProductSettlementRespVO.java index 3d0ec810c..c5bd455ea 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeProductSettlementRespVO.java +++ b/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 { @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Long id; - @Schema(description = "支付价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer payPrice; // 优惠后价格 + @Schema(description = "优惠后价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") + private Integer promotionPrice; - @Schema(description = "营销类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer promotionType; // 对应 PromotionTypeEnum 枚举 + @Schema(description = "营销类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "4") + private Integer promotionType; // 对应 PromotionTypeEnum 枚举,目前只有 4 和 6 两种 @Schema(description = "营销编号", requiredMode = Schema.RequiredMode.REQUIRED) private Long promotionId; // 目前只有限时折扣活动的编号 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java index db61b0dd3..35225db32 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java +++ b/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 { List skuList = spuIdAndSkuListMap.get(spuId); List skuVOList = convertList(skuList, sku -> { AppTradeProductSettlementRespVO.Sku skuVO = new AppTradeProductSettlementRespVO.Sku() - .setId(sku.getId()).setPayPrice(sku.getPrice()); + .setId(sku.getId()).setPromotionPrice(sku.getPrice()); TradePriceCalculateRespBO.OrderItem orderItem = new TradePriceCalculateRespBO.OrderItem() .setPayPrice(sku.getPrice()).setCount(1); // 计算限时折扣的优惠价格 @@ -134,11 +134,11 @@ public class TradePriceServiceImpl implements TradePriceService { } // 选择一个大的优惠 if (discountPrice > vipPrice) { - return skuVO.setPayPrice(sku.getPrice() - discountPrice) + return skuVO.setPromotionPrice(sku.getPrice() - discountPrice) .setPromotionType(PromotionTypeEnum.DISCOUNT_ACTIVITY.getType()) .setPromotionId(discountProduct.getId()).setPromotionEndTime(discountProduct.getActivityEndTime()); } else { - return skuVO.setPayPrice(sku.getPrice() - vipPrice) + return skuVO.setPromotionPrice(sku.getPrice() - vipPrice) .setPromotionType(PromotionTypeEnum.MEMBER_LEVEL.getType()); } });