|
|
|
@ -23,6 +23,7 @@ import javax.persistence.criteria.Root;
|
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
|
@ -81,8 +82,12 @@ public class MembershipCodeService {
|
|
|
|
|
public String generateMembershipCode(String token, Integer duration, Integer life) {
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
|
|
// UUID作为会员码
|
|
|
|
|
String code = UUID.randomUUID().toString();
|
|
|
|
|
// 8位随机数字作为会员码
|
|
|
|
|
String code = RandomStringUtils.randomNumeric(8);
|
|
|
|
|
while (membershipCodeDao.findMembershipCodeByCode(code) != null) {
|
|
|
|
|
code = RandomStringUtils.randomNumeric(8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MembershipCode build = MembershipCode.builder()
|
|
|
|
|
.id(String.valueOf(idWorker.nextId()))
|
|
|
|
|
.code(code)
|
|
|
|
@ -146,7 +151,7 @@ public class MembershipCodeService {
|
|
|
|
|
UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get();
|
|
|
|
|
|
|
|
|
|
String result = "";
|
|
|
|
|
if (userInfo.getVipStatus() == UserVipStatusEnum.INITIAL.getCode()) {
|
|
|
|
|
if (Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.INITIAL.getCode())) {
|
|
|
|
|
// 首次开通会员
|
|
|
|
|
Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.BUY_MEMBER, token);
|
|
|
|
|
result = "首次开通会员,积分增加" + point + "分";
|
|
|
|
@ -159,8 +164,8 @@ public class MembershipCodeService {
|
|
|
|
|
// 非永久会员码
|
|
|
|
|
// 计算会员到期时间
|
|
|
|
|
LocalDate vipExpireTime;
|
|
|
|
|
if (Objects.equals(UserVipStatusEnum.INITIAL.getCode(), userInfo.getVipStatus())) {
|
|
|
|
|
vipExpireTime = userInfo.getVipExpireTime().plusDays(membershipCode.getDuration());
|
|
|
|
|
if (!Objects.equals(UserVipStatusEnum.INITIAL.getCode(), userInfo.getVipStatus())) {
|
|
|
|
|
vipExpireTime = (userInfo.getVipExpireTime() == null ? LocalDate.now() : userInfo.getVipExpireTime()).plusDays(membershipCode.getDuration());
|
|
|
|
|
} else {
|
|
|
|
|
// 从今天开始,增加membershipCode的duration天
|
|
|
|
|
userInfo.setVipStatus(UserVipStatusEnum.INITIAL.getCode());
|
|
|
|
|