|
|
@@ -1,14 +1,20 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
+import com.izouma.nineth.domain.AirDrop;
|
|
|
+import com.izouma.nineth.domain.Collection;
|
|
|
import com.izouma.nineth.domain.IdentityAuth;
|
|
|
import com.izouma.nineth.domain.User;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
+import com.izouma.nineth.enums.AirDropType;
|
|
|
import com.izouma.nineth.enums.AuthStatus;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
+import com.izouma.nineth.repo.AirDropRepo;
|
|
|
+import com.izouma.nineth.repo.CollectionRepo;
|
|
|
import com.izouma.nineth.repo.IdentityAuthRepo;
|
|
|
import com.izouma.nineth.repo.UserRepo;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -21,6 +27,10 @@ public class IdentityAuthService {
|
|
|
private IdentityAuthRepo identityAuthRepo;
|
|
|
private UserRepo userRepo;
|
|
|
private AdapayService adapayService;
|
|
|
+ private CollectionRepo collectionRepo;
|
|
|
+ private AirDropRepo airDropRepo;
|
|
|
+ private AirDropService airDropService;
|
|
|
+ private SysConfigService sysConfigService;
|
|
|
|
|
|
public Page<IdentityAuth> all(PageQuery pageQuery) {
|
|
|
return identityAuthRepo.findAll(JpaUtils.toSpecification(pageQuery, IdentityAuth.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
@@ -52,10 +62,40 @@ public class IdentityAuthService {
|
|
|
User user = userRepo.findByIdAndDelFalse(auth.getUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
if (status == AuthStatus.SUCCESS) {
|
|
|
user.setAuthId(auth.getId());
|
|
|
+ if (user.getInvitor() != null) {
|
|
|
+ userRepo.findByIdAndDelFalse(user.getInvitor()).ifPresent(user1 -> {
|
|
|
+ user1.setInviteNum(user1.getInviteNum() + 1);
|
|
|
+ if (user1.getInviteNum() >= 10) {
|
|
|
+ int inviteCollection = sysConfigService.getInt("inviteCollection");
|
|
|
+ // 藏品数量
|
|
|
+ Collection collection = collectionRepo.findById(1187810L)
|
|
|
+ .orElseThrow(new BusinessException("无藏品"));
|
|
|
+ if (collection.getStock() > 0) {
|
|
|
+ List<Long> userIds = List.of(user.getInvitor());
|
|
|
+ String name = "邀请新人得空投奖励";
|
|
|
+ List<AirDrop> airDrops = airDropRepo.findAllByUserIdsAndName(String.valueOf(user.getInvitor()), name);
|
|
|
+ if (CollectionUtils.isEmpty(airDrops)) {
|
|
|
+ airDropService.create(AirDrop.builder()
|
|
|
+ .name(name)
|
|
|
+ .type(AirDropType.asset)
|
|
|
+ .collectionId((long) inviteCollection)
|
|
|
+ .phone(List.of(user1.getPhone()))
|
|
|
+ .userIds(userIds)
|
|
|
+ .projectId(1)
|
|
|
+ .build());
|
|
|
+ user1.setInviteAirDrop(user1.getInviteAirDrop() + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ userRepo.save(user1);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- auth.setStatus(status);
|
|
|
- identityAuthRepo.save(auth);
|
|
|
user.setAuthStatus(status);
|
|
|
userRepo.save(user);
|
|
|
+ auth.setStatus(status);
|
|
|
+ identityAuthRepo.save(auth);
|
|
|
}
|
|
|
}
|