Authored by LUOXC

添加转账接口

... ... @@ -612,7 +612,7 @@ public class PaymentServiceImpl implements IPaymentService {
if (alipayTransferChancelSelector.isTransferWithWallet()) {
transfer.setInterfaceType(INTERFACE_TYPE_TRANSFER_WALLET);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
TransferResult transferResult = walletTransferService.transfer(logTag, transfer.getUid(), orderCode, record.getTradeType(), amount);
TransferResult transferResult = walletTransferService.transfer(logTag, record);
if (transferResult.getCode() == 200) {
transfer.setStatus(1);
return true;
... ... @@ -973,12 +973,12 @@ public class PaymentServiceImpl implements IPaymentService {
}
private void transferWithWalletAndAddSuccessTradeBills(String logTag, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account, BigDecimal amount, OrdersPayTransfer transfer) {
TransferResult transferResult = walletTransferService.transfer(logTag,account.getUid(),orderCode,tradeBills.getTradeType(),amount);
TransferResult transferResult = walletTransferService.transfer(logTag,tradeBills);
parseTransferResultAndAddSuccessTradeBills(logTag, tradeBills, orderCode, transfer, transferResult);
}
private void transferWithWallet(String logTag, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account, BigDecimal amount, OrdersPayTransfer transfer) {
TransferResult transferResult = walletTransferService.transfer(logTag,account.getUid(),orderCode,tradeBills.getTradeType(),amount);
TransferResult transferResult = walletTransferService.transfer(logTag,tradeBills);
parseTransferResultAndUpdateTradeBillToSuccess(logTag, tradeBills, orderCode, transfer, transferResult);
}
... ...
package com.yohoufo.order.service.proxy;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.dal.order.model.OrdersPayTransfer;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.dal.order.model.TradeBills;
import com.yohoufo.order.service.transfer.TransferResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
... ... @@ -12,20 +14,72 @@ import java.math.BigDecimal;
@Slf4j
@Service
public class DefaultWalletTransferService implements WalletTransferService {
@Autowired
private ServiceCaller serviceCaller;
@Override
public TransferResult transfer(String logTag,
Integer uid,
Long orderCode,
Integer tradeType,
BigDecimal transferAmount) {
//TODO
log.info("{}, transfer success uid is {} orderCode is {} tradeType is {} transferAmount is {}",
logTag, uid, orderCode, tradeType, transferAmount);
return TransferResult.builder()
.code(505)
.transferOrderCode(orderCode.toString())
.msg("转账到钱包接口未实现")
.build();
public TransferResult transfer(String logTag, TradeBills tradeBills) {
return transfer(logTag,
tradeBills.getUid(),
tradeBills.getOrderCode(),
tradeBills.getUserType(),
tradeBills.getTradeType(),
tradeBills.getAmount());
}
private TransferResult transfer(String logTag,
Integer uid,
Long orderCode,
int useType,
int tradeType,
BigDecimal transferAmount) {
// 0:未知、1:订单货款、2:买家补偿金、3:卖家补偿金、4:保证金
Integer trgTradeType;
if (tradeType == 1) {
trgTradeType = 4;
} else if (tradeType == 2) {
trgTradeType = 1;
} else if (tradeType == 3) {
trgTradeType = useType == 1 ? 2 : useType == 2 ? 3 : 0;
} else {
trgTradeType = 0;
}
JSONObject request = new JSONObject();
request.fluentPut("uid", uid)
.fluentPut("amount", transferAmount)
.fluentPut("orderCode", orderCode)
.fluentPut("tradeType", trgTradeType)
// source 1:UFO
.fluentPut("source", 1);
try {
JSONObject result = serviceCaller.asyncCall("wallet.addWalletBalance", request, JSONObject.class).get(1);
log.info("{}, transfer success uid is {} orderCode is {} tradeType is {} transferAmount is {}",
logTag, uid, orderCode, tradeType, transferAmount);
return TransferResult.builder()
.transferOrderCode(orderCode.toString())
.code(result.getIntValue("code"))
.msg(result.getString("message"))
.build();
} catch (ServiceException e) {
log.info("{}, transfer fail uid is {} orderCode is {} tradeType is {} transferAmount is {}",
logTag, uid, orderCode, tradeType, transferAmount);
return TransferResult.builder()
.transferOrderCode(orderCode.toString())
.code(e.getCode())
.msg(e.getErrorMessage())
.build();
} catch (Exception e) {
log.info("{}, transfer fail uid is {} orderCode is {} tradeType is {} transferAmount is {}",
logTag, uid, orderCode, tradeType, transferAmount);
return TransferResult.builder()
.transferOrderCode(orderCode.toString())
.code(599)
.msg(e.getMessage())
.build();
}
}
}
... ...
package com.yohoufo.order.service.proxy;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.dal.order.model.OrdersPayTransfer;
import com.yohoufo.dal.order.model.TradeBills;
import com.yohoufo.order.service.transfer.TransferResult;
import java.math.BigDecimal;
public interface WalletTransferService {
TransferResult transfer(String logTag,
Integer uid,
Long orderCode,
Integer tradeType,
BigDecimal amount);
TransferResult transfer(String logTag, TradeBills tradeBills);
}
... ...