You've already forked FrameTour-BE
- 新增 CouponManagementController 控制器,实现优惠券配置和领取记录的管理 - 新增 ICouponManagementService 接口和 CouponManagementServiceImpl 实现类,提供优惠券管理服务 - 在 PricingConfigController 中添加获取所有优惠券配置和领取记录的接口 - 新增 BundleProductListTypeHandler 类,用于处理一口价商品列表的序列化和反序列化 - 更新 PriceCouponClaimRecordMapper 和 PriceCouponConfigMapper,添加管理端所需的查询接口
106 lines
4.3 KiB
Java
106 lines
4.3 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, " +
|
|
"updated_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, created_time, updated_time) VALUES " +
|
|
"(#{couponName}, #{couponType}, #{discountValue}, #{minAmount}, #{maxDiscount}, " +
|
|
"#{applicableProducts}, #{totalQuantity}, #{usedQuantity}, #{validFrom}, #{validUntil}, " +
|
|
"#{isActive}, 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}, " +
|
|
"updated_time = NOW() WHERE id = #{id}")
|
|
int updateCoupon(PriceCouponConfig coupon);
|
|
|
|
// ==================== 管理端接口 ====================
|
|
|
|
/**
|
|
* 管理端:查询所有优惠券配置(包含禁用的)
|
|
*/
|
|
@Select("SELECT * FROM price_coupon_config ORDER BY created_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>" +
|
|
"</where>" +
|
|
"ORDER BY created_time DESC" +
|
|
"</script>")
|
|
List<PriceCouponConfig> selectByConditionsForAdmin(@Param("isActive") Boolean isActive,
|
|
@Param("couponName") String couponName);
|
|
|
|
/**
|
|
* 管理端:根据状态查询优惠券配置
|
|
*/
|
|
@Select("SELECT * FROM price_coupon_config WHERE is_active = #{isActive} ORDER BY created_time DESC")
|
|
List<PriceCouponConfig> selectByStatusForAdmin(@Param("isActive") Boolean isActive);
|
|
|
|
/**
|
|
* 管理端:更新优惠券状态
|
|
*/
|
|
@Update("UPDATE price_coupon_config SET is_active = #{isActive}, updated_time = NOW() WHERE id = #{id}")
|
|
int updateCouponStatus(@Param("id") Long id, @Param("isActive") Boolean isActive);
|
|
|
|
/**
|
|
* 管理端:删除优惠券配置
|
|
*/
|
|
@Update("UPDATE price_coupon_config SET deleted = 1, updated_time = NOW() WHERE id = #{id}")
|
|
int deleteCoupon(Long id);
|
|
} |