|
|
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();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |
...
|
...
|
|