feat(pricing): 增加券码重复使用功能并优化相关数据结构

- 在 PriceVoucherUsageRecord 和 VoucherUsageRecordResp 中添加 usageSequence 字段,用于记录券码的使用序号- 更新 PriceVoucherCode 实体和相关 mapper,增加 currentUseCount 和 lastUsedTime 字段
- 修改 VoucherCodeServiceImpl 和 VoucherServiceImpl 中的券码使用逻辑,支持重复使用
- 新增VoucherBatchOverviewResp、VoucherDetailResp、VoucherUsageSummaryResp 和 VoucherValidationResp 等新的响应 DTO 类,用于提供券码批次概览、详情、使用统计和验证等功能
This commit is contained in:
2025-09-16 20:54:37 +08:00
parent 8380b02fbb
commit 1506ae95b8
10 changed files with 536 additions and 175 deletions

View File

@@ -0,0 +1,80 @@
package com.ycwl.basic.pricing.dto.resp;
import lombok.Data;
import java.math.BigDecimal;
/**
* 券码批次概览响应
*/
@Data
public class VoucherBatchOverviewResp {
/**
* 批次ID
*/
private Long batchId;
/**
* 批次名称
*/
private String batchName;
/**
* 券码总数
*/
private Integer totalCodes;
/**
* 已领取券码数
*/
private Integer claimedCodes;
/**
* 已使用券码数(至少使用过一次)
*/
private Integer usedCodes;
/**
* 已达到最大使用次数的券码数
*/
private Integer exhaustedCodes;
/**
* 总使用记录数(支持重复使用)
*/
private Integer totalUsageRecords;
/**
* 平均每个券码使用次数
*/
private BigDecimal averageUsagePerCode;
/**
* 重复使用率 (重复使用的券码数/已使用券码数 * 100)
*/
private BigDecimal repeatUsageRate;
/**
* 可重复使用设置
*/
private RepeatableSettings repeatableSettings;
@Data
public static class RepeatableSettings {
/**
* 每个券码最大使用次数
*/
private Integer maxUseCount;
/**
* 每个用户最大使用次数
*/
private Integer maxUsePerUser;
/**
* 使用间隔小时数
*/
private Integer useIntervalHours;
}
}

View File

@@ -0,0 +1,142 @@
package com.ycwl.basic.pricing.dto.resp;
import com.ycwl.basic.pricing.enums.ProductType;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 券码详情响应
*/
@Data
public class VoucherDetailResp {
/**
* 券码
*/
private String voucherCode;
/**
* 批次信息
*/
private BatchInfo batchInfo;
/**
* 使用信息
*/
private UsageInfo usageInfo;
/**
* 用户信息
*/
private UserInfo userInfo;
/**
* 状态信息
*/
private StatusInfo statusInfo;
@Data
public static class BatchInfo {
/**
* 批次ID
*/
private Long batchId;
/**
* 批次名称
*/
private String batchName;
/**
* 优惠类型 (0: 赠品兑换, 1: 金额抵扣, 2: 百分比折扣)
*/
private Integer discountType;
/**
* 优惠值
*/
private BigDecimal discountValue;
/**
* 适用商品类型
*/
private List<ProductType> applicableProducts;
}
@Data
public static class UsageInfo {
/**
* 最大使用次数
*/
private Integer maxUseCount;
/**
* 当前已使用次数
*/
private Integer currentUseCount;
/**
* 剩余使用次数
*/
private Integer remainingUseCount;
/**
* 每个用户最大使用次数
*/
private Integer maxUsePerUser;
/**
* 使用间隔小时数
*/
private Integer useIntervalHours;
/**
* 是否还能使用
*/
private Boolean canUseMore;
}
@Data
public static class UserInfo {
/**
* 用户人脸ID
*/
private Long faceId;
/**
* 该用户已使用此券码的次数
*/
private Integer userUsageCount;
/**
* 最后使用时间
*/
private Date lastUsedTime;
/**
* 下次可用时间
*/
private Date nextAvailableTime;
}
@Data
public static class StatusInfo {
/**
* 状态码
*/
private Integer status;
/**
* 状态名称
*/
private String statusName;
/**
* 领取时间
*/
private Date claimedTime;
}
}

View File

@@ -47,6 +47,11 @@ public class VoucherUsageRecordResp {
*/
private String batchName;
/**
* 使用序号(该券码的第几次使用)
*/
private Integer usageSequence;
/**
* 使用时间
*/

View File

@@ -0,0 +1,100 @@
package com.ycwl.basic.pricing.dto.resp;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 券码使用统计摘要响应
*/
@Data
public class VoucherUsageSummaryResp {
/**
* 券码
*/
private String voucherCode;
/**
* 批次ID
*/
private Long batchId;
/**
* 批次名称
*/
private String batchName;
/**
* 总使用记录数(重复使用产生多条记录)
*/
private Integer totalUsageRecords;
/**
* 使用过的独立用户数
*/
private Integer uniqueUsers;
/**
* 使用统计
*/
private UsageStatistics usageStatistics;
/**
* 使用时间轴
*/
private List<UsageTimeline> usageTimeline;
@Data
public static class UsageStatistics {
/**
* 最大可使用次数
*/
private Integer maxUseCount;
/**
* 当前已使用次数
*/
private Integer currentUseCount;
/**
* 剩余使用次数
*/
private Integer remainingUseCount;
/**
* 使用率
*/
private BigDecimal usageRate;
/**
* 是否还能使用
*/
private Boolean canUseMore;
}
@Data
public static class UsageTimeline {
/**
* 使用时间
*/
private Date useTime;
/**
* 用户人脸ID
*/
private Long faceId;
/**
* 订单ID
*/
private String orderId;
/**
* 优惠金额
*/
private BigDecimal discountAmount;
}
}

View File

@@ -0,0 +1,33 @@
package com.ycwl.basic.pricing.dto.resp;
import com.ycwl.basic.pricing.dto.VoucherInfo;
import lombok.Builder;
import lombok.Data;
/**
* 券码验证响应
*/
@Data
@Builder
public class VoucherValidationResp {
/**
* 券码
*/
private String voucherCode;
/**
* 是否可用
*/
private Boolean available;
/**
* 不可用原因
*/
private String unavailableReason;
/**
* 券码详细信息
*/
private VoucherInfo voucherInfo;
}