...
|
...
|
@@ -28,10 +28,11 @@ import com.yohoufo.order.model.PayRefundBo; |
|
|
import com.yohoufo.order.model.PaymentData;
|
|
|
import com.yohoufo.order.model.TransferData;
|
|
|
import com.yohoufo.order.model.request.PaymentRequest;
|
|
|
import com.yohoufo.order.model.request.TranseferCellNode;
|
|
|
import com.yohoufo.order.model.request.TransferMoneyRequest;
|
|
|
import com.yohoufo.order.model.response.PaymentConfirmRsp;
|
|
|
import com.yohoufo.order.model.response.PrepayResponse;
|
|
|
import com.yohoufo.order.mq.TopicConstants;
|
|
|
import com.yohoufo.order.mq.producer.TradeMqSender;
|
|
|
import com.yohoufo.order.service.AbstractOrderPaymentService;
|
|
|
import com.yohoufo.order.service.BuyerOrderPaymentService;
|
|
|
import com.yohoufo.order.service.IPaymentService;
|
...
|
...
|
@@ -49,7 +50,6 @@ import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; |
|
|
import com.yohoufo.order.service.transfer.TransferResult;
|
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
|
|
import com.yohoufo.order.utils.PaymentHelper;
|
|
|
import lombok.val;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
...
|
...
|
@@ -57,6 +57,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Optional;
|
...
|
...
|
@@ -151,6 +152,9 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
@Autowired
|
|
|
private TradeBillsService tradeBillsService;
|
|
|
|
|
|
@Autowired
|
|
|
private TradeMqSender tradeMqSender;
|
|
|
|
|
|
/**
|
|
|
* 获取主场的订单service
|
|
|
* @param codeMeta
|
...
|
...
|
@@ -576,87 +580,38 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
*/
|
|
|
@Database(ForceMaster = true)
|
|
|
public void transferMon(TransferMoneyRequest request){
|
|
|
logger.info("transferMon转账开始,request = {}", request);
|
|
|
long buyerOrderCode = request.getBuyerOrderCode();
|
|
|
String logTag = String.format("transfer money orderCode is %s",buyerOrderCode);
|
|
|
logger.info("transferMon参数检查");
|
|
|
// 订单号check
|
|
|
if (buyerOrderCode < 1L) {
|
|
|
logger.warn("transferMonErr orderCode empty");
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
// 类型检查
|
|
|
TransferCase transferCase = TransferCase.getTransferCase(request.getType());
|
|
|
if (transferCase == null) {
|
|
|
logger.warn("transferMonErr transferType invalid");
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
TransferMoneyModel transferMoneyModel = new TransferMoneyModel(request).invoke();
|
|
|
String logTag = transferMoneyModel.getLogTag();
|
|
|
long buyerOrderCode = transferMoneyModel.getBuyerOrderCode();
|
|
|
TransferCase transferCase = transferMoneyModel.getTransferCase();
|
|
|
SellerOrder sellerOrder = transferMoneyModel.getSellerOrder();
|
|
|
long sellerOrderCode = transferMoneyModel.getSellerOrderCode();
|
|
|
Integer targetUid = transferMoneyModel.getTargetUid();
|
|
|
int now = transferMoneyModel.getNow();
|
|
|
|
|
|
// 买家订单检查
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(buyerOrderCode);
|
|
|
if (buyerOrder == null) {
|
|
|
logger.warn("transferMonErr getOrderInfo buyer order not exist, orderCode is {}", buyerOrderCode);
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
|
|
|
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), buyerOrderCode);
|
|
|
if (buyerOrderGoods == null) {
|
|
|
logger.warn("transferMonErr buyerOrderGoods not exist, orderCode is {}", buyerOrderCode);
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
|
|
|
// 卖家订单检查
|
|
|
Integer skup = buyerOrderGoods.getSkup();
|
|
|
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
|
|
if (sellerOrder == null){
|
|
|
logger.warn("transferMonErr getOrderInfo seller order not exist, skup is {}", buyerOrderGoods.getSkup());
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
Integer sellerUid = sellerOrder.getUid();
|
|
|
long sellerOrderCode = sellerOrder.getOrderCode();
|
|
|
penaltyEarnestIfWalletSellerOrder(request.getPenaltyEarnestFunction(), request.getSwdType(), sellerOrder);
|
|
|
val targetUserType = transferCase == EARNEST_MONEY_TO_BUYER ? TargetUserType.buyer : TargetUserType.seller;
|
|
|
val targetUid = targetUserType == TargetUserType.buyer ? buyerOrder.getUid() : sellerUid;
|
|
|
|
|
|
if (targetUid == null || targetUid < 1) {
|
|
|
logger.warn("transferMonErr uid {} 不合法", targetUid);
|
|
|
throw new ServiceException(400, "uid[" + targetUid + "]不合法");
|
|
|
}
|
|
|
int now = (int) (System.currentTimeMillis()/1000);
|
|
|
// 查看是否已经有转账记录
|
|
|
checkTransferExist(buyerOrderCode);
|
|
|
|
|
|
OrdersPayTransfer transfer = createTransfer(buyerOrderCode, sellerOrderCode, transferCase.getCode(), null, targetUid, BigDecimal.ZERO, now);
|
|
|
|
|
|
// 增加流水记录
|
|
|
TradeBills record = new TradeBills();
|
|
|
record.setUid(targetUid);
|
|
|
record.setOrderCode(buyerOrderCode);
|
|
|
record.setUserType(targetUserType.getCode());
|
|
|
record.setPayType(1);
|
|
|
// 如果[全部货款->卖家],否则[补偿款->卖家或买家] 2:货款;3:补偿款
|
|
|
record.setTradeType(transferCase == TransferCase.ALL_GOODS_MONEY_TO_SELLER ? 2 : 3);
|
|
|
record.setIncomeOutcome(1);
|
|
|
record.setTradeStatus(0);
|
|
|
record.setCreateTime(now);
|
|
|
TradeBills record = transferMoneyModel.newTradeBills();
|
|
|
|
|
|
logger.info("transferMon参数检查成功!插入初始化转账信息成功,接下来计算费用");
|
|
|
TranseferCellNode transeferCellNode = request.getTranseferCellNode();
|
|
|
// 算费
|
|
|
BigDecimal transferAmount = transeferCellNode.getAmount();
|
|
|
logger.info("transferMon计算费用结果为 {}", transferAmount);
|
|
|
if (transferAmount == null) {
|
|
|
logger.warn("transferMonErr transferMon计算费用结果为 null, 不合法的金额");
|
|
|
alarm("转账金额不合法", "ufo.order.transferMon", "订单号:" + buyerOrderCode + "操作类型(" + transferCase.getCode() + ")计算金额结果为null");
|
|
|
record.setTradeStatus(BillTradeStatus.AMOUNT_IS_ILLEGAL.getCode());
|
|
|
addTradeBills(record);
|
|
|
throw new ServiceException(400, "计算金额错误!:");
|
|
|
}
|
|
|
transfer.setAmount(transferAmount);
|
|
|
// 转账费
|
|
|
BigDecimal transferAmount = request.getTranseferCellNode().getAmount();
|
|
|
|
|
|
if (transferAmount == null) {
|
|
|
logger.warn("{}, transfer amount is null", logTag);
|
|
|
alarm("转账金额不合法", "ufo.order.transferMon", "订单号:" + buyerOrderCode + "操作类型(" + transferCase.getCode() + ")计算金额结果为空");
|
|
|
record.setTradeStatus(BillTradeStatus.AMOUNT_IS_ILLEGAL.getCode());
|
|
|
addTradeBills(record);
|
|
|
throw new ServiceException(400, "计算金额错误!:");
|
|
|
}
|
|
|
logger.info("{}, transfer amount is {}", logTag, transferAmount);
|
|
|
record.setAmount(transferAmount);
|
|
|
// 因为转账支付宝扣费累计计算,使用转账额
|
|
|
// ???因为转账支付宝扣费累计计算,使用转账额
|
|
|
record.setSystemAmount(transferAmount.multiply(new BigDecimal("-1")));
|
|
|
if (transferAmount.compareTo(new BigDecimal("0.1")) < 0) {
|
|
|
logger.warn("transferMonErr transferMon计算费用结果为 {}, 小于0.1", transferAmount);
|
|
|
logger.info("{}, transfer amount is {}, it less than 0.1", logTag, transferAmount);
|
|
|
alarm("转账金额小于0.1", "ufo.order.transferMon", "订单号:" + buyerOrderCode + "操作类型(" + transferCase.getCode() + ")计算金额结果为" + transferAmount);
|
|
|
record.setTradeStatus(BillTradeStatus.AMOUNT_IS_ILLEGAL.getCode());
|
|
|
addTradeBills(record);
|
...
|
...
|
@@ -665,29 +620,25 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
|
|
|
AuthorizeResultRespVO account = getOneValidAlipayAccountOr(targetUid, invalidAccount -> {
|
|
|
if ("invalid".equals(invalidAccount)) {
|
|
|
record.setTradeStatus(BillTradeStatus.YH_STORE_AMOUNT_WAIT_PAYMENT.getCode());
|
|
|
record.setTradeStatus(BillTradeStatus.YOHO_STORE_AMOUNT_WAIT_PAYMENT.getCode());
|
|
|
} else if ("invalid_hk".equals(invalidAccount)) {
|
|
|
record.setTradeStatus(BillTradeStatus.HK_AMOUNT_WAIT_PAYMENT.getCode());
|
|
|
tradeMqSender.send(TopicConstants.HK_AMOUNT_WAIT_PAYMENT, Collections.singletonMap("uid", record.getUid()));
|
|
|
} else {
|
|
|
record.setTradeStatus(BillTradeStatus.NOT_EXIST_ALI_ACCOUNT.getCode());
|
|
|
record.setTradeStatus(BillTradeStatus.NOT_EXIST_ALIPAY_ACCOUNT.getCode());
|
|
|
}
|
|
|
addTradeBills(record);
|
|
|
throw new ServiceException(400, "uid[" + targetUid + "]没有获取到有效的支付宝账号");
|
|
|
});
|
|
|
|
|
|
if(account == null){
|
|
|
throw new ServiceException(400, "uid[" + targetUid + "]没有获取到有效的支付宝账号");
|
|
|
}
|
|
|
tradeBillsMapper.insert(record);
|
|
|
|
|
|
if(StringUtils.isNotBlank(account.getAlipayId())) {
|
|
|
transfer.setAlipayAccount(account.getAlipayId());
|
|
|
} else if(StringUtils.isNotBlank(account.getAlipayAccount())) {
|
|
|
transfer.setAlipayAccount(account.getAlipayAccount());
|
|
|
}
|
|
|
String alipayAccount = StringUtils.isNotBlank(account.getAlipayId()) ? account.getAlipayId() : account.getAlipayAccount();
|
|
|
transfer.setAlipayAccount(alipayAccount);
|
|
|
transfer.setUpdateTime(now);
|
|
|
transfer.setAmount(transferAmount);
|
|
|
|
|
|
transfer.setUpdateTime(now);
|
|
|
tradeBillsMapper.insert(record);
|
|
|
|
|
|
String alipayAccount = transfer.getAlipayAccount();
|
|
|
// 转账
|
|
|
try {
|
|
|
logger.info("{}, transfer alipayAccount={}, transferAmount={}", logTag, alipayAccount, transferAmount);
|
...
|
...
|
@@ -719,7 +670,7 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
@Database(ForceMaster = true)
|
|
|
@Database(ForceMaster = true)
|
|
|
public boolean transAllEarnest(long orderCode, Integer uid, BigDecimal amount, AuthorizeResultRespVO aliPayAccount){
|
|
|
logger.info("退还商家所有保证金,转账开始,orderCode = {}, uid={}, amount={}, alipayAccount={}", orderCode, uid, amount, aliPayAccount);
|
|
|
|
...
|
...
|
@@ -758,7 +709,7 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
|
|
|
if (StringUtils.isBlank(aliPayAccount.getAlipayAccount()) && StringUtils.isBlank(aliPayAccount.getAlipayId()) ) {
|
|
|
logger.warn("transAllEarnestErr uid {} 支付宝账号不合法", account);
|
|
|
record.setTradeStatus(BillTradeStatus.NOT_EXIST_ALI_ACCOUNT.getCode());
|
|
|
record.setTradeStatus(BillTradeStatus.NOT_EXIST_ALIPAY_ACCOUNT.getCode());
|
|
|
addTradeBills(record);
|
|
|
throw new ServiceException(400, "uid[" + uid + "]支付宝账号不合法");
|
|
|
}
|
...
|
...
|
@@ -1455,5 +1406,120 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
}
|
|
|
|
|
|
|
|
|
private class TransferMoneyModel {
|
|
|
private TransferMoneyRequest request;
|
|
|
private long buyerOrderCode;
|
|
|
private String logTag;
|
|
|
private TransferCase transferCase;
|
|
|
private SellerOrder sellerOrder;
|
|
|
private long sellerOrderCode;
|
|
|
private TargetUserType targetUserType;
|
|
|
private Integer targetUid;
|
|
|
private int now;
|
|
|
|
|
|
public TransferMoneyModel(TransferMoneyRequest request) {
|
|
|
this.request = request;
|
|
|
}
|
|
|
|
|
|
public long getBuyerOrderCode() {
|
|
|
return buyerOrderCode;
|
|
|
}
|
|
|
|
|
|
public String getLogTag() {
|
|
|
return logTag;
|
|
|
}
|
|
|
|
|
|
public TransferCase getTransferCase() {
|
|
|
return transferCase;
|
|
|
}
|
|
|
|
|
|
public SellerOrder getSellerOrder() {
|
|
|
return sellerOrder;
|
|
|
}
|
|
|
|
|
|
public long getSellerOrderCode() {
|
|
|
return sellerOrderCode;
|
|
|
}
|
|
|
|
|
|
public TargetUserType getTargetUserType() {
|
|
|
return targetUserType;
|
|
|
}
|
|
|
|
|
|
public Integer getTargetUid() {
|
|
|
return targetUid;
|
|
|
}
|
|
|
|
|
|
public int getNow() {
|
|
|
return now;
|
|
|
}
|
|
|
|
|
|
public TransferMoneyModel invoke() {
|
|
|
logger.info("transferMon转账开始,request = {}", request);
|
|
|
buyerOrderCode = request.getBuyerOrderCode();
|
|
|
logTag = String.format("transfer money orderCode is %s", buyerOrderCode);
|
|
|
logger.info("transferMon参数检查");
|
|
|
// 订单号check
|
|
|
if (buyerOrderCode < 1L) {
|
|
|
logger.warn("transferMonErr orderCode empty");
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
// 类型检查
|
|
|
transferCase = TransferCase.getTransferCase(request.getType());
|
|
|
if (transferCase == null) {
|
|
|
logger.warn("transferMonErr transferType invalid");
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
|
|
|
// 买家订单检查
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(buyerOrderCode);
|
|
|
if (buyerOrder == null) {
|
|
|
logger.warn("transferMonErr getOrderInfo buyer order not exist, orderCode is {}", buyerOrderCode);
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
|
|
|
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), buyerOrderCode);
|
|
|
if (buyerOrderGoods == null) {
|
|
|
logger.warn("transferMonErr buyerOrderGoods not exist, orderCode is {}", buyerOrderCode);
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
|
|
|
// 卖家订单检查
|
|
|
Integer skup = buyerOrderGoods.getSkup();
|
|
|
sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
|
|
if (sellerOrder == null){
|
|
|
logger.warn("transferMonErr getOrderInfo seller order not exist, skup is {}", buyerOrderGoods.getSkup());
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
Integer sellerUid = sellerOrder.getUid();
|
|
|
sellerOrderCode = sellerOrder.getOrderCode();
|
|
|
|
|
|
targetUserType = transferCase == EARNEST_MONEY_TO_BUYER ? TargetUserType.buyer : TargetUserType.seller;
|
|
|
targetUid = targetUserType == TargetUserType.buyer ? buyerOrder.getUid() : sellerUid;
|
|
|
|
|
|
if (targetUid == null || targetUid < 1) {
|
|
|
logger.warn("transferMonErr uid {} 不合法", targetUid);
|
|
|
throw new ServiceException(400, "uid[" + targetUid + "]不合法");
|
|
|
}
|
|
|
now = (int) (System.currentTimeMillis() / 1000);
|
|
|
// 查看是否已经有转账记录
|
|
|
checkTransferExist(buyerOrderCode);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
|
|
|
public TradeBills newTradeBills(){
|
|
|
// 增加流水记录
|
|
|
TradeBills record = new TradeBills();
|
|
|
record.setUid(targetUid);
|
|
|
record.setOrderCode(buyerOrderCode);
|
|
|
record.setUserType(targetUserType.getCode());
|
|
|
record.setPayType(1);
|
|
|
// 如果[全部货款->卖家],否则[补偿款->卖家或买家] 2:货款;3:补偿款
|
|
|
record.setTradeType(transferCase == TransferCase.ALL_GOODS_MONEY_TO_SELLER ? 2 : 3);
|
|
|
record.setIncomeOutcome(1);
|
|
|
record.setTradeStatus(BillTradeStatus.NEW.getCode());
|
|
|
record.setCreateTime(now);
|
|
|
return record;
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|