前后端:商品确认页,增加优惠劵接入

后端:修改了价格计算的逻辑
This commit is contained in:
YunaiV
2019-04-18 22:46:27 +08:00
parent 8962631b6a
commit 7277ecb2d4
34 changed files with 550 additions and 143 deletions

View File

@@ -11,6 +11,8 @@ import cn.iocoder.mall.order.application.convert.CartConvert;
import cn.iocoder.mall.order.application.vo.UsersCalcSkuPriceVO;
import cn.iocoder.mall.order.application.vo.UsersCartDetailVO;
import cn.iocoder.mall.order.application.vo.UsersOrderConfirmCreateVO;
import cn.iocoder.mall.promotion.api.CouponService;
import cn.iocoder.mall.promotion.api.bo.CouponCardAvailableBO;
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
@@ -28,6 +30,8 @@ public class UsersCartController {
private CartService cartService;
@Reference(validation = "true")
private OrderService orderService;
@Reference(validation = "true")
private CouponService couponService;
@PostMapping("add")
public CommonResult<Integer> add(@RequestParam("skuId") Integer skuId,
@@ -102,8 +106,9 @@ public class UsersCartController {
@GetMapping("/confirm_create_order")
public CommonResult<UsersOrderConfirmCreateVO> getConfirmCreateOrder() {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
// 获得购物车中选中的
List<CartItemBO> cartItems = cartService.list(UserSecurityContextHolder.getContext().getUserId(), true).getData();
List<CartItemBO> cartItems = cartService.list(userId, true).getData();
// 购物车为空时,构造空的 UsersOrderConfirmCreateVO 返回
if (cartItems.isEmpty()) {
UsersOrderConfirmCreateVO result = new UsersOrderConfirmCreateVO();
@@ -116,8 +121,13 @@ public class UsersCartController {
if (calcOrderPriceResult.isError()) {
return CommonResult.error(calcOrderPriceResult);
}
// 获得优惠劵
CalcOrderPriceBO calcOrderPrice = calcOrderPriceResult.getData();
List<CouponCardAvailableBO> couponCards = couponService.getCouponCardList(userId,
CartConvert.INSTANCE.convertList(calcOrderPrice.getItemGroups())).getData();
// 执行数据拼装
return CommonResult.success(CartConvert.INSTANCE.convert(calcOrderPriceResult.getData()));
return CommonResult.success(CartConvert.INSTANCE.convert(calcOrderPrice)
.setCouponCards(couponCards));
}
private CommonResult<CalcOrderPriceBO> list0(List<CartItemBO> cartItems) {

View File

@@ -5,9 +5,14 @@ import cn.iocoder.mall.order.api.bo.CalcSkuPriceBO;
import cn.iocoder.mall.order.application.vo.UsersCalcSkuPriceVO;
import cn.iocoder.mall.order.application.vo.UsersCartDetailVO;
import cn.iocoder.mall.order.application.vo.UsersOrderConfirmCreateVO;
import cn.iocoder.mall.promotion.api.dto.CouponCardSpuDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Mapper
public interface CartConvert {
@@ -19,4 +24,17 @@ public interface CartConvert {
UsersCalcSkuPriceVO convert2(CalcSkuPriceBO calcSkuPriceBO);
default List<CouponCardSpuDTO> convertList(List<CalcOrderPriceBO.ItemGroup> itemGroups) {
List<CouponCardSpuDTO> items = new ArrayList<>();
itemGroups.forEach(itemGroup -> items.addAll(itemGroup.getItems().stream().map(
item -> new CouponCardSpuDTO()
.setSpuId(item.getSpu().getId())
.setSkuId(item.getId())
.setCategoryId(item.getSpu().getCid())
.setPrice(item.getBuyPrice())
.setQuantity(item.getBuyQuantity()))
.collect(Collectors.toList())));
return items;
}
}

View File

@@ -29,6 +29,6 @@ public class UsersCalcSkuPriceVO {
/**
* 最终价格,单位:分。
*/
private Integer presentPrice;
private Integer buyPrice;
}

View File

@@ -36,25 +36,16 @@ public class UsersCartDetailVO {
*/
private PromotionActivityBO activity; // TODO 芋艿,偷懒
/**
* 优惠活动是否生效
* 促销减少的金额
*
* 多个商品,参与某个活动,因为并发达到条件,所以会存在未生效的情况。所以一共有三种情况
*
* 1. activity 非空activityEffectEffective 为 true参与活动且生效
* 2. activity 非空activityEffectEffective 为 false ,参与活动,并未生效
* 3. activity 为空activityEffectEffective 为空,并未参与活动。
* 1. 若未参与促销活动,或不满足促销条件,返回 null
* 2. 该金额,已经分摊到每个 Item 的 discountTotal ,需要注意。
*/
private Boolean activityEffectEffective;
private Integer activityDiscountTotal;
/**
* 商品数组
*/
private List<Sku> items;
/**
* 费用
*
* TODO 芋艿这里先偷懒postageTotal 字段用不到。
*/
private Fee fee;
}
@@ -103,15 +94,36 @@ public class UsersCartDetailVO {
*/
private PromotionActivityBO activity;
/**
* 折扣价
* 原始单价,单位:分。
*/
private Integer discountPrice;
private Integer originPrice;
/**
* 费用
*
* TODO 芋艿这里先偷懒postageTotal 字段用不到。
* 购买单价,单位:分
*/
private Fee fee;
private Integer buyPrice;
/**
* 最终价格,单位:分。
*/
private Integer presentPrice;
/**
* 购买总金额,单位:分
*
* 用途类似 {@link #presentTotal}
*/
private Integer buyTotal;
/**
* 优惠总金额,单位:分。
*/
private Integer discountTotal;
/**
* 最终总金额,单位:分。
*
* 注意presentPrice * quantity 不一定等于 presentTotal 。
* 因为,存在无法整除的情况。
* 举个例子presentPrice = 8.33 quantity = 3 的情况presentTotal 有可能是 24.99 ,也可能是 25 。
* 所以,需要存储一个该字段。
*/
private Integer presentTotal;
}
@@ -152,9 +164,9 @@ public class UsersCartDetailVO {
public static class Fee {
/**
* 总价
* 购买总价
*/
private Integer originalTotal;
private Integer buyTotal;
/**
* 优惠总价
*
@@ -175,8 +187,8 @@ public class UsersCartDetailVO {
public Fee() {
}
public Fee(Integer originalTotal, Integer discountTotal, Integer postageTotal, Integer presentTotal) {
this.originalTotal = originalTotal;
public Fee(Integer buyTotal, Integer discountTotal, Integer postageTotal, Integer presentTotal) {
this.buyTotal = buyTotal;
this.discountTotal = discountTotal;
this.postageTotal = postageTotal;
this.presentTotal = presentTotal;

View File

@@ -1,6 +1,7 @@
package cn.iocoder.mall.order.application.vo;
import cn.iocoder.mall.product.api.bo.ProductAttrAndValuePairBO;
import cn.iocoder.mall.promotion.api.bo.CouponCardAvailableBO;
import cn.iocoder.mall.promotion.api.bo.PromotionActivityBO;
import lombok.Data;
import lombok.experimental.Accessors;
@@ -19,6 +20,10 @@ public class UsersOrderConfirmCreateVO {
* 费用
*/
private Fee fee;
/**
* 优惠劵列表 TODO 芋艿,后续改改
*/
private List<CouponCardAvailableBO> couponCards;
/**
* 商品分组
@@ -79,9 +84,36 @@ public class UsersOrderConfirmCreateVO {
*/
private Integer buyQuantity;
/**
* 折扣价
* 原始单价,单位:分。
*/
private Integer discountPrice;
private Integer originPrice;
/**
* 购买单价,单位:分
*/
private Integer buyPrice;
/**
* 最终价格,单位:分。
*/
private Integer presentPrice;
/**
* 购买总金额,单位:分
*
* 用途类似 {@link #presentTotal}
*/
private Integer buyTotal;
/**
* 优惠总金额,单位:分。
*/
private Integer discountTotal;
/**
* 最终总金额,单位:分。
*
* 注意presentPrice * quantity 不一定等于 presentTotal 。
* 因为,存在无法整除的情况。
* 举个例子presentPrice = 8.33 quantity = 3 的情况presentTotal 有可能是 24.99 ,也可能是 25 。
* 所以,需要存储一个该字段。
*/
private Integer presentTotal;
}
@@ -122,9 +154,9 @@ public class UsersOrderConfirmCreateVO {
public static class Fee {
/**
* 总价
* 购买总价
*/
private Integer originalTotal;
private Integer buyTotal;
/**
* 优惠总价
*
@@ -145,8 +177,8 @@ public class UsersOrderConfirmCreateVO {
public Fee() {
}
public Fee(Integer originalTotal, Integer discountTotal, Integer postageTotal, Integer presentTotal) {
this.originalTotal = originalTotal;
public Fee(Integer buyTotal, Integer discountTotal, Integer postageTotal, Integer presentTotal) {
this.buyTotal = buyTotal;
this.discountTotal = discountTotal;
this.postageTotal = postageTotal;
this.presentTotal = presentTotal;