|
|
@@ -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;
|
|
|
@@ -72,6 +73,7 @@ public class UserService {
|
|
|
private TokenHistoryRepo tokenHistoryRepo;
|
|
|
private CollectionRepo collectionRepo;
|
|
|
private AdapayMerchantService adapayMerchantService;
|
|
|
+ private Environment env;
|
|
|
|
|
|
public User update(User user) {
|
|
|
if (!SecurityUtils.hasRole(AuthorityName.ROLE_ADMIN)) {
|
|
|
@@ -147,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;
|
|
|
}
|
|
|
|
|
|
@@ -232,6 +236,81 @@ public class UserService {
|
|
|
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;
|
|
|
+ }
|
|
|
+
|
|
|
public void del(Long id) {
|
|
|
User user = userRepo.findById(id).orElseThrow(new BusinessException("用户不存在"));
|
|
|
user.setDel(true);
|