【功能完善】商城:App 满减送活动的详情,增加 description 规则描述

This commit is contained in:
YunaiV 2024-09-16 18:15:49 +08:00
parent 6f740fab7c
commit ce9f00edef
7 changed files with 67 additions and 33 deletions

View File

@ -88,6 +88,7 @@ public class RewardActivityBaseVO {
return point == null || point >= 0;
}
}
@AssertTrue(message = "商品范围编号的数组不能为空")

View File

@ -30,8 +30,18 @@ public class AppRewardActivityController {
@Operation(summary = "获得满减送活动")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
public CommonResult<AppRewardActivityRespVO> 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);
}
}

View File

@ -36,6 +36,15 @@ public class AppRewardActivityRespVO {
private List<Long> productScopeValues;
@Schema(description = "优惠规则的数组")
private List<RewardActivityBaseVO.Rule> rules;
private List<Rule> rules;
@Schema(description = "优惠规则")
@Data
public static class Rule extends RewardActivityBaseVO.Rule {
@Schema(description = "规则描述")
private String description; // 通过 {@link #limit}{@link #discountPrice} 等字段进行拼接
}
}

View File

@ -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<RewardActivityMatchRespDTO> getMatchRewardActivityListBySpuIds(Collection<Long> 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<String> 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);
}
}

View File

@ -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;
});
}

View File

@ -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; // 目前只有限时折扣活动的编号

View File

@ -121,7 +121,7 @@ public class TradePriceServiceImpl implements TradePriceService {
List<ProductSkuRespDTO> skuList = spuIdAndSkuListMap.get(spuId);
List<AppTradeProductSettlementRespVO.Sku> 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());
}
});