...
|
...
|
@@ -11,8 +11,6 @@ import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class DefaultWalletTransferService implements WalletTransferService {
|
...
|
...
|
@@ -22,68 +20,62 @@ public class DefaultWalletTransferService implements WalletTransferService { |
|
|
|
|
|
|
|
|
@Override
|
|
|
public TransferResult transfer(String logTag, TradeBills tradeBills) {
|
|
|
return transfer(logTag,
|
|
|
tradeBills.getUid(),
|
|
|
tradeBills.getOrderCode(),
|
|
|
tradeBills.getUserType(),
|
|
|
TradeType.getTradeTypeByCode(tradeBills.getTradeType()),
|
|
|
tradeBills.getAmount());
|
|
|
public boolean canTransfer(TradeBills tradeBills) {
|
|
|
return transformTradeType(tradeBills) > 0;
|
|
|
}
|
|
|
|
|
|
private TransferResult transfer(String logTag,
|
|
|
Integer uid,
|
|
|
Long orderCode,
|
|
|
int useType,
|
|
|
TradeType tradeType,
|
|
|
BigDecimal transferAmount) {
|
|
|
@Override
|
|
|
public TransferResult transfer(String logTag, TradeBills tradeBills) {
|
|
|
|
|
|
// 0:未知、1:订单货款、2:买家补偿金、3:卖家补偿金、4:保证金
|
|
|
Integer trgTradeType;
|
|
|
if (tradeType == TradeType.guarantee_cash) {
|
|
|
trgTradeType = 4;
|
|
|
} else if (tradeType == TradeType.goods_income) {
|
|
|
trgTradeType = 1;
|
|
|
} else if (tradeType == TradeType.compensateIncome) {
|
|
|
trgTradeType = useType == PaymentServiceImpl.TargetUserType.buyer.getCode() ? 2
|
|
|
: useType == PaymentServiceImpl.TargetUserType.seller.getCode() ? 3
|
|
|
: 0;
|
|
|
} else {
|
|
|
trgTradeType = 0;
|
|
|
}
|
|
|
JSONObject request = new JSONObject();
|
|
|
request.fluentPut("uid", uid)
|
|
|
.fluentPut("amount", transferAmount)
|
|
|
.fluentPut("orderCode", orderCode)
|
|
|
.fluentPut("tradeType", trgTradeType)
|
|
|
request.fluentPut("uid", tradeBills.getUid())
|
|
|
.fluentPut("amount", tradeBills.getAmount())
|
|
|
.fluentPut("orderCode", tradeBills.getOrderCode())
|
|
|
.fluentPut("tradeType", transformTradeType(tradeBills))
|
|
|
// 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);
|
|
|
log.info("{}, transfer success", logTag);
|
|
|
return TransferResult.builder()
|
|
|
.transferOrderCode(orderCode.toString())
|
|
|
.transferOrderCode(tradeBills.getOrderCode().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);
|
|
|
log.info("{}, transfer fail", logTag);
|
|
|
return TransferResult.builder()
|
|
|
.transferOrderCode(orderCode.toString())
|
|
|
.transferOrderCode(tradeBills.getOrderCode().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);
|
|
|
log.info("{}, transfer fail", logTag, e);
|
|
|
return TransferResult.builder()
|
|
|
.transferOrderCode(orderCode.toString())
|
|
|
.transferOrderCode(tradeBills.getOrderCode().toString())
|
|
|
.code(599)
|
|
|
.msg(e.getMessage())
|
|
|
.build();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param tradeBills
|
|
|
* @return 0:无效、1:订单货款、2:买家补偿金、3:卖家补偿金、4:保证金
|
|
|
*/
|
|
|
private int transformTradeType(TradeBills tradeBills) {
|
|
|
int useType = tradeBills.getUserType();
|
|
|
TradeType tradeType = TradeType.getTradeTypeByCode(tradeBills.getTradeType());
|
|
|
if (tradeType == TradeType.guarantee_cash) {
|
|
|
return 4;
|
|
|
} else if (tradeType == TradeType.goods_income) {
|
|
|
return 1;
|
|
|
} else if (tradeType == TradeType.compensateIncome) {
|
|
|
return useType == PaymentServiceImpl.TargetUserType.buyer.getCode() ? 2
|
|
|
: useType == PaymentServiceImpl.TargetUserType.seller.getCode() ? 3
|
|
|
: 0;
|
|
|
} else {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|