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