From bc2bf52039145ecc5fcee36836f00f24467043d0 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 20 Apr 2019 01:22:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF+=E5=90=8E=E7=AB=AF=EF=BC=9A?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E6=8E=A5=E5=85=A5=E8=AE=A2=E5=8D=95=E7=A1=AE?= =?UTF-8?q?=E8=AE=A4=E7=9A=84=E4=BC=98=E6=83=A0=E5=8A=B5=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mobile-web/src/api/order.js | 8 +++---- mobile-web/src/page/shipping/order.vue | 23 ++++++++++++++++++- .../controller/users/UsersCartController.java | 2 +- .../users/UsersOrderController.java | 2 +- .../vo/UsersOrderConfirmCreateVO.java | 4 ++++ .../order/biz/service/CartServiceImpl.java | 5 ++-- .../promotion/api/bo/CouponCardDetailBO.java | 3 ++- .../biz/service/CouponServiceImpl.java | 11 ++++----- 8 files changed, 42 insertions(+), 16 deletions(-) diff --git a/mobile-web/src/api/order.js b/mobile-web/src/api/order.js index fda924a28..bcd52f71b 100644 --- a/mobile-web/src/api/order.js +++ b/mobile-web/src/api/order.js @@ -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 } }); } diff --git a/mobile-web/src/page/shipping/order.vue b/mobile-web/src/page/shipping/order.vue index 3dee90f55..7ac160792 100644 --- a/mobile-web/src/page/shipping/order.vue +++ b/mobile-web/src/page/shipping/order.vue @@ -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 => { diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersCartController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersCartController.java index e24ca194f..01e1ed7b2 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersCartController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersCartController.java @@ -105,7 +105,7 @@ public class UsersCartController { } @GetMapping("/confirm_create_order") - public CommonResult getConfirmCreateOrder(@RequestParam("couponCardId") Integer couponCardId) { + public CommonResult getConfirmCreateOrder(@RequestParam(value = "couponCardId", required = false) Integer couponCardId) { Integer userId = UserSecurityContextHolder.getContext().getUserId(); // 获得购物车中选中的 List cartItems = cartService.list(userId, true).getData(); diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java index 4e5fe7b7b..c376725a8 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java @@ -94,7 +94,7 @@ public class UsersOrderController { @ApiOperation("确认创建订单") public CommonResult 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()) diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/vo/UsersOrderConfirmCreateVO.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/vo/UsersOrderConfirmCreateVO.java index 5551a7694..21c0379c7 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/vo/UsersOrderConfirmCreateVO.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/vo/UsersOrderConfirmCreateVO.java @@ -24,6 +24,10 @@ public class UsersOrderConfirmCreateVO { * 优惠劵列表 TODO 芋艿,后续改改 */ private List couponCards; + /** + * 优惠劵优惠金额 + */ + private Integer couponCardDiscountTotal; /** * 商品分组 * diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java index a7f5aae9f..745562581 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java @@ -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 items = itemGroup.getItems().stream().filter(item -> !item.getSelected()) + List 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(); diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/CouponCardDetailBO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/CouponCardDetailBO.java index 444fbfbf8..b1dd75474 100644 --- a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/CouponCardDetailBO.java +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/CouponCardDetailBO.java @@ -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 ========== /** diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java index a8e834102..c7e0b21cf 100644 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java @@ -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> getCouponCardList(Integer userId, List spus) { // 查询用户未使用的优惠劵列表 List cards = couponCardMapper.selectListByUserIdAndStatus(userId, CouponCardStatusEnum.UNUSED.getValue()); - - // TODO: 2019-04-19 芋艿 如果没有优惠券,处理 + if (cards.isEmpty()) { + return CommonResult.success(Collections.emptyList()); + } + // 查询优惠劵模板集合 Map templates = couponTemplateMapper.selectListByIds(cards.stream().map(CouponCardDO::getTemplateId).collect(Collectors.toSet())) .stream().collect(Collectors.toMap(CouponTemplateDO::getId, template -> template)); // 逐个判断是否可用