前端+后端:完整接入订单确认的优惠劵计算
This commit is contained in:
parent
cb07eb3f71
commit
bc2bf52039
@ -35,13 +35,14 @@ export function confirmReceiving(orderId) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getOrderConfirmCreateOrder(skuId, quantity) {
|
export function getOrderConfirmCreateOrder(skuId, quantity, couponCardId) {
|
||||||
return request({
|
return request({
|
||||||
url: '/order-api/users/order/confirm_create_order',
|
url: '/order-api/users/order/confirm_create_order',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
params: {
|
params: {
|
||||||
skuId,
|
skuId,
|
||||||
quantity,
|
quantity,
|
||||||
|
couponCardId,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -109,13 +110,12 @@ export function updateCartSelected(skuIds, selected) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCartConfirmCreateOrder(skuId, quantity) {
|
export function getCartConfirmCreateOrder(couponCardId) {
|
||||||
return request({
|
return request({
|
||||||
url: '/order-api/users/cart/confirm_create_order',
|
url: '/order-api/users/cart/confirm_create_order',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
params: {
|
params: {
|
||||||
skuId,
|
couponCardId
|
||||||
quantity,
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,21 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onCouponChange(index) {
|
onCouponChange(index) {
|
||||||
|
// debugger;
|
||||||
|
let couponCardId = this.coupons[index].id;
|
||||||
|
if (this.from === 'direct_order') {
|
||||||
|
getOrderConfirmCreateOrder(this.skuId, this.quantity, couponCardId).then(data => {
|
||||||
|
// this.itemGroups = data.itemGroups;
|
||||||
|
this.fee = data.fee;
|
||||||
|
this.coupons[index].value = data.couponCardDiscountTotal; // 修改优惠劵减免的金额
|
||||||
|
})
|
||||||
|
} else if (this.from === 'cart') {
|
||||||
|
getCartConfirmCreateOrder(couponCardId).then(data => {
|
||||||
|
// this.itemGroups = data.itemGroups;
|
||||||
|
this.fee = data.fee;
|
||||||
|
this.coupons[index].value = data.couponCardDiscountTotal; // 修改优惠劵减免的金额
|
||||||
|
})
|
||||||
|
}
|
||||||
this.chosenCoupon = index;
|
this.chosenCoupon = index;
|
||||||
this.showCouponPopup = false;
|
this.showCouponPopup = false;
|
||||||
},
|
},
|
||||||
@ -205,7 +220,7 @@
|
|||||||
endAt: card.validEndTime / 1000,
|
endAt: card.validEndTime / 1000,
|
||||||
// description: '述信息,优惠券可用时展示',
|
// description: '述信息,优惠券可用时展示',
|
||||||
reason: card.unavailableReason,
|
reason: card.unavailableReason,
|
||||||
value: 0, // TODO ,需要服务端算
|
value: 0,
|
||||||
valueDesc: card.preferentialType === 1 ? card.priceOff / 100 : card.percentOff / 10.0,
|
valueDesc: card.preferentialType === 1 ? card.priceOff / 100 : card.percentOff / 10.0,
|
||||||
unitDesc: card.preferentialType === 1 ? '元' : '折'
|
unitDesc: card.preferentialType === 1 ? '元' : '折'
|
||||||
})
|
})
|
||||||
@ -228,6 +243,12 @@
|
|||||||
this.itemGroups = data.itemGroups;
|
this.itemGroups = data.itemGroups;
|
||||||
this.fee = data.fee;
|
this.fee = data.fee;
|
||||||
// 获得优惠劵列表
|
// 获得优惠劵列表
|
||||||
|
this.coupons = this.convertCouponList(data.couponCards.filter(function (element) {
|
||||||
|
return element.available;
|
||||||
|
}));
|
||||||
|
this.disabledCoupons = this.convertCouponList(data.couponCards.filter(function (element) {
|
||||||
|
return !element.available;
|
||||||
|
}));
|
||||||
})
|
})
|
||||||
} else if (this.from === 'cart') {
|
} else if (this.from === 'cart') {
|
||||||
getCartConfirmCreateOrder().then(data => {
|
getCartConfirmCreateOrder().then(data => {
|
||||||
|
@ -105,7 +105,7 @@ public class UsersCartController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/confirm_create_order")
|
@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();
|
Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
||||||
// 获得购物车中选中的
|
// 获得购物车中选中的
|
||||||
List<CartItemBO> cartItems = cartService.list(userId, true).getData();
|
List<CartItemBO> cartItems = cartService.list(userId, true).getData();
|
||||||
|
@ -94,7 +94,7 @@ public class UsersOrderController {
|
|||||||
@ApiOperation("确认创建订单")
|
@ApiOperation("确认创建订单")
|
||||||
public CommonResult<UsersOrderConfirmCreateVO> getConfirmCreateOrder(@RequestParam("skuId") Integer skuId,
|
public CommonResult<UsersOrderConfirmCreateVO> getConfirmCreateOrder(@RequestParam("skuId") Integer skuId,
|
||||||
@RequestParam("quantity") Integer quantity,
|
@RequestParam("quantity") Integer quantity,
|
||||||
@RequestParam("couponCardId") Integer couponCardId) {
|
@RequestParam(value = "couponCardId", required = false) Integer couponCardId) {
|
||||||
// 创建 CalcOrderPriceDTO 对象,并执行价格计算
|
// 创建 CalcOrderPriceDTO 对象,并执行价格计算
|
||||||
CalcOrderPriceDTO calcOrderPriceDTO = new CalcOrderPriceDTO()
|
CalcOrderPriceDTO calcOrderPriceDTO = new CalcOrderPriceDTO()
|
||||||
.setUserId(UserSecurityContextHolder.getContext().getUserId())
|
.setUserId(UserSecurityContextHolder.getContext().getUserId())
|
||||||
|
@ -24,6 +24,10 @@ public class UsersOrderConfirmCreateVO {
|
|||||||
* 优惠劵列表 TODO 芋艿,后续改改
|
* 优惠劵列表 TODO 芋艿,后续改改
|
||||||
*/
|
*/
|
||||||
private List<CouponCardAvailableBO> couponCards;
|
private List<CouponCardAvailableBO> couponCards;
|
||||||
|
/**
|
||||||
|
* 优惠劵优惠金额
|
||||||
|
*/
|
||||||
|
private Integer couponCardDiscountTotal;
|
||||||
/**
|
/**
|
||||||
* 商品分组
|
* 商品分组
|
||||||
*
|
*
|
||||||
|
@ -379,7 +379,8 @@ public class CartServiceImpl implements CartService {
|
|||||||
Assert.isTrue(presentTotal > 0, "计算后,价格为负数:" + presentTotal);
|
Assert.isTrue(presentTotal > 0, "计算后,价格为负数:" + presentTotal);
|
||||||
} else if (PreferentialTypeEnum.DISCOUNT.getValue().equals(couponCard.getPreferentialType())) { // 打折
|
} else if (PreferentialTypeEnum.DISCOUNT.getValue().equals(couponCard.getPreferentialType())) { // 打折
|
||||||
presentTotal = originalTotal * couponCard.getPercentOff() / 100;
|
presentTotal = originalTotal * couponCard.getPercentOff() / 100;
|
||||||
if (originalTotal - presentTotal > couponCard.getDiscountPriceLimit()) {
|
if (couponCard.getDiscountPriceLimit() != null // 空,代表不限制优惠上限
|
||||||
|
&& originalTotal - presentTotal > couponCard.getDiscountPriceLimit()) {
|
||||||
presentTotal = originalTotal - couponCard.getDiscountPriceLimit();
|
presentTotal = originalTotal - couponCard.getDiscountPriceLimit();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -432,7 +433,7 @@ public class CartServiceImpl implements CartService {
|
|||||||
Assert.isTrue(PromotionActivityTypeEnum.FULL_PRIVILEGE.getValue().equals(activity.getActivityType()),
|
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());
|
.collect(Collectors.toList());
|
||||||
Integer itemCnt = items.stream().mapToInt(CalcOrderPriceBO.Item::getBuyQuantity).sum();
|
Integer itemCnt = items.stream().mapToInt(CalcOrderPriceBO.Item::getBuyQuantity).sum();
|
||||||
Integer originalTotal = items.stream().mapToInt(CalcOrderPriceBO.Item::getPresentTotal).sum();
|
Integer originalTotal = items.stream().mapToInt(CalcOrderPriceBO.Item::getPresentTotal).sum();
|
||||||
|
@ -3,6 +3,7 @@ package cn.iocoder.mall.promotion.api.bo;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class CouponCardDetailBO {
|
public class CouponCardDetailBO implements Serializable {
|
||||||
|
|
||||||
// ========== 基本信息 BEGIN ==========
|
// ========== 基本信息 BEGIN ==========
|
||||||
/**
|
/**
|
||||||
|
@ -20,10 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示
|
@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示
|
||||||
@ -279,8 +276,10 @@ public class CouponServiceImpl implements CouponService {
|
|||||||
public CommonResult<List<CouponCardAvailableBO>> getCouponCardList(Integer userId, List<CouponCardSpuDTO> spus) {
|
public CommonResult<List<CouponCardAvailableBO>> getCouponCardList(Integer userId, List<CouponCardSpuDTO> spus) {
|
||||||
// 查询用户未使用的优惠劵列表
|
// 查询用户未使用的优惠劵列表
|
||||||
List<CouponCardDO> cards = couponCardMapper.selectListByUserIdAndStatus(userId, CouponCardStatusEnum.UNUSED.getValue());
|
List<CouponCardDO> cards = couponCardMapper.selectListByUserIdAndStatus(userId, CouponCardStatusEnum.UNUSED.getValue());
|
||||||
|
if (cards.isEmpty()) {
|
||||||
// TODO: 2019-04-19 芋艿 如果没有优惠券,处理
|
return CommonResult.success(Collections.emptyList());
|
||||||
|
}
|
||||||
|
// 查询优惠劵模板集合
|
||||||
Map<Integer, CouponTemplateDO> templates = couponTemplateMapper.selectListByIds(cards.stream().map(CouponCardDO::getTemplateId).collect(Collectors.toSet()))
|
Map<Integer, CouponTemplateDO> templates = couponTemplateMapper.selectListByIds(cards.stream().map(CouponCardDO::getTemplateId).collect(Collectors.toSet()))
|
||||||
.stream().collect(Collectors.toMap(CouponTemplateDO::getId, template -> template));
|
.stream().collect(Collectors.toMap(CouponTemplateDO::getId, template -> template));
|
||||||
// 逐个判断是否可用
|
// 逐个判断是否可用
|
||||||
|
Loading…
Reference in New Issue
Block a user