mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-31 09:30:05 +08:00
!1060 【功能新增】商城: 满减送活动下单后,赠送积分、优惠劵、包邮
Merge pull request !1060 from puhui999/develop
This commit is contained in:
commit
7a7ca4293c
@ -3,9 +3,10 @@ package cn.iocoder.yudao.module.promotion.api.coupon;
|
|||||||
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO;
|
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO;
|
||||||
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO;
|
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO;
|
||||||
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO;
|
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO;
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 优惠劵 API 接口
|
* 优惠劵 API 接口
|
||||||
*
|
*
|
||||||
@ -35,4 +36,13 @@ public interface CouponApi {
|
|||||||
*/
|
*/
|
||||||
CouponRespDTO validateCoupon(@Valid CouponValidReqDTO validReqDTO);
|
CouponRespDTO validateCoupon(@Valid CouponValidReqDTO validReqDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【管理员】给指定用户批量发送优惠券
|
||||||
|
*
|
||||||
|
* @param templateIds 优惠劵编号的数组
|
||||||
|
* @param counts 优惠券数量的数组
|
||||||
|
* @param userId 用户编号
|
||||||
|
*/
|
||||||
|
void takeCouponsByAdmin(List<Long> templateIds, List<Integer> counts, Long userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,11 @@ import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO;
|
|||||||
import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert;
|
import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert;
|
||||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
|
||||||
import cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
|
import cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 优惠劵 API 实现类
|
* 优惠劵 API 实现类
|
||||||
@ -41,4 +42,9 @@ public class CouponApiImpl implements CouponApi {
|
|||||||
return CouponConvert.INSTANCE.convert(coupon);
|
return CouponConvert.INSTANCE.convert(coupon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeCouponsByAdmin(List<Long> templateIds, List<Integer> counts, Long userId) {
|
||||||
|
couponService.takeCouponsByAdmin(templateIds, counts, userId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ public class RewardActivityBaseVO {
|
|||||||
@AssertTrue(message = "优惠劵和数量必须一一对应")
|
@AssertTrue(message = "优惠劵和数量必须一一对应")
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public boolean isCouponCountsValid() {
|
public boolean isCouponCountsValid() {
|
||||||
return BooleanUtil.isFalse(givePoint) || CollUtil.size(couponIds) == CollUtil.size(couponCounts);
|
return BooleanUtil.isFalse(giveCoupon) || CollUtil.size(couponIds) == CollUtil.size(couponCounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "赠送的积分不能小于 1")
|
@AssertTrue(message = "赠送的积分不能小于 1")
|
||||||
|
@ -340,7 +340,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
|||||||
CombinationRecordStatusEnum.FAILED);
|
CombinationRecordStatusEnum.FAILED);
|
||||||
// 2. 订单取消
|
// 2. 订单取消
|
||||||
headAndRecords.forEach(item -> tradeOrderApi.cancelPaidOrder(item.getUserId(), item.getOrderId(),
|
headAndRecords.forEach(item -> tradeOrderApi.cancelPaidOrder(item.getUserId(), item.getOrderId(),
|
||||||
TradeOrderCancelTypeEnum.COMBINATION_CLOSE));
|
TradeOrderCancelTypeEnum.COMBINATION_CLOSE.getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,6 +105,15 @@ public interface CouponService {
|
|||||||
takeCoupon(templateId, userIds, CouponTakeTypeEnum.ADMIN);
|
takeCoupon(templateId, userIds, CouponTakeTypeEnum.ADMIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【管理员】给指定用户批量发送优惠券
|
||||||
|
*
|
||||||
|
* @param templateIds 优惠劵编号的数组
|
||||||
|
* @param counts 优惠券数量的数组
|
||||||
|
* @param userId 用户编号
|
||||||
|
*/
|
||||||
|
void takeCouponsByAdmin(List<Long> templateIds, List<Integer> counts, Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 【会员】领取优惠券
|
* 【会员】领取优惠券
|
||||||
*
|
*
|
||||||
|
@ -19,19 +19,19 @@ import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponMapper;
|
|||||||
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum;
|
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum;
|
||||||
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum;
|
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum;
|
||||||
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum;
|
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
||||||
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
|
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
@ -175,10 +175,34 @@ public class CouponServiceImpl implements CouponService {
|
|||||||
// 3. 批量保存优惠劵
|
// 3. 批量保存优惠劵
|
||||||
couponMapper.insertBatch(convertList(userIds, userId -> CouponConvert.INSTANCE.convert(template, userId)));
|
couponMapper.insertBatch(convertList(userIds, userId -> CouponConvert.INSTANCE.convert(template, userId)));
|
||||||
|
|
||||||
// 3. 增加优惠劵模板的领取数量
|
// 4. 增加优惠劵模板的领取数量
|
||||||
couponTemplateService.updateCouponTemplateTakeCount(templateId, userIds.size());
|
couponTemplateService.updateCouponTemplateTakeCount(templateId, userIds.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeCouponsByAdmin(List<Long> templateIds, List<Integer> counts, Long userId) {
|
||||||
|
// 1. 获得优惠券模版
|
||||||
|
List<CouponTemplateDO> templateList = couponTemplateService.getCouponTemplateList(templateIds);
|
||||||
|
if (CollUtil.isEmpty(templateList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Long, CouponTemplateDO> templateMap = convertMap(templateList, CouponTemplateDO::getId);
|
||||||
|
// 2.1 批量构建优惠券
|
||||||
|
List<CouponDO> couponList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < templateIds.size(); i++) {
|
||||||
|
int finalI = i;
|
||||||
|
findAndThen(templateMap, templateIds.get(i), template -> {
|
||||||
|
for (int j = 0; j < counts.get(finalI); j++) {
|
||||||
|
couponList.add(CouponConvert.INSTANCE.convert(template, userId)
|
||||||
|
.setTakeType(CouponTakeTypeEnum.ADMIN.getValue()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 2.2 批量保存优惠券
|
||||||
|
couponMapper.insertBatch(couponList);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void takeCouponByRegister(Long userId) {
|
public void takeCouponByRegister(Long userId) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.trade.api.order;
|
package cn.iocoder.yudao.module.trade.api.order;
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
|
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
|
||||||
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderCancelTypeEnum;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -34,8 +33,8 @@ public interface TradeOrderApi {
|
|||||||
*
|
*
|
||||||
* @param userId 用户编号
|
* @param userId 用户编号
|
||||||
* @param orderId 订单编号
|
* @param orderId 订单编号
|
||||||
* @param cancelTypeEnum 取消类型
|
* @param cancelType 取消类型
|
||||||
*/
|
*/
|
||||||
void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelTypeEnum);
|
void cancelPaidOrder(Long userId, Long orderId, Integer cancelType);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,7 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1_011_003_002, "计算快递运费异常,找不到对应的运费模板");
|
ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1_011_003_002, "计算快递运费异常,找不到对应的运费模板");
|
||||||
ErrorCode PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER = new ErrorCode(1_011_003_004, "参与秒杀、拼团、砍价的营销商品,无法使用优惠劵");
|
ErrorCode PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER = new ErrorCode(1_011_003_004, "参与秒杀、拼团、砍价的营销商品,无法使用优惠劵");
|
||||||
ErrorCode PRICE_CALCULATE_SECKILL_TOTAL_LIMIT_COUNT = new ErrorCode(1_011_003_005, "参与秒杀的商品,超过了秒杀总限购数量");
|
ErrorCode PRICE_CALCULATE_SECKILL_TOTAL_LIMIT_COUNT = new ErrorCode(1_011_003_005, "参与秒杀的商品,超过了秒杀总限购数量");
|
||||||
|
ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TYPE_ILLEGAL = new ErrorCode(1_011_003_006, "计算快递运费异常,配送方式不匹配");
|
||||||
|
|
||||||
// ========== 物流 Express 模块 1-011-004-000 ==========
|
// ========== 物流 Express 模块 1-011-004-000 ==========
|
||||||
ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1_011_004_000, "快递公司不存在");
|
ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1_011_004_000, "快递公司不存在");
|
||||||
|
@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.trade.api.order;
|
|||||||
|
|
||||||
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
|
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
|
||||||
import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
|
import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
|
||||||
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderCancelTypeEnum;
|
|
||||||
import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
|
import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
|
||||||
import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService;
|
import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
@ -37,8 +36,8 @@ public class TradeOrderApiImpl implements TradeOrderApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelTypeEnum) {
|
public void cancelPaidOrder(Long userId, Long orderId, Integer cancelType) {
|
||||||
tradeOrderUpdateService.cancelPaidOrder(userId, orderId, cancelTypeEnum);
|
tradeOrderUpdateService.cancelPaidOrder(userId, orderId, cancelType);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
|||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 交易订单 DO
|
* 交易订单 DO
|
||||||
@ -290,6 +291,18 @@ public class TradeOrderDO extends BaseDO {
|
|||||||
* VIP 减免金额,单位:分
|
* VIP 减免金额,单位:分
|
||||||
*/
|
*/
|
||||||
private Integer vipPrice;
|
private Integer vipPrice;
|
||||||
|
/**
|
||||||
|
* 赠送的优惠劵编号的数组
|
||||||
|
*
|
||||||
|
* 目的:用于后续取消或者售后订单时,需要扣减赠送
|
||||||
|
*/
|
||||||
|
private List<Long> couponIds;
|
||||||
|
/**
|
||||||
|
* 赠送的优惠券数量的数组
|
||||||
|
*
|
||||||
|
* 目的:用于后续取消或者售后订单时,需要扣减赠送
|
||||||
|
*/
|
||||||
|
private List<Integer> couponCounts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 秒杀活动编号
|
* 秒杀活动编号
|
||||||
|
@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettle
|
|||||||
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO;
|
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO;
|
import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
||||||
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderCancelTypeEnum;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -186,14 +185,13 @@ public interface TradeOrderUpdateService {
|
|||||||
*/
|
*/
|
||||||
void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId);
|
void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId);
|
||||||
|
|
||||||
// TODO @puhui999:不传递枚举哈。因为 rpc 不好支持。
|
|
||||||
/**
|
/**
|
||||||
* 取消支付订单
|
* 取消支付订单
|
||||||
*
|
*
|
||||||
* @param userId 用户编号
|
* @param userId 用户编号
|
||||||
* @param orderId 订单编号
|
* @param orderId 订单编号
|
||||||
* @param cancelType 取消类型
|
* @param cancelType 取消类型
|
||||||
*/
|
*/
|
||||||
void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelType);
|
void cancelPaidOrder(Long userId, Long orderId, Integer cancelType);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -201,6 +201,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
|
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
|
||||||
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.setCouponIds(calculateRespBO.getCouponIds()).setCouponCounts(calculateRespBO.getCouponCounts());
|
||||||
// 支付 + 退款信息
|
// 支付 + 退款信息
|
||||||
order.setAdjustPrice(0).setPayStatus(false);
|
order.setAdjustPrice(0).setPayStatus(false);
|
||||||
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0);
|
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0);
|
||||||
@ -858,8 +860,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelType) {
|
public void cancelPaidOrder(Long userId, Long orderId, Integer cancelType) {
|
||||||
// TODO @puhui999:这里校验下 cancelType 只允许拼团关闭;
|
// 1. 这里校验下 cancelType 只允许拼团关闭;
|
||||||
|
if (!TradeOrderCancelTypeEnum.COMBINATION_CLOSE.getType().equals(cancelType)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 1.1 检验订单存在
|
// 1.1 检验订单存在
|
||||||
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId);
|
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId);
|
||||||
if (order == null) {
|
if (order == null) {
|
||||||
@ -876,13 +881,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2.1 取消订单
|
// 2.1 取消订单
|
||||||
cancelOrder0(order, cancelType);
|
cancelOrder0(order, TradeOrderCancelTypeEnum.COMBINATION_CLOSE);
|
||||||
// 2.2 创建退款单
|
// 2.2 创建退款单
|
||||||
payRefundApi.createRefund(new PayRefundCreateReqDTO()
|
payRefundApi.createRefund(new PayRefundCreateReqDTO()
|
||||||
.setAppKey(tradeOrderProperties.getPayAppKey()).setUserIp(getClientIP()) // 支付应用
|
.setAppKey(tradeOrderProperties.getPayAppKey()).setUserIp(getClientIP()) // 支付应用
|
||||||
.setMerchantOrderId(String.valueOf(order.getId())) // 支付单号
|
.setMerchantOrderId(String.valueOf(order.getId())) // 支付单号
|
||||||
.setMerchantRefundId(String.valueOf(order.getId()))
|
.setMerchantRefundId(String.valueOf(order.getId()))
|
||||||
.setReason(cancelType.getName()).setPrice(order.getPayPrice()));// 价格信息
|
.setReason(TradeOrderCancelTypeEnum.COMBINATION_CLOSE.getName()).setPrice(order.getPayPrice()));// 价格信息
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package cn.iocoder.yudao.module.trade.service.order.handler;
|
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.CouponApi;
|
||||||
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO;
|
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,12 +32,26 @@ public class TradeCouponOrderHandler implements TradeOrderHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterCancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
public void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||||
if (order.getCouponId() == null || order.getCouponId() <= 0) {
|
if (CollUtil.isEmpty(order.getCouponIds())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 退回优惠劵
|
// 赠送优惠券
|
||||||
couponApi.returnUsedCoupon(order.getCouponId());
|
couponApi.takeCouponsByAdmin(order.getCouponIds(), order.getCouponCounts(), order.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterCancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||||
|
// 情况一:退还订单使用的优惠券
|
||||||
|
if (order.getCouponId() != null && order.getCouponId() > 0) {
|
||||||
|
// 退回优惠劵
|
||||||
|
couponApi.returnUsedCoupon(order.getCouponId());
|
||||||
|
}
|
||||||
|
// 情况二:收回赠送的优惠券
|
||||||
|
if (CollUtil.isEmpty(order.getCouponIds())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// TODO @puhui999: 收回优惠券再考虑一下,是直接删除券还是改个状态
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,20 @@ public class TradePriceCalculateRespBO {
|
|||||||
*/
|
*/
|
||||||
private Long bargainActivityId;
|
private Long bargainActivityId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否包邮
|
||||||
|
*/
|
||||||
|
private Boolean freeDelivery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 赠送的优惠劵编号的数组
|
||||||
|
*/
|
||||||
|
private List<Long> couponIds;
|
||||||
|
/**
|
||||||
|
* 赠送的优惠券数量的数组
|
||||||
|
*/
|
||||||
|
private List<Integer> couponCounts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单价格
|
* 订单价格
|
||||||
*/
|
*/
|
||||||
@ -213,8 +227,19 @@ public class TradePriceCalculateRespBO {
|
|||||||
*/
|
*/
|
||||||
private Long categoryId;
|
private Long categoryId;
|
||||||
|
|
||||||
|
// ========== 物流相关字段 =========
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 运费模板 Id
|
* 配送方式数组
|
||||||
|
*
|
||||||
|
* 对应 DeliveryTypeEnum 枚举
|
||||||
|
*/
|
||||||
|
private List<Integer> deliveryTypes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物流配置模板编号
|
||||||
|
*
|
||||||
|
* 对应 TradeDeliveryExpressTemplateDO 的 id 编号
|
||||||
*/
|
*/
|
||||||
private Long deliveryTemplateId;
|
private Long deliveryTemplateId;
|
||||||
|
|
||||||
@ -234,7 +259,7 @@ public class TradePriceCalculateRespBO {
|
|||||||
private List<ProductPropertyValueDetailRespDTO> properties;
|
private List<ProductPropertyValueDetailRespDTO> properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用的积分
|
* 赠送的积分
|
||||||
*/
|
*/
|
||||||
private Integer givePoint;
|
private Integer givePoint;
|
||||||
|
|
||||||
|
@ -6,8 +6,6 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.module.member.api.address.MemberAddressApi;
|
import cn.iocoder.yudao.module.member.api.address.MemberAddressApi;
|
||||||
import cn.iocoder.yudao.module.member.api.address.dto.MemberAddressRespDTO;
|
import cn.iocoder.yudao.module.member.api.address.dto.MemberAddressRespDTO;
|
||||||
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
|
|
||||||
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
|
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO;
|
||||||
import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryExpressChargeModeEnum;
|
import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryExpressChargeModeEnum;
|
||||||
@ -30,8 +28,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||||
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PICK_UP_STORE_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
|
||||||
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 运费的 {@link TradePriceCalculator} 实现类
|
* 运费的 {@link TradePriceCalculator} 实现类
|
||||||
@ -52,19 +49,15 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
|
|||||||
private DeliveryExpressTemplateService deliveryExpressTemplateService;
|
private DeliveryExpressTemplateService deliveryExpressTemplateService;
|
||||||
@Resource
|
@Resource
|
||||||
private TradeConfigService tradeConfigService;
|
private TradeConfigService tradeConfigService;
|
||||||
@Resource
|
|
||||||
private ProductSpuApi productSpuApi;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
|
public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
|
||||||
if (param.getDeliveryType() == null) {
|
if (param.getDeliveryType() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO @puhui999:1)TradePriceCalculateRespBO 传递进来 delveryType 配送方式,减少读取;2)如果不匹配,抛出业务异常; = = 不然就不扣钱啦。
|
|
||||||
// 校验是不是存在商品不能门店自提,或者不能快递发货的情况。就是说,配送方式不匹配哈
|
// 校验是不是存在商品不能门店自提,或者不能快递发货的情况。就是说,配送方式不匹配哈
|
||||||
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(convertSet(result.getItems(), OrderItem::getSpuId));
|
if (anyMatch(result.getItems(), item -> !item.getDeliveryTypes().contains(param.getDeliveryType()))) {
|
||||||
if (anyMatch(spuList, item -> !item.getDeliveryTypes().contains(param.getDeliveryType()))) {
|
throw exception(PRICE_CALCULATE_DELIVERY_PRICE_TYPE_ILLEGAL);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DeliveryTypeEnum.PICK_UP.getType().equals(param.getDeliveryType())) {
|
if (DeliveryTypeEnum.PICK_UP.getType().equals(param.getDeliveryType())) {
|
||||||
@ -101,7 +94,12 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 情况二:快递模版
|
// 情况二:活动包邮
|
||||||
|
if (Boolean.TRUE.equals(result.getFreeDelivery())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 情况三:快递模版
|
||||||
// 2.1 过滤出已选中的商品 SKU
|
// 2.1 过滤出已选中的商品 SKU
|
||||||
List<OrderItem> selectedItem = filterList(result.getItems(), OrderItem::getSelected);
|
List<OrderItem> selectedItem = filterList(result.getItems(), OrderItem::getSelected);
|
||||||
Set<Long> deliveryTemplateIds = convertSet(selectedItem, OrderItem::getDeliveryTemplateId);
|
Set<Long> deliveryTemplateIds = convertSet(selectedItem, OrderItem::getDeliveryTemplateId);
|
||||||
|
@ -31,8 +31,8 @@ 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));
|
result.setType(getOrderType(param)).setPromotions(new ArrayList<>())
|
||||||
result.setPromotions(new ArrayList<>());
|
.setCouponIds(new ArrayList<>()).setCouponCounts(new ArrayList<>());
|
||||||
|
|
||||||
// 创建它的 OrderItem 属性
|
// 创建它的 OrderItem 属性
|
||||||
result.setItems(new ArrayList<>(param.getItems().size()));
|
result.setItems(new ArrayList<>(param.getItems().size()));
|
||||||
@ -60,7 +60,7 @@ public class TradePriceCalculatorHelper {
|
|||||||
.setWeight(sku.getWeight()).setVolume(sku.getVolume());
|
.setWeight(sku.getWeight()).setVolume(sku.getVolume());
|
||||||
// spu 信息
|
// spu 信息
|
||||||
orderItem.setSpuName(spu.getName()).setCategoryId(spu.getCategoryId())
|
orderItem.setSpuName(spu.getName()).setCategoryId(spu.getCategoryId())
|
||||||
.setDeliveryTemplateId(spu.getDeliveryTemplateId())
|
.setDeliveryTypes(spu.getDeliveryTypes()).setDeliveryTemplateId(spu.getDeliveryTemplateId())
|
||||||
.setGivePoint(spu.getGiveIntegral()).setUsePoint(0);
|
.setGivePoint(spu.getGiveIntegral()).setUsePoint(0);
|
||||||
if (StrUtil.isBlank(orderItem.getPicUrl())) {
|
if (StrUtil.isBlank(orderItem.getPicUrl())) {
|
||||||
orderItem.setPicUrl(spu.getPicUrl());
|
orderItem.setPicUrl(spu.getPicUrl());
|
||||||
|
@ -3,9 +3,11 @@ package cn.iocoder.yudao.module.trade.service.price.calculator;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
|
||||||
import cn.iocoder.yudao.module.promotion.api.reward.RewardActivityApi;
|
import cn.iocoder.yudao.module.promotion.api.reward.RewardActivityApi;
|
||||||
import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO;
|
import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO;
|
||||||
import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum;
|
import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum;
|
||||||
|
import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
|
||||||
import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
|
import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
|
||||||
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
|
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
|
||||||
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
|
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
|
||||||
@ -14,7 +16,10 @@ import jakarta.annotation.Resource;
|
|||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
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.convertSet;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
|
||||||
@ -61,7 +66,7 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
|
|||||||
if (rule == null) {
|
if (rule == null) {
|
||||||
TradePriceCalculatorHelper.addNotMatchPromotion(result, orderItems,
|
TradePriceCalculatorHelper.addNotMatchPromotion(result, orderItems,
|
||||||
rewardActivity.getId(), rewardActivity.getName(), PromotionTypeEnum.REWARD_ACTIVITY.getType(),
|
rewardActivity.getId(), rewardActivity.getName(), PromotionTypeEnum.REWARD_ACTIVITY.getType(),
|
||||||
getRewardActivityNotMeetTip(rewardActivity));
|
getRewardActivityNotMeetTip(rewardActivity, orderItems));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,6 +89,36 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
|
|||||||
TradePriceCalculatorHelper.recountPayPrice(orderItem);
|
TradePriceCalculatorHelper.recountPayPrice(orderItem);
|
||||||
}
|
}
|
||||||
TradePriceCalculatorHelper.recountAllPrice(result);
|
TradePriceCalculatorHelper.recountAllPrice(result);
|
||||||
|
|
||||||
|
// 4.1 记录赠送的积分
|
||||||
|
if (rule.getGivePoint()) {
|
||||||
|
List<Integer> dividePoints = TradePriceCalculatorHelper.dividePrice(orderItems, rule.getPoint());
|
||||||
|
for (int i = 0; i < orderItems.size(); i++) {
|
||||||
|
TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i);
|
||||||
|
// 商品可能赠送了积分,所以这里要加上
|
||||||
|
orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 4.2 记录订单是否包邮
|
||||||
|
if (rule.getFreeDelivery()) {
|
||||||
|
// 只要满足一个活动包邮那么这单就包邮
|
||||||
|
result.setFreeDelivery(true);
|
||||||
|
}
|
||||||
|
// 4.3 记录赠送的优惠券
|
||||||
|
if (rule.getGiveCoupon()) {
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,9 +130,21 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
|
|||||||
*/
|
*/
|
||||||
private List<TradePriceCalculateRespBO.OrderItem> filterMatchActivityOrderItems(TradePriceCalculateRespBO result,
|
private List<TradePriceCalculateRespBO.OrderItem> filterMatchActivityOrderItems(TradePriceCalculateRespBO result,
|
||||||
RewardActivityMatchRespDTO rewardActivity) {
|
RewardActivityMatchRespDTO rewardActivity) {
|
||||||
// TODO @puhui999:是不是得根据类型过滤哈
|
// 情况一:全部商品都可以参与
|
||||||
return filterList(result.getItems(),
|
if (PromotionProductScopeEnum.isAll(rewardActivity.getProductScope())) {
|
||||||
orderItem -> CollUtil.contains(rewardActivity.getProductScopeValues(), orderItem.getSpuId()));
|
return result.getItems();
|
||||||
|
}
|
||||||
|
// 情况二:指定商品参与
|
||||||
|
if (PromotionProductScopeEnum.isSpu(rewardActivity.getProductScope())) {
|
||||||
|
return filterList(result.getItems(),
|
||||||
|
orderItem -> CollUtil.contains(rewardActivity.getProductScopeValues(), orderItem.getSpuId()));
|
||||||
|
}
|
||||||
|
// 情况三:指定商品类型参与
|
||||||
|
if (PromotionProductScopeEnum.isCategory(rewardActivity.getProductScope())) {
|
||||||
|
return filterList(result.getItems(),
|
||||||
|
orderItem -> CollUtil.contains(rewardActivity.getProductScopeValues(), orderItem.getCategoryId()));
|
||||||
|
}
|
||||||
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,14 +177,30 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得满减送活动部匹配时的提示
|
* 获得满减送活动不匹配时的提示
|
||||||
*
|
*
|
||||||
* @param rewardActivity 满减送活动
|
* @param rewardActivity 满减送活动
|
||||||
* @return 提示
|
* @return 提示
|
||||||
*/
|
*/
|
||||||
private String getRewardActivityNotMeetTip(RewardActivityMatchRespDTO rewardActivity) {
|
private String getRewardActivityNotMeetTip(RewardActivityMatchRespDTO rewardActivity,
|
||||||
// TODO 芋艿:后面再想想;应该找第一个规则,算下还差多少即可。
|
List<TradePriceCalculateRespBO.OrderItem> orderItems) {
|
||||||
return "TODO";
|
// 1. 计算数量和价格
|
||||||
|
Integer count = TradePriceCalculatorHelper.calculateTotalCount(orderItems);
|
||||||
|
Integer price = TradePriceCalculatorHelper.calculateTotalPayPrice(orderItems);
|
||||||
|
assert count != null && price != null;
|
||||||
|
|
||||||
|
// 2. 构建不满足时的提示信息-按最低档规则算
|
||||||
|
String meetTip = "满减送:购满 {} {},可以减 {} 元";
|
||||||
|
List<RewardActivityMatchRespDTO.Rule> rules = new ArrayList<>(rewardActivity.getRules());
|
||||||
|
rules.sort(Comparator.comparing(RewardActivityMatchRespDTO.Rule::getLimit)); // 按优惠门槛降序
|
||||||
|
RewardActivityMatchRespDTO.Rule rule = rules.get(0);
|
||||||
|
if (PromotionConditionTypeEnum.PRICE.getType().equals(rewardActivity.getConditionType())) {
|
||||||
|
return StrUtil.format(meetTip, rule.getLimit(), "元", MoneyUtils.fenToYuanStr(rule.getDiscountPrice()));
|
||||||
|
}
|
||||||
|
if (PromotionConditionTypeEnum.COUNT.getType().equals(rewardActivity.getConditionType())) {
|
||||||
|
return StrUtil.format(meetTip, rule.getLimit(), "件", MoneyUtils.fenToYuanStr(rule.getDiscountPrice()));
|
||||||
|
}
|
||||||
|
return StrUtil.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user