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);