Authored by LUOXC

add transfer check

... ... @@ -578,7 +578,7 @@ public class PaymentServiceImpl implements IPaymentService {
} else if (transferChancelSelector.isTransferWithAlipayExceedMillionTransfer()) {//超过百万,使用更大额度的接口
transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_WHEN_EXCEED_MILLION);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
transferWithAlipayExceedMillionTransfer(logTag, record, buyerOrderCode, account, transferAmount, transfer);
transferWithAlipayExceedMillionTransfer(logTag, record, buyerOrderCode, account, transferAmount, transfer,false);
} else {
transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_NON_EXCEED_MILLION);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
... ... @@ -829,7 +829,7 @@ public class PaymentServiceImpl implements IPaymentService {
private void doManualDeal(Integer tradeBillsId, ManualDealRequest req) {
throwServiceExceptionIf(tradeBillsId == null || tradeBillsId < 1, "流水Id不合法");
throwServiceExceptionIf(req.getOperateUid() == null || req.getOperateUid() < 1, "客服uid不合法");
throwServiceExceptionIf(req.getOperateUid() == null || req.getOperateUid() < 0, "客服uid不合法");
throwServiceExceptionIf(StringUtils.isBlank(req.getOperateUname()), "客服名称不合法");
TradeBills tradeBills = tradeBillsMapper.selectByPrimaryKey(tradeBillsId);
throwServiceExceptionIf(tradeBills == null, "流水不存在");
... ... @@ -838,16 +838,9 @@ public class PaymentServiceImpl implements IPaymentService {
// 是否处理过的
throwServiceExceptionIf(Objects.nonNull(tradeBillsMapper.selectByDealRelateId(tradeBillsId)), "该流水已经处理过");
String logTag = String.format("manual deal orderCode is %s tradeBillId is %s uid is %s", tradeBills.getOrderCode(), tradeBillsId, tradeBills.getUid());
BigDecimal amount = null;
try {
amount = new BigDecimal(req.getAmount()).setScale(2, BigDecimal.ROUND_HALF_DOWN);
} catch (Exception e) {
throwServiceException("转账金额不合法");
}
throwServiceExceptionIf(amount.compareTo(new BigDecimal("0.1")) < 0, "转账金额小于0.1");
throwServiceExceptionIf(tradeBills.getAmount().compareTo(amount) != 0, "转账金额有误");
throwServiceExceptionIf(tradeBills.getTradeStatus() == HK_AMOUNT_WAIT_PAYMENT.getCode()
|| tradeBills.getTradeStatus() == YOHO_STORE_AMOUNT_WAIT_PAYMENT.getCode(), "该流不可操作:待结算");
... ... @@ -867,8 +860,16 @@ public class PaymentServiceImpl implements IPaymentService {
tradeBills.setPayType(optMarkPaidPayType(req.getSceneId()).get());
markPaid(logTag, tradeBills, lockKey);
}
BigDecimal amount = null;
try {
amount = new BigDecimal(req.getAmount()).setScale(2, BigDecimal.ROUND_HALF_DOWN);
} catch (Exception e) {
throwServiceException("转账金额不合法");
}
throwServiceExceptionIf(amount.compareTo(new BigDecimal("0.1")) < 0, "转账金额小于0.1");
throwServiceExceptionIf(tradeBills.getAmount().compareTo(amount) != 0, "转账金额有误");
// 退求购定金、货款、普通用户退保证金
else if (isRefundGoodsMoneyOrDepositMoneyTradeBills(tradeBills) || isRefundEarnestMoneyTradeBills(tradeBills)) {
if (isRefundGoodsMoneyOrDepositMoneyTradeBills(tradeBills) || isRefundEarnestMoneyTradeBills(tradeBills)) {
refund(logTag, tradeBills, amount, lockKey);
}
// 转账
... ... @@ -981,7 +982,7 @@ public class PaymentServiceImpl implements IPaymentService {
if (transferChancelSelector.isTransferWithWallet(interfaceType)) {
transferWithWalletAndAddSuccessTradeBills(logTag, tradeBills, orderCode, account, amount, transfer);
} else if (transferChancelSelector.isTransferWithAlipayExceedMillionTransfer(interfaceType)) {
transferWithAlipayExceedMillionTransfer(logTag, tradeBills, orderCode, account, amount, transfer);
transferWithAlipayExceedMillionTransfer(logTag, tradeBills, orderCode, account, amount, transfer,true);
} else {
transferWithAlipayTransferAndAddSuccessTradeBills(logTag, tradeBills, orderCode, account, amount, transfer);
}
... ... @@ -1111,7 +1112,8 @@ public class PaymentServiceImpl implements IPaymentService {
long orderCode,
AuthorizeResultRespVO account,
BigDecimal amount,
OrdersPayTransfer transfer) {
OrdersPayTransfer transfer,
boolean isCheckTransferStatus) {
String businessId = transfer.getId() + "_" + tradeBills.getId();
TransferResult transferResult = alipayService.newAlipayExceedMillionTransfer(account.getUid())
.transferOrderCode(Long.toString(orderCode))
... ... @@ -1121,6 +1123,7 @@ public class PaymentServiceImpl implements IPaymentService {
.businessId(businessId)
.userName(account.getCertName())
.riskWatcher(Arrays.asList((uid, aar) -> shoppingRiskWatchDog.checkAlipayBlackUser(uid, aar)))
.withTransferStatusQueryInterceptIf(isCheckTransferStatus)
.transfer();
// success to wait
if (transferResult.getCode() == 200) {
... ...
... ... @@ -27,6 +27,7 @@ import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.pay.alipay.bean.TtnStatusQueryResponse;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.transfer.TransferChannel;
import com.yohoufo.order.service.transfer.TransferInterceptor;
import com.yohoufo.order.service.transfer.TransferResult;
import com.yohoufo.order.utils.AlipayExceedMillionTransferErrors;
import lombok.AccessLevel;
... ... @@ -234,6 +235,11 @@ public abstract class AbstractAlipayService extends AbstractPayService {
}
@Override
public TransferChannel check() {
return this;
}
@Override
public TransferResult transfer() {
AuthorizeResultRespVO aar = AuthorizeResultRespVO.builder().alipayId(alipayUid)
.alipayAccount(alipayAccount).build();
... ... @@ -329,9 +335,12 @@ public abstract class AbstractAlipayService extends AbstractPayService {
String businessId;
String userName;
List<BiConsumer<Integer, AuthorizeResultRespVO>> riskWatcher;
List<TransferInterceptor> transferInterceptors;
boolean transferSuccess;
private AlipayExceedMillionTransferChannel(int uid) {
this.uid = uid;
this.transferInterceptors = new ArrayList<>();
}
public AlipayExceedMillionTransferChannel transferOrderCode(String transferOrderCode) {
... ... @@ -369,8 +378,58 @@ public abstract class AbstractAlipayService extends AbstractPayService {
return this;
}
public AlipayExceedMillionTransferChannel withTransferStatusQueryInterceptIf(boolean condition) {
return condition ? withTransferStatusQueryIntercept() : this;
}
public AlipayExceedMillionTransferChannel withTransferStatusQueryIntercept() {
transferInterceptors.add(new TransferInterceptor() {
@Override
public void preIntercept(TransferChannel transferChannel) {
transferSuccess = transferTtnStatusQuery(transferOrderCode).isTransferSuccess(businessId, transferAmount);
}
@Override
public void postIntercept(TransferChannel transferChannel, TransferResult result) {
}
@Override
public void onError(TransferChannel transferChannel, Throwable throwable) {
}
});
return this;
}
@Override
public TransferResult transfer() {
for (TransferInterceptor transferInterceptor : transferInterceptors) {
transferInterceptor.preIntercept(this);
}
try {
TransferResult result = doTransfer();
for (TransferInterceptor transferInterceptor : transferInterceptors) {
transferInterceptor.postIntercept(this, result);
}
return result;
} catch (Throwable e) {
for (TransferInterceptor transferInterceptor : transferInterceptors) {
transferInterceptor.onError(this, e);
}
throw e;
}
}
private TransferResult doTransfer() {
if (this.transferSuccess) {
return TransferResult.builder()
.code(200)
.msg("ok")
.build();
}
AuthorizeResultRespVO aar = AuthorizeResultRespVO.builder().alipayId(alipayUid)
.alipayAccount(alipayAccount).build();
riskWatcher.stream().forEach(x -> x.accept(uid, aar));
... ...
package com.yohoufo.order.service.transfer;
public interface TransferInterceptor {
void preIntercept(TransferChannel transferChannel);
void postIntercept(TransferChannel transferChannel, TransferResult result);
void onError(TransferChannel transferChannel, Throwable throwable);
}
... ...