From 07593694c8ea130f0c5d37b52829782d2014485f Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Thu, 8 Jan 2026 16:45:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(pricing):=20=E6=B7=BB=E5=8A=A0=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8=E9=85=8D=E7=BD=AE=E4=B8=AD=E7=9A=84=E7=94=B3?= =?UTF-8?q?=E9=A2=86=E6=95=B0=E9=87=8F=E5=92=8C=E7=94=A8=E6=88=B7=E7=94=B3?= =?UTF-8?q?=E9=A2=86=E9=99=90=E5=88=B6=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 PriceCouponConfigMapper 中新增 claimed_quantity 和 user_claim_limit 字段映射 - 更新 INSERT 语句以包含新的申领相关字段 - 修改 insertCoupon 方法以支持优惠券申领数量控制功能 --- .../mapper/PriceCouponConfigMapper.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 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 95b4e924..c7e8710c 100644 --- a/src/main/java/com/ycwl/basic/pricing/mapper/PriceCouponConfigMapper.java +++ b/src/main/java/com/ycwl/basic/pricing/mapper/PriceCouponConfigMapper.java @@ -17,19 +17,19 @@ import java.util.List; public interface PriceCouponConfigMapper extends BaseMapper { /** - * 查询有效的优惠券配置 + * 查询有效的优惠券配置(可领取的) */ @Select("SELECT * FROM price_coupon_config WHERE is_active = 1 " + "AND valid_from <= NOW() AND valid_until > NOW() " + - "AND used_quantity < total_quantity") + "AND (total_quantity IS NULL OR total_quantity <= 0 OR COALESCE(claimed_quantity, 0) < total_quantity)") List selectValidCoupons(); - + /** - * 根据ID查询优惠券(包括使用数量检查) + * 根据ID查询优惠券(包括库存检查) */ @Select("SELECT * FROM price_coupon_config WHERE id = #{couponId} " + "AND is_active = 1 AND valid_from <= NOW() AND valid_until > NOW() " + - "AND used_quantity < total_quantity") + "AND (total_quantity IS NULL OR total_quantity <= 0 OR COALESCE(claimed_quantity, 0) < total_quantity)") PriceCouponConfig selectValidCouponById(Long couponId); /** @@ -51,10 +51,12 @@ public interface PriceCouponConfigMapper extends BaseMapper { * 插入优惠券配置 */ @Insert("INSERT INTO price_coupon_config (coupon_name, coupon_type, discount_value, min_amount, " + - "max_discount, applicable_products, required_attribute_keys, total_quantity, used_quantity, valid_from, valid_until, " + + "max_discount, applicable_products, required_attribute_keys, total_quantity, used_quantity, " + + "claimed_quantity, user_claim_limit, valid_from, valid_until, " + "is_active, scenic_id, create_time, update_time) VALUES " + "(#{couponName}, #{couponType}, #{discountValue}, #{minAmount}, #{maxDiscount}, " + - "#{applicableProducts}, #{requiredAttributeKeys}, #{totalQuantity}, #{usedQuantity}, #{validFrom}, #{validUntil}, " + + "#{applicableProducts}, #{requiredAttributeKeys}, #{totalQuantity}, #{usedQuantity}, " + + "#{claimedQuantity}, #{userClaimLimit}, #{validFrom}, #{validUntil}, " + "#{isActive}, #{scenicId}, NOW(), NOW())") int insertCoupon(PriceCouponConfig coupon); @@ -63,7 +65,8 @@ public interface PriceCouponConfigMapper extends BaseMapper { */ @Update("UPDATE price_coupon_config SET coupon_name = #{couponName}, coupon_type = #{couponType}, " + "discount_value = #{discountValue}, min_amount = #{minAmount}, max_discount = #{maxDiscount}, " + - "applicable_products = #{applicableProducts}, required_attribute_keys = #{requiredAttributeKeys}, total_quantity = #{totalQuantity}, " + + "applicable_products = #{applicableProducts}, required_attribute_keys = #{requiredAttributeKeys}, " + + "total_quantity = #{totalQuantity}, user_claim_limit = #{userClaimLimit}, " + "valid_from = #{validFrom}, valid_until = #{validUntil}, is_active = #{isActive}, " + "scenic_id = #{scenicId}, update_time = NOW() WHERE id = #{id}") int updateCoupon(PriceCouponConfig coupon); @@ -117,11 +120,11 @@ public interface PriceCouponConfigMapper extends BaseMapper { int deleteCoupon(Long id); /** - * 查询指定景区的有效优惠券配置 + * 查询指定景区的有效优惠券配置(可领取的) */ @Select("SELECT * FROM price_coupon_config WHERE is_active = 1 " + "AND valid_from <= NOW() AND valid_until > NOW() " + - "AND used_quantity < total_quantity " + + "AND (total_quantity IS NULL OR total_quantity <= 0 OR COALESCE(claimed_quantity, 0) < total_quantity) " + "AND (scenic_id IS NULL OR scenic_id = #{scenicId})") List selectValidCouponsByScenicId(@Param("scenicId") String scenicId);