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