Authored by LUOXC

add transfer check

@@ -578,7 +578,7 @@ public class PaymentServiceImpl implements IPaymentService { @@ -578,7 +578,7 @@ public class PaymentServiceImpl implements IPaymentService {
578 } else if (transferChancelSelector.isTransferWithAlipayExceedMillionTransfer()) {//超过百万,使用更大额度的接口 578 } else if (transferChancelSelector.isTransferWithAlipayExceedMillionTransfer()) {//超过百万,使用更大额度的接口
579 transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_WHEN_EXCEED_MILLION); 579 transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_WHEN_EXCEED_MILLION);
580 ordersPayTransferMapper.updateByPrimaryKeySelective(transfer); 580 ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
581 - transferWithAlipayExceedMillionTransfer(logTag, record, buyerOrderCode, account, transferAmount, transfer); 581 + transferWithAlipayExceedMillionTransfer(logTag, record, buyerOrderCode, account, transferAmount, transfer,false);
582 } else { 582 } else {
583 transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_NON_EXCEED_MILLION); 583 transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_NON_EXCEED_MILLION);
584 ordersPayTransferMapper.updateByPrimaryKeySelective(transfer); 584 ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
@@ -829,7 +829,7 @@ public class PaymentServiceImpl implements IPaymentService { @@ -829,7 +829,7 @@ public class PaymentServiceImpl implements IPaymentService {
829 829
830 private void doManualDeal(Integer tradeBillsId, ManualDealRequest req) { 830 private void doManualDeal(Integer tradeBillsId, ManualDealRequest req) {
831 throwServiceExceptionIf(tradeBillsId == null || tradeBillsId < 1, "流水Id不合法"); 831 throwServiceExceptionIf(tradeBillsId == null || tradeBillsId < 1, "流水Id不合法");
832 - throwServiceExceptionIf(req.getOperateUid() == null || req.getOperateUid() < 1, "客服uid不合法"); 832 + throwServiceExceptionIf(req.getOperateUid() == null || req.getOperateUid() < 0, "客服uid不合法");
833 throwServiceExceptionIf(StringUtils.isBlank(req.getOperateUname()), "客服名称不合法"); 833 throwServiceExceptionIf(StringUtils.isBlank(req.getOperateUname()), "客服名称不合法");
834 TradeBills tradeBills = tradeBillsMapper.selectByPrimaryKey(tradeBillsId); 834 TradeBills tradeBills = tradeBillsMapper.selectByPrimaryKey(tradeBillsId);
835 throwServiceExceptionIf(tradeBills == null, "流水不存在"); 835 throwServiceExceptionIf(tradeBills == null, "流水不存在");
@@ -838,16 +838,9 @@ public class PaymentServiceImpl implements IPaymentService { @@ -838,16 +838,9 @@ public class PaymentServiceImpl implements IPaymentService {
838 // 是否处理过的 838 // 是否处理过的
839 throwServiceExceptionIf(Objects.nonNull(tradeBillsMapper.selectByDealRelateId(tradeBillsId)), "该流水已经处理过"); 839 throwServiceExceptionIf(Objects.nonNull(tradeBillsMapper.selectByDealRelateId(tradeBillsId)), "该流水已经处理过");
840 840
841 -  
842 String logTag = String.format("manual deal orderCode is %s tradeBillId is %s uid is %s", tradeBills.getOrderCode(), tradeBillsId, tradeBills.getUid()); 841 String logTag = String.format("manual deal orderCode is %s tradeBillId is %s uid is %s", tradeBills.getOrderCode(), tradeBillsId, tradeBills.getUid());
843 - BigDecimal amount = null;  
844 - try {  
845 - amount = new BigDecimal(req.getAmount()).setScale(2, BigDecimal.ROUND_HALF_DOWN);  
846 - } catch (Exception e) {  
847 - throwServiceException("转账金额不合法");  
848 - }  
849 - throwServiceExceptionIf(amount.compareTo(new BigDecimal("0.1")) < 0, "转账金额小于0.1");  
850 - throwServiceExceptionIf(tradeBills.getAmount().compareTo(amount) != 0, "转账金额有误"); 842 +
  843 +
851 throwServiceExceptionIf(tradeBills.getTradeStatus() == HK_AMOUNT_WAIT_PAYMENT.getCode() 844 throwServiceExceptionIf(tradeBills.getTradeStatus() == HK_AMOUNT_WAIT_PAYMENT.getCode()
852 || tradeBills.getTradeStatus() == YOHO_STORE_AMOUNT_WAIT_PAYMENT.getCode(), "该流不可操作:待结算"); 845 || tradeBills.getTradeStatus() == YOHO_STORE_AMOUNT_WAIT_PAYMENT.getCode(), "该流不可操作:待结算");
853 846
@@ -867,8 +860,16 @@ public class PaymentServiceImpl implements IPaymentService { @@ -867,8 +860,16 @@ public class PaymentServiceImpl implements IPaymentService {
867 tradeBills.setPayType(optMarkPaidPayType(req.getSceneId()).get()); 860 tradeBills.setPayType(optMarkPaidPayType(req.getSceneId()).get());
868 markPaid(logTag, tradeBills, lockKey); 861 markPaid(logTag, tradeBills, lockKey);
869 } 862 }
  863 + BigDecimal amount = null;
  864 + try {
  865 + amount = new BigDecimal(req.getAmount()).setScale(2, BigDecimal.ROUND_HALF_DOWN);
  866 + } catch (Exception e) {
  867 + throwServiceException("转账金额不合法");
  868 + }
  869 + throwServiceExceptionIf(amount.compareTo(new BigDecimal("0.1")) < 0, "转账金额小于0.1");
  870 + throwServiceExceptionIf(tradeBills.getAmount().compareTo(amount) != 0, "转账金额有误");
870 // 退求购定金、货款、普通用户退保证金 871 // 退求购定金、货款、普通用户退保证金
871 - else if (isRefundGoodsMoneyOrDepositMoneyTradeBills(tradeBills) || isRefundEarnestMoneyTradeBills(tradeBills)) { 872 + if (isRefundGoodsMoneyOrDepositMoneyTradeBills(tradeBills) || isRefundEarnestMoneyTradeBills(tradeBills)) {
872 refund(logTag, tradeBills, amount, lockKey); 873 refund(logTag, tradeBills, amount, lockKey);
873 } 874 }
874 // 转账 875 // 转账
@@ -981,7 +982,7 @@ public class PaymentServiceImpl implements IPaymentService { @@ -981,7 +982,7 @@ public class PaymentServiceImpl implements IPaymentService {
981 if (transferChancelSelector.isTransferWithWallet(interfaceType)) { 982 if (transferChancelSelector.isTransferWithWallet(interfaceType)) {
982 transferWithWalletAndAddSuccessTradeBills(logTag, tradeBills, orderCode, account, amount, transfer); 983 transferWithWalletAndAddSuccessTradeBills(logTag, tradeBills, orderCode, account, amount, transfer);
983 } else if (transferChancelSelector.isTransferWithAlipayExceedMillionTransfer(interfaceType)) { 984 } else if (transferChancelSelector.isTransferWithAlipayExceedMillionTransfer(interfaceType)) {
984 - transferWithAlipayExceedMillionTransfer(logTag, tradeBills, orderCode, account, amount, transfer); 985 + transferWithAlipayExceedMillionTransfer(logTag, tradeBills, orderCode, account, amount, transfer,true);
985 } else { 986 } else {
986 transferWithAlipayTransferAndAddSuccessTradeBills(logTag, tradeBills, orderCode, account, amount, transfer); 987 transferWithAlipayTransferAndAddSuccessTradeBills(logTag, tradeBills, orderCode, account, amount, transfer);
987 } 988 }
@@ -1111,7 +1112,8 @@ public class PaymentServiceImpl implements IPaymentService { @@ -1111,7 +1112,8 @@ public class PaymentServiceImpl implements IPaymentService {
1111 long orderCode, 1112 long orderCode,
1112 AuthorizeResultRespVO account, 1113 AuthorizeResultRespVO account,
1113 BigDecimal amount, 1114 BigDecimal amount,
1114 - OrdersPayTransfer transfer) { 1115 + OrdersPayTransfer transfer,
  1116 + boolean isCheckTransferStatus) {
1115 String businessId = transfer.getId() + "_" + tradeBills.getId(); 1117 String businessId = transfer.getId() + "_" + tradeBills.getId();
1116 TransferResult transferResult = alipayService.newAlipayExceedMillionTransfer(account.getUid()) 1118 TransferResult transferResult = alipayService.newAlipayExceedMillionTransfer(account.getUid())
1117 .transferOrderCode(Long.toString(orderCode)) 1119 .transferOrderCode(Long.toString(orderCode))
@@ -1121,6 +1123,7 @@ public class PaymentServiceImpl implements IPaymentService { @@ -1121,6 +1123,7 @@ public class PaymentServiceImpl implements IPaymentService {
1121 .businessId(businessId) 1123 .businessId(businessId)
1122 .userName(account.getCertName()) 1124 .userName(account.getCertName())
1123 .riskWatcher(Arrays.asList((uid, aar) -> shoppingRiskWatchDog.checkAlipayBlackUser(uid, aar))) 1125 .riskWatcher(Arrays.asList((uid, aar) -> shoppingRiskWatchDog.checkAlipayBlackUser(uid, aar)))
  1126 + .withTransferStatusQueryInterceptIf(isCheckTransferStatus)
1124 .transfer(); 1127 .transfer();
1125 // success to wait 1128 // success to wait
1126 if (transferResult.getCode() == 200) { 1129 if (transferResult.getCode() == 200) {
@@ -27,6 +27,7 @@ import com.yohoufo.order.service.pay.AbstractPayService; @@ -27,6 +27,7 @@ import com.yohoufo.order.service.pay.AbstractPayService;
27 import com.yohoufo.order.service.pay.alipay.bean.TtnStatusQueryResponse; 27 import com.yohoufo.order.service.pay.alipay.bean.TtnStatusQueryResponse;
28 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; 28 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
29 import com.yohoufo.order.service.transfer.TransferChannel; 29 import com.yohoufo.order.service.transfer.TransferChannel;
  30 +import com.yohoufo.order.service.transfer.TransferInterceptor;
30 import com.yohoufo.order.service.transfer.TransferResult; 31 import com.yohoufo.order.service.transfer.TransferResult;
31 import com.yohoufo.order.utils.AlipayExceedMillionTransferErrors; 32 import com.yohoufo.order.utils.AlipayExceedMillionTransferErrors;
32 import lombok.AccessLevel; 33 import lombok.AccessLevel;
@@ -234,6 +235,11 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -234,6 +235,11 @@ public abstract class AbstractAlipayService extends AbstractPayService {
234 } 235 }
235 236
236 @Override 237 @Override
  238 + public TransferChannel check() {
  239 + return this;
  240 + }
  241 +
  242 + @Override
237 public TransferResult transfer() { 243 public TransferResult transfer() {
238 AuthorizeResultRespVO aar = AuthorizeResultRespVO.builder().alipayId(alipayUid) 244 AuthorizeResultRespVO aar = AuthorizeResultRespVO.builder().alipayId(alipayUid)
239 .alipayAccount(alipayAccount).build(); 245 .alipayAccount(alipayAccount).build();
@@ -329,9 +335,12 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -329,9 +335,12 @@ public abstract class AbstractAlipayService extends AbstractPayService {
329 String businessId; 335 String businessId;
330 String userName; 336 String userName;
331 List<BiConsumer<Integer, AuthorizeResultRespVO>> riskWatcher; 337 List<BiConsumer<Integer, AuthorizeResultRespVO>> riskWatcher;
  338 + List<TransferInterceptor> transferInterceptors;
  339 + boolean transferSuccess;
332 340
333 private AlipayExceedMillionTransferChannel(int uid) { 341 private AlipayExceedMillionTransferChannel(int uid) {
334 this.uid = uid; 342 this.uid = uid;
  343 + this.transferInterceptors = new ArrayList<>();
335 } 344 }
336 345
337 public AlipayExceedMillionTransferChannel transferOrderCode(String transferOrderCode) { 346 public AlipayExceedMillionTransferChannel transferOrderCode(String transferOrderCode) {
@@ -369,8 +378,58 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -369,8 +378,58 @@ public abstract class AbstractAlipayService extends AbstractPayService {
369 return this; 378 return this;
370 } 379 }
371 380
  381 + public AlipayExceedMillionTransferChannel withTransferStatusQueryInterceptIf(boolean condition) {
  382 + return condition ? withTransferStatusQueryIntercept() : this;
  383 + }
  384 +
  385 + public AlipayExceedMillionTransferChannel withTransferStatusQueryIntercept() {
  386 +
  387 + transferInterceptors.add(new TransferInterceptor() {
  388 +
  389 + @Override
  390 + public void preIntercept(TransferChannel transferChannel) {
  391 + transferSuccess = transferTtnStatusQuery(transferOrderCode).isTransferSuccess(businessId, transferAmount);
  392 + }
  393 +
  394 + @Override
  395 + public void postIntercept(TransferChannel transferChannel, TransferResult result) {
  396 +
  397 + }
  398 +
  399 + @Override
  400 + public void onError(TransferChannel transferChannel, Throwable throwable) {
  401 +
  402 + }
  403 + });
  404 + return this;
  405 + }
  406 +
372 @Override 407 @Override
373 public TransferResult transfer() { 408 public TransferResult transfer() {
  409 + for (TransferInterceptor transferInterceptor : transferInterceptors) {
  410 + transferInterceptor.preIntercept(this);
  411 + }
  412 + try {
  413 + TransferResult result = doTransfer();
  414 + for (TransferInterceptor transferInterceptor : transferInterceptors) {
  415 + transferInterceptor.postIntercept(this, result);
  416 + }
  417 + return result;
  418 + } catch (Throwable e) {
  419 + for (TransferInterceptor transferInterceptor : transferInterceptors) {
  420 + transferInterceptor.onError(this, e);
  421 + }
  422 + throw e;
  423 + }
  424 + }
  425 +
  426 + private TransferResult doTransfer() {
  427 + if (this.transferSuccess) {
  428 + return TransferResult.builder()
  429 + .code(200)
  430 + .msg("ok")
  431 + .build();
  432 + }
374 AuthorizeResultRespVO aar = AuthorizeResultRespVO.builder().alipayId(alipayUid) 433 AuthorizeResultRespVO aar = AuthorizeResultRespVO.builder().alipayId(alipayUid)
375 .alipayAccount(alipayAccount).build(); 434 .alipayAccount(alipayAccount).build();
376 riskWatcher.stream().forEach(x -> x.accept(uid, aar)); 435 riskWatcher.stream().forEach(x -> x.accept(uid, aar));
  1 +package com.yohoufo.order.service.transfer;
  2 +
  3 +public interface TransferInterceptor {
  4 +
  5 + void preIntercept(TransferChannel transferChannel);
  6 +
  7 + void postIntercept(TransferChannel transferChannel, TransferResult result);
  8 +
  9 + void onError(TransferChannel transferChannel, Throwable throwable);
  10 +
  11 +}