Authored by LUOXC

不转账香港号

... ... @@ -10,6 +10,8 @@ public enum BillTradeStatus {
FAIL(200),
NOT_EXIST_ALI_ACCOUNT(201),
AMOUNT_IS_ILLEGAL(202),
HK_AMOUNT_WAIT_PAYMENT(203),
YH_STORE_AMOUNT_WAIT_PAYMENT(204),
TRANSFER_FAIL(299);
int code;
... ...
... ... @@ -61,6 +61,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import static com.yohoufo.order.common.TransferCase.EARNEST_MONEY_TO_BUYER;
... ... @@ -662,20 +663,27 @@ public class PaymentServiceImpl implements IPaymentService {
throw new ServiceException(400, "不合法的金额:" + transferAmount);
}
AuthorizeResultRespVO account = getOneValidAlipayAccount(targetUid);
if (account == null) {
logger.warn("transferMonErr uid {} 没有获取到有效的支付宝账号", targetUid);
record.setTradeStatus(BillTradeStatus.NOT_EXIST_ALI_ACCOUNT.getCode());
addTradeBills(record);
throw new ServiceException(400, "uid[" + targetUid + "]没有获取到有效的支付宝账号");
}
AuthorizeResultRespVO account = getOneValidAlipayAccountOr(targetUid, invalidAccount -> {
if ("invalid".equals(invalidAccount)) {
record.setTradeStatus(BillTradeStatus.YH_STORE_AMOUNT_WAIT_PAYMENT.getCode());
} else if ("invalid_hk".equals(invalidAccount)) {
record.setTradeStatus(BillTradeStatus.HK_AMOUNT_WAIT_PAYMENT.getCode());
} else {
record.setTradeStatus(BillTradeStatus.NOT_EXIST_ALI_ACCOUNT.getCode());
}
addTradeBills(record);
});
if(account == null){
throw new ServiceException(400, "uid[" + targetUid + "]没有获取到有效的支付宝账号");
}
if(StringUtils.isNotBlank(account.getAlipayId())) {
logger.info("transferMon uid {} 支付宝账号uid有值优先使用{}", targetUid, account.getAlipayId());
transfer.setAlipayAccount(account.getAlipayId());
} else if(StringUtils.isNotBlank(account.getAlipayAccount())) {
logger.info("transferMon uid {} 支付宝账号uid无值使用账号{}", targetUid, account.getAlipayAccount());
transfer.setAlipayAccount(account.getAlipayAccount());
}
transfer.setUpdateTime(now);
tradeBillsMapper.insert(record);
... ... @@ -1276,25 +1284,41 @@ public class PaymentServiceImpl implements IPaymentService {
private void addTradeBills(TradeBills record) {
tradeBillsService.addTradeBills(record);
}
private AuthorizeResultRespVO getOneValidAlipayAccount(int targetUid) {
return getOneValidAlipayAccountOr(targetUid, invalidAccount -> {});
}
private AuthorizeResultRespVO getOneValidAlipayAccount(int targetUid) {
private AuthorizeResultRespVO getOneValidAlipayAccountOr(int targetUid, Consumer<String> invalidAccountHandler) {
ApiResponse<AuthorizeResultRespVO> resp = ufoServiceCaller.call("ufo.user.aliPayAccountQuery", ApiResponse.class, targetUid);
AuthorizeResultRespVO account = null;
if (resp != null) {
account = (AuthorizeResultRespVO) resp.getData();
}
if (account == null ||
(StringUtils.isBlank(account.getAlipayAccount()) && StringUtils.isBlank(account.getAlipayId()))
|| StringUtils.equals("invalid", account.getAlipayAccount())
|| StringUtils.equals("invalid", account.getAlipayId())) {
// 账户不存在
if (account == null) {
invalidAccountHandler.accept(null);
return null;
}
return account;
// 账户不存在
else if ((StringUtils.isBlank(account.getAlipayAccount()) && StringUtils.isBlank(account.getAlipayId()))) {
invalidAccountHandler.accept(null);
return null;
}
// 无效的支付宝账号
else if (StringUtils.contains(account.getAlipayAccount(), "invalid")) {
invalidAccountHandler.accept(account.getAlipayAccount());
return null;
}
// 无效的支付宝账号
else if (StringUtils.contains(account.getAlipayId(), "invalid")) {
invalidAccountHandler.accept(account.getAlipayId());
return null;
} else {
return account;
}
}
... ...