|
|
@@ -36,6 +36,7 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.context.event.EventListener;
|
|
|
+import org.springframework.core.env.Environment;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
@@ -46,7 +47,6 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.regex.Pattern;
|
|
|
@@ -73,8 +73,7 @@ public class UserService {
|
|
|
private TokenHistoryRepo tokenHistoryRepo;
|
|
|
private CollectionRepo collectionRepo;
|
|
|
private AdapayMerchantService adapayMerchantService;
|
|
|
- private PointRecordRepo pointRecordRepo;
|
|
|
- private CollectionService collectionService;
|
|
|
+ private Environment env;
|
|
|
|
|
|
public User update(User user) {
|
|
|
if (!SecurityUtils.hasRole(AuthorityName.ROLE_ADMIN)) {
|
|
|
@@ -150,7 +149,9 @@ public class UserService {
|
|
|
user.setPassword(new BCryptPasswordEncoder().encode(userRegister.getPassword()));
|
|
|
}
|
|
|
user = userRepo.saveAndFlush(user);
|
|
|
- nftService.createAccount(user.getId());
|
|
|
+ if (Arrays.asList(env.getActiveProfiles()).contains("prod")) {
|
|
|
+ nftService.createAccount(user.getId());
|
|
|
+ }
|
|
|
return user;
|
|
|
}
|
|
|
|
|
|
@@ -171,15 +172,19 @@ public class UserService {
|
|
|
invite = inviteRepo.findFirstByCode(inviteCode).orElse(null);
|
|
|
}
|
|
|
smsService.verify(phone, code);
|
|
|
- Collection collection = null;
|
|
|
+ Collection collection;
|
|
|
if (collectionId != null) {
|
|
|
collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("无藏品"));
|
|
|
- if (!collection.isOnShelf() || !collection.isSalable()) {
|
|
|
+// if (!collection.isOnShelf() || !collection.isSalable()) {
|
|
|
+// collectionId = null;
|
|
|
+// } else if (collection.isScheduleSale()) {
|
|
|
+// if (collection.getStartTime().isAfter(LocalDateTime.now())) {
|
|
|
+// collectionId = null;
|
|
|
+// }
|
|
|
+// }
|
|
|
+ // 只看是否开去分享
|
|
|
+ if (ObjectUtils.isEmpty(collection.getOpenQuota()) || !collection.getOpenQuota()) {
|
|
|
collectionId = null;
|
|
|
- } else if (collection.isScheduleSale()) {
|
|
|
- if (collection.getStartTime().isAfter(LocalDateTime.now())) {
|
|
|
- collectionId = null;
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
User user = create(UserRegister.builder()
|
|
|
@@ -200,34 +205,109 @@ public class UserService {
|
|
|
}
|
|
|
|
|
|
// 加积分
|
|
|
- if (collectionId != null && invitor != null) {
|
|
|
- // 额度或者额度为空, 库存不为空
|
|
|
- if (collection.getStock() > 0 && (collection.getVipQuota() > 0 || ObjectUtils.isEmpty(collection.getVipQuota()))) {
|
|
|
- int countUser = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, invitor);
|
|
|
- // 邀请人数
|
|
|
- if (countUser >= collection.getAssignment()) {
|
|
|
- int point = pointRecordRepo.countByUserIdAndCollectionId(invitor, collectionId);
|
|
|
- // 是否已有积分
|
|
|
- if (point <= 0) {
|
|
|
- long count = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, invitor);
|
|
|
- if (count >= collection.getAssignment()) {
|
|
|
- // 扣除藏品额度
|
|
|
- if (ObjectUtils.isNotEmpty(collection.getVipQuota())) {
|
|
|
- collectionService.decreaseQuota(collectionId, 1);
|
|
|
- }
|
|
|
- userRepo.updateVipPoint(invitor, 1);
|
|
|
- pointRecordRepo.save(PointRecord.builder()
|
|
|
- .collectionId(collectionId)
|
|
|
- .userId(invitor)
|
|
|
- .type("VIP_POINT")
|
|
|
- .point(1)
|
|
|
- .build());
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+// if (collectionId != null && invitor != null) {
|
|
|
+// // 额度或者额度为空, 库存不为空
|
|
|
+// if (collection.getStock() > 0 && (collection.getVipQuota() > 0 || ObjectUtils.isEmpty(collection.getVipQuota()))) {
|
|
|
+// int countUser = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, invitor);
|
|
|
+// // 邀请人数
|
|
|
+// if (countUser >= collection.getAssignment()) {
|
|
|
+// int point = pointRecordRepo.countByUserIdAndCollectionId(invitor, collectionId);
|
|
|
+// // 是否已有积分
|
|
|
+// if (point <= 0) {
|
|
|
+// long count = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, invitor);
|
|
|
+// if (count >= collection.getAssignment()) {
|
|
|
+// // 扣除藏品额度
|
|
|
+// if (ObjectUtils.isNotEmpty(collection.getVipQuota())) {
|
|
|
+// collectionService.decreaseQuota(collectionId, 1);
|
|
|
+// }
|
|
|
+// userRepo.updateVipPoint(invitor, 1);
|
|
|
+// pointRecordRepo.save(PointRecord.builder()
|
|
|
+// .collectionId(collectionId)
|
|
|
+// .userId(invitor)
|
|
|
+// .type("VIP_POINT")
|
|
|
+// .point(1)
|
|
|
+// .build());
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ public User testPhoneRegister() {
|
|
|
+ String phone = "19" + RandomStringUtils.randomNumeric(11);
|
|
|
+ String password = "123456";
|
|
|
+ String inviteCode = null;
|
|
|
+ Long invitor = null;
|
|
|
+ Long collectionId = null;
|
|
|
+ String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
|
|
|
+ Invite invite = null;
|
|
|
+ if (StringUtils.isNotBlank(inviteCode)) {
|
|
|
+ invite = inviteRepo.findFirstByCode(inviteCode).orElse(null);
|
|
|
+ }
|
|
|
+ Collection collection;
|
|
|
+ if (collectionId != null) {
|
|
|
+ collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("无藏品"));
|
|
|
+// if (!collection.isOnShelf() || !collection.isSalable()) {
|
|
|
+// collectionId = null;
|
|
|
+// } else if (collection.isScheduleSale()) {
|
|
|
+// if (collection.getStartTime().isAfter(LocalDateTime.now())) {
|
|
|
+// collectionId = null;
|
|
|
+// }
|
|
|
+// }
|
|
|
+ // 只看是否开去分享
|
|
|
+ if (ObjectUtils.isEmpty(collection.getOpenQuota()) || !collection.getOpenQuota()) {
|
|
|
+ collectionId = null;
|
|
|
}
|
|
|
}
|
|
|
+ User user = create(UserRegister.builder()
|
|
|
+ .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
|
|
|
+ .username(name)
|
|
|
+ .nickname(name)
|
|
|
+ .password(password)
|
|
|
+ .avatar(Constants.DEFAULT_AVATAR)
|
|
|
+ .phone(phone)
|
|
|
+ .invitorPhone(Optional.ofNullable(invite).map(Invite::getPhone).orElse(null))
|
|
|
+ .invitorName(Optional.ofNullable(invite).map(Invite::getName).orElse(null))
|
|
|
+ .inviteCode(Optional.ofNullable(invite).map(Invite::getCode).orElse(null))
|
|
|
+ .collectionInvitor(invitor)
|
|
|
+ .collectionId(collectionId)
|
|
|
+ .build());
|
|
|
+ if (invite != null) {
|
|
|
+ inviteRepo.increaseNum(invite.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加积分
|
|
|
+// if (collectionId != null && invitor != null) {
|
|
|
+// // 额度或者额度为空, 库存不为空
|
|
|
+// if (collection.getStock() > 0 && (collection.getVipQuota() > 0 || ObjectUtils.isEmpty(collection.getVipQuota()))) {
|
|
|
+// int countUser = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, invitor);
|
|
|
+// // 邀请人数
|
|
|
+// if (countUser >= collection.getAssignment()) {
|
|
|
+// int point = pointRecordRepo.countByUserIdAndCollectionId(invitor, collectionId);
|
|
|
+// // 是否已有积分
|
|
|
+// if (point <= 0) {
|
|
|
+// long count = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, invitor);
|
|
|
+// if (count >= collection.getAssignment()) {
|
|
|
+// // 扣除藏品额度
|
|
|
+// if (ObjectUtils.isNotEmpty(collection.getVipQuota())) {
|
|
|
+// collectionService.decreaseQuota(collectionId, 1);
|
|
|
+// }
|
|
|
+// userRepo.updateVipPoint(invitor, 1);
|
|
|
+// pointRecordRepo.save(PointRecord.builder()
|
|
|
+// .collectionId(collectionId)
|
|
|
+// .userId(invitor)
|
|
|
+// .type("VIP_POINT")
|
|
|
+// .point(1)
|
|
|
+// .build());
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
return user;
|
|
|
}
|
|
|
|
|
|
@@ -672,4 +752,5 @@ public class UserService {
|
|
|
public User my(Long id) {
|
|
|
return userRepo.findById(id).orElseThrow(new BusinessException("用户不存在"));
|
|
|
}
|
|
|
+
|
|
|
}
|