邀请码绑定只允许3天内注册的新用户

This commit is contained in:
tianfeng 2025-10-22 15:10:30 +08:00
parent b206158d06
commit 1dd40c1206

View File

@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Objects;
@ -64,7 +65,22 @@ public class BindInviteCodeExe {
// 3. 校验用户是否存在
UserProfile userProfile = userProfileGateway.getByUserId(userId);
if (userProfile == null) {
throw new RuntimeException("The user does not exist.");
throw new RuntimeException("The user does not exist.");
}
// 校验用户创建时间是否超过3天
Timestamp createTime = userProfile.getCreateTime();
if (createTime != null) {
long createTimeMillis = createTime.getTime();
long currentTime = TimestampUtils.now().getTime();
long threeDaysInMillis = 3 * 24 * 60 * 60 * 1000L; // 3天的毫秒数
long timeDiff = currentTime - createTimeMillis;
if (timeDiff > threeDaysInMillis) {
log.warn("用户创建时间超过3天不允许绑定邀请码, userId={}, createTime={}, currentTime={}, diffDays={}",
userId, createTimeMillis, currentTime, timeDiff / (24 * 60 * 60 * 1000L));
throw new RuntimeException("User registration time has exceeded 3 days and cannot bind invitation code");
}
}
// 4. 校验是否已绑定过邀请人userId=邀请人, inviteUserId=被邀请人