送优惠券时,只有指定vip才可以送

This commit is contained in:
wyn
2026-06-23 15:41:07 +08:00
parent 60e507b750
commit eef9e7ff69
2 changed files with 28 additions and 3 deletions

View File

@@ -62,6 +62,9 @@ public class CouponEntity {
//使用门槛
private Integer useLevel;
//限定VIP类型逗号分隔如1,11,5,51用户开通其中任意VIP可现金券直接换积分
private String userVipIds;
private Date createTime;
@TableLogic

View File

@@ -271,6 +271,15 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
return set;
}
private boolean matchUserVipIds(String userVipIds, List<UserVip> userVipList) {
Set<Integer> allowedVipTypes = Arrays.stream(userVipIds.split(","))
.map(String::trim)
.filter(StringUtils::isNotEmpty)
.map(Integer::parseInt)
.collect(Collectors.toSet());
return userVipList.stream().anyMatch(userVip -> allowedVipTypes.contains(userVip.getType()));
}
public void getCourseMedicalIds(int courseMedicalId,List<Integer> list){
CourseMedicine courseMedicine = courseMedicineDao.selectById(courseMedicalId);
if (courseMedicine.getIsLast()==1){
@@ -380,7 +389,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
List<Map<String,Object>> buyOrderProducts = couponToProductDao.selectJoinMaps(wrapper);
for (Map<String,Object> map : buyOrderProducts) {
ShopProduct shopProduct = shopProductDao.selectById(map.get("product_id").toString());
//预售书+赠送现金券VIP用户将券额转为积分仅产品id=2023时需为妇幼生殖vip(type=10)
//预售书+赠送现金券VIP用户将券额转为积分配置user_vip_ids时按限定VIP匹配不匹配不送券
if ("03".equals(shopProduct.getGoodsType())){
MyUserEntity userEntity = userDao.selectById(order.getUserId());
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
@@ -389,8 +398,21 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
int productId = Integer.parseInt(map.get("product_id").toString());
int couponId = Integer.parseInt(map.get("coupon_id").toString());
CouponEntity couponEntity = couponDao.selectById(couponId);
boolean isFyszVip = userVipList.stream().anyMatch(userVip -> Integer.valueOf(10).equals(userVip.getType()));
boolean couponToJf = couponEntity.getCouponType() == 0 && (productId == 2023 ? isFyszVip : userVipList.size() > 0);
boolean shouldGrantCoupon = true;
boolean couponToJf = false;
if (StringUtils.isNotEmpty(couponEntity.getUserVipIds())) {
if (!matchUserVipIds(couponEntity.getUserVipIds(), userVipList)) {
shouldGrantCoupon = false;
} else {
couponToJf = couponEntity.getCouponType() == 0;
}
} else {
boolean isFyszVip = userVipList.stream().anyMatch(userVip -> Integer.valueOf(10).equals(userVip.getType()));
couponToJf = couponEntity.getCouponType() == 0 && (productId == 2023 ? isFyszVip : userVipList.size() > 0);
}
if (!shouldGrantCoupon) {
continue;
}
if (couponToJf){
BigDecimal jf = BigDecimal.ZERO;
for (int i=0;i<Integer.parseInt(map.get("quantity").toString());i++){