xiongzhu 4 years ago
parent
commit
8e7981f7ef

+ 0 - 173
src/main/java/com/izouma/nineth/dto/adapay/Member.java

@@ -1,173 +0,0 @@
-package com.izouma.nineth.dto.adapay;
-
-import com.alibaba.fastjson.annotation.JSONField;
-
-import java.util.List;
-
-public class Member{
-
-	@JSONField(name="member_id")
-	private String memberId;
-
-	@JSONField(name="created_time")
-	private String createdTime;
-
-	@JSONField(name="cert_type")
-	private String certType;
-
-	@JSONField(name="gender")
-	private String gender;
-
-	@JSONField(name="identified")
-	private String identified;
-
-	@JSONField(name="tel_no")
-	private String telNo;
-
-	@JSONField(name="prod_mode")
-	private String prodMode;
-
-	@JSONField(name="nickname")
-	private String nickname;
-
-	@JSONField(name="disabled")
-	private String disabled;
-
-	@JSONField(name="location")
-	private String location;
-
-	@JSONField(name="app_id")
-	private String appId;
-
-	@JSONField(name="settle_accounts")
-	private List<SettleAccountsItem> settleAccounts;
-
-	@JSONField(name="email")
-	private String email;
-
-	@JSONField(name="object")
-	private String object;
-
-	@JSONField(name="status")
-	private String status;
-
-	public void setMemberId(String memberId){
-		this.memberId = memberId;
-	}
-
-	public String getMemberId(){
-		return memberId;
-	}
-
-	public void setCreatedTime(String createdTime){
-		this.createdTime = createdTime;
-	}
-
-	public String getCreatedTime(){
-		return createdTime;
-	}
-
-	public void setCertType(String certType){
-		this.certType = certType;
-	}
-
-	public String getCertType(){
-		return certType;
-	}
-
-	public void setGender(String gender){
-		this.gender = gender;
-	}
-
-	public String getGender(){
-		return gender;
-	}
-
-	public void setIdentified(String identified){
-		this.identified = identified;
-	}
-
-	public String getIdentified(){
-		return identified;
-	}
-
-	public void setTelNo(String telNo){
-		this.telNo = telNo;
-	}
-
-	public String getTelNo(){
-		return telNo;
-	}
-
-	public void setProdMode(String prodMode){
-		this.prodMode = prodMode;
-	}
-
-	public String getProdMode(){
-		return prodMode;
-	}
-
-	public void setNickname(String nickname){
-		this.nickname = nickname;
-	}
-
-	public String getNickname(){
-		return nickname;
-	}
-
-	public void setDisabled(String disabled){
-		this.disabled = disabled;
-	}
-
-	public String getDisabled(){
-		return disabled;
-	}
-
-	public void setLocation(String location){
-		this.location = location;
-	}
-
-	public String getLocation(){
-		return location;
-	}
-
-	public void setAppId(String appId){
-		this.appId = appId;
-	}
-
-	public String getAppId(){
-		return appId;
-	}
-
-	public void setSettleAccounts(List<SettleAccountsItem> settleAccounts){
-		this.settleAccounts = settleAccounts;
-	}
-
-	public List<SettleAccountsItem> getSettleAccounts(){
-		return settleAccounts;
-	}
-
-	public void setEmail(String email){
-		this.email = email;
-	}
-
-	public String getEmail(){
-		return email;
-	}
-
-	public void setObject(String object){
-		this.object = object;
-	}
-
-	public String getObject(){
-		return object;
-	}
-
-	public void setStatus(String status){
-		this.status = status;
-	}
-
-	public String getStatus(){
-		return status;
-	}
-}

+ 206 - 0
src/main/java/com/izouma/nineth/dto/adapay/MemberInfo.java

@@ -0,0 +1,206 @@
+package com.izouma.nineth.dto.adapay;
+
+import com.alibaba.fastjson.annotation.JSONField;
+
+import java.util.List;
+
+public class MemberInfo {
+
+    @JSONField(name = "member_id")
+    private String memberId;
+
+    @JSONField(name = "created_time")
+    private String createdTime;
+
+    @JSONField(name = "cert_type")
+    private String certType;
+
+    @JSONField(name = "gender")
+    private String gender;
+
+    @JSONField(name = "identified")
+    private String identified;
+
+    @JSONField(name = "tel_no")
+    private String telNo;
+
+    @JSONField(name = "prod_mode")
+    private String prodMode;
+
+    @JSONField(name = "nickname")
+    private String nickname;
+
+    @JSONField(name = "disabled")
+    private String disabled;
+
+    @JSONField(name = "location")
+    private String location;
+
+    @JSONField(name = "app_id")
+    private String appId;
+
+    @JSONField(name = "settle_accounts")
+    private List<SettleAccountsItem> settleAccounts;
+
+    @JSONField(name = "email")
+    private String email;
+
+    @JSONField(name = "object")
+    private String object;
+
+    @JSONField(name = "status")
+    private String status;
+
+    @JSONField(name = "error_type")
+    private String errorType;
+
+    @JSONField(name = "error_code")
+    private String errorCode;
+
+    @JSONField(name = "error_msg")
+    private String errorMsg;
+
+    public void setMemberId(String memberId) {
+        this.memberId = memberId;
+    }
+
+    public String getMemberId() {
+        return memberId;
+    }
+
+    public void setCreatedTime(String createdTime) {
+        this.createdTime = createdTime;
+    }
+
+    public String getCreatedTime() {
+        return createdTime;
+    }
+
+    public void setCertType(String certType) {
+        this.certType = certType;
+    }
+
+    public String getCertType() {
+        return certType;
+    }
+
+    public void setGender(String gender) {
+        this.gender = gender;
+    }
+
+    public String getGender() {
+        return gender;
+    }
+
+    public void setIdentified(String identified) {
+        this.identified = identified;
+    }
+
+    public String getIdentified() {
+        return identified;
+    }
+
+    public void setTelNo(String telNo) {
+        this.telNo = telNo;
+    }
+
+    public String getTelNo() {
+        return telNo;
+    }
+
+    public void setProdMode(String prodMode) {
+        this.prodMode = prodMode;
+    }
+
+    public String getProdMode() {
+        return prodMode;
+    }
+
+    public void setNickname(String nickname) {
+        this.nickname = nickname;
+    }
+
+    public String getNickname() {
+        return nickname;
+    }
+
+    public void setDisabled(String disabled) {
+        this.disabled = disabled;
+    }
+
+    public String getDisabled() {
+        return disabled;
+    }
+
+    public void setLocation(String location) {
+        this.location = location;
+    }
+
+    public String getLocation() {
+        return location;
+    }
+
+    public void setAppId(String appId) {
+        this.appId = appId;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public void setSettleAccounts(List<SettleAccountsItem> settleAccounts) {
+        this.settleAccounts = settleAccounts;
+    }
+
+    public List<SettleAccountsItem> getSettleAccounts() {
+        return settleAccounts;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setObject(String object) {
+        this.object = object;
+    }
+
+    public String getObject() {
+        return object;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public String getErrorType() {
+        return errorType;
+    }
+
+    public void setErrorType(String errorType) {
+        this.errorType = errorType;
+    }
+
+    public String getErrorCode() {
+        return errorCode;
+    }
+
+    public void setErrorCode(String errorCode) {
+        this.errorCode = errorCode;
+    }
+
+    public String getErrorMsg() {
+        return errorMsg;
+    }
+
+    public void setErrorMsg(String errorMsg) {
+        this.errorMsg = errorMsg;
+    }
+}

+ 42 - 0
src/main/java/com/izouma/nineth/service/AdapayMerchantService.java

@@ -8,6 +8,8 @@ import com.huifu.adapay.model.*;
 import com.izouma.nineth.config.AdapayProperties;
 import com.izouma.nineth.config.AdapayProperties;
 import com.izouma.nineth.domain.AdapayMerchant;
 import com.izouma.nineth.domain.AdapayMerchant;
 import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.dto.adapay.MemberInfo;
+import com.izouma.nineth.dto.adapay.SettleAccountsItem;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.AdapayMerchantRepo;
 import com.izouma.nineth.repo.AdapayMerchantRepo;
 import com.izouma.nineth.utils.JpaUtils;
 import com.izouma.nineth.utils.JpaUtils;
@@ -173,6 +175,38 @@ public class AdapayMerchantService {
         return MapUtils.getString(res, "id");
         return MapUtils.getString(res, "id");
     }
     }
 
 
+    public void delSettleAccountForAll(String memberId) throws BaseAdaPayException {
+        for (AdapayMerchant merchant : adapayMerchantRepo.findAll()) {
+            delSettleAccount(merchant.getName(), merchant.getAppId(), memberId);
+        }
+    }
+
+    public void delSettleAccount(String merchant, String appId, String memberId) throws BaseAdaPayException {
+        Map<String, Object> memberParams = new HashMap<>();
+        memberParams.put("member_id", memberId);
+        memberParams.put("app_id", appId);
+        Map<String, Object> member = Member.query(memberParams, merchant);
+        log.info("query member, merchant={} member={} res={}",
+                merchant, memberId, JSON.toJSONString(member, SerializerFeature.PrettyFormat));
+        MemberInfo memberInfo = JSON.parseObject(JSON.toJSONString(member), MemberInfo.class);
+        if ("succeeded".equals(memberInfo.getStatus())) {
+            if (memberInfo.getSettleAccounts() != null && memberInfo.getSettleAccounts().size() > 0) {
+                SettleAccountsItem settleAccountsItem = memberInfo.getSettleAccounts().get(0);
+                Map<String, Object> settleCountParams = new HashMap<>();
+                settleCountParams.put("settle_account_id", settleAccountsItem.getId());
+                settleCountParams.put("member_id", memberId);
+                settleCountParams.put("app_id", adapayProperties.getAppId());
+                Map<String, Object> settleCount = SettleAccount.delete(settleCountParams, merchant);
+                log.info("delSettleAccount, merchant={} member={} res={}",
+                        merchant, memberId, JSON.toJSONString(settleCount, SerializerFeature.PrettyFormat));
+                checkSuccess(settleCount);
+            }
+        } else if ("member_not_exists".equals(memberInfo.getErrorCode())) {
+            log.info("delSettleAccount member_not_exists, merchant={} member={}", merchant, memberId);
+        } else {
+            throw new BusinessException(memberInfo.getErrorMsg() + memberInfo.getErrorCode());
+        }
+    }
 
 
     public void queryMembers(String merchant, String appId) {
     public void queryMembers(String merchant, String appId) {
         boolean hasMore = true;
         boolean hasMore = true;
@@ -214,4 +248,12 @@ public class AdapayMerchantService {
         log.info(JSON.toJSONString(response, SerializerFeature.PrettyFormat));
         log.info(JSON.toJSONString(response, SerializerFeature.PrettyFormat));
         return response;
         return response;
     }
     }
+
+    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 + ")");
+        }
+    }
 }
 }

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

@@ -523,7 +523,7 @@ public class UserService {
     public void removeBankCard(Long userId) throws BaseAdaPayException {
     public void removeBankCard(Long userId) throws BaseAdaPayException {
         User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
         User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
         if (StringUtils.isNotBlank(user.getSettleAccountId()) && StringUtils.isNotBlank(user.getMemberId())) {
         if (StringUtils.isNotBlank(user.getSettleAccountId()) && StringUtils.isNotBlank(user.getMemberId())) {
-            adapayService.delSettleAccount(user.getMemberId(), user.getSettleAccountId());
+            adapayMerchantService.delSettleAccountForAll(user.getMemberId());
             user.setSettleAccountId(null);
             user.setSettleAccountId(null);
             userRepo.save(user);
             userRepo.save(user);
             userBankCardRepo.deleteByUserId(userId);
             userBankCardRepo.deleteByUserId(userId);

+ 2 - 1
src/test/java/com/izouma/nineth/service/AdapayTest.java

@@ -8,6 +8,7 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.huifu.adapay.Adapay;
 import com.huifu.adapay.Adapay;
 import com.huifu.adapay.core.exception.BaseAdaPayException;
 import com.huifu.adapay.core.exception.BaseAdaPayException;
 import com.huifu.adapay.model.*;
 import com.huifu.adapay.model.*;
+import com.izouma.nineth.dto.adapay.MemberInfo;
 import com.izouma.nineth.utils.SnowflakeIdWorker;
 import com.izouma.nineth.utils.SnowflakeIdWorker;
 import com.izouma.nineth.utils.excel.BigIntegerConverter;
 import com.izouma.nineth.utils.excel.BigIntegerConverter;
 import com.izouma.nineth.utils.excel.LocalDateConverter;
 import com.izouma.nineth.utils.excel.LocalDateConverter;
@@ -254,7 +255,7 @@ public class AdapayTest {
         memberParams.put("app_id", appId);
         memberParams.put("app_id", appId);
         Map<String, Object> member = Member.query(memberParams);
         Map<String, Object> member = Member.query(memberParams);
         System.out.println(JSON.toJSONString(member, SerializerFeature.PrettyFormat));
         System.out.println(JSON.toJSONString(member, SerializerFeature.PrettyFormat));
-        com.izouma.nineth.dto.adapay.Member m = JSON.parseObject(JSON.toJSONString(member), com.izouma.nineth.dto.adapay.Member.class);
+        MemberInfo m = JSON.parseObject(JSON.toJSONString(member), MemberInfo.class);
         System.out.println(m);
         System.out.println(m);
 
 
     }
     }