From 69c1790fd03a84748063d7c361db837a289b81bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9D=BE?= <8605635+zhang3064194730@user.noreply.gitee.com> Date: Mon, 18 Nov 2024 14:32:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E6=83=A0=E5=88=B8=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/service/CartService.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index 5959f26..5329497 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -1231,7 +1231,12 @@ public class CartService { }); HashMap> usedCouponMap = new HashMap<>(); ArrayList outRecords = new ArrayList<>(); + ArrayList resetCouponList = new ArrayList<>(); for (TbCashierCart cashierCart : cartInfoDTO.getNewCashierCarts()) { + if (!couponMap.isEmpty()) { + resetCouponList.add(cashierCart); + cashierCart.setUserCouponId(null); + } discountAmount = reduceProCoupon(couponMap, cashierCart, usedCouponMap, discountAmount, balanceCartList, outRecords, memberId); } @@ -1241,6 +1246,20 @@ public class CartService { cashierCartService.saveBatch(balanceCartList); } // 更新购物车信息 + if (!resetCouponList.isEmpty()) { + // 取消之前使用的历史券 + ArrayList resetCartIds = new ArrayList<>(); + resetCouponList.forEach(item -> { + if (item.getUserCouponId() == null) { + resetCartIds.add(item.getId()); + } + }); + if (!resetCartIds.isEmpty()) { + cashierCartService.update(new LambdaUpdateWrapper() + .in(TbCashierCart::getId, resetCartIds) + .set(TbCashierCart::getUserCouponId, null)); + } + } cashierCartService.updateBatchById(cartInfoDTO.getNewCashierCarts()); couponInfoDTO.setOutRecordList(outRecords);