前端+后端:完整接入订单确认的优惠劵计算

This commit is contained in:
YunaiV
2019-04-20 01:22:39 +08:00
parent cb07eb3f71
commit bc2bf52039
8 changed files with 42 additions and 16 deletions

View File

@@ -105,7 +105,7 @@ public class UsersCartController {
}
@GetMapping("/confirm_create_order")
public CommonResult<UsersOrderConfirmCreateVO> getConfirmCreateOrder(@RequestParam("couponCardId") Integer couponCardId) {
public CommonResult<UsersOrderConfirmCreateVO> getConfirmCreateOrder(@RequestParam(value = "couponCardId", required = false) Integer couponCardId) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
// 获得购物车中选中的
List<CartItemBO> cartItems = cartService.list(userId, true).getData();

View File

@@ -94,7 +94,7 @@ public class UsersOrderController {
@ApiOperation("确认创建订单")
public CommonResult<UsersOrderConfirmCreateVO> getConfirmCreateOrder(@RequestParam("skuId") Integer skuId,
@RequestParam("quantity") Integer quantity,
@RequestParam("couponCardId") Integer couponCardId) {
@RequestParam(value = "couponCardId", required = false) Integer couponCardId) {
// 创建 CalcOrderPriceDTO 对象,并执行价格计算
CalcOrderPriceDTO calcOrderPriceDTO = new CalcOrderPriceDTO()
.setUserId(UserSecurityContextHolder.getContext().getUserId())

View File

@@ -24,6 +24,10 @@ public class UsersOrderConfirmCreateVO {
* 优惠劵列表 TODO 芋艿,后续改改
*/
private List<CouponCardAvailableBO> couponCards;
/**
* 优惠劵优惠金额
*/
private Integer couponCardDiscountTotal;
/**
* 商品分组
*

View File

@@ -379,7 +379,8 @@ public class CartServiceImpl implements CartService {
Assert.isTrue(presentTotal > 0, "计算后,价格为负数:" + presentTotal);
} else if (PreferentialTypeEnum.DISCOUNT.getValue().equals(couponCard.getPreferentialType())) { // 打折
presentTotal = originalTotal * couponCard.getPercentOff() / 100;
if (originalTotal - presentTotal > couponCard.getDiscountPriceLimit()) {
if (couponCard.getDiscountPriceLimit() != null // 空,代表不限制优惠上限
&& originalTotal - presentTotal > couponCard.getDiscountPriceLimit()) {
presentTotal = originalTotal - couponCard.getDiscountPriceLimit();
}
} else {
@@ -432,7 +433,7 @@ public class CartServiceImpl implements CartService {
Assert.isTrue(PromotionActivityTypeEnum.FULL_PRIVILEGE.getValue().equals(activity.getActivityType()),
"传入的必须的满减送活动必须是满减送");
// 获得优惠信息
List<CalcOrderPriceBO.Item> items = itemGroup.getItems().stream().filter(item -> !item.getSelected())
List<CalcOrderPriceBO.Item> items = itemGroup.getItems().stream().filter(CalcOrderPriceBO.Item::getSelected)
.collect(Collectors.toList());
Integer itemCnt = items.stream().mapToInt(CalcOrderPriceBO.Item::getBuyQuantity).sum();
Integer originalTotal = items.stream().mapToInt(CalcOrderPriceBO.Item::getPresentTotal).sum();