fix: 优惠券使用修改

This commit is contained in:
张松
2024-11-18 14:32:26 +08:00
parent eb48ae66ff
commit 69c1790fd0

View File

@@ -1231,7 +1231,12 @@ public class CartService {
});
HashMap<String, List<TbUserCouponVo>> usedCouponMap = new HashMap<>();
ArrayList<TbActivateOutRecord> outRecords = new ArrayList<>();
ArrayList<TbCashierCart> 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<Integer> resetCartIds = new ArrayList<>();
resetCouponList.forEach(item -> {
if (item.getUserCouponId() == null) {
resetCartIds.add(item.getId());
}
});
if (!resetCartIds.isEmpty()) {
cashierCartService.update(new LambdaUpdateWrapper<TbCashierCart>()
.in(TbCashierCart::getId, resetCartIds)
.set(TbCashierCart::getUserCouponId, null));
}
}
cashierCartService.updateBatchById(cartInfoDTO.getNewCashierCarts());
couponInfoDTO.setOutRecordList(outRecords);