mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-15 10:41:54 +08:00
【功能新增】商城: 满减送活动下单后,赠送优惠劵
This commit is contained in:
@@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 交易订单 DO
|
||||
@@ -290,6 +291,18 @@ public class TradeOrderDO extends BaseDO {
|
||||
* VIP 减免金额,单位:分
|
||||
*/
|
||||
private Integer vipPrice;
|
||||
/**
|
||||
* 赠送的优惠劵编号的数组
|
||||
*
|
||||
* 目的:用于后续取消或者售后订单时,需要扣减赠送
|
||||
*/
|
||||
private List<Long> couponIds;
|
||||
/**
|
||||
* 赠送的优惠券数量的数组
|
||||
*
|
||||
* 目的:用于后续取消或者售后订单时,需要扣减赠送
|
||||
*/
|
||||
private List<Integer> couponCounts;
|
||||
|
||||
/**
|
||||
* 秒杀活动编号
|
||||
|
@@ -160,19 +160,6 @@ public class TradeOrderItemDO extends BaseDO {
|
||||
*/
|
||||
private Integer vipPrice;
|
||||
|
||||
/**
|
||||
* 赠送的优惠劵编号的数组
|
||||
*
|
||||
* 目的:用于后续取消或者售后订单时,需要扣减赠送
|
||||
*/
|
||||
private List<Long> couponIds;
|
||||
/**
|
||||
* 赠送的优惠券数量的数组
|
||||
*
|
||||
* 目的:用于后续取消或者售后订单时,需要扣减赠送
|
||||
*/
|
||||
private List<Integer> couponCounts;
|
||||
|
||||
// ========== 售后基本信息 ==========
|
||||
|
||||
/**
|
||||
|
@@ -201,6 +201,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
|
||||
order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum));
|
||||
order.setUserIp(getClientIP()).setTerminal(getTerminal());
|
||||
// 优惠券
|
||||
order.setCouponIds(calculateRespBO.getCouponIds()).setCouponCounts(calculateRespBO.getCouponCounts());
|
||||
// 支付 + 退款信息
|
||||
order.setAdjustPrice(0).setPayStatus(false);
|
||||
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0);
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.trade.service.order.handler;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi;
|
||||
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO;
|
||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
||||
@@ -32,16 +33,25 @@ public class TradeCouponOrderHandler implements TradeOrderHandler {
|
||||
|
||||
@Override
|
||||
public void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||
|
||||
if (CollUtil.isEmpty(order.getCouponIds())) {
|
||||
return;
|
||||
}
|
||||
// 赠送优惠券
|
||||
couponApi.takeCouponsByAdmin(order.getCouponIds(), order.getCouponCounts(), order.getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||
if (order.getCouponId() == null || order.getCouponId() <= 0) {
|
||||
// 情况一:退还订单使用的优惠券
|
||||
if (order.getCouponId() != null && order.getCouponId() > 0) {
|
||||
// 退回优惠劵
|
||||
couponApi.returnUsedCoupon(order.getCouponId());
|
||||
}
|
||||
// 情况二:收回赠送的优惠券
|
||||
if (CollUtil.isEmpty(order.getCouponIds())) {
|
||||
return;
|
||||
}
|
||||
// 退回优惠劵
|
||||
couponApi.returnUsedCoupon(order.getCouponId());
|
||||
// TODO @puhui999: 收回优惠券再考虑一下,是直接删除券还是改个状态
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -72,7 +72,6 @@ public class TradePriceCalculateRespBO {
|
||||
*/
|
||||
private Boolean freeDelivery;
|
||||
|
||||
// TODO @puhui999: 订单保存时需要保存
|
||||
/**
|
||||
* 赠送的优惠劵编号的数组
|
||||
*/
|
||||
|
@@ -19,6 +19,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
|
||||
@@ -105,8 +106,18 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
|
||||
}
|
||||
// 4.3 记录赠送的优惠券
|
||||
if (rule.getGiveCoupon()) {
|
||||
// TODO @puhui999: 需要考虑赠送的优惠券是否重叠,重叠则对数量进行累加
|
||||
result.setCouponIds(rule.getCouponIds()).setCouponCounts(rule.getCouponCounts());
|
||||
for (int i = 0; i < rule.getCouponIds().size(); i++) {
|
||||
Long couponId = result.getCouponIds().get(i);
|
||||
Integer couponCount = result.getCouponCounts().get(i);
|
||||
int index = CollUtil.indexOf(result.getCouponIds(), id -> Objects.equals(couponId, id));
|
||||
if (index != -1) { // 情况一:别的满减活动送过同类优惠券,则直接增加数量
|
||||
List<Integer> couponCounts = result.getCouponCounts();
|
||||
couponCounts.set(index, couponCounts.get(index) + couponCount);
|
||||
result.setCouponCounts(couponCounts);
|
||||
} else { // 情况二:还没有赠送的优惠券
|
||||
result.setCouponIds(rule.getCouponIds()).setCouponCounts(rule.getCouponCounts());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user