From 0eced869fad995b551ade4f798b7fea762fae11c Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sat, 17 Jan 2026 01:55:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(pricing):=20=E6=94=AF=E6=8C=81=E6=97=A0?= =?UTF-8?q?=E9=99=90=E9=87=8F=E4=BC=98=E6=83=A0=E5=88=B8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改数据库更新逻辑以支持无限量优惠券 - 当 total_quantity 为 NULL 或 <= 0 时不限制使用数量 - 使用 COALESCE 函数处理空值情况 - 更新 SQL 条件判断逻辑以兼容无限量场景 --- .../basic/pricing/mapper/PriceCouponConfigMapper.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ycwl/basic/pricing/mapper/PriceCouponConfigMapper.java b/src/main/java/com/ycwl/basic/pricing/mapper/PriceCouponConfigMapper.java index 7e491dc6..00de5da6 100644 --- a/src/main/java/com/ycwl/basic/pricing/mapper/PriceCouponConfigMapper.java +++ b/src/main/java/com/ycwl/basic/pricing/mapper/PriceCouponConfigMapper.java @@ -33,10 +33,12 @@ public interface PriceCouponConfigMapper extends BaseMapper { PriceCouponConfig selectValidCouponById(Long couponId); /** - * 增加优惠券使用数量 + * 增加优惠券使用数量(支持无限量优惠券) + * 当 total_quantity 为 NULL 或 <= 0 时表示不限制使用数量 */ - @Update("UPDATE price_coupon_config SET used_quantity = used_quantity + 1, " + - "update_time = NOW() WHERE id = #{couponId} AND used_quantity < total_quantity") + @Update("UPDATE price_coupon_config SET used_quantity = COALESCE(used_quantity, 0) + 1, " + + "update_time = NOW() WHERE id = #{couponId} " + + "AND (total_quantity IS NULL OR total_quantity <= 0 OR COALESCE(used_quantity, 0) < total_quantity)") int incrementUsedQuantity(Long couponId); /**