|
@@ -6,7 +6,6 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
|
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.CommissionRecord;
|
|
|
|
|
import com.izouma.jiashanxia.domain.User;
|
|
import com.izouma.jiashanxia.domain.User;
|
|
|
import com.izouma.jiashanxia.dto.PageQuery;
|
|
import com.izouma.jiashanxia.dto.PageQuery;
|
|
|
import com.izouma.jiashanxia.dto.UserRegister;
|
|
import com.izouma.jiashanxia.dto.UserRegister;
|
|
@@ -73,14 +72,26 @@ public class UserService {
|
|
|
return userRepo.save(user);
|
|
return userRepo.save(user);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void del(Long id) {
|
|
|
|
|
+ User user = userRepo.findById(id).orElseThrow(new BusinessException("用户不存在"));
|
|
|
|
|
+ user.setDel(true);
|
|
|
|
|
+ if (StringUtils.isNoneEmpty(user.getOpenId())) {
|
|
|
|
|
+ user.setOpenId(user.getOpenId() + "###" + RandomStringUtils.randomAlphabetic(8));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNoneEmpty(user.getPhone())) {
|
|
|
|
|
+ user.setPhone(user.getPhone() + "###" + RandomStringUtils.randomAlphabetic(8));
|
|
|
|
|
+ }
|
|
|
|
|
+ userRepo.save(user);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public User loginByPhone(String phone) {
|
|
public User loginByPhone(String phone) {
|
|
|
- return userRepo.findByPhone(phone);
|
|
|
|
|
|
|
+ return userRepo.findByPhoneAndDelFalse(phone);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public User loginMp(String code) throws WxErrorException {
|
|
public User loginMp(String code) throws WxErrorException {
|
|
|
WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code);
|
|
WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code);
|
|
|
WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(accessToken, null);
|
|
WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(accessToken, null);
|
|
|
- User user = userRepo.findByOpenId(wxMpUser.getOpenId());
|
|
|
|
|
|
|
+ User user = userRepo.findByOpenIdAndDelFalse(wxMpUser.getOpenId());
|
|
|
if (user == null) {
|
|
if (user == null) {
|
|
|
user = User.builder()
|
|
user = User.builder()
|
|
|
.username(UUID.randomUUID().toString())
|
|
.username(UUID.randomUUID().toString())
|
|
@@ -104,7 +115,7 @@ public class UserService {
|
|
|
WxMaJscode2SessionResult result = wxMaService.jsCode2SessionInfo(code);
|
|
WxMaJscode2SessionResult result = wxMaService.jsCode2SessionInfo(code);
|
|
|
String openId = result.getOpenid();
|
|
String openId = result.getOpenid();
|
|
|
String sessionKey = result.getSessionKey();
|
|
String sessionKey = result.getSessionKey();
|
|
|
- User userInfo = userRepo.findByOpenId(openId);
|
|
|
|
|
|
|
+ User userInfo = userRepo.findByOpenIdAndDelFalse(openId);
|
|
|
if (userInfo != null) {
|
|
if (userInfo != null) {
|
|
|
// 上级不为空 && 用户上级为空
|
|
// 上级不为空 && 用户上级为空
|
|
|
if (ObjectUtil.isNotEmpty(parent) && ObjectUtil.isNull(userInfo.getParent())) {
|
|
if (ObjectUtil.isNotEmpty(parent) && ObjectUtil.isNull(userInfo.getParent())) {
|
|
@@ -143,7 +154,7 @@ public class UserService {
|
|
|
|
|
|
|
|
// 解密用户信息
|
|
// 解密用户信息
|
|
|
WxMaUserInfo wxUserInfo = wxMaService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
|
|
WxMaUserInfo wxUserInfo = wxMaService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
|
|
|
- User user = userRepo.findByOpenId(wxUserInfo.getOpenId());
|
|
|
|
|
|
|
+ User user = userRepo.findByOpenIdAndDelFalse(wxUserInfo.getOpenId());
|
|
|
|
|
|
|
|
String avatarUrl = Constants.DEFAULT_AVATAR;
|
|
String avatarUrl = Constants.DEFAULT_AVATAR;
|
|
|
try {
|
|
try {
|
|
@@ -230,11 +241,11 @@ public class UserService {
|
|
|
List<User> users = new ArrayList<>();
|
|
List<User> users = new ArrayList<>();
|
|
|
// 如果是企业创始人,查出下级所有推广
|
|
// 如果是企业创始人,查出下级所有推广
|
|
|
if (user.getTeamFounder()) {
|
|
if (user.getTeamFounder()) {
|
|
|
- List<User> employees = userRepo.findAllByCompanyId(user.getCompanyId());
|
|
|
|
|
|
|
+ List<User> employees = userRepo.findAllByCompanyIdAndDelFalse(user.getCompanyId());
|
|
|
List<Long> collect = employees.stream().map(User::getId).collect(Collectors.toList());
|
|
List<Long> collect = employees.stream().map(User::getId).collect(Collectors.toList());
|
|
|
- users.addAll(userRepo.findAllByParentIn(collect));
|
|
|
|
|
|
|
+ users.addAll(userRepo.findAllByParentInAndDelFalse(collect));
|
|
|
}
|
|
}
|
|
|
- users.addAll(userRepo.findAllByParent(userId));
|
|
|
|
|
|
|
+ users.addAll(userRepo.findAllByParentAndDelFalse(userId));
|
|
|
return users;
|
|
return users;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -248,7 +259,7 @@ public class UserService {
|
|
|
return userRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
return userRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
List<Predicate> and = JpaUtils.toPredicates(pageQuery, User.class, root, criteriaQuery, criteriaBuilder);
|
|
List<Predicate> and = JpaUtils.toPredicates(pageQuery, User.class, root, criteriaQuery, criteriaBuilder);
|
|
|
if (user.getTeamFounder()) {
|
|
if (user.getTeamFounder()) {
|
|
|
- List<User> employees = userRepo.findAllByCompanyId(user.getCompanyId());
|
|
|
|
|
|
|
+ List<User> employees = userRepo.findAllByCompanyIdAndDelFalse(user.getCompanyId());
|
|
|
List<Long> collect = employees.stream().map(User::getId).collect(Collectors.toList());
|
|
List<Long> collect = employees.stream().map(User::getId).collect(Collectors.toList());
|
|
|
and.add(root.get("parent").in(collect));
|
|
and.add(root.get("parent").in(collect));
|
|
|
} else {
|
|
} else {
|
|
@@ -306,7 +317,7 @@ public class UserService {
|
|
|
}
|
|
}
|
|
|
map.put("commission", empPromote.add(promote));
|
|
map.put("commission", empPromote.add(promote));
|
|
|
map.put("withdraw", commissionRecordRepo.sumByUserId(userId, TransactionType.WITHDRAW));
|
|
map.put("withdraw", commissionRecordRepo.sumByUserId(userId, TransactionType.WITHDRAW));
|
|
|
- map.put("promote", userRepo.countByParent(userId));
|
|
|
|
|
|
|
+ map.put("promote", userRepo.countByParentAndDelFalse(userId));
|
|
|
return map;
|
|
return map;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|