@@ -327,8 +327,11 @@ public class AdapayService {
String wechatAppId = pileMerchantInfoService . queryAppIdByMerchantId ( dto . getMerchantId ( ) ) ;
SettleAccountDTO request = buildSettleAccountDTO ( dto ) ;
Map < String , Object > settleCount = createSettleAccountRequest ( request , adapayMemberAccount . getAdapayMemberId ( ) , wechatAppId ) ;
if ( settleCount = = null | | StringUtils . equals ( ( String ) settleCount . get ( " status " ) , " failed " ) ) {
String errorMsg = settleCount = = null ? " 创建汇付结算账户失败 " : ( String ) settleCount . get ( " error_msg " ) ;
if ( settleCount = = null
| | ! AdapayStatusEnum . SUCCEEDED . getValue ( ) . equals ( settleCount . get ( " status " ) )
| | StringUtils . isBlank ( ( String ) settleCount . get ( " id " ) ) ) {
String errorMsg = settleCount = = null ? null : ( String ) settleCount . get ( " error_msg " ) ;
errorMsg = StringUtils . isNotBlank ( errorMsg ) ? errorMsg : " 创建汇付结算账户失败 " ;
throw new BusinessException ( " 00500001 " , errorMsg ) ;
}
@@ -348,13 +351,7 @@ public class AdapayService {
return Lists . newArrayList ( ) ;
}
String wechatAppId = pileMerchantInfoService . queryAppIdByMerchantId ( merchantId ) ;
String settleAccountId = adapayMemberAccount . getSettleAccountId ( ) ;
if ( StringUtils . isBlank ( settleAccountId ) & & isCorpMember ( adapayMemberAccount . getAdapayMemberId ( ) ) ) {
AdapayCorpMemberVO corpMemberVO = queryCorpAdapayMemberInfo ( adapayMemberAccount . getAdapayMemberId ( ) , wechatAppId ) ;
if ( corpMemberVO ! = null ) {
settleAccountId = corpMemberVO . getSettleAccountId ( ) ;
}
}
String settleAccountId = resolveSettleAccountId ( adapayMemberAccount , wechatAppId ) ;
AdapaySettleAccountVO adapaySettleAccountVO = queryAdapaySettleAccount ( adapayMemberAccount . getAdapayMemberId ( ) , settleAccountId , wechatAppId ) ;
if ( adapaySettleAccountVO = = null ) {
return Lists . newArrayList ( ) ;
@@ -363,6 +360,35 @@ public class AdapayService {
return Lists . newArrayList ( adapaySettleAccountVO ) ;
}
private String resolveSettleAccountId ( AdapayMemberAccount account , String wechatAppId ) throws BaseAdaPayException {
if ( StringUtils . isNotBlank ( account . getSettleAccountId ( ) ) ) {
return account . getSettleAccountId ( ) ;
}
String settleAccountId = null ;
if ( isPersonalMember ( account . getAdapayMemberId ( ) ) ) {
AdapayMemberInfoVO memberInfo = queryAdapayMemberInfo ( account . getAdapayMemberId ( ) , wechatAppId ) ;
if ( memberInfo ! = null ) {
settleAccountId = memberInfo . getSettleAccountId ( ) ;
}
} else {
AdapayCorpMemberVO corpMember = queryCorpAdapayMemberInfo ( account . getAdapayMemberId ( ) , wechatAppId ) ;
if ( corpMember ! = null ) {
settleAccountId = corpMember . getSettleAccountId ( ) ;
}
}
if ( StringUtils . isNotBlank ( settleAccountId ) ) {
AdapayMemberAccount updateRecord = new AdapayMemberAccount ( ) ;
updateRecord . setMerchantId ( account . getMerchantId ( ) ) ;
updateRecord . setAdapayMemberId ( account . getAdapayMemberId ( ) ) ;
updateRecord . setSettleAccountId ( settleAccountId ) ;
adapayMemberAccountService . updateAdapayMemberAccountByMemberId ( updateRecord ) ;
account . setSettleAccountId ( settleAccountId ) ;
}
return settleAccountId ;
}
/**
* 创建汇付会员
*
@@ -501,12 +527,21 @@ public class AdapayService {
}
QueryMemberResponse queryMemberResponse = JSON . parseObject ( JSON . toJSONString ( member ) , QueryMemberResponse . class ) ;
String settleAccountId = null ;
if ( CollectionUtils . isNotEmpty ( queryMemberResponse . getSettle_accounts ( ) ) ) {
settleAccountId = queryMemberResponse . getSettle_accounts ( ) . stream ( )
. map ( QueryMemberResponse . SettleAccount : : getId )
. filter ( StringUtils : : isNotBlank )
. findFirst ( )
. orElse ( null ) ;
}
AdapayMemberInfoVO resultVO = AdapayMemberInfoVO . builder ( )
. memberId ( adapayMemberId )
. nickname ( queryMemberResponse . getNickname ( ) )
. gender ( queryMemberResponse . getGender ( ) )
. email ( queryMemberResponse . getEmail ( ) )
. location ( queryMemberResponse . getLocation ( ) )
. settleAccountId ( settleAccountId )
. build ( ) ;
return resultVO ;
}
@@ -686,6 +721,9 @@ public class AdapayService {
. bankAcctType ( accountInfo . getBank_acct_type ( ) )
. provCode ( accountInfo . getProv_code ( ) )
. areaCode ( accountInfo . getArea_code ( ) )
. minAmt ( accountInfo . getMin_amt ( ) )
. remainedAmt ( accountInfo . getRemained_amt ( ) )
. channelRemark ( accountInfo . getChannel_remark ( ) )
. build ( ) ;
return resultVO ;
}
@@ -776,6 +814,7 @@ public class AdapayService {
* @throws BaseAdaPayException
*/
public void updateSettleAccountConfig ( UpdateAccountConfigDTO dto ) throws BaseAdaPayException {
assertActionAllowed ( dto . getMerchantId ( ) , AdapayOpenActionEnum . UPDATE_SETTLE_ACCOUNT_CONFIG ) ;
String wechatAppId = pileMerchantInfoService . queryAppIdByMerchantId ( dto . getMerchantId ( ) ) ;
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory . getConfig ( wechatAppId ) ;
@@ -784,16 +823,19 @@ public class AdapayService {
}
// 通过merchantId 查询出汇付会员id 和 结算账户id, 用来查询余额
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService . selectByMerchantId ( dto . getMerchantId ( ) ) ;
if ( adapayMemberAccount = = null ) {
log . error ( " 通过merchantId:{}, 没有查询到结算账户配置 " , dto . getMercha ntId ( ) ) ;
return ;
AdapayMemberAccount adapayMemberAccount = requireCurrentMemberAccount ( dto . getMerchantId ( ) ) ;
String settleAccountId = resolveSettleAccountId ( adapayMemberAccount , wechatAppId ) ;
if ( StringUtils . isBlank ( settleAccou ntId ) ) {
throw new BusinessException ( " " , " 未查询到结算账户 " ) ;
}
if ( StringUtils . isAllBlank ( dto . getMinAmt ( ) , dto . getRemainedAmt ( ) , dto . getChannelRemark ( ) ) ) {
throw new BusinessException ( " " , " 结算起始金额、结算留存金额和结算摘要至少填写一项 " ) ;
}
// 修改账户配置
Map < String , Object > params = Maps . newHashMap ( ) ;
params . put ( " app_id " , config . getAdapayAppId ( ) ) ;
params . put ( " member_id " , adapayMemberAccount . getAdapayMemberId ( ) ) ;
params . put ( " settle_account_id " , adapayMemberAccount . getS ettleAccountId( ) );
params . put ( " settle_account_id " , s ettleAccountId) ;
if ( StringUtils . isNotBlank ( dto . getMinAmt ( ) ) ) {
params . put ( " min_amt " , dto . getMinAmt ( ) ) ;
}
@@ -803,8 +845,13 @@ public class AdapayService {
if ( StringUtils . isNotBlank ( dto . getChannelRemark ( ) ) ) {
params . put ( " channel_remark " , dto . getChannelRemark ( ) ) ;
}
Map < String , Object > settleCount = SettleAccount . update ( params ) ;
Map < String , Object > settleCount = SettleAccount . modify ( params , config . getWechatAppId ( ) );
log . info ( " 更新结算账户设置 param:{}, result:{} " , JSON . toJSONString ( params ) , JSON . toJSONString ( settleCount ) ) ;
if ( settleCount = = null
| | ! AdapayStatusEnum . SUCCEEDED . getValue ( ) . equals ( settleCount . get ( " status " ) ) ) {
String errorMsg = settleCount = = null ? null : ( String ) settleCount . get ( " error_msg " ) ;
throw new BusinessException ( " " , StringUtils . isNotBlank ( errorMsg ) ? errorMsg : " 修改汇付结算配置失败 " ) ;
}
}
/**
@@ -1683,38 +1730,20 @@ public class AdapayService {
* 用户需要换绑银行卡 1-删除结算账户信息, 2-使用新账户信息创建结算账户】
*/
public void changeBankCard ( ChangeBankCardDTO dto ) throws BaseAdaPayException {
String wechatAppId = pileMerchantInfoService . queryAppIdByM erchantId( dto . getMerchantId ( ) ) ;
// 获取汇付支会员信息
AdapayMemberAccount account = adapayMemberAccountService . selectByM erchantId ( dto . getMerchantId ( ) ) ;
if ( account = = null ) {
return ;
}
// 1-删除结算账户信息
String adapayMemberId = account . getAdapayMemberId ( ) ;
String settleAccountId = null ;
AdapayCorpMemberVO adapayCorpMemberVO = this . queryCorpAdapayMemberInfo ( adapayMemberId , wechatAppId ) ;
if ( adapayCorpMemberVO ! = null ) {
settleAccountId = adapayCorpMemberVO . getSettleAccountI d ( ) ;
}
this . createDeleteSettleAccountRequest ( adapayMemberId , settleAccountId , wechatAppId ) ;
// 2-使用新账户信息创建结算账户
SettleAccountDTO settleAccountDTO = new SettleAccountDTO ( ) ;
settleAccountDTO . setCardId ( dto . getCardId ( ) ) ;
settleAccountDTO . setCardName ( dto . getCardName ( ) ) ;
settleAccountDTO . setTelNo ( dto . getTelNo ( ) ) ;
settleAccountDTO . setBankCode ( dto . getBankCode ( ) ) ;
settleAccountDTO . setBankAcctType ( dto . getBankAcctType ( ) ) ;
settleAccountDTO . setProvCode ( dto . getProvCode ( ) ) ;
settleAccountDTO . setAreaCode ( dto . getAreaCode ( ) ) ;
Map < String , Object > settleAccount = this . createSettleAccountRequest ( settleAccountDTO , adapayMemberId , wechatAppId ) ;
if ( settleAccount ! = null & & ! StringUtils . equals ( ( String ) settleAccount . get ( " status " ) , " failed " ) ) {
AdapayMemberAccount updateRecord = new AdapayMemberAccount ( ) ;
updateRecord . setAdapayMemberId ( adapayMemberId ) ;
updateRecord . setMerchantId ( dto . getMerchantId ( ) ) ;
updateRecord . setSettleAccountId ( ( String ) settleAccount . get ( " id " ) ) ;
adapayMemberAccountService . updateAdapayMemberAccountByMemberId ( updateRecord ) ;
}
deleteSettleAccount ( AdapayMemberInfoDTO . builder ( ) . m erchantId( dto . getMerchantId ( ) ) . build ( ) ) ;
CreateSettleAccountDTO createRequest = CreateSettleAccountDTO . builder ( )
. m erchantId ( dto . getMerchantId ( ) )
. bankAcctType ( dto . getBankAcctType ( ) )
. cardId ( dto . getCardId ( ) )
. cardName ( dto . getCardName ( ) )
. certId ( dto . getCertId ( ) )
. certType ( dto . getCertType ( ) )
. telNo ( dto . getTelNo ( ) )
. bankCode ( dto . getBankCode ( ) )
. provCode ( dto . getProvCode ( ) )
. areaCode ( dto . getAreaCode ( ) )
. buil d ( ) ;
createSettleAccount ( createRequest ) ;
}
/**
@@ -1805,21 +1834,27 @@ public class AdapayService {
assertActionAllowed ( dto . getMerchantId ( ) , AdapayOpenActionEnum . DELETE_SETTLE_ACCOUNT ) ;
AdapayMemberAccount adapayMemberAccount = requireCurrentMemberAccount ( dto . getMerchantId ( ) ) ;
String wechatAppId = pileMerchantInfoService . queryAppIdByMerchantId ( dto . getMerchantId ( ) ) ;
String adapayMemberId = StringUtils . isNotBlank ( dto . getAdapayMemberId ( ) ) ? dto . getAdapayMemberId ( ) : adapayMemberAccount. getAdapayMemberId ( ) ;
String settleAccountId = StringUtils . isNotBlank ( dto . getSettleAccountId ( ) ) ? dto . getSettleAccountId ( ) : adapayMemberAccount . getSettleAccount Id ( ) ;
if ( StringUtils . isBlank ( settleAccountId ) & & isCorp Member( adapayMemberId ) ) {
AdapayCorpMemberVO corpMemberVO = queryCorpAdapayMemberInfo ( adapayMemberId , wechatAppId ) ;
if ( corpMemberVO ! = null ) {
settleAccountId = corpMemberVO . getSettleAccountId ( ) ;
}
String adapayMemberId = adapayMemberAccount . getAdapayMemberId ( ) ;
if ( StringUtils . isNotBlank ( dto . getAdapayMember Id ( ) )
& & ! StringUtils . equals ( dto . getAdapay MemberId () , adapayMemberId ) ) {
throw new BusinessException ( " " , " 汇付用户信息不匹配 " ) ;
}
String settleAccountId = resolveSettleAccountId ( adapayMemberAccount , wechatAppId ) ;
if ( StringUtils . isBlank ( settleAccountId ) ) {
throw new BusinessException ( " " , " 未查询到结算账户 " ) ;
}
if ( StringUtils . isNotBlank ( dto . getSettleAccountId ( ) )
& & ! StringUtils . equals ( dto . getSettleAccountId ( ) , settleAccountId ) ) {
throw new BusinessException ( " " , " 结算账户信息不匹配 " ) ;
}
assertSettleAccountCanDelete ( dto . getMerchantId ( ) ) ;
this . createDeleteSettleAccountRequest ( adapayMemberId , settleAccountId , wechatAppId ) ;
adapayMemberAccountService . clearSettleAccountByMerchantId ( dto . getMerchantId ( ) ) ;
int cleared = adapayMemberAccountService . clearCurrent SettleAccount(
adapayMemberAccount . getId ( ) , dto . getMerchantId ( ) , adapayMemberId , settleAccountId ) ;
if ( cleared ! = 1 ) {
throw new BusinessException ( " " , " 汇付结算账户已删除,但本地账户状态更新失败,请联系管理员处理 " ) ;
}
}
public void deleteAdapayMember ( DeleteAdapayMemberDTO dto ) throws BaseAdaPayException {
@@ -2018,6 +2053,7 @@ public class AdapayService {
break ;
case PERSONAL_COMPLETED :
actions . add ( AdapayOpenActionEnum . UPDATE_PERSONAL_MEMBER . getValue ( ) ) ;
actions . add ( AdapayOpenActionEnum . UPDATE_SETTLE_ACCOUNT_CONFIG . getValue ( ) ) ;
actions . add ( AdapayOpenActionEnum . DELETE_SETTLE_ACCOUNT . getValue ( ) ) ;
break ;
case CORP_AUDITING :
@@ -2035,6 +2071,7 @@ public class AdapayService {
break ;
case CORP_COMPLETED :
actions . add ( AdapayOpenActionEnum . UPDATE_CORP_MEMBER . getValue ( ) ) ;
actions . add ( AdapayOpenActionEnum . UPDATE_SETTLE_ACCOUNT_CONFIG . getValue ( ) ) ;
actions . add ( AdapayOpenActionEnum . DELETE_SETTLE_ACCOUNT . getValue ( ) ) ;
break ;
default :