You've already forked FrameTour-BE
feat(coupon): 添加优惠券领取功能
- 新增 CouponClaimRequest 和 CouponClaimResult 类用于处理优惠券领取请求和结果 - 在 ICouponService 接口中添加 claimCoupon 方法 - 在 CouponServiceImpl 中实现 claimCoupon 方法,包括参数验证、优惠券查询、库存检查、记录创建等步骤 - 优化日志记录和异常处理
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package com.ycwl.basic.pricing.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 优惠券领取请求DTO
|
||||
*/
|
||||
@Data
|
||||
public class CouponClaimRequest {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 优惠券ID
|
||||
*/
|
||||
private Long couponId;
|
||||
|
||||
/**
|
||||
* 景区ID(可选,记录在哪个景区领取)
|
||||
*/
|
||||
private String scenicId;
|
||||
|
||||
/**
|
||||
* 领取来源(可选,如:活动页面、签到奖励等)
|
||||
*/
|
||||
private String claimSource;
|
||||
|
||||
public CouponClaimRequest() {
|
||||
}
|
||||
|
||||
public CouponClaimRequest(Long userId, Long couponId) {
|
||||
this.userId = userId;
|
||||
this.couponId = couponId;
|
||||
}
|
||||
|
||||
public CouponClaimRequest(Long userId, Long couponId, String scenicId) {
|
||||
this.userId = userId;
|
||||
this.couponId = couponId;
|
||||
this.scenicId = scenicId;
|
||||
}
|
||||
|
||||
public CouponClaimRequest(Long userId, Long couponId, String scenicId, String claimSource) {
|
||||
this.userId = userId;
|
||||
this.couponId = couponId;
|
||||
this.scenicId = scenicId;
|
||||
this.claimSource = claimSource;
|
||||
}
|
||||
}
|
||||
100
src/main/java/com/ycwl/basic/pricing/dto/CouponClaimResult.java
Normal file
100
src/main/java/com/ycwl/basic/pricing/dto/CouponClaimResult.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package com.ycwl.basic.pricing.dto;
|
||||
|
||||
import com.ycwl.basic.pricing.entity.PriceCouponClaimRecord;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 优惠券领取结果DTO
|
||||
*/
|
||||
@Data
|
||||
public class CouponClaimResult {
|
||||
|
||||
/**
|
||||
* 是否成功
|
||||
*/
|
||||
private boolean success;
|
||||
|
||||
/**
|
||||
* 错误消息(失败时)
|
||||
*/
|
||||
private String errorMessage;
|
||||
|
||||
/**
|
||||
* 错误码(失败时)
|
||||
*/
|
||||
private String errorCode;
|
||||
|
||||
/**
|
||||
* 领取记录ID(成功时)
|
||||
*/
|
||||
private Long claimRecordId;
|
||||
|
||||
/**
|
||||
* 优惠券ID
|
||||
*/
|
||||
private Long couponId;
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String couponName;
|
||||
|
||||
/**
|
||||
* 领取时间
|
||||
*/
|
||||
private Date claimTime;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 景区ID
|
||||
*/
|
||||
private String scenicId;
|
||||
|
||||
/**
|
||||
* 创建成功结果
|
||||
*/
|
||||
public static CouponClaimResult success(PriceCouponClaimRecord record, String couponName) {
|
||||
CouponClaimResult result = new CouponClaimResult();
|
||||
result.success = true;
|
||||
result.claimRecordId = record.getId();
|
||||
result.couponId = record.getCouponId();
|
||||
result.couponName = couponName;
|
||||
result.claimTime = record.getClaimTime();
|
||||
result.userId = record.getUserId();
|
||||
result.scenicId = record.getScenicId();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建失败结果
|
||||
*/
|
||||
public static CouponClaimResult failure(String errorCode, String errorMessage) {
|
||||
CouponClaimResult result = new CouponClaimResult();
|
||||
result.success = false;
|
||||
result.errorCode = errorCode;
|
||||
result.errorMessage = errorMessage;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建失败结果(仅错误消息)
|
||||
*/
|
||||
public static CouponClaimResult failure(String errorMessage) {
|
||||
return failure("CLAIM_FAILED", errorMessage);
|
||||
}
|
||||
|
||||
// 常用错误码常量
|
||||
public static final String ERROR_COUPON_NOT_FOUND = "COUPON_NOT_FOUND";
|
||||
public static final String ERROR_COUPON_EXPIRED = "COUPON_EXPIRED";
|
||||
public static final String ERROR_COUPON_INACTIVE = "COUPON_INACTIVE";
|
||||
public static final String ERROR_COUPON_OUT_OF_STOCK = "COUPON_OUT_OF_STOCK";
|
||||
public static final String ERROR_ALREADY_CLAIMED = "ALREADY_CLAIMED";
|
||||
public static final String ERROR_INVALID_PARAMS = "INVALID_PARAMS";
|
||||
public static final String ERROR_SYSTEM_ERROR = "SYSTEM_ERROR";
|
||||
}
|
||||
Reference in New Issue
Block a user