新增 免费创建家族VIP等级权益逻辑

This commit is contained in:
tianfeng 2026-03-16 17:58:21 +08:00
parent d7c516ab98
commit e882e29eb5
4 changed files with 73 additions and 5 deletions

View File

@ -11,6 +11,7 @@ import com.red.circle.framework.core.response.CommonErrorCode;
import com.red.circle.framework.core.response.ResponseErrorCode;
import com.red.circle.other.app.common.account.FamilyAccountShortProduction;
import com.red.circle.other.app.dto.cmd.family.FamilyCreateCmd;
import com.red.circle.other.domain.enums.VipAbilityType;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway;
import com.red.circle.other.domain.model.user.OwnSpecialId;
@ -175,6 +176,11 @@ public class FamilyCreateExe {
return;
}
boolean hasAbility = userProfileGateway.getUserVipAbility(cmd.getReqUserId(), VipAbilityType.CREATE_FAMILY_FREE);
if (hasAbility) {
return;
}
//创建家族扣除金币
consumeCandy(cmd, createRules);

View File

@ -0,0 +1,48 @@
package com.red.circle.other.domain.enums;
/**
* VIP 布尔权限类型.
* 各等级顺序: VIP1(VISCOUNT) ~ VIP6(EMPEROR)
*/
public enum VipAbilityType {
/** 拒绝陌生人联系 */
BLOCK_STRANGERS(false, false, false, true, true, true),
/** 免费创建家族 */
CREATE_FAMILY_FREE(false, false, false, true, true, true),
/** 防踢 */
KICK_PREVENTION(false, false, false, false, true, true),
/** 防拉黑 */
ANTI_BLOCK(false, false, false, false, false, true),
/** 神秘隐身 */
MYSTERIOUS_INVISIBILITY(false, false, false, false, false, true);
// index 0~5 = VIP1~VIP6
private final boolean[] levels;
VipAbilityType(boolean... levels) {
this.levels = levels;
}
/**
* 根据 VIP name 判断是否拥有该权限非VIP或未匹配返回 false.
*/
public boolean hasAbility(String vipName) {
if (vipName == null) {
return false;
}
switch (vipName) {
case "VISCOUNT": return levels[0];
case "EARL": return levels[1];
case "MARQUIS": return levels[2];
case "DUKE": return levels[3];
case "KING": return levels[4];
case "EMPEROR": return levels[5];
default: return false;
}
}
}

View File

@ -2,6 +2,7 @@ package com.red.circle.other.domain.gateway.user;
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.other.domain.enums.VipAbilityType;
import com.red.circle.other.domain.enums.VipBenefitType;
import java.math.BigDecimal;
import com.red.circle.other.domain.model.user.NobleAbilityCO;
@ -196,4 +197,10 @@ public interface UserProfileGateway {
*/
BigDecimal getUserVipBenefit(Long userId, VipBenefitType benefitType);
/**
* 判断用户是否拥有指定VIP权限.
* 非VIP或等级不足返回 false.
*/
boolean getUserVipAbility(Long userId, VipAbilityType abilityType);
}

View File

@ -8,6 +8,7 @@ import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.common.business.core.level.LevelUtils;
import com.red.circle.external.inner.endpoint.message.ImAccountClient;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.other.domain.enums.VipAbilityType;
import com.red.circle.other.domain.enums.VipBenefitType;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.gateway.user.UserRunProfileTransportGateway;
@ -497,14 +498,22 @@ public class UserProfileGatewayImpl implements UserProfileGateway {
return userCacheService.getUserActualEquityEnum(userId, this::getUserPropsVipActualEquity);
}
@Override
public boolean getUserVipAbility(Long userId, VipAbilityType abilityType) {
return abilityType.hasAbility(resolveUserVipName(userId));
}
@Override
public BigDecimal getUserVipBenefit(Long userId, VipBenefitType benefitType) {
return benefitType.getValue(resolveUserVipName(userId));
}
private String resolveUserVipName(Long userId) {
UserProfile userProfile = getByUserId(userId);
if (Objects.isNull(userProfile) || CollectionUtils.isEmpty(userProfile.getUseProps())) {
return benefitType.getDefaultValue();
return null;
}
String vipName = userProfile.getUseProps().stream()
return userProfile.getUseProps().stream()
.filter(props -> Objects.nonNull(props.getPropsResources())
&& PropsCommodityType.NOBLE_VIP.name().equals(props.getPropsResources().getType())
&& props.getExpireTime() != null
@ -512,8 +521,6 @@ public class UserProfileGatewayImpl implements UserProfileGateway {
.map(props -> props.getPropsResources().getName())
.findFirst()
.orElse(null);
return benefitType.getValue(vipName);
}
@Override