前端+后端:完整接入订单确认的优惠劵计算
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({
|
||||
url: '/order-api/users/order/confirm_create_order',
|
||||
method: 'get',
|
||||
params: {
|
||||
skuId,
|
||||
quantity,
|
||||
couponCardId,
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -109,13 +110,12 @@ export function updateCartSelected(skuIds, selected) {
|
||||
});
|
||||
}
|
||||
|
||||
export function getCartConfirmCreateOrder(skuId, quantity) {
|
||||
export function getCartConfirmCreateOrder(couponCardId) {
|
||||
return request({
|
||||
url: '/order-api/users/cart/confirm_create_order',
|
||||
method: 'get',
|
||||
params: {
|
||||
skuId,
|
||||
quantity,
|
||||
couponCardId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -125,6 +125,21 @@
|
||||
},
|
||||
methods: {
|
||||
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.showCouponPopup = false;
|
||||
},
|
||||
@ -205,7 +220,7 @@
|
||||
endAt: card.validEndTime / 1000,
|
||||
// description: '述信息,优惠券可用时展示',
|
||||
reason: card.unavailableReason,
|
||||
value: 0, // TODO ,需要服务端算
|
||||
value: 0,
|
||||
valueDesc: card.preferentialType === 1 ? card.priceOff / 100 : card.percentOff / 10.0,
|
||||
unitDesc: card.preferentialType === 1 ? '元' : '折'
|
||||
})
|
||||
@ -228,6 +243,12 @@
|
||||
this.itemGroups = data.itemGroups;
|
||||
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') {
|
||||
getCartConfirmCreateOrder().then(data => {
|
||||
|
@ -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();
|
||||
|
@ -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())
|
||||
|
@ -24,6 +24,10 @@ public class UsersOrderConfirmCreateVO {
|
||||
* 优惠劵列表 TODO 芋艿,后续改改
|
||||
*/
|
||||
private List<CouponCardAvailableBO> couponCards;
|
||||
/**
|
||||
* 优惠劵优惠金额
|
||||
*/
|
||||
private Integer couponCardDiscountTotal;
|
||||
/**
|
||||
* 商品分组
|
||||
*
|
||||
|
@ -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();
|
||||
|
@ -3,6 +3,7 @@ package cn.iocoder.mall.promotion.api.bo;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -13,7 +14,7 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class CouponCardDetailBO {
|
||||
public class CouponCardDetailBO implements Serializable {
|
||||
|
||||
// ========== 基本信息 BEGIN ==========
|
||||
/**
|
||||
|
@ -20,10 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示
|
||||
@ -279,8 +276,10 @@ public class CouponServiceImpl implements CouponService {
|
||||
public CommonResult<List<CouponCardAvailableBO>> getCouponCardList(Integer userId, List<CouponCardSpuDTO> spus) {
|
||||
// 查询用户未使用的优惠劵列表
|
||||
List<CouponCardDO> cards = couponCardMapper.selectListByUserIdAndStatus(userId, CouponCardStatusEnum.UNUSED.getValue());
|
||||
|
||||
// TODO: 2019-04-19 芋艿 如果没有优惠券,处理
|
||||
if (cards.isEmpty()) {
|
||||
return CommonResult.success(Collections.emptyList());
|
||||
}
|
||||
// 查询优惠劵模板集合
|
||||
Map<Integer, CouponTemplateDO> templates = couponTemplateMapper.selectListByIds(cards.stream().map(CouponCardDO::getTemplateId).collect(Collectors.toSet()))
|
||||
.stream().collect(Collectors.toMap(CouponTemplateDO::getId, template -> template));
|
||||
// 逐个判断是否可用
|
||||
|
Loading…
Reference in New Issue
Block a user