You've already forked FrameTour-BE
feat(pricing): 更新用户优惠券查询接口返回完整信息
- 修改 getUserCoupons 接口不再需要传入 userId 参数,从上下文获取当前登录用户 - 新增 UserCouponResp DTO 包含领取记录和优惠券配置的完整信息 - 更新 ICouponService 接口返回类型为 UserCouponResp 列表 - 在 Controller 层添加 getUserId 方法用于获取当前登录用户ID - 实现完整的用户优惠券信息组装逻辑,包含领取时间、过期时间等记录信息
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.ycwl.basic.pricing.controller;
|
||||
|
||||
import com.ycwl.basic.constant.BaseContextHandler;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import com.ycwl.basic.pricing.dto.*;
|
||||
import com.ycwl.basic.pricing.dto.resp.UserCouponResp;
|
||||
import com.ycwl.basic.pricing.service.ICouponService;
|
||||
import com.ycwl.basic.pricing.service.IPriceCalculationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -53,16 +55,37 @@ public class PriceCalculationController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户可用优惠券
|
||||
* 查询用户可用优惠券(包含领取记录信息)
|
||||
*/
|
||||
@GetMapping("/coupons/my-coupons")
|
||||
public ApiResponse<List<CouponInfo>> getUserCoupons(@RequestParam Long userId) {
|
||||
public ApiResponse<List<UserCouponResp>> getUserCoupons() {
|
||||
Long userId = getUserId();
|
||||
if (userId == null) {
|
||||
return ApiResponse.fail("用户未登录");
|
||||
}
|
||||
|
||||
log.info("查询用户可用优惠券: userId={}", userId);
|
||||
|
||||
List<CouponInfo> coupons = couponService.getUserAvailableCoupons(userId);
|
||||
|
||||
|
||||
List<UserCouponResp> coupons = couponService.getUserAvailableCoupons(userId);
|
||||
|
||||
log.info("用户可用优惠券数量: {}", coupons.size());
|
||||
|
||||
|
||||
return ApiResponse.success(coupons);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户ID
|
||||
*/
|
||||
private Long getUserId() {
|
||||
try {
|
||||
String userIdStr = BaseContextHandler.getUserId();
|
||||
if (userIdStr == null || userIdStr.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return Long.valueOf(userIdStr);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("无法解析用户ID: {}", BaseContextHandler.getUserId());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.ycwl.basic.pricing.dto.resp;
|
||||
|
||||
import com.ycwl.basic.pricing.enums.CouponStatus;
|
||||
import com.ycwl.basic.pricing.enums.CouponType;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户优惠券响应DTO(包含领取记录+优惠券配置)
|
||||
*/
|
||||
@Data
|
||||
public class UserCouponResp {
|
||||
|
||||
// ==================== 领取记录信息 ====================
|
||||
|
||||
/**
|
||||
* 领取记录ID
|
||||
*/
|
||||
private Long claimRecordId;
|
||||
|
||||
/**
|
||||
* 领取时间
|
||||
*/
|
||||
private Date claimTime;
|
||||
|
||||
/**
|
||||
* 过期时间(根据领取时间+领取后有效期计算)
|
||||
*/
|
||||
private Date expireTime;
|
||||
|
||||
/**
|
||||
* 优惠券状态
|
||||
*/
|
||||
private CouponStatus status;
|
||||
|
||||
/**
|
||||
* 领取时的景区ID
|
||||
*/
|
||||
private String claimScenicId;
|
||||
|
||||
// ==================== 优惠券配置信息 ====================
|
||||
|
||||
/**
|
||||
* 优惠券ID
|
||||
*/
|
||||
private Long couponId;
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String couponName;
|
||||
|
||||
/**
|
||||
* 优惠类型
|
||||
*/
|
||||
private CouponType couponType;
|
||||
|
||||
/**
|
||||
* 优惠值(百分比时为折扣比例,固定金额时为具体金额)
|
||||
*/
|
||||
private BigDecimal discountValue;
|
||||
|
||||
/**
|
||||
* 最小使用金额(门槛)
|
||||
*/
|
||||
private BigDecimal minAmount;
|
||||
|
||||
/**
|
||||
* 最大优惠金额
|
||||
*/
|
||||
private BigDecimal maxDiscount;
|
||||
|
||||
/**
|
||||
* 适用景区ID(NULL表示不限景区)
|
||||
*/
|
||||
private String scenicId;
|
||||
|
||||
/**
|
||||
* 优惠券全局有效期开始时间
|
||||
*/
|
||||
private Date validFrom;
|
||||
|
||||
/**
|
||||
* 优惠券全局有效期结束时间
|
||||
*/
|
||||
private Date validUntil;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.ycwl.basic.pricing.dto.CouponUseResult;
|
||||
import com.ycwl.basic.pricing.dto.CouponClaimRequest;
|
||||
import com.ycwl.basic.pricing.dto.CouponClaimResult;
|
||||
import com.ycwl.basic.pricing.dto.ProductItem;
|
||||
import com.ycwl.basic.pricing.dto.resp.UserCouponResp;
|
||||
import com.ycwl.basic.pricing.entity.PriceCouponConfig;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -55,12 +56,12 @@ public interface ICouponService {
|
||||
CouponUseResult useCoupon(CouponUseRequest request);
|
||||
|
||||
/**
|
||||
* 查询用户可用优惠券
|
||||
*
|
||||
* 查询用户可用优惠券(包含领取记录信息)
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 可用优惠券列表
|
||||
* @return 用户优惠券列表(包含领取记录+优惠券配置)
|
||||
*/
|
||||
List<CouponInfo> getUserAvailableCoupons(Long userId);
|
||||
List<UserCouponResp> getUserAvailableCoupons(Long userId);
|
||||
|
||||
/**
|
||||
* 领取优惠券(内部调用方法)
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.ycwl.basic.pricing.service.impl;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.ycwl.basic.pricing.dto.*;
|
||||
import com.ycwl.basic.pricing.dto.resp.UserCouponResp;
|
||||
import com.ycwl.basic.pricing.entity.PriceCouponClaimRecord;
|
||||
import com.ycwl.basic.pricing.entity.PriceCouponConfig;
|
||||
import com.ycwl.basic.pricing.enums.CouponStatus;
|
||||
@@ -274,19 +275,43 @@ public class CouponServiceImpl implements ICouponService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CouponInfo> getUserAvailableCoupons(Long userId) {
|
||||
public List<UserCouponResp> getUserAvailableCoupons(Long userId) {
|
||||
List<PriceCouponClaimRecord> records = couponClaimRecordMapper.selectUserAvailableCoupons(userId);
|
||||
List<CouponInfo> coupons = new ArrayList<>();
|
||||
|
||||
List<UserCouponResp> coupons = new ArrayList<>();
|
||||
|
||||
for (PriceCouponClaimRecord record : records) {
|
||||
PriceCouponConfig config = couponConfigMapper.selectById(record.getCouponId());
|
||||
if (config != null) {
|
||||
coupons.add(buildCouponInfo(config, null));
|
||||
coupons.add(buildUserCouponResp(record, config));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return coupons;
|
||||
}
|
||||
|
||||
private UserCouponResp buildUserCouponResp(PriceCouponClaimRecord record, PriceCouponConfig config) {
|
||||
UserCouponResp resp = new UserCouponResp();
|
||||
|
||||
// 领取记录信息
|
||||
resp.setClaimRecordId(record.getId());
|
||||
resp.setClaimTime(record.getClaimTime());
|
||||
resp.setExpireTime(record.getExpireTime());
|
||||
resp.setStatus(record.getStatus());
|
||||
resp.setClaimScenicId(record.getScenicId());
|
||||
|
||||
// 优惠券配置信息
|
||||
resp.setCouponId(config.getId());
|
||||
resp.setCouponName(config.getCouponName());
|
||||
resp.setCouponType(config.getCouponType());
|
||||
resp.setDiscountValue(config.getDiscountValue());
|
||||
resp.setMinAmount(config.getMinAmount());
|
||||
resp.setMaxDiscount(config.getMaxDiscount());
|
||||
resp.setScenicId(config.getScenicId());
|
||||
resp.setValidFrom(config.getValidFrom());
|
||||
resp.setValidUntil(config.getValidUntil());
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
private CouponInfo buildCouponInfo(PriceCouponConfig coupon, BigDecimal actualDiscountAmount) {
|
||||
CouponInfo info = new CouponInfo();
|
||||
|
||||
Reference in New Issue
Block a user