You've already forked FrameTour-BE
- 将 created_time 修改为 create_time -将 updated_time 修改为 update_time - 调整相关 SQL 查询和插入语句中的字段名称
136 lines
5.7 KiB
Java
136 lines
5.7 KiB
Java
package com.ycwl.basic.pricing.mapper;
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
import com.ycwl.basic.pricing.entity.PriceCouponConfig;
|
|
import org.apache.ibatis.annotations.Insert;
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
import org.apache.ibatis.annotations.Param;
|
|
import org.apache.ibatis.annotations.Select;
|
|
import org.apache.ibatis.annotations.Update;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 优惠券配置Mapper
|
|
*/
|
|
@Mapper
|
|
public interface PriceCouponConfigMapper extends BaseMapper<PriceCouponConfig> {
|
|
|
|
/**
|
|
* 查询有效的优惠券配置
|
|
*/
|
|
@Select("SELECT * FROM price_coupon_config WHERE is_active = 1 " +
|
|
"AND valid_from <= NOW() AND valid_until > NOW() " +
|
|
"AND used_quantity < total_quantity")
|
|
List<PriceCouponConfig> selectValidCoupons();
|
|
|
|
/**
|
|
* 根据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")
|
|
PriceCouponConfig selectValidCouponById(Long couponId);
|
|
|
|
/**
|
|
* 增加优惠券使用数量
|
|
*/
|
|
@Update("UPDATE price_coupon_config SET used_quantity = used_quantity + 1, " +
|
|
"update_time = NOW() WHERE id = #{couponId} AND used_quantity < total_quantity")
|
|
int incrementUsedQuantity(Long couponId);
|
|
|
|
/**
|
|
* 插入优惠券配置
|
|
*/
|
|
@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, scenic_id, create_time, update_time) VALUES " +
|
|
"(#{couponName}, #{couponType}, #{discountValue}, #{minAmount}, #{maxDiscount}, " +
|
|
"#{applicableProducts}, #{totalQuantity}, #{usedQuantity}, #{validFrom}, #{validUntil}, " +
|
|
"#{isActive}, #{scenicId}, NOW(), NOW())")
|
|
int insertCoupon(PriceCouponConfig coupon);
|
|
|
|
/**
|
|
* 更新优惠券配置
|
|
*/
|
|
@Update("UPDATE price_coupon_config SET coupon_name = #{couponName}, coupon_type = #{couponType}, " +
|
|
"discount_value = #{discountValue}, min_amount = #{minAmount}, max_discount = #{maxDiscount}, " +
|
|
"applicable_products = #{applicableProducts}, total_quantity = #{totalQuantity}, " +
|
|
"valid_from = #{validFrom}, valid_until = #{validUntil}, is_active = #{isActive}, " +
|
|
"scenic_id = #{scenicId}, update_time = NOW() WHERE id = #{id}")
|
|
int updateCoupon(PriceCouponConfig coupon);
|
|
|
|
// ==================== 管理端接口 ====================
|
|
|
|
/**
|
|
* 管理端:查询所有优惠券配置(包含禁用的)
|
|
*/
|
|
@Select("SELECT * FROM price_coupon_config ORDER BY create_time DESC")
|
|
List<PriceCouponConfig> selectAllForAdmin();
|
|
|
|
/**
|
|
* 管理端:根据条件查询优惠券配置(支持分页)
|
|
*/
|
|
@Select("<script>" +
|
|
"SELECT * FROM price_coupon_config " +
|
|
"<where>" +
|
|
"<if test='isActive != null'>" +
|
|
"AND is_active = #{isActive}" +
|
|
"</if>" +
|
|
"<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 create_time DESC" +
|
|
"</script>")
|
|
List<PriceCouponConfig> selectByConditionsForAdmin(@Param("isActive") Boolean isActive,
|
|
@Param("couponName") String couponName,
|
|
@Param("scenicId") String scenicId);
|
|
|
|
/**
|
|
* 管理端:根据状态查询优惠券配置
|
|
*/
|
|
@Select("SELECT * FROM price_coupon_config WHERE is_active = #{isActive} ORDER BY create_time DESC")
|
|
List<PriceCouponConfig> selectByStatusForAdmin(@Param("isActive") Boolean isActive);
|
|
|
|
/**
|
|
* 管理端:更新优惠券状态
|
|
*/
|
|
@Update("UPDATE price_coupon_config SET is_active = #{isActive}, update_time = NOW() WHERE id = #{id}")
|
|
int updateCouponStatus(@Param("id") Long id, @Param("isActive") Boolean isActive);
|
|
|
|
/**
|
|
* 管理端:删除优惠券配置
|
|
*/
|
|
@Update("UPDATE price_coupon_config SET deleted = 1, update_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 create_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);
|
|
} |