...
|
...
|
@@ -17,6 +17,7 @@ import com.yohoufo.common.utils.TimeUtils; |
|
|
import com.yohoufo.dal.order.*;
|
|
|
import com.yohoufo.dal.order.model.*;
|
|
|
import com.yohoufo.order.common.Payment;
|
|
|
import com.yohoufo.order.common.TransferCase;
|
|
|
import com.yohoufo.order.constants.RefundContant;
|
|
|
import com.yohoufo.order.model.PayQueryBo;
|
|
|
import com.yohoufo.order.model.PayRefundBo;
|
...
|
...
|
@@ -29,6 +30,7 @@ import com.yohoufo.order.service.AbstractOrderPaymentService; |
|
|
import com.yohoufo.order.service.BuyerOrderPaymentService;
|
|
|
import com.yohoufo.order.service.IPaymentService;
|
|
|
import com.yohoufo.order.service.SellerOrderPaymentService;
|
|
|
import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler;
|
|
|
import com.yohoufo.order.service.pay.AbstractPayService;
|
|
|
import com.yohoufo.order.service.pay.alipay.AlipayOuyinService;
|
|
|
import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService;
|
...
|
...
|
@@ -52,7 +54,18 @@ import javax.annotation.PostConstruct; |
|
|
|
|
|
@Service
|
|
|
public class PaymentServiceImpl implements IPaymentService {
|
|
|
public enum TargetUserType {
|
|
|
buyer(1),seller(2);
|
|
|
int code;
|
|
|
|
|
|
TargetUserType(int code) {
|
|
|
this.code = code;
|
|
|
}
|
|
|
|
|
|
public int getCode() {
|
|
|
return code;
|
|
|
}
|
|
|
}
|
|
|
private static final Logger logger = LoggerUtils.getPayConfirmLogger();
|
|
|
|
|
|
|
...
|
...
|
@@ -104,19 +117,10 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
@Autowired
|
|
|
TradeBillsMapper tradeBillsMapper;
|
|
|
|
|
|
@Value("${order.buyer.cancelWhenSellerDelivery.money}")
|
|
|
private String buyerCancelDelivery;
|
|
|
@Value("${order.buyer.cancelWhenSellerUnDelivery.money}")
|
|
|
private String buyerCancelUnDelivery;
|
|
|
@Value("${order.buyer.cancelWhenSellerDelivery.sellerGetMoneyRate}")
|
|
|
private String sellerGetRateDelivery;
|
|
|
@Value("${order.buyer.cancelWhenSellerUnDelivery.sellerGetMoneyRate}")
|
|
|
private String sellerGetRateUnDelivery;
|
|
|
@Autowired
|
|
|
private BuyerCancelCompensateComputeHandler buyerCancelCompensateComputeHandler;
|
|
|
|
|
|
private BigDecimal buyerCancelDeliveryMoney;
|
|
|
private BigDecimal buyerCancelUnDeliveryMoney;
|
|
|
private BigDecimal sellerGetRateDeliveryMoney;
|
|
|
private BigDecimal sellerGetRateUnDeliveryMoney;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取主场的订单service
|
...
|
...
|
@@ -418,6 +422,7 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* <pre>
|
|
|
* 1:鉴定通过(货款-->卖家);
|
...
|
...
|
@@ -433,18 +438,17 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
@Database(ForceMaster = true)
|
|
|
public void transferMon(TransferMoneyRequest request){
|
|
|
logger.info("transferMon转账开始,request = {}", request);
|
|
|
|
|
|
long buyerOrderCode = request.getBuyerOrderCode();
|
|
|
int transferType = request.getType();
|
|
|
|
|
|
logger.info("transferMon参数检查");
|
|
|
// 订单号check
|
|
|
if (buyerOrderCode < 1) {
|
|
|
if (buyerOrderCode < 1L) {
|
|
|
logger.warn("transferMonErr orderCode empty");
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
// 类型检查
|
|
|
if (transferType < 1 || transferType > 5) {
|
|
|
int transferType = request.getType();
|
|
|
TransferCase transferCase = TransferCase.getTransferCase(transferType);
|
|
|
if (transferCase == null) {
|
|
|
logger.warn("transferMonErr transferType invalid");
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
...
|
...
|
@@ -470,8 +474,10 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
}
|
|
|
|
|
|
long sellerOrderCode = sellerOrder.getOrderCode();
|
|
|
Integer targetUserType = (transferType == 2 || transferType == 3) ? 1 : 2;
|
|
|
Integer targetUid = targetUserType == 1 ? buyerOrder.getUid() : sellerOrder.getUid();
|
|
|
TargetUserType targetUserType = (transferType == TransferCase.APPRAISE_FAIL.getCode()
|
|
|
|| transferType == TransferCase.SELLER_PLAY_BUYER.getCode()) ? TargetUserType.buyer : TargetUserType.seller;
|
|
|
//Integer targetUserType = (transferType == 2 || transferType == 3) ? 1 : 2;
|
|
|
Integer targetUid = targetUserType == TargetUserType.buyer ? buyerOrder.getUid() : sellerOrder.getUid();
|
|
|
|
|
|
if (targetUid == null || targetUid < 1) {
|
|
|
logger.warn("transferMonErr uid {} 不合法", targetUid);
|
...
|
...
|
@@ -508,7 +514,7 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
TradeBills record = new TradeBills();
|
|
|
record.setUid(targetUid);
|
|
|
record.setOrderCode(buyerOrderCode);
|
|
|
record.setUserType(targetUserType);
|
|
|
record.setUserType(targetUserType.getCode());
|
|
|
record.setPayType(1);
|
|
|
record.setTradeType(transferType == 1 ? 2 : 3);
|
|
|
record.setIncomeOutcome(1);
|
...
|
...
|
@@ -520,7 +526,7 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
|
|
|
logger.info("transferMon插入初始化转账信息成功,接下来计算费用");
|
|
|
// 算费
|
|
|
BigDecimal transferAmount = calcTransferAmount(sellerOrder.getUid(), sellerOrder.getSkup(), transferType);
|
|
|
BigDecimal transferAmount = calcTransferAmount(sellerOrder.getUid(), sellerOrder.getSkup(), transferCase);
|
|
|
logger.info("transferMon计算费用结果为 {}", transferAmount);
|
|
|
if (transferAmount == null) {
|
|
|
logger.warn("transferMonErr transferMon计算费用结果为 null, 不合法的金额");
|
...
|
...
|
@@ -917,14 +923,21 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
addTradeBills(record);
|
|
|
}
|
|
|
|
|
|
private BigDecimal getBuyerCancelBeforeSellerDeliver(){
|
|
|
//todo
|
|
|
return buyerCancelCompensateComputeHandler.calBeforeSellerDeliver();
|
|
|
}
|
|
|
private BigDecimal getBuyerCancelBeforeDepotReceive(){
|
|
|
//todo
|
|
|
return buyerCancelCompensateComputeHandler.calBeforeDepotReceive();
|
|
|
}
|
|
|
|
|
|
|
|
|
private BigDecimal calcTransferAmount(Integer sellerUid, Integer skup, int transferType) {
|
|
|
if (transferType == 4) {
|
|
|
return sellerGetRateUnDeliveryMoney;
|
|
|
private BigDecimal calcTransferAmount(Integer sellerUid, Integer skup, TransferCase transferCase) {
|
|
|
if (transferCase == TransferCase.BUYER_CANCEL_BEFORE_SELLER_DELIVER) {
|
|
|
return getBuyerCancelBeforeSellerDeliver();
|
|
|
}
|
|
|
if (transferType == 5) {
|
|
|
return sellerGetRateDeliveryMoney;
|
|
|
if (transferCase == TransferCase.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE) {
|
|
|
return getBuyerCancelBeforeDepotReceive();
|
|
|
}
|
|
|
|
|
|
SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
|
...
|
...
|
@@ -940,7 +953,7 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
try {
|
|
|
JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
|
|
|
// 交易成功的情况
|
|
|
if (transferType == 1) {
|
|
|
if (transferCase == TransferCase.APPRAISE_SUCCESS) {
|
|
|
return metavalue.getBigDecimal("income");
|
|
|
}
|
|
|
// (1-Y)*A
|
...
|
...
|
@@ -1048,33 +1061,6 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
CommonAlarmEventPublisher.publish(name, type, content);
|
|
|
}
|
|
|
|
|
|
@PostConstruct
|
|
|
private void init() {
|
|
|
try {
|
|
|
buyerCancelDeliveryMoney = new BigDecimal(buyerCancelUnDelivery);
|
|
|
buyerCancelUnDeliveryMoney = new BigDecimal(buyerCancelUnDelivery);
|
|
|
sellerGetRateDeliveryMoney = buyerCancelDeliveryMoney.multiply(new BigDecimal(sellerGetRateDelivery))
|
|
|
.setScale(2, BigDecimal.ROUND_HALF_DOWN);
|
|
|
sellerGetRateUnDeliveryMoney = buyerCancelUnDeliveryMoney.multiply(new BigDecimal(sellerGetRateUnDelivery))
|
|
|
.setScale(2, BigDecimal.ROUND_HALF_DOWN);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("买家取消罚款金额相关参数配置错误!", e);
|
|
|
throw new Error("买家取消罚款金额相关参数配置错误!");
|
|
|
}
|
|
|
if (buyerCancelDeliveryMoney.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
throw new Error("buyerCancelDeliveryMoney买家取消(货已寄出)罚款金额不能为负数");
|
|
|
}
|
|
|
if (buyerCancelUnDeliveryMoney.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
throw new Error("buyerCancelUnDeliveryMoney买家取消(货未寄出)罚款金额不能为负数");
|
|
|
}
|
|
|
if (sellerGetRateDeliveryMoney.compareTo(BigDecimal.ZERO) < 0
|
|
|
|| sellerGetRateDeliveryMoney.compareTo(BigDecimal.ONE) > 0) {
|
|
|
throw new Error("sellerGetRateDeliveryMoney买家取消(货已寄出)卖家获得赔偿比率必须在[0,1]");
|
|
|
}
|
|
|
if (sellerGetRateUnDeliveryMoney.compareTo(BigDecimal.ZERO) < 0
|
|
|
|| sellerGetRateUnDeliveryMoney.compareTo(BigDecimal.ONE) > 0) {
|
|
|
throw new Error("sellerGetRateUnDeliveryMoney买家取消(货未寄出)卖家获得赔偿比率必须在[0,1]");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|