mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 01:01:52 +08:00
【代码优化】商城: 满减送活动
This commit is contained in:
parent
1bf7fd39fc
commit
79cb96702a
@ -95,8 +95,10 @@ public class RewardActivityMatchRespDTO {
|
|||||||
*
|
*
|
||||||
* key: 优惠劵模版编号
|
* key: 优惠劵模版编号
|
||||||
* value:对应的优惠券数量
|
* value:对应的优惠券数量
|
||||||
|
*
|
||||||
|
* 目的:用于订单支付后赠送优惠券
|
||||||
*/
|
*/
|
||||||
private Map<Long, Integer> giveCoupons;
|
private Map<Long, Integer> giveCouponTemplateCounts;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public class RewardActivityBaseVO {
|
|||||||
private Integer point;
|
private Integer point;
|
||||||
|
|
||||||
@Schema(description = "赠送的优惠劵编号的数组")
|
@Schema(description = "赠送的优惠劵编号的数组")
|
||||||
private Map<Long, Integer> giveCoupons;
|
private Map<Long, Integer> giveCouponTemplateCounts;
|
||||||
|
|
||||||
@AssertTrue(message = "赠送的积分不能小于 0")
|
@AssertTrue(message = "赠送的积分不能小于 0")
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
@ -107,9 +107,12 @@ public class RewardActivityDO extends BaseDO {
|
|||||||
/**
|
/**
|
||||||
* 赠送的优惠劵
|
* 赠送的优惠劵
|
||||||
*
|
*
|
||||||
* key: 优惠劵模版编号,value:对应的数量
|
* key: 优惠劵模版编号
|
||||||
|
* value:对应的优惠券数量
|
||||||
|
*
|
||||||
|
* 目的:用于订单支付后赠送优惠券
|
||||||
*/
|
*/
|
||||||
private Map<Long, Integer> giveCoupons;
|
private Map<Long, Integer> giveCouponTemplateCounts;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +296,6 @@ public class TradeOrderDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private Integer vipPrice;
|
private Integer vipPrice;
|
||||||
|
|
||||||
// TODO @puhui999:我们要不要把相关的字段,定义的更明确一点?例如说,giveCouponTemplateCounts 赠送的优惠劵模版数量,或者 giveCouponCounts 赠送的优惠劵数量。感受上,Coupons 和 Map 有点点重叠哈。
|
|
||||||
/**
|
/**
|
||||||
* 赠送的优惠劵
|
* 赠送的优惠劵
|
||||||
*
|
*
|
||||||
@ -306,7 +305,7 @@ public class TradeOrderDO extends BaseDO {
|
|||||||
* 目的:用于订单支付后赠送优惠券
|
* 目的:用于订单支付后赠送优惠券
|
||||||
*/
|
*/
|
||||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
private Map<Long, Integer> giveCouponsMap;
|
private Map<Long, Integer> giveCouponTemplateCounts;
|
||||||
/**
|
/**
|
||||||
* 赠送的优惠劵编号
|
* 赠送的优惠劵编号
|
||||||
*
|
*
|
||||||
|
@ -202,7 +202,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum));
|
order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum));
|
||||||
order.setUserIp(getClientIP()).setTerminal(getTerminal());
|
order.setUserIp(getClientIP()).setTerminal(getTerminal());
|
||||||
// 使用 + 赠送优惠券
|
// 使用 + 赠送优惠券
|
||||||
order.setGiveCouponsMap(calculateRespBO.getGiveCoupons());
|
order.setGiveCouponTemplateCounts(calculateRespBO.getGiveCouponTemplateCounts());
|
||||||
// 支付 + 退款信息
|
// 支付 + 退款信息
|
||||||
order.setAdjustPrice(0).setPayStatus(false);
|
order.setAdjustPrice(0).setPayStatus(false);
|
||||||
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0);
|
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0);
|
||||||
|
@ -42,11 +42,11 @@ public class TradeCouponOrderHandler implements TradeOrderHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
public void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||||
if (CollUtil.isEmpty(order.getGiveCouponsMap())) {
|
if (CollUtil.isEmpty(order.getGiveCouponTemplateCounts())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 赠送优惠券
|
// 赠送优惠券
|
||||||
List<Long> couponIds = couponApi.takeCouponsByAdmin(order.getGiveCouponsMap(), order.getUserId());
|
List<Long> couponIds = couponApi.takeCouponsByAdmin(order.getGiveCouponTemplateCounts(), order.getUserId());
|
||||||
if (CollUtil.isEmpty(couponIds)) {
|
if (CollUtil.isEmpty(couponIds)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -76,10 +76,12 @@ public class TradePriceCalculateRespBO {
|
|||||||
/**
|
/**
|
||||||
* 赠送的优惠劵
|
* 赠送的优惠劵
|
||||||
*
|
*
|
||||||
* key: 优惠劵编号,value:对应的优惠券数量
|
* key: 优惠劵模版编号
|
||||||
* 目的:用于后续取消或者售后订单时,需要扣减赠送
|
* value:对应的优惠券数量
|
||||||
|
*
|
||||||
|
* 目的:用于订单支付后赠送优惠券
|
||||||
*/
|
*/
|
||||||
private Map<Long, Integer> giveCoupons;
|
private Map<Long, Integer> giveCouponTemplateCounts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单价格
|
* 订单价格
|
||||||
|
@ -32,7 +32,7 @@ public class TradePriceCalculatorHelper {
|
|||||||
List<ProductSpuRespDTO> spuList, List<ProductSkuRespDTO> skuList) {
|
List<ProductSpuRespDTO> spuList, List<ProductSkuRespDTO> skuList) {
|
||||||
// 创建 PriceCalculateRespDTO 对象
|
// 创建 PriceCalculateRespDTO 对象
|
||||||
TradePriceCalculateRespBO result = new TradePriceCalculateRespBO();
|
TradePriceCalculateRespBO result = new TradePriceCalculateRespBO();
|
||||||
result.setType(getOrderType(param)).setPromotions(new ArrayList<>()).setGiveCoupons(new LinkedHashMap<>());
|
result.setType(getOrderType(param)).setPromotions(new ArrayList<>()).setGiveCouponTemplateCounts(new LinkedHashMap<>());
|
||||||
|
|
||||||
// 创建它的 OrderItem 属性
|
// 创建它的 OrderItem 属性
|
||||||
result.setItems(new ArrayList<>(param.getItems().size()));
|
result.setItems(new ArrayList<>(param.getItems().size()));
|
||||||
|
@ -107,13 +107,13 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
|
|||||||
result.setFreeDelivery(true);
|
result.setFreeDelivery(true);
|
||||||
}
|
}
|
||||||
// 4.3 记录赠送的优惠券
|
// 4.3 记录赠送的优惠券
|
||||||
if (CollUtil.isNotEmpty(rule.getGiveCoupons())) {
|
if (CollUtil.isNotEmpty(rule.getGiveCouponTemplateCounts())) {
|
||||||
for (Map.Entry<Long, Integer> entry : rule.getGiveCoupons().entrySet()) {
|
for (Map.Entry<Long, Integer> entry : rule.getGiveCouponTemplateCounts().entrySet()) {
|
||||||
Map<Long, Integer> giveCoupons = result.getGiveCoupons();
|
Map<Long, Integer> giveCouponTemplateCounts = result.getGiveCouponTemplateCounts();
|
||||||
if (giveCoupons.get(entry.getKey()) == null) { // 情况一:还没有赠送的优惠券
|
if (giveCouponTemplateCounts.get(entry.getKey()) == null) { // 情况一:还没有赠送的优惠券
|
||||||
result.setGiveCoupons(rule.getGiveCoupons());
|
result.setGiveCouponTemplateCounts(rule.getGiveCouponTemplateCounts());
|
||||||
} else { // 情况二:别的满减活动送过同类优惠券,则直接增加数量
|
} else { // 情况二:别的满减活动送过同类优惠券,则直接增加数量
|
||||||
giveCoupons.put(entry.getKey(), giveCoupons.get(entry.getKey()) + entry.getValue());
|
giveCouponTemplateCounts.put(entry.getKey(), giveCouponTemplateCounts.get(entry.getKey()) + entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class TradeRewardActivityPriceCalculatorTest extends BaseMockitoUnitTest
|
|||||||
TradePriceCalculateRespBO result = new TradePriceCalculateRespBO()
|
TradePriceCalculateRespBO result = new TradePriceCalculateRespBO()
|
||||||
.setType(TradeOrderTypeEnum.NORMAL.getType())
|
.setType(TradeOrderTypeEnum.NORMAL.getType())
|
||||||
.setPrice(new TradePriceCalculateRespBO.Price())
|
.setPrice(new TradePriceCalculateRespBO.Price())
|
||||||
.setPromotions(new ArrayList<>()).setGiveCoupons(new LinkedHashMap<>())
|
.setPromotions(new ArrayList<>()).setGiveCouponTemplateCounts(new LinkedHashMap<>())
|
||||||
.setItems(asList(
|
.setItems(asList(
|
||||||
new TradePriceCalculateRespBO.OrderItem().setSkuId(10L).setCount(2).setSelected(true)
|
new TradePriceCalculateRespBO.OrderItem().setSkuId(10L).setCount(2).setSelected(true)
|
||||||
.setPrice(100).setSpuId(1L),
|
.setPrice(100).setSpuId(1L),
|
||||||
|
Loading…
Reference in New Issue
Block a user