完成购物车的修改~

This commit is contained in:
YunaiV
2020-08-15 18:27:55 +08:00
parent 8818b350d6
commit 9fb421360f
13 changed files with 89 additions and 62 deletions

View File

@@ -36,7 +36,7 @@ public class PriceProductCalcReqDTO implements Serializable {
*/
@Data
@Accessors(chain = true)
public static class Item {
public static class Item implements Serializable {
/**
* SKU 编号

View File

@@ -47,7 +47,7 @@ public class PriceProductCalcRespDTO implements Serializable {
*/
@Data
@Accessors(chain = true)
public static class ItemGroup {
public static class ItemGroup implements Serializable {
/**
* 优惠活动
@@ -79,7 +79,7 @@ public class PriceProductCalcRespDTO implements Serializable {
@Data
@Accessors(chain = true)
public static class Item {
public static class Item implements Serializable {
/**
* 商品 SPU 编号
@@ -149,7 +149,7 @@ public class PriceProductCalcRespDTO implements Serializable {
*/
@Data
@Accessors(chain = true)
public static class Fee {
public static class Fee implements Serializable {
/**
* 购买总价
@@ -188,7 +188,7 @@ public class PriceProductCalcRespDTO implements Serializable {
*/
@Data
@Accessors(chain = true)
public static class Postage {
public static class Postage implements Serializable {
/**
* 需要满足多少钱,可以包邮。单位:分

View File

@@ -80,9 +80,9 @@ public class PriceManager {
int discountTotal = 0;
int presentTotal = 0;
for (PriceProductCalcRespDTO.ItemGroup itemGroup : calcRespDTO.getItemGroups()) {
buyTotal += itemGroup.getItems().stream().mapToInt(PriceProductCalcRespDTO.Item::getBuyTotal).sum();
discountTotal += itemGroup.getItems().stream().mapToInt(PriceProductCalcRespDTO.Item::getDiscountTotal).sum();
presentTotal += itemGroup.getItems().stream().mapToInt(PriceProductCalcRespDTO.Item::getPresentTotal).sum();
buyTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getBuyTotal() : 0).sum();
discountTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getDiscountTotal() : 0).sum();
presentTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getPresentTotal() : 0).sum();
}
Assert.isTrue(buyTotal - discountTotal == presentTotal,
String.format("价格合计( %d - %d == %d )不正确", buyTotal, discountTotal, presentTotal));
@@ -106,6 +106,7 @@ public class PriceManager {
PriceProductCalcReqDTO.Item calcOrderItem = calcProductItemDTOMap.get(sku.getId());
item.setSpuId(sku.getSpuId()).setSkuId(sku.getId());
item.setCid(spuIdCategoryIdMap.get(sku.getSpuId()));
item.setSelected(calcOrderItem.getSelected());
item.setBuyQuantity(calcOrderItem.getQuantity());
// 计算初始价格
item.setOriginPrice(sku.getPrice());
@@ -235,7 +236,8 @@ public class PriceManager {
Assert.isTrue(PromotionActivityTypeEnum.FULL_PRIVILEGE.getValue().equals(activity.getActivityType()),
"传入的必须的满减送活动必须是满减送");
// 获得优惠信息
List<PriceProductCalcRespDTO.Item> items = itemGroup.getItems();
List<PriceProductCalcRespDTO.Item> items = itemGroup.getItems().stream().filter(PriceProductCalcRespDTO.Item::getSelected)
.collect(Collectors.toList());
Integer itemCnt = items.stream().mapToInt(PriceProductCalcRespDTO.Item::getBuyQuantity).sum();
Integer originalTotal = items.stream().mapToInt(PriceProductCalcRespDTO.Item::getPresentTotal).sum();
List<PromotionActivityRespDTO.FullPrivilege.Privilege> privileges = activity.getFullPrivilege().getPrivileges().stream()

View File

@@ -20,8 +20,8 @@ public class PriceManagerTest {
@Test
public void testCalcProductPrice() {
PriceProductCalcReqDTO calcReqDTO = new PriceProductCalcReqDTO();
PriceProductCalcReqDTO.Item item01 = new PriceProductCalcReqDTO.Item(33, 2); // 满足满减送的商品
PriceProductCalcReqDTO.Item item02 = new PriceProductCalcReqDTO.Item(34, 2); // 满足限时折扣的商品
PriceProductCalcReqDTO.Item item01 = new PriceProductCalcReqDTO.Item(33, 2, true); // 满足满减送的商品
PriceProductCalcReqDTO.Item item02 = new PriceProductCalcReqDTO.Item(34, 2, true); // 满足限时折扣的商品
calcReqDTO.setItems(Arrays.asList(item01, item02));
PriceProductCalcRespDTO calcRespDTO = priceManager.calcProductPrice(calcReqDTO);
System.out.println(calcRespDTO);