mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-12 17:21:52 +08:00
promotion:去除已经不使用的代码
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
package cn.iocoder.yudao.module.promotion.api.combination;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 拼团活动 Api 接口实现类
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Service
|
||||
public class CombinationActivityApiImpl implements CombinationActivityApi {
|
||||
|
||||
}
|
@@ -44,11 +44,6 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
|
||||
return CombinationRecordStatusEnum.isSuccess(record.getStatus());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRecordStatusToFailed(Long userId, Long orderId) {
|
||||
recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.FAILED.getStatus(), userId, orderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) {
|
||||
return recordService.validateJoinCombination(userId, activityId, headId, skuId, count);
|
||||
|
@@ -1,28 +0,0 @@
|
||||
package cn.iocoder.yudao.module.promotion.api.price;
|
||||
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.service.price.PriceService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 价格 API 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
public class PriceApiImpl implements PriceApi {
|
||||
|
||||
@Resource
|
||||
private PriceService priceService;
|
||||
|
||||
@Override
|
||||
public PriceCalculateRespDTO calculatePrice(PriceCalculateReqDTO calculateReqDTO) {
|
||||
//return priceService.calculatePrice(calculateReqDTO); TODO 没有 calculatePrice 这个方法
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
package cn.iocoder.yudao.module.promotion.convert.price;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.CouponMeetRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO;
|
||||
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface PriceConvert {
|
||||
|
||||
PriceConvert INSTANCE = Mappers.getMapper(PriceConvert.class);
|
||||
|
||||
default PriceCalculateRespDTO convert(PriceCalculateReqDTO calculateReqDTO, List<ProductSkuRespDTO> skuList) {
|
||||
// 创建 PriceCalculateRespDTO 对象
|
||||
PriceCalculateRespDTO priceCalculate = new PriceCalculateRespDTO();
|
||||
// 创建它的 Order 属性
|
||||
PriceCalculateRespDTO.Order order = new PriceCalculateRespDTO.Order().setTotalPrice(0).setDiscountPrice(0)
|
||||
.setCouponPrice(0).setPointPrice(0).setDeliveryPrice(0).setPayPrice(0)
|
||||
.setItems(new ArrayList<>()).setCouponId(calculateReqDTO.getCouponId());
|
||||
priceCalculate.setOrder(order).setPromotions(new ArrayList<>());
|
||||
// 创建它的 OrderItem 属性
|
||||
Map<Long, Integer> skuIdCountMap = CollectionUtils.convertMap(calculateReqDTO.getItems(),
|
||||
PriceCalculateReqDTO.Item::getSkuId, PriceCalculateReqDTO.Item::getCount);
|
||||
skuList.forEach(sku -> {
|
||||
Integer count = skuIdCountMap.get(sku.getId());
|
||||
PriceCalculateRespDTO.OrderItem orderItem = new PriceCalculateRespDTO.OrderItem()
|
||||
.setSpuId(sku.getSpuId()).setSkuId(sku.getId()).setCount(count)
|
||||
.setOriginalUnitPrice(sku.getPrice()).setOriginalPrice(sku.getPrice() * count)
|
||||
.setDiscountPrice(0).setOrderPartPrice(0);
|
||||
orderItem.setPayPrice(orderItem.getOriginalPrice()).setOrderDividePrice(orderItem.getOriginalPrice());
|
||||
priceCalculate.getOrder().getItems().add(orderItem);
|
||||
// 补充价格信息到 Order 中
|
||||
order.setTotalPrice(order.getTotalPrice() + orderItem.getOriginalPrice())
|
||||
.setPayPrice(order.getTotalPrice());
|
||||
});
|
||||
return priceCalculate;
|
||||
}
|
||||
|
||||
CouponMeetRespDTO convert(CouponDO coupon);
|
||||
|
||||
}
|
@@ -21,15 +21,6 @@ import java.util.Map;
|
||||
*/
|
||||
public interface CombinationRecordService {
|
||||
|
||||
/**
|
||||
* 更新拼团状态
|
||||
*
|
||||
* @param status 状态
|
||||
* @param userId 用户编号
|
||||
* @param orderId 订单编号
|
||||
*/
|
||||
void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId);
|
||||
|
||||
/**
|
||||
* 【下单前】校验是否满足拼团活动条件
|
||||
*
|
||||
@@ -62,15 +53,6 @@ public interface CombinationRecordService {
|
||||
*/
|
||||
CombinationRecordDO getCombinationRecord(Long userId, Long orderId);
|
||||
|
||||
/**
|
||||
* 获取拼团记录
|
||||
*
|
||||
* @param userId 用户 id
|
||||
* @param activityId 活动 id
|
||||
* @return 拼团记录列表
|
||||
*/
|
||||
List<CombinationRecordDO> getCombinationRecordListByUserIdAndActivityId(Long userId, Long activityId);
|
||||
|
||||
/**
|
||||
* 【下单前】校验是否满足拼团活动条件
|
||||
*
|
||||
|
@@ -66,25 +66,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
@Resource
|
||||
private TradeOrderApi tradeOrderApi;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId) {
|
||||
// 校验拼团是否存在
|
||||
CombinationRecordDO record = validateCombinationRecord(userId, orderId);
|
||||
|
||||
// 更新状态
|
||||
combinationRecordMapper.updateById(new CombinationRecordDO().setId(record.getId()).setStatus(status));
|
||||
}
|
||||
|
||||
private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) {
|
||||
// 校验拼团是否存在
|
||||
CombinationRecordDO recordDO = combinationRecordMapper.selectByUserIdAndOrderId(userId, orderId);
|
||||
if (recordDO == null) {
|
||||
throw exception(COMBINATION_RECORD_NOT_EXISTS);
|
||||
}
|
||||
return recordDO;
|
||||
}
|
||||
|
||||
// TODO @芋艿:在详细预览下;
|
||||
@Override
|
||||
public KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord(
|
||||
@@ -229,11 +210,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
return combinationRecordMapper.selectByUserIdAndOrderId(userId, orderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CombinationRecordDO> getCombinationRecordListByUserIdAndActivityId(Long userId, Long activityId) {
|
||||
return combinationRecordMapper.selectListByUserIdAndActivityId(userId, activityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId,
|
||||
Long skuId, Integer count) {
|
||||
|
@@ -1,23 +0,0 @@
|
||||
package cn.iocoder.yudao.module.promotion.service.price;
|
||||
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.CouponMeetRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 价格计算 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface PriceService {
|
||||
|
||||
/**
|
||||
* 获得优惠劵的匹配信息列表
|
||||
*
|
||||
* @param calculateReqDTO 价格请求
|
||||
* @return 价格响应
|
||||
*/
|
||||
List<CouponMeetRespDTO> getMeetCouponList(PriceCalculateReqDTO calculateReqDTO);
|
||||
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
package cn.iocoder.yudao.module.promotion.service.price;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.CouponMeetRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.convert.price.PriceConvert;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
|
||||
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum;
|
||||
import cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue;
|
||||
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_VALID_TIME_NOT_NOW;
|
||||
|
||||
/**
|
||||
* 价格计算 Service 实现类
|
||||
*
|
||||
* 优惠计算顺序:min(限时折扣, 会员折扣) > 满减送 > 优惠券。
|
||||
* 参考文档:
|
||||
* 1. <a href="https://help.youzan.com/displaylist/detail_4_4-1-60384">有赞文档:限时折扣、满减送、优惠券哪个优先计算?</a>
|
||||
*
|
||||
* TODO 芋艿:进一步完善
|
||||
* 1. 限时折扣:指定金额、减免金额、折扣
|
||||
* 2. 满减送:循环、折扣
|
||||
* 3. 优惠劵:待定
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class PriceServiceImpl implements PriceService {
|
||||
|
||||
@Resource
|
||||
private CouponService couponService;
|
||||
|
||||
@Override
|
||||
public List<CouponMeetRespDTO> getMeetCouponList(PriceCalculateReqDTO calculateReqDTO) {
|
||||
// 先计算一轮价格
|
||||
// PriceCalculateRespDTO priceCalculate = calculatePrice(calculateReqDTO);
|
||||
PriceCalculateRespDTO priceCalculate = null;
|
||||
|
||||
// 获得用户的待使用优惠劵
|
||||
List<CouponDO> couponList = couponService.getCouponList(calculateReqDTO.getUserId(), CouponStatusEnum.UNUSED.getStatus());
|
||||
if (CollUtil.isEmpty(couponList)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// 获得优惠劵的匹配信息
|
||||
return CollectionUtils.convertList(couponList, coupon -> {
|
||||
CouponMeetRespDTO couponMeetRespDTO = PriceConvert.INSTANCE.convert(coupon);
|
||||
try {
|
||||
// 校验优惠劵
|
||||
couponService.validCoupon(coupon);
|
||||
|
||||
// 获得匹配的商品 SKU 数组
|
||||
// TODO 芋艿:后续处理
|
||||
// List<PriceCalculateRespDTO.OrderItem> orderItems = getMatchCouponOrderItems(priceCalculate, coupon);
|
||||
List<PriceCalculateRespDTO.OrderItem> orderItems = null;
|
||||
if (CollUtil.isEmpty(orderItems)) {
|
||||
return couponMeetRespDTO.setMeet(false).setMeetTip("所结算商品没有符合条件的商品");
|
||||
}
|
||||
|
||||
// 计算是否满足优惠劵的使用金额
|
||||
Integer originPrice = getSumValue(orderItems, PriceCalculateRespDTO.OrderItem::getOrderDividePrice, Integer::sum);
|
||||
assert originPrice != null;
|
||||
if (originPrice < coupon.getUsePrice()) {
|
||||
return couponMeetRespDTO.setMeet(false)
|
||||
// .setMeetTip(String.format("差 %s 元可用优惠劵", formatPrice(coupon.getUsePrice() - originPrice)));
|
||||
.setMeetTip("所结算的商品中未满足使用的金额");
|
||||
}
|
||||
} catch (ServiceException serviceException) {
|
||||
couponMeetRespDTO.setMeet(false);
|
||||
if (serviceException.getCode().equals(COUPON_VALID_TIME_NOT_NOW.getCode())) {
|
||||
couponMeetRespDTO.setMeetTip("优惠劵未到使用时间");
|
||||
} else {
|
||||
log.error("[getMeetCouponList][calculateReqDTO({}) 获得优惠劵匹配信息异常]", calculateReqDTO, serviceException);
|
||||
couponMeetRespDTO.setMeetTip("优惠劵不满足使用条件");
|
||||
}
|
||||
return couponMeetRespDTO;
|
||||
}
|
||||
// 满足
|
||||
return couponMeetRespDTO.setMeet(true);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -1,104 +0,0 @@
|
||||
package cn.iocoder.yudao.module.promotion.service.price;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest;
|
||||
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
|
||||
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.CouponMeetRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
|
||||
import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
|
||||
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum;
|
||||
import cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
|
||||
import cn.iocoder.yudao.module.promotion.service.reward.RewardActivityService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_VALID_TIME_NOT_NOW;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* {@link PriceServiceImpl} 的单元测试
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public class PriceServiceTest extends BaseMockitoUnitTest {
|
||||
|
||||
@InjectMocks
|
||||
private PriceServiceImpl priceService;
|
||||
|
||||
@Mock
|
||||
private RewardActivityService rewardActivityService;
|
||||
@Mock
|
||||
private CouponService couponService;
|
||||
@Mock
|
||||
private ProductSkuApi productSkuApi;
|
||||
|
||||
/**
|
||||
* 测试满减送活动,不匹配的情况
|
||||
*/
|
||||
@Test
|
||||
public void testCalculatePrice_rewardActivityNotMeet() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMeetCouponList() {
|
||||
// 准备参数
|
||||
PriceCalculateReqDTO calculateReqDTO = new PriceCalculateReqDTO().setUserId(1024L)
|
||||
.setItems(singletonList(new PriceCalculateReqDTO.Item().setSkuId(10L).setCount(2)));
|
||||
// mock 方法(商品 SKU 信息)
|
||||
ProductSkuRespDTO productSku = randomPojo(ProductSkuRespDTO.class, o -> o.setId(10L).setPrice(100));
|
||||
when(productSkuApi.getSkuList(eq(asSet(10L)))).thenReturn(singletonList(productSku));
|
||||
// mock 方法(情况一:优惠劵未到使用时间)
|
||||
CouponDO coupon01 = randomPojo(CouponDO.class);
|
||||
doThrow(new ServiceException(COUPON_VALID_TIME_NOT_NOW)).when(couponService).validCoupon(coupon01);
|
||||
// mock 方法(情况二:所结算商品没有符合条件的商品)
|
||||
CouponDO coupon02 = randomPojo(CouponDO.class);
|
||||
// mock 方法(情况三:使用金额不足)
|
||||
CouponDO coupon03 = randomPojo(CouponDO.class, o -> o.setProductScope(PromotionProductScopeEnum.ALL.getScope())
|
||||
.setUsePrice(300));
|
||||
// mock 方法(情况五:满足条件)
|
||||
CouponDO coupon04 = randomPojo(CouponDO.class, o -> o.setProductScope(PromotionProductScopeEnum.ALL.getScope())
|
||||
.setUsePrice(190));
|
||||
// mock 方法(获得用户的待使用优惠劵)
|
||||
when(couponService.getCouponList(eq(1024L), eq(CouponStatusEnum.UNUSED.getStatus())))
|
||||
.thenReturn(asList(coupon01, coupon02, coupon03, coupon04));
|
||||
// 调用
|
||||
List<CouponMeetRespDTO> list = priceService.getMeetCouponList(calculateReqDTO);
|
||||
// 断言
|
||||
assertEquals(list.size(), 4);
|
||||
// 断言情况一:优惠劵未到使用时间
|
||||
CouponMeetRespDTO couponMeetRespDTO01 = list.get(0);
|
||||
assertPojoEquals(couponMeetRespDTO01, coupon01);
|
||||
assertFalse(couponMeetRespDTO01.getMeet());
|
||||
assertEquals(couponMeetRespDTO01.getMeetTip(), "优惠劵未到使用时间");
|
||||
// 断言情况二:所结算商品没有符合条件的商品
|
||||
CouponMeetRespDTO couponMeetRespDTO02 = list.get(1);
|
||||
assertPojoEquals(couponMeetRespDTO02, coupon02);
|
||||
assertFalse(couponMeetRespDTO02.getMeet());
|
||||
assertEquals(couponMeetRespDTO02.getMeetTip(), "所结算商品没有符合条件的商品");
|
||||
// 断言情况三:差 %s 元可用优惠劵
|
||||
CouponMeetRespDTO couponMeetRespDTO03 = list.get(2);
|
||||
assertPojoEquals(couponMeetRespDTO03, coupon03);
|
||||
assertFalse(couponMeetRespDTO03.getMeet());
|
||||
assertEquals(couponMeetRespDTO03.getMeetTip(), "所结算的商品中未满足使用的金额");
|
||||
// 断言情况四:满足条件
|
||||
CouponMeetRespDTO couponMeetRespDTO04 = list.get(3);
|
||||
assertPojoEquals(couponMeetRespDTO04, coupon04);
|
||||
assertTrue(couponMeetRespDTO04.getMeet());
|
||||
assertNull(couponMeetRespDTO04.getMeetTip());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user