Răsfoiți Sursa

Merge branch 'dev' of http://git.izouma.com/licailing/modern_point into dev

panhui 3 ani în urmă
părinte
comite
9180554fde

+ 2 - 0
src/main/java/com/izouma/nineth/dto/UserBankCard.java

@@ -26,4 +26,6 @@ public class UserBankCard extends BaseEntity {
     private String cardTypeDesc;
     private String cardTypeDesc;
 
 
     private String bankNo;
     private String bankNo;
+
+    private String phone;
 }
 }

+ 2 - 0
src/main/java/com/izouma/nineth/repo/UserRepo.java

@@ -161,4 +161,6 @@ public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExe
     void setSales(Long userId, int sales);
     void setSales(Long userId, int sales);
 
 
     List<User> findByAuthoritiesContains(Authority authority);
     List<User> findByAuthoritiesContains(Authority authority);
+
+    List<User> findBySettleAccountIdIsNotNull();
 }
 }

+ 90 - 5
src/main/java/com/izouma/nineth/service/UserService.java

@@ -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");
+    }
 }
 }

+ 28 - 0
src/main/java/com/izouma/nineth/utils/AdapayUtils.java

@@ -0,0 +1,28 @@
+package com.izouma.nineth.utils;
+
+import com.huifu.adapay.core.exception.BaseAdaPayException;
+import com.huifu.adapay.core.exception.FailureCode;
+import com.izouma.nineth.exception.BusinessException;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+public class AdapayUtils {
+    public static String packageRequestUrl(Map<String, Object> requestParams) throws BaseAdaPayException {
+        String adapayFuncCode = (String) requestParams.get("adapay_func_code");
+        if (StringUtils.isBlank(adapayFuncCode)) {
+            throw new BaseAdaPayException(FailureCode.ADAPAY_FUNC_CODE_NOT_BLANK.getFailureCode());
+        }
+        String adapayApiVersion = (String) requestParams.getOrDefault("adapay_api_version", "v1");
+        return "/" + adapayApiVersion + "/" + StringUtils.replace(adapayFuncCode, ".", "/");
+    }
+
+    public static void checkSuccess(Map<String, Object> map) {
+        if (!"succeeded".equals(MapUtils.getString(map, "status"))) {
+            String errMsg = MapUtils.getString(map, "error_msg");
+            String errCode = MapUtils.getString(map, "error_code");
+            throw new BusinessException(errMsg + "(" + errCode + ")");
+        }
+    }
+}

+ 2 - 3
src/main/java/com/izouma/nineth/web/AssetController.java

@@ -9,7 +9,6 @@ import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.dto.UserHistory;
 import com.izouma.nineth.dto.UserHistory;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.AssetRepo;
 import com.izouma.nineth.repo.AssetRepo;
-import com.izouma.nineth.repo.TokenHistoryRepo;
 import com.izouma.nineth.service.AssetMintService;
 import com.izouma.nineth.service.AssetMintService;
 import com.izouma.nineth.service.AssetService;
 import com.izouma.nineth.service.AssetService;
 import com.izouma.nineth.service.GiftOrderService;
 import com.izouma.nineth.service.GiftOrderService;
@@ -36,7 +35,6 @@ public class AssetController extends BaseController {
     private AssetService     assetService;
     private AssetService     assetService;
     private AssetRepo        assetRepo;
     private AssetRepo        assetRepo;
     private GiftOrderService giftOrderService;
     private GiftOrderService giftOrderService;
-    private TokenHistoryRepo tokenHistoryRepo;
     private AssetMintService assetMintService;
     private AssetMintService assetMintService;
 
 
     //@PreAuthorize("hasRole('ADMIN')")
     //@PreAuthorize("hasRole('ADMIN')")
@@ -107,7 +105,8 @@ public class AssetController extends BaseController {
     @PostMapping("/gift")
     @PostMapping("/gift")
     @ApiOperation("转赠")
     @ApiOperation("转赠")
     public GiftOrder gift(@RequestParam Long assetId, @RequestParam Long toUserId) {
     public GiftOrder gift(@RequestParam Long assetId, @RequestParam Long toUserId) {
-        return giftOrderService.gift(SecurityUtils.getAuthenticatedUser().getId(), assetId, toUserId);
+        throw new BusinessException("无转赠");
+//        return giftOrderService.gift(SecurityUtils.getAuthenticatedUser().getId(), assetId, toUserId);
     }
     }
 
 
     @GetMapping("/tokenHistory")
     @GetMapping("/tokenHistory")

+ 7 - 0
src/main/java/com/izouma/nineth/web/UserController.java

@@ -238,6 +238,13 @@ public class UserController extends BaseController {
                 .getContent();
                 .getContent();
         ExcelUtils.export(response, data);
         ExcelUtils.export(response, data);
     }
     }
+
+    @PreAuthorize("hasAnyRole('ADMIN')")
+    @GetMapping("/switchAccount")
+    public String switchAccount() {
+        userService.switchAccount();
+        return "ok";
+    }
 }
 }