You've already forked FrameTour-BE
feat(pricing): 增加景区优惠券统计功能并优化优惠券使用逻辑
- 新增景区优惠券统计接口和相关查询方法 - 为优惠券配置和使用记录添加景区ID字段 - 实现优惠券使用时的景区限制检查 - 优化优惠券适用性的判断逻辑,增加对景区和商品类型的检查
This commit is contained in:
@@ -44,10 +44,10 @@ public interface PriceCouponConfigMapper extends BaseMapper<PriceCouponConfig> {
|
||||
*/
|
||||
@Insert("INSERT INTO price_coupon_config (coupon_name, coupon_type, discount_value, min_amount, " +
|
||||
"max_discount, applicable_products, total_quantity, used_quantity, valid_from, valid_until, " +
|
||||
"is_active, created_time, updated_time) VALUES " +
|
||||
"is_active, scenic_id, created_time, updated_time) VALUES " +
|
||||
"(#{couponName}, #{couponType}, #{discountValue}, #{minAmount}, #{maxDiscount}, " +
|
||||
"#{applicableProducts}, #{totalQuantity}, #{usedQuantity}, #{validFrom}, #{validUntil}, " +
|
||||
"#{isActive}, NOW(), NOW())")
|
||||
"#{isActive}, #{scenicId}, NOW(), NOW())")
|
||||
int insertCoupon(PriceCouponConfig coupon);
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ public interface PriceCouponConfigMapper extends BaseMapper<PriceCouponConfig> {
|
||||
"discount_value = #{discountValue}, min_amount = #{minAmount}, max_discount = #{maxDiscount}, " +
|
||||
"applicable_products = #{applicableProducts}, total_quantity = #{totalQuantity}, " +
|
||||
"valid_from = #{validFrom}, valid_until = #{validUntil}, is_active = #{isActive}, " +
|
||||
"updated_time = NOW() WHERE id = #{id}")
|
||||
"scenic_id = #{scenicId}, updated_time = NOW() WHERE id = #{id}")
|
||||
int updateCoupon(PriceCouponConfig coupon);
|
||||
|
||||
// ==================== 管理端接口 ====================
|
||||
@@ -80,11 +80,15 @@ public interface PriceCouponConfigMapper extends BaseMapper<PriceCouponConfig> {
|
||||
"<if test='couponName != null and couponName != \"\"'>" +
|
||||
"AND coupon_name LIKE CONCAT('%', #{couponName}, '%')" +
|
||||
"</if>" +
|
||||
"<if test='scenicId != null and scenicId != \"\"'>" +
|
||||
"AND scenic_id = #{scenicId}" +
|
||||
"</if>" +
|
||||
"</where>" +
|
||||
"ORDER BY created_time DESC" +
|
||||
"</script>")
|
||||
List<PriceCouponConfig> selectByConditionsForAdmin(@Param("isActive") Boolean isActive,
|
||||
@Param("couponName") String couponName);
|
||||
@Param("couponName") String couponName,
|
||||
@Param("scenicId") String scenicId);
|
||||
|
||||
/**
|
||||
* 管理端:根据状态查询优惠券配置
|
||||
@@ -103,4 +107,30 @@ public interface PriceCouponConfigMapper extends BaseMapper<PriceCouponConfig> {
|
||||
*/
|
||||
@Update("UPDATE price_coupon_config SET deleted = 1, updated_time = NOW() WHERE id = #{id}")
|
||||
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 (scenic_id IS NULL OR scenic_id = #{scenicId})")
|
||||
List<PriceCouponConfig> selectValidCouponsByScenicId(@Param("scenicId") String scenicId);
|
||||
|
||||
/**
|
||||
* 管理端:根据景区ID查询优惠券配置
|
||||
*/
|
||||
@Select("SELECT * FROM price_coupon_config WHERE scenic_id = #{scenicId} ORDER BY created_time DESC")
|
||||
List<PriceCouponConfig> selectByScenicIdForAdmin(@Param("scenicId") String scenicId);
|
||||
|
||||
/**
|
||||
* 统计景区优惠券配置数量
|
||||
*/
|
||||
@Select("SELECT " +
|
||||
"COUNT(*) as total_coupons, " +
|
||||
"COUNT(CASE WHEN is_active = 1 THEN 1 END) as active_coupons, " +
|
||||
"SUM(total_quantity) as total_quantity, " +
|
||||
"SUM(used_quantity) as used_quantity " +
|
||||
"FROM price_coupon_config WHERE scenic_id = #{scenicId}")
|
||||
java.util.Map<String, Object> selectScenicCouponConfigStats(@Param("scenicId") String scenicId);
|
||||
}
|
Reference in New Issue
Block a user