|
@@ -8,6 +8,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.izouma.jiashanxia.config.Constants;
|
|
import com.izouma.jiashanxia.config.Constants;
|
|
|
import com.izouma.jiashanxia.domain.User;
|
|
import com.izouma.jiashanxia.domain.User;
|
|
|
|
|
+import com.izouma.jiashanxia.enums.Member;
|
|
|
import com.izouma.jiashanxia.dto.PageQuery;
|
|
import com.izouma.jiashanxia.dto.PageQuery;
|
|
|
import com.izouma.jiashanxia.dto.PromotionDTO;
|
|
import com.izouma.jiashanxia.dto.PromotionDTO;
|
|
|
import com.izouma.jiashanxia.dto.UserRegister;
|
|
import com.izouma.jiashanxia.dto.UserRegister;
|
|
@@ -19,7 +20,6 @@ import com.izouma.jiashanxia.repo.OrderInfoRepo;
|
|
|
import com.izouma.jiashanxia.repo.UserRepo;
|
|
import com.izouma.jiashanxia.repo.UserRepo;
|
|
|
import com.izouma.jiashanxia.security.Authority;
|
|
import com.izouma.jiashanxia.security.Authority;
|
|
|
import com.izouma.jiashanxia.security.JwtTokenUtil;
|
|
import com.izouma.jiashanxia.security.JwtTokenUtil;
|
|
|
-import com.izouma.jiashanxia.security.JwtUser;
|
|
|
|
|
import com.izouma.jiashanxia.security.JwtUserFactory;
|
|
import com.izouma.jiashanxia.security.JwtUserFactory;
|
|
|
import com.izouma.jiashanxia.service.sms.SmsService;
|
|
import com.izouma.jiashanxia.service.sms.SmsService;
|
|
|
import com.izouma.jiashanxia.service.storage.StorageService;
|
|
import com.izouma.jiashanxia.service.storage.StorageService;
|
|
@@ -49,15 +49,16 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
|
public class UserService {
|
|
public class UserService {
|
|
|
- private UserRepo userRepo;
|
|
|
|
|
- private WxMaService wxMaService;
|
|
|
|
|
- private WxMpService wxMpService;
|
|
|
|
|
- private SmsService smsService;
|
|
|
|
|
- private StorageService storageService;
|
|
|
|
|
- private JwtTokenUtil jwtTokenUtil;
|
|
|
|
|
- private CaptchaService captchaService;
|
|
|
|
|
- private OrderInfoRepo orderInfoRepo;
|
|
|
|
|
- private CommissionRecordRepo commissionRecordRepo;
|
|
|
|
|
|
|
+ private final UserRepo userRepo;
|
|
|
|
|
+ private final WxMaService wxMaService;
|
|
|
|
|
+ private final WxMpService wxMpService;
|
|
|
|
|
+ private final SmsService smsService;
|
|
|
|
|
+ private final StorageService storageService;
|
|
|
|
|
+ private final JwtTokenUtil jwtTokenUtil;
|
|
|
|
|
+ private final CaptchaService captchaService;
|
|
|
|
|
+ private final OrderInfoRepo orderInfoRepo;
|
|
|
|
|
+ private final CommissionRecordRepo commissionRecordRepo;
|
|
|
|
|
+ private final SysConfigService sysConfigService;
|
|
|
|
|
|
|
|
public Page<User> all(PageQuery pageQuery) {
|
|
public Page<User> all(PageQuery pageQuery) {
|
|
|
pageQuery.setSort("createdAt,desc");
|
|
pageQuery.setSort("createdAt,desc");
|
|
@@ -70,6 +71,7 @@ public class UserService {
|
|
|
user.setVip(false);
|
|
user.setVip(false);
|
|
|
user.setWxAuthorized(false);
|
|
user.setWxAuthorized(false);
|
|
|
user.setAmount(BigDecimal.ZERO);
|
|
user.setAmount(BigDecimal.ZERO);
|
|
|
|
|
+ user.setMember(Member.NORMAL);
|
|
|
if (StringUtils.isNotBlank(userRegister.getPassword())) {
|
|
if (StringUtils.isNotBlank(userRegister.getPassword())) {
|
|
|
user.setPassword(new BCryptPasswordEncoder().encode(userRegister.getPassword()));
|
|
user.setPassword(new BCryptPasswordEncoder().encode(userRegister.getPassword()));
|
|
|
}
|
|
}
|
|
@@ -121,10 +123,13 @@ public class UserService {
|
|
|
String sessionKey = result.getSessionKey();
|
|
String sessionKey = result.getSessionKey();
|
|
|
User userInfo = userRepo.findByOpenIdAndDelFalse(openId);
|
|
User userInfo = userRepo.findByOpenIdAndDelFalse(openId);
|
|
|
if (userInfo != null) {
|
|
if (userInfo != null) {
|
|
|
- // 上级不为空 && 用户上级为空
|
|
|
|
|
- if (ObjectUtil.isNotEmpty(parent) && ObjectUtil.isNull(userInfo.getParent())) {
|
|
|
|
|
- userInfo.setParent(parent);
|
|
|
|
|
- userRepo.saveAndFlush(userInfo);
|
|
|
|
|
|
|
+ // 插入上级
|
|
|
|
|
+ if (ObjectUtil.isNotNull(parent)) {
|
|
|
|
|
+ Long parent1 = this.getParent(parent, userInfo);
|
|
|
|
|
+ if (ObjectUtil.isNotNull(parent1)) {
|
|
|
|
|
+ userInfo.setParent(parent);
|
|
|
|
|
+ userRepo.saveAndFlush(userInfo);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
userInfo.setSessionKey(sessionKey);
|
|
userInfo.setSessionKey(sessionKey);
|
|
|
return userInfo;
|
|
return userInfo;
|
|
@@ -139,7 +144,15 @@ public class UserService {
|
|
|
.amount(BigDecimal.ZERO)
|
|
.amount(BigDecimal.ZERO)
|
|
|
.teamFounder(false)
|
|
.teamFounder(false)
|
|
|
.sessionKey(sessionKey)
|
|
.sessionKey(sessionKey)
|
|
|
|
|
+ .member(Member.NORMAL)
|
|
|
.build();
|
|
.build();
|
|
|
|
|
+ // 插入上级
|
|
|
|
|
+ if (ObjectUtil.isNotNull(parent)) {
|
|
|
|
|
+ Long parent1 = this.getParent(parent, userInfo);
|
|
|
|
|
+ if (ObjectUtil.isNotNull(parent1)) {
|
|
|
|
|
+ userInfo.setParent(parent);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
userInfo = userRepo.saveAndFlush(userInfo);
|
|
userInfo = userRepo.saveAndFlush(userInfo);
|
|
|
log.info("loginMa {}", userInfo.getCreatedAt());
|
|
log.info("loginMa {}", userInfo.getCreatedAt());
|
|
|
return userInfo;
|
|
return userInfo;
|
|
@@ -149,6 +162,31 @@ public class UserService {
|
|
|
throw new BusinessException("登录失败");
|
|
throw new BusinessException("登录失败");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ 获取上级
|
|
|
|
|
+ */
|
|
|
|
|
+ public Long getParent(Long parent, User userInfo) {
|
|
|
|
|
+ // 用户上级为空
|
|
|
|
|
+ if (ObjectUtil.isNull(userInfo.getParent())) {
|
|
|
|
|
+ return parent;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 用户原有上级不为空
|
|
|
|
|
+ User userParent = userRepo.findById(userInfo.getParent()).orElse(null);
|
|
|
|
|
+ if (ObjectUtil.isNull(userParent)) {
|
|
|
|
|
+ return parent;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 不是达人
|
|
|
|
|
+ if (Member.NORMAL.equals(userParent.getMember())) {
|
|
|
|
|
+ // 传过来的上级
|
|
|
|
|
+ User user1 = userRepo.findById(parent).orElse(null);
|
|
|
|
|
+
|
|
|
|
|
+ if (ObjectUtil.isNotNull(user1) && !Member.NORMAL.equals(user1.getMember())) {
|
|
|
|
|
+ return parent;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public User getMaUserInfo(String sessionKey, String rawData, String signature,
|
|
public User getMaUserInfo(String sessionKey, String rawData, String signature,
|
|
|
String encryptedData, String iv) {
|
|
String encryptedData, String iv) {
|
|
|
// 用户信息校验
|
|
// 用户信息校验
|
|
@@ -186,6 +224,7 @@ public class UserService {
|
|
|
.amount(BigDecimal.ZERO)
|
|
.amount(BigDecimal.ZERO)
|
|
|
.teamFounder(false)
|
|
.teamFounder(false)
|
|
|
.wxAuthorized(true)
|
|
.wxAuthorized(true)
|
|
|
|
|
+ .member(Member.NORMAL)
|
|
|
.build();
|
|
.build();
|
|
|
user = userRepo.save(user);
|
|
user = userRepo.save(user);
|
|
|
|
|
|
|
@@ -367,4 +406,20 @@ public class UserService {
|
|
|
map.put("promote", userRepo.countByParentAndDelFalse(userId));
|
|
map.put("promote", userRepo.countByParentAndDelFalse(userId));
|
|
|
return map;
|
|
return map;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ 成为达人
|
|
|
|
|
+ */
|
|
|
|
|
+ public User becomeExpert(User user) {
|
|
|
|
|
+ if (!Member.NORMAL.equals(user.getMember())) {
|
|
|
|
|
+ return user;
|
|
|
|
|
+ }
|
|
|
|
|
+ user.setMember(Member.EXPERT);
|
|
|
|
|
+ long num = userRepo.countByParentAndDelFalse(user.getId());
|
|
|
|
|
+ int players_required = sysConfigService.getInt("PLAYERS_REQUIRED");
|
|
|
|
|
+ if (num >= players_required) {
|
|
|
|
|
+ user.setMember(Member.BIG_EXPERT);
|
|
|
|
|
+ }
|
|
|
|
|
+ return userRepo.save(user);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|