feat(coupon): add enum ClaimConditionType and whitelist support\n\n- Add CouponClaimConditionType enum (ALL/FILTER/WHITELIST)\n- Schema: add custom_whitelist JSON column (Flyway V2)\n- Entity/VO: add customWhitelist; claimConditionType now 0/1/2\n- Service: enforce whitelist when claimConditionType=2\n- Controller: validate whitelist when creating coupon\n- Fix imports per formatting
This commit is contained in:
@@ -18,12 +18,10 @@ import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -146,6 +144,10 @@ public class PlayCouponInfoController {
|
||||
}
|
||||
entity.setDiscountContent(discountContent);
|
||||
entity.setCouponOnLineState("1");
|
||||
// 领取白名单校验:当为2时必须配置白名单
|
||||
if ("2".equals(vo.getClaimConditionType()) && (vo.getCustomWhitelist() == null || vo.getCustomWhitelist().isEmpty())) {
|
||||
throw new CustomException("领取条件为白名单时,必须设置领取白名单");
|
||||
}
|
||||
boolean success = playCouponInfoService.create(entity);
|
||||
if (success) {
|
||||
return R.ok();
|
||||
|
||||
@@ -118,10 +118,16 @@ public class PlayCouponInfoEntity extends BaseEntity<PlayCouponInfoEntity> {
|
||||
private Integer clerkObtainedMaxQuantity;
|
||||
|
||||
/**
|
||||
* 领取条件类型(0:所有人可领取,1:指定条件领取)
|
||||
* 领取条件类型:0=所有人可领取;1=按条件领取;2=仅白名单可领取。
|
||||
*/
|
||||
private String claimConditionType;
|
||||
|
||||
/**
|
||||
* 领取白名单(claimConditionType=2 生效)。JSON存储用户ID列表。
|
||||
*/
|
||||
@TableField(typeHandler = StringTypeHandler.class)
|
||||
private List<String> customWhitelist;
|
||||
|
||||
/**
|
||||
* 顾客等级选择状态(0:未选择,1:选择)
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.starry.admin.modules.shop.module.enums;
|
||||
|
||||
/**
|
||||
* 优惠券领取条件类型
|
||||
*/
|
||||
public enum CouponClaimConditionType {
|
||||
ALL("0"),
|
||||
FILTER("1"),
|
||||
WHITELIST("2");
|
||||
|
||||
private final String code;
|
||||
|
||||
CouponClaimConditionType(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String code() { return code; }
|
||||
|
||||
public static CouponClaimConditionType of(String code) {
|
||||
for (CouponClaimConditionType t : values()) {
|
||||
if (t.code.equals(code)) return t;
|
||||
}
|
||||
return ALL;
|
||||
}
|
||||
}
|
||||
@@ -120,12 +120,17 @@ public class PlayCouponInfoAddVo {
|
||||
private Integer clerkObtainedMaxQuantity;
|
||||
|
||||
/**
|
||||
* 领取条件类型(0:所有人可领取,1:指定条件领取)
|
||||
* 领取条件类型:0=所有人;1=按条件;2=白名单。
|
||||
*/
|
||||
@NotNull(message = "领取条件类型不能为空")
|
||||
@Pattern(regexp = "[0|1]", message = "店员范围只能为0或者1")
|
||||
@Pattern(regexp = "^(0|1|2)$", message = "领取条件类型只能为0或1或2")
|
||||
private String claimConditionType;
|
||||
|
||||
/**
|
||||
* 领取白名单(claimConditionType=2 时校验):用户ID列表
|
||||
*/
|
||||
private List<String> customWhitelist;
|
||||
|
||||
/**
|
||||
* 顾客等级选择状态(0:未选择,1:选择)
|
||||
*/
|
||||
|
||||
@@ -109,10 +109,16 @@ public class PlayCouponInfoReturnVo {
|
||||
private Integer clerkObtainedMaxQuantity;
|
||||
|
||||
/**
|
||||
* 领取条件类型(0:所有人可领取,1:指定条件领取)
|
||||
* 领取条件类型:0=所有人;1=按条件;2=白名单。
|
||||
*/
|
||||
private String claimConditionType;
|
||||
|
||||
/**
|
||||
* 领取白名单(claimConditionType=2 生效)
|
||||
*/
|
||||
@TableField(typeHandler = StringTypeHandler.class)
|
||||
private List<String> customWhitelist;
|
||||
|
||||
/**
|
||||
* 顾客等级选择状态(0:未选择,1:选择)
|
||||
*/
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.starry.admin.common.exception.CustomException;
|
||||
import com.starry.admin.modules.custom.module.entity.PlayCustomUserInfoEntity;
|
||||
import com.starry.admin.modules.shop.mapper.PlayCouponInfoMapper;
|
||||
import com.starry.admin.modules.shop.module.entity.PlayCouponInfoEntity;
|
||||
import com.starry.admin.modules.shop.module.enums.CouponClaimConditionType;
|
||||
import com.starry.admin.modules.shop.module.vo.PlayCouponInfoQueryVo;
|
||||
import com.starry.admin.modules.shop.module.vo.PlayCouponInfoReturnVo;
|
||||
import com.starry.admin.modules.shop.service.IPlayCouponInfoService;
|
||||
@@ -84,10 +85,17 @@ public class PlayCouponInfoServiceImpl extends ServiceImpl<PlayCouponInfoMapper,
|
||||
@Override
|
||||
public String getReasonForNotObtainingCoupons(PlayCouponInfoEntity entity,
|
||||
PlayCustomUserInfoEntity customUserInfo) {
|
||||
// 优惠券是否设置指定条件领取
|
||||
if ("0".equals(entity.getClaimConditionType())) {
|
||||
CouponClaimConditionType type = CouponClaimConditionType.of(entity.getClaimConditionType());
|
||||
switch (type) {
|
||||
case ALL:
|
||||
return "";
|
||||
case WHITELIST:
|
||||
if (entity.getCustomWhitelist() == null || entity.getCustomWhitelist().isEmpty()) {
|
||||
return "未配置白名单";
|
||||
}
|
||||
return entity.getCustomWhitelist().contains(customUserInfo.getId()) ? "" : "非指定用户";
|
||||
case FILTER:
|
||||
default:
|
||||
// 顾客等级判断
|
||||
String msg = reasonForNotObtainingCoupons(entity.getCustomLevelCheckType(), entity.getCustomLevel(),
|
||||
customUserInfo.getLevelId(), "0");
|
||||
@@ -96,15 +104,14 @@ public class PlayCouponInfoServiceImpl extends ServiceImpl<PlayCouponInfoMapper,
|
||||
}
|
||||
// 顾客性别判断
|
||||
msg = reasonForNotObtainingCoupons(entity.getCustomSexCheckType(), entity.getCustomSex(),
|
||||
customUserInfo.getSex().toString(), "`1");
|
||||
String.valueOf(customUserInfo.getSex()), "1");
|
||||
if (StrUtil.isNotEmpty(msg)) {
|
||||
return msg;
|
||||
}
|
||||
// 顾客关注公众号状态判断
|
||||
|
||||
// 顾客是否是新用户判断
|
||||
// TODO: 关注状态、新用户等其他条件可在此扩展
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠券不可领取的原因
|
||||
|
||||
@@ -25,13 +25,11 @@ import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Add whitelist for coupon self-claim restriction (specific users only)
|
||||
-- MySQL dialect
|
||||
ALTER TABLE `play_coupon_info`
|
||||
ADD COLUMN `custom_whitelist` TEXT NULL COMMENT '领取白名单用户ID(JSON)';
|
||||
|
||||
Reference in New Issue
Block a user