You've already forked FrameTour-BE
feat(pricing): 添加优惠券管理功能
- 新增 CouponManagementController 控制器,实现优惠券配置和领取记录的管理 - 新增 ICouponManagementService 接口和 CouponManagementServiceImpl 实现类,提供优惠券管理服务 - 在 PricingConfigController 中添加获取所有优惠券配置和领取记录的接口 - 新增 BundleProductListTypeHandler 类,用于处理一口价商品列表的序列化和反序列化 - 更新 PriceCouponClaimRecordMapper 和 PriceCouponConfigMapper,添加管理端所需的查询接口
This commit is contained in:
@@ -60,4 +60,116 @@ public interface PriceCouponClaimRecordMapper extends BaseMapper<PriceCouponClai
|
||||
@Update("UPDATE price_coupon_claim_record SET status = #{status}, use_time = #{useTime}, " +
|
||||
"order_id = #{orderId}, updated_time = NOW() WHERE id = #{id}")
|
||||
int updateClaimRecord(PriceCouponClaimRecord record);
|
||||
|
||||
// ==================== 管理端接口 ====================
|
||||
|
||||
/**
|
||||
* 管理端:查询所有优惠券领取记录(支持分页)
|
||||
*/
|
||||
@Select("SELECT r.*, c.coupon_name, c.coupon_type, c.discount_value " +
|
||||
"FROM price_coupon_claim_record r " +
|
||||
"LEFT JOIN price_coupon_config c ON r.coupon_id = c.id " +
|
||||
"ORDER BY r.created_time DESC")
|
||||
List<PriceCouponClaimRecord> selectAllForAdmin();
|
||||
|
||||
/**
|
||||
* 管理端:根据条件查询优惠券领取记录(支持分页)
|
||||
*/
|
||||
@Select("<script>" +
|
||||
"SELECT r.*, c.coupon_name, c.coupon_type, c.discount_value " +
|
||||
"FROM price_coupon_claim_record r " +
|
||||
"LEFT JOIN price_coupon_config c ON r.coupon_id = c.id " +
|
||||
"<where>" +
|
||||
"<if test='userId != null'>" +
|
||||
"AND r.user_id = #{userId}" +
|
||||
"</if>" +
|
||||
"<if test='couponId != null'>" +
|
||||
"AND r.coupon_id = #{couponId}" +
|
||||
"</if>" +
|
||||
"<if test='status != null'>" +
|
||||
"AND r.status = #{status}" +
|
||||
"</if>" +
|
||||
"<if test='startTime != null and startTime != \"\"'>" +
|
||||
"AND r.claim_time >= #{startTime}" +
|
||||
"</if>" +
|
||||
"<if test='endTime != null and endTime != \"\"'>" +
|
||||
"AND r.claim_time <= #{endTime}" +
|
||||
"</if>" +
|
||||
"</where>" +
|
||||
"ORDER BY r.created_time DESC" +
|
||||
"</script>")
|
||||
List<PriceCouponClaimRecord> selectByConditionsForAdmin(@Param("userId") Long userId,
|
||||
@Param("couponId") Long couponId,
|
||||
@Param("status") CouponStatus status,
|
||||
@Param("startTime") String startTime,
|
||||
@Param("endTime") String endTime);
|
||||
|
||||
/**
|
||||
* 管理端:根据用户ID查询优惠券领取记录
|
||||
*/
|
||||
@Select("SELECT r.*, c.coupon_name, c.coupon_type, c.discount_value " +
|
||||
"FROM price_coupon_claim_record r " +
|
||||
"LEFT JOIN price_coupon_config c ON r.coupon_id = c.id " +
|
||||
"WHERE r.user_id = #{userId} " +
|
||||
"ORDER BY r.created_time DESC")
|
||||
List<PriceCouponClaimRecord> selectByUserIdForAdmin(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 管理端:根据优惠券ID查询领取记录
|
||||
*/
|
||||
@Select("SELECT r.*, c.coupon_name, c.coupon_type, c.discount_value " +
|
||||
"FROM price_coupon_claim_record r " +
|
||||
"LEFT JOIN price_coupon_config c ON r.coupon_id = c.id " +
|
||||
"WHERE r.coupon_id = #{couponId} " +
|
||||
"ORDER BY r.created_time DESC")
|
||||
List<PriceCouponClaimRecord> selectByCouponIdForAdmin(@Param("couponId") Long couponId);
|
||||
|
||||
/**
|
||||
* 管理端:根据状态查询领取记录
|
||||
*/
|
||||
@Select("SELECT r.*, c.coupon_name, c.coupon_type, c.discount_value " +
|
||||
"FROM price_coupon_claim_record r " +
|
||||
"LEFT JOIN price_coupon_config c ON r.coupon_id = c.id " +
|
||||
"WHERE r.status = #{status} " +
|
||||
"ORDER BY r.created_time DESC")
|
||||
List<PriceCouponClaimRecord> selectByStatusForAdmin(@Param("status") CouponStatus status);
|
||||
|
||||
/**
|
||||
* 管理端:统计优惠券使用情况
|
||||
*/
|
||||
@Select("SELECT " +
|
||||
"COUNT(*) as total_claimed, " +
|
||||
"COUNT(CASE WHEN status = 'USED' THEN 1 END) as total_used, " +
|
||||
"COUNT(CASE WHEN status = 'CLAIMED' THEN 1 END) as total_available " +
|
||||
"FROM price_coupon_claim_record WHERE coupon_id = #{couponId}")
|
||||
java.util.Map<String, Object> selectCouponUsageStats(@Param("couponId") Long couponId);
|
||||
|
||||
/**
|
||||
* 管理端:统计优惠券详细使用情况
|
||||
*/
|
||||
@Select("SELECT " +
|
||||
"COUNT(*) as total_claimed, " +
|
||||
"COUNT(CASE WHEN status = 'USED' THEN 1 END) as total_used, " +
|
||||
"COUNT(CASE WHEN status = 'CLAIMED' THEN 1 END) as total_available, " +
|
||||
"CASE WHEN COUNT(*) > 0 THEN COUNT(CASE WHEN status = 'USED' THEN 1 END) / COUNT(*) ELSE 0 END as usage_rate, " +
|
||||
"CASE WHEN COUNT(CASE WHEN status = 'USED' THEN 1 END) > 0 THEN " +
|
||||
"AVG(CASE WHEN status = 'USED' AND use_time IS NOT NULL AND claim_time IS NOT NULL THEN " +
|
||||
"DATEDIFF(use_time, claim_time) END) ELSE 0 END as avg_days_to_use " +
|
||||
"FROM price_coupon_claim_record WHERE coupon_id = #{couponId}")
|
||||
java.util.Map<String, Object> selectCouponDetailStats(@Param("couponId") Long couponId);
|
||||
|
||||
/**
|
||||
* 管理端:统计时间范围内的数据
|
||||
*/
|
||||
@Select("SELECT " +
|
||||
"COUNT(*) as total_claimed, " +
|
||||
"COUNT(CASE WHEN status = 'USED' THEN 1 END) as total_used, " +
|
||||
"COUNT(CASE WHEN status = 'CLAIMED' THEN 1 END) as total_available, " +
|
||||
"COUNT(CASE WHEN status = 'EXPIRED' THEN 1 END) as total_expired, " +
|
||||
"COUNT(DISTINCT coupon_id) as total_coupon_types, " +
|
||||
"COUNT(DISTINCT user_id) as total_users " +
|
||||
"FROM price_coupon_claim_record " +
|
||||
"WHERE claim_time >= #{startDate} AND claim_time <= #{endDate}")
|
||||
java.util.Map<String, Object> selectPeriodStats(@Param("startDate") String startDate,
|
||||
@Param("endDate") String endDate);
|
||||
}
|
||||
@@ -59,4 +59,48 @@ public interface PriceCouponConfigMapper extends BaseMapper<PriceCouponConfig> {
|
||||
"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);
|
||||
}
|
||||
Reference in New Issue
Block a user