You've already forked FrameTour-BE
feat(voucher): 支持券码重复使用
- 新增VoucherBatchCreateReqV2 请求对象,用于创建支持重复使用的券码批次 - 添加 VoucherUsageController 控制器,实现券码使用记录和统计功能 - 在VoucherInfo 对象中增加与重复使用相关的字段 - 修改 PriceVoucherBatchConfig 和 PriceVoucherCode 实体,支持重复使用相关属性 - 更新 VoucherBatchServiceImpl 和 VoucherServiceImpl,增加处理重复使用逻辑的方法
This commit is contained in:
@@ -2,6 +2,7 @@ package com.ycwl.basic.pricing.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherBatchCreateReq;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherBatchCreateReqV2;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherBatchQueryReq;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherClaimReq;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherCodeQueryReq;
|
||||
@@ -34,6 +35,12 @@ public class VoucherManagementController {
|
||||
return ApiResponse.success(batchId);
|
||||
}
|
||||
|
||||
@PostMapping("/batch/create/v2")
|
||||
public ApiResponse<Long> createBatchV2(@RequestBody VoucherBatchCreateReqV2 req) {
|
||||
Long batchId = voucherBatchService.createBatchV2(req);
|
||||
return ApiResponse.success(batchId);
|
||||
}
|
||||
|
||||
@PostMapping("/batch/list")
|
||||
public ApiResponse<Page<VoucherBatchResp>> getBatchList(@RequestBody VoucherBatchQueryReq req) {
|
||||
Page<VoucherBatchResp> page = voucherBatchService.queryBatchList(req);
|
||||
|
@@ -0,0 +1,97 @@
|
||||
package com.ycwl.basic.pricing.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ycwl.basic.common.ApiResponse;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherUsageHistoryReq;
|
||||
import com.ycwl.basic.pricing.dto.resp.VoucherUsageRecordResp;
|
||||
import com.ycwl.basic.pricing.dto.resp.VoucherUsageStatsResp;
|
||||
import com.ycwl.basic.pricing.service.IVoucherUsageService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 券码使用记录管理控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/pricing/voucher/usage")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "券码使用记录管理", description = "券码使用历史和统计API")
|
||||
public class VoucherUsageController {
|
||||
|
||||
private final IVoucherUsageService voucherUsageService;
|
||||
|
||||
@PostMapping("/history")
|
||||
@Operation(summary = "分页查询券码使用记录")
|
||||
public ApiResponse<Page<VoucherUsageRecordResp>> getUsageHistory(@RequestBody VoucherUsageHistoryReq req) {
|
||||
try {
|
||||
Page<VoucherUsageRecordResp> result = voucherUsageService.getUsageHistory(req);
|
||||
return ApiResponse.success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("查询券码使用记录失败", e);
|
||||
return ApiResponse.fail("查询失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{voucherCode}/records")
|
||||
@Operation(summary = "获取指定券码的使用记录")
|
||||
public ApiResponse<List<VoucherUsageRecordResp>> getRecordsByCode(
|
||||
@Parameter(description = "券码") @PathVariable String voucherCode) {
|
||||
try {
|
||||
List<VoucherUsageRecordResp> records = voucherUsageService.getUsageRecordsByCode(voucherCode);
|
||||
return ApiResponse.success(records);
|
||||
} catch (Exception e) {
|
||||
log.error("查询券码使用记录失败: {}", voucherCode, e);
|
||||
return ApiResponse.fail("查询失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{voucherCode}/stats")
|
||||
@Operation(summary = "获取券码使用统计信息")
|
||||
public ApiResponse<VoucherUsageStatsResp> getUsageStats(
|
||||
@Parameter(description = "券码") @PathVariable String voucherCode) {
|
||||
try {
|
||||
VoucherUsageStatsResp stats = voucherUsageService.getUsageStats(voucherCode);
|
||||
if (stats == null) {
|
||||
return ApiResponse.fail("券码不存在");
|
||||
}
|
||||
return ApiResponse.success(stats);
|
||||
} catch (Exception e) {
|
||||
log.error("查询券码统计信息失败: {}", voucherCode, e);
|
||||
return ApiResponse.fail("查询失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/user/{faceId}/scenic/{scenicId}")
|
||||
@Operation(summary = "获取用户在指定景区的券码使用记录")
|
||||
public ApiResponse<List<VoucherUsageRecordResp>> getUserUsageRecords(
|
||||
@Parameter(description = "用户faceId") @PathVariable Long faceId,
|
||||
@Parameter(description = "景区ID") @PathVariable Long scenicId) {
|
||||
try {
|
||||
List<VoucherUsageRecordResp> records = voucherUsageService.getUserUsageRecords(faceId, scenicId);
|
||||
return ApiResponse.success(records);
|
||||
} catch (Exception e) {
|
||||
log.error("查询用户券码使用记录失败: faceId={}, scenicId={}", faceId, scenicId, e);
|
||||
return ApiResponse.fail("查询失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/batch/{batchId}/stats")
|
||||
@Operation(summary = "获取批次券码使用统计信息")
|
||||
public ApiResponse<List<VoucherUsageStatsResp>> getBatchUsageStats(
|
||||
@Parameter(description = "批次ID") @PathVariable Long batchId) {
|
||||
try {
|
||||
List<VoucherUsageStatsResp> statsList = voucherUsageService.getBatchUsageStats(batchId);
|
||||
return ApiResponse.success(statsList);
|
||||
} catch (Exception e) {
|
||||
log.error("查询批次券码统计信息失败: batchId={}", batchId, e);
|
||||
return ApiResponse.fail("查询失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user