feat(pricing): 支持无限量优惠券功能

- 修改数据库更新逻辑以支持无限量优惠券
- 当 total_quantity 为 NULL 或 <= 0 时不限制使用数量
- 使用 COALESCE 函数处理空值情况
- 更新 SQL 条件判断逻辑以兼容无限量场景
This commit is contained in:
2026-01-17 01:55:49 +08:00
parent aa2611d369
commit 0eced869fa

View File

@@ -33,10 +33,12 @@ public interface PriceCouponConfigMapper extends BaseMapper<PriceCouponConfig> {
PriceCouponConfig selectValidCouponById(Long couponId); PriceCouponConfig selectValidCouponById(Long couponId);
/** /**
* 增加优惠券使用数量 * 增加优惠券使用数量(支持无限量优惠券)
* 当 total_quantity 为 NULL 或 <= 0 时表示不限制使用数量
*/ */
@Update("UPDATE price_coupon_config SET used_quantity = used_quantity + 1, " + @Update("UPDATE price_coupon_config SET used_quantity = COALESCE(used_quantity, 0) + 1, " +
"update_time = NOW() WHERE id = #{couponId} AND used_quantity < total_quantity") "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); int incrementUsedQuantity(Long couponId);
/** /**