|
@@ -3,7 +3,12 @@ package com.izouma.nineth.service;
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
|
|
|
+import com.huifu.adapay.model.AdapayCommon;
|
|
|
|
|
+import com.huifu.adapay.model.SettleAccount;
|
|
|
|
|
+import com.izouma.nineth.config.AdapayProperties;
|
|
|
import com.izouma.nineth.config.Constants;
|
|
import com.izouma.nineth.config.Constants;
|
|
|
import com.izouma.nineth.domain.Follow;
|
|
import com.izouma.nineth.domain.Follow;
|
|
|
import com.izouma.nineth.domain.IdentityAuth;
|
|
import com.izouma.nineth.domain.IdentityAuth;
|
|
@@ -29,6 +34,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
|
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
|
|
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
|
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
|
|
|
|
+import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -65,6 +71,7 @@ public class UserService {
|
|
|
private UserBankCardRepo userBankCardRepo;
|
|
private UserBankCardRepo userBankCardRepo;
|
|
|
private CacheService cacheService;
|
|
private CacheService cacheService;
|
|
|
private InviteRepo inviteRepo;
|
|
private InviteRepo inviteRepo;
|
|
|
|
|
+ private AdapayProperties adapayProperties;
|
|
|
|
|
|
|
|
@CacheEvict(value = "user", key = "#user.username")
|
|
@CacheEvict(value = "user", key = "#user.username")
|
|
|
public User update(User user) {
|
|
public User update(User user) {
|
|
@@ -98,7 +105,8 @@ public class UserService {
|
|
|
|
|
|
|
|
if (pageQuery.getQuery().containsKey("hasRole")) {
|
|
if (pageQuery.getQuery().containsKey("hasRole")) {
|
|
|
String roleName = (String) pageQuery.getQuery().get("hasRole");
|
|
String roleName = (String) pageQuery.getQuery().get("hasRole");
|
|
|
- and.add(criteriaBuilder.isMember(Authority.get(AuthorityName.valueOf(roleName)), root.get("authorities")));
|
|
|
|
|
|
|
+ and.add(criteriaBuilder
|
|
|
|
|
+ .isMember(Authority.get(AuthorityName.valueOf(roleName)), root.get("authorities")));
|
|
|
}
|
|
}
|
|
|
return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
});
|
|
});
|
|
@@ -406,7 +414,7 @@ public class UserService {
|
|
|
throw new BusinessException("用户不存在或未认证");
|
|
throw new BusinessException("用户不存在或未认证");
|
|
|
}
|
|
}
|
|
|
String realName = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(
|
|
String realName = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(
|
|
|
- user.getId(), AuthStatus.SUCCESS)
|
|
|
|
|
|
|
+ user.getId(), AuthStatus.SUCCESS)
|
|
|
.map(IdentityAuth::getRealName).orElse("").replaceAll(".*(?=.)", "**");
|
|
.map(IdentityAuth::getRealName).orElse("").replaceAll(".*(?=.)", "**");
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("id", user.getId());
|
|
map.put("id", user.getId());
|
|
@@ -419,8 +427,8 @@ public class UserService {
|
|
|
|
|
|
|
|
public Map<String, Object> searchByPhoneAdmin(String phoneStr) {
|
|
public Map<String, Object> searchByPhoneAdmin(String phoneStr) {
|
|
|
List<String> phone = Arrays.stream(phoneStr.replaceAll("\n", " ")
|
|
List<String> phone = Arrays.stream(phoneStr.replaceAll("\n", " ")
|
|
|
- .replaceAll("\r\n", " ")
|
|
|
|
|
- .split(" "))
|
|
|
|
|
|
|
+ .replaceAll("\r\n", " ")
|
|
|
|
|
+ .split(" "))
|
|
|
.map(String::trim)
|
|
.map(String::trim)
|
|
|
.filter(s -> !StringUtils.isEmpty(s))
|
|
.filter(s -> !StringUtils.isEmpty(s))
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
@@ -435,7 +443,8 @@ public class UserService {
|
|
|
|
|
|
|
|
public void addBankCard(Long userId, String bankNo, String phone, String code) throws BaseAdaPayException {
|
|
public void addBankCard(Long userId, String bankNo, String phone, String code) throws BaseAdaPayException {
|
|
|
User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
- IdentityAuth identityAuth = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(userId, AuthStatus.SUCCESS)
|
|
|
|
|
|
|
+ IdentityAuth identityAuth = identityAuthRepo
|
|
|
|
|
+ .findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(userId, AuthStatus.SUCCESS)
|
|
|
.orElseThrow(new BusinessException("用户未认证"));
|
|
.orElseThrow(new BusinessException("用户未认证"));
|
|
|
if (identityAuth.isOrg()) {
|
|
if (identityAuth.isOrg()) {
|
|
|
//throw new BusinessException("企业认证用户请绑定对公账户");
|
|
//throw new BusinessException("企业认证用户请绑定对公账户");
|
|
@@ -465,6 +474,7 @@ public class UserService {
|
|
|
.cardType(bankValidate.getCardType())
|
|
.cardType(bankValidate.getCardType())
|
|
|
.cardTypeDesc(bankValidate.getCardTypeDesc())
|
|
.cardTypeDesc(bankValidate.getCardTypeDesc())
|
|
|
.userId(userId)
|
|
.userId(userId)
|
|
|
|
|
+ .phone(phone)
|
|
|
.build());
|
|
.build());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -520,4 +530,79 @@ public class UserService {
|
|
|
map.put("success", success);
|
|
map.put("success", success);
|
|
|
return map;
|
|
return map;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public void switchAccount() {
|
|
|
|
|
+ switchAccount(adapayProperties.getAppId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void switchAccount(String appId) {
|
|
|
|
|
+ userRepo.findBySettleAccountIdIsNotNull().parallelStream().forEach(user -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ IdentityAuth identityAuth = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(user.getId(), AuthStatus.SUCCESS)
|
|
|
|
|
+ .orElseThrow(new BusinessException("用户未认证"));
|
|
|
|
|
+ UserBankCard userBankCard = userBankCardRepo.findByUserId(user.getId()).stream().findAny()
|
|
|
|
|
+ .orElseThrow(new BusinessException("未绑卡"));
|
|
|
|
|
+ createMember(appId, user.getId().toString(), Optional.ofNullable(userBankCard.getPhone())
|
|
|
|
|
+ .orElse(user.getPhone()), identityAuth.getRealName(), identityAuth.getIdNo());
|
|
|
|
|
+ createSettleAccount(appId, user.getId()
|
|
|
|
|
+ .toString(), identityAuth.getRealName(), identityAuth.getIdNo(), Optional.ofNullable(userBankCard.getPhone())
|
|
|
|
|
+ .orElse(user.getPhone()), userBankCard.getBankNo());
|
|
|
|
|
+ userBankCard.setPhone(Optional.ofNullable(userBankCard.getPhone()).orElse(user.getPhone()));
|
|
|
|
|
+ userBankCardRepo.save(userBankCard);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ adapayService.delSettleAccount(user.getMemberId(), user.getSettleAccountId());
|
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ user.setSettleAccountId(null);
|
|
|
|
|
+ userRepo.save(user);
|
|
|
|
|
+ userBankCardRepo.deleteByUserId(user.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void createMember(String appId, String memberId, String tel, String realName, String idno) throws BaseAdaPayException {
|
|
|
|
|
+ Map<String, Object> memberParams = new HashMap<>();
|
|
|
|
|
+ memberParams.put("adapay_func_code", "members.realname");
|
|
|
|
|
+ memberParams.put("member_id", memberId);
|
|
|
|
|
+ memberParams.put("app_id", appId);
|
|
|
|
|
+ memberParams.put("tel_no", tel);
|
|
|
|
|
+ memberParams.put("user_name", realName);
|
|
|
|
|
+ memberParams.put("cert_type", "00");
|
|
|
|
|
+ memberParams.put("cert_id", idno);
|
|
|
|
|
+ Map<String, Object> res = AdapayCommon.requestAdapay(memberParams);
|
|
|
|
|
+ log.info("createMember\n{}", JSON.toJSONString(res, SerializerFeature.PrettyFormat));
|
|
|
|
|
+ if (!("succeeded".equals(MapUtils.getString(res, "status"))
|
|
|
|
|
+ || "member_id_exists".equals(MapUtils.getString(res, "error_code")))) {
|
|
|
|
|
+ String errMsg = MapUtils.getString(res, "error_msg");
|
|
|
|
|
+ String errCode = MapUtils.getString(res, "error_code");
|
|
|
|
|
+ throw new BusinessException(errMsg + "(" + errCode + ")");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String createSettleAccount(String appId, String memberId, String realName, String idNo, String phone, String bankNo) throws BaseAdaPayException {
|
|
|
|
|
+ Map<String, Object> settleCountParams = new HashMap<>();
|
|
|
|
|
+ Map<String, Object> accountInfo = new HashMap<>();
|
|
|
|
|
+ accountInfo.put("card_id", bankNo);
|
|
|
|
|
+ accountInfo.put("card_name", realName);
|
|
|
|
|
+ accountInfo.put("cert_id", idNo);
|
|
|
|
|
+ accountInfo.put("cert_type", "00");
|
|
|
|
|
+ accountInfo.put("tel_no", phone);
|
|
|
|
|
+ accountInfo.put("bank_acct_type", "2");
|
|
|
|
|
+ settleCountParams.put("member_id", memberId);
|
|
|
|
|
+ settleCountParams.put("app_id", appId);
|
|
|
|
|
+ settleCountParams.put("channel", "bank_account");
|
|
|
|
|
+ settleCountParams.put("account_info", accountInfo);
|
|
|
|
|
+ Map<String, Object> res = SettleAccount.create(settleCountParams);
|
|
|
|
|
+ log.info("createSettleAccount\n{}", JSON.toJSONString(res, SerializerFeature.PrettyFormat));
|
|
|
|
|
+ if (!("succeeded".equals(MapUtils.getString(res, "status"))
|
|
|
|
|
+ || "account_exists".equals(MapUtils.getString(res, "error_code")))) {
|
|
|
|
|
+ String errMsg = MapUtils.getString(res, "error_msg");
|
|
|
|
|
+ String errCode = MapUtils.getString(res, "error_code");
|
|
|
|
|
+ throw new BusinessException(errMsg + "(" + errCode + ")");
|
|
|
|
|
+ }
|
|
|
|
|
+ return MapUtils.getString(res, "id");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|