You've already forked FrameTour-BE
feat(pricing): 实现批次统计功能
- 查询批次配置和券码数据 - 统计每个券码的使用情况,包括状态、使用次数、剩余次数等信息 - 计算是否还能使用和剩余使用次数 - 获取使用记录数和最后使用时间 - 返回批次统计结果列表
This commit is contained in:
@@ -140,10 +140,83 @@ public class VoucherUsageServiceImpl implements IVoucherUsageService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<VoucherUsageStatsResp> getBatchUsageStats(Long batchId) {
|
public List<VoucherUsageStatsResp> getBatchUsageStats(Long batchId) {
|
||||||
// 这里可以实现批次统计,暂时返回空列表
|
if (batchId == null) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询批次配置
|
||||||
|
PriceVoucherBatchConfig batchConfig = batchConfigMapper.selectById(batchId);
|
||||||
|
if (batchConfig == null || batchConfig.getDeleted() == 1) {
|
||||||
|
log.warn("批次配置不存在或已删除: batchId={}", batchId);
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询该批次下的所有券码
|
||||||
|
List<PriceVoucherCode> voucherCodes = voucherCodeMapper.selectByBatchId(batchId);
|
||||||
|
if (voucherCodes == null || voucherCodes.isEmpty()) {
|
||||||
|
log.info("批次下无券码数据: batchId={}", batchId);
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<VoucherUsageStatsResp> statsList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (PriceVoucherCode voucherCode : voucherCodes) {
|
||||||
|
if (voucherCode.getDeleted() == 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
VoucherUsageStatsResp stats = new VoucherUsageStatsResp();
|
||||||
|
stats.setVoucherCodeId(voucherCode.getId());
|
||||||
|
stats.setVoucherCode(voucherCode.getCode());
|
||||||
|
stats.setBatchId(batchConfig.getId());
|
||||||
|
stats.setBatchName(batchConfig.getBatchName());
|
||||||
|
stats.setScenicId(voucherCode.getScenicId());
|
||||||
|
stats.setStatus(voucherCode.getStatus());
|
||||||
|
|
||||||
|
// 设置状态名称
|
||||||
|
VoucherCodeStatus statusEnum = VoucherCodeStatus.getByCode(voucherCode.getStatus());
|
||||||
|
if (statusEnum != null) {
|
||||||
|
stats.setStatusName(statusEnum.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置使用次数相关信息
|
||||||
|
Integer currentUseCount = voucherCode.getCurrentUseCount() != null ?
|
||||||
|
voucherCode.getCurrentUseCount() : 0;
|
||||||
|
stats.setCurrentUseCount(currentUseCount);
|
||||||
|
stats.setMaxUseCount(batchConfig.getMaxUseCount());
|
||||||
|
stats.setMaxUsePerUser(batchConfig.getMaxUsePerUser());
|
||||||
|
stats.setUseIntervalHours(batchConfig.getUseIntervalHours());
|
||||||
|
|
||||||
|
// 计算是否还能使用
|
||||||
|
boolean canUseMore = true;
|
||||||
|
if (batchConfig.getMaxUseCount() != null) {
|
||||||
|
canUseMore = currentUseCount < batchConfig.getMaxUseCount();
|
||||||
|
}
|
||||||
|
stats.setCanUseMore(canUseMore);
|
||||||
|
|
||||||
|
// 计算剩余使用次数
|
||||||
|
if (batchConfig.getMaxUseCount() != null) {
|
||||||
|
int remaining = batchConfig.getMaxUseCount() - currentUseCount;
|
||||||
|
stats.setRemainingUseCount(Math.max(0, remaining));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取使用记录数
|
||||||
|
List<PriceVoucherUsageRecord> usageRecords = usageRecordMapper.selectByVoucherCodeId(voucherCode.getId());
|
||||||
|
stats.setTotalUsageRecords(usageRecords != null ? usageRecords.size() : 0);
|
||||||
|
|
||||||
|
// 格式化最后使用时间
|
||||||
|
if (voucherCode.getLastUsedTime() != null) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
stats.setLastUsedTime(sdf.format(voucherCode.getLastUsedTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
statsList.add(stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("批次统计完成: batchId={}, 券码数量={}", batchId, statsList.size());
|
||||||
|
return statsList;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recordVoucherUsage(String voucherCode, Long faceId, String orderId,
|
public void recordVoucherUsage(String voucherCode, Long faceId, String orderId,
|
||||||
BigDecimal discountAmount, String remark) {
|
BigDecimal discountAmount, String remark) {
|
||||||
|
Reference in New Issue
Block a user