feat(pricing): 添加券码管理和使用功能

- 新增券码批次配置和券码实体
- 实现券码创建、领取、使用等接口
- 添加券码状态和优惠类型枚举
- 优化价格计算逻辑,支持券码优惠
- 新增优惠检测和应用相关功能
This commit is contained in:
2025-08-21 09:35:08 +08:00
parent e9035af542
commit eb327723cd
52 changed files with 2572 additions and 455 deletions

View File

@@ -0,0 +1,74 @@
package com.ycwl.basic.pricing.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 券码状态枚举
*/
@Getter
@AllArgsConstructor
public enum VoucherCodeStatus {
/**
* 未领取
*/
UNCLAIMED(0, "未领取"),
/**
* 已领取未使用
*/
CLAIMED_UNUSED(1, "已领取未使用"),
/**
* 已使用
*/
USED(2, "已使用");
private final Integer code;
private final String name;
/**
* 根据代码获取枚举值
* @param code 代码
* @return 枚举值
*/
public static VoucherCodeStatus getByCode(Integer code) {
if (code == null) {
return null;
}
for (VoucherCodeStatus status : values()) {
if (status.getCode().equals(code)) {
return status;
}
}
return null;
}
/**
* 检查是否为有效的状态代码
* @param code 代码
* @return 是否有效
*/
public static boolean isValidCode(Integer code) {
return getByCode(code) != null;
}
/**
* 检查是否可以使用(已领取未使用状态)
* @param code 状态代码
* @return 是否可以使用
*/
public static boolean canUse(Integer code) {
return CLAIMED_UNUSED.getCode().equals(code);
}
/**
* 检查是否已使用
* @param code 状态代码
* @return 是否已使用
*/
public static boolean isUsed(Integer code) {
return USED.getCode().equals(code);
}
}

View File

@@ -0,0 +1,57 @@
package com.ycwl.basic.pricing.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 券码优惠类型枚举
*/
@Getter
@AllArgsConstructor
public enum VoucherDiscountType {
/**
* 全场免费 - 所有商品免费
*/
FREE_ALL(0, "全场免费", "所有商品免费"),
/**
* 商品降价 - 每个商品减免指定金额
*/
REDUCE_PRICE(1, "商品降价", "每个商品减免指定金额"),
/**
* 商品打折 - 每个商品按百分比打折
*/
DISCOUNT(2, "商品打折", "每个商品按百分比打折");
private final Integer code;
private final String name;
private final String description;
/**
* 根据代码获取枚举值
* @param code 代码
* @return 枚举值
*/
public static VoucherDiscountType getByCode(Integer code) {
if (code == null) {
return null;
}
for (VoucherDiscountType type : values()) {
if (type.getCode().equals(code)) {
return type;
}
}
return null;
}
/**
* 检查是否为有效的优惠类型代码
* @param code 代码
* @return 是否有效
*/
public static boolean isValidCode(Integer code) {
return getByCode(code) != null;
}
}