mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-23 20:45:10 +08:00
订单分账逻辑
This commit is contained in:
@@ -9,6 +9,7 @@ import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
|
||||
import com.jsowell.adapay.operation.PaymentConfirmOperation;
|
||||
import com.jsowell.adapay.response.PaymentConfirmResponse;
|
||||
import com.jsowell.adapay.response.PaymentReverseResponse;
|
||||
import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
|
||||
@@ -761,17 +762,11 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
*/
|
||||
OrderSettleResult orderSettleResult = null;
|
||||
if (StringUtils.equals(delayMode, Constants.ADAPAY_PAY_MODE_DELAY)) {
|
||||
// 延时分账的处理逻辑
|
||||
if (OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue().equals(orderBasicInfo.getPayMode())) {
|
||||
// 余额支付的订单
|
||||
orderSettleResult = doBalancePaymentWithDelay(orderBasicInfo, adapayMemberAccount, appId);
|
||||
} else {
|
||||
// 在线支付,进行支付确认分账
|
||||
orderSettleResult = doPaymentConfirmWithDelay(orderBasicInfo, adapayMemberAccount, appId);
|
||||
}
|
||||
// 延迟商家订单处理逻辑
|
||||
orderSettleResult = delayMerchantOrderProcessingLogic(orderBasicInfo, adapayMemberAccount, appId);
|
||||
} else {
|
||||
// 不使用延时分账的汇付商户,钱已经到基本账户中了,只需要退款就可以
|
||||
orderSettleResult = notDelayOrder(orderBasicInfo, adapayMemberAccount, appId);
|
||||
// 不延迟商家订单处理逻辑 不使用延时分账的汇付商户,钱已经到基本账户中了,只需要退款就可以
|
||||
orderSettleResult = notDelayMerchantOrderProcessingLogic(orderBasicInfo, adapayMemberAccount, appId);
|
||||
}
|
||||
|
||||
// 退款逻辑/需要退款的情况
|
||||
@@ -789,16 +784,41 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param orderBasicInfo
|
||||
* @param adapayMemberAccount
|
||||
* @param wechatAppId
|
||||
* 不延迟商家订单处理逻辑
|
||||
* 例如:希晓
|
||||
*
|
||||
* @param orderBasicInfo 订单信息
|
||||
* @param adapayMemberAccount 汇付用户信息
|
||||
* @param wechatAppId 小程序appId
|
||||
* @return
|
||||
*/
|
||||
private OrderSettleResult notDelayOrder(OrderBasicInfo orderBasicInfo, AdapayMemberAccount adapayMemberAccount, String wechatAppId) {
|
||||
private OrderSettleResult notDelayMerchantOrderProcessingLogic(OrderBasicInfo orderBasicInfo, AdapayMemberAccount adapayMemberAccount, String wechatAppId) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 延迟商家订单处理逻辑
|
||||
* 例如:举视以及下面的二级运营商
|
||||
*
|
||||
* @param orderBasicInfo 订单信息
|
||||
* @param adapayMemberAccount 汇付用户信息
|
||||
* @param wechatAppId 小程序appId
|
||||
* @return
|
||||
*/
|
||||
private OrderSettleResult delayMerchantOrderProcessingLogic(OrderBasicInfo orderBasicInfo, AdapayMemberAccount adapayMemberAccount, String wechatAppId) {
|
||||
OrderSettleResult orderSettleResult;
|
||||
// 延时分账的处理逻辑
|
||||
if (OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue().equals(orderBasicInfo.getPayMode())) {
|
||||
// 余额支付的订单
|
||||
orderSettleResult = doBalancePaymentWithDelay(orderBasicInfo, adapayMemberAccount, wechatAppId);
|
||||
} else {
|
||||
// 在线支付,进行支付确认分账
|
||||
orderSettleResult = doPaymentConfirmWithDelay(orderBasicInfo, adapayMemberAccount, wechatAppId);
|
||||
}
|
||||
return orderSettleResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回更新后的OrderBasicInfo对象
|
||||
* 专用方法,其他地方如果要用请仔细检查
|
||||
@@ -1255,12 +1275,14 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
*/
|
||||
@Override
|
||||
public OrderSettleResult doBalancePaymentWithDelay(OrderBasicInfo orderBasicInfo, AdapayMemberAccount adapayMemberAccount, String wechatAppId) {
|
||||
// 订单结算金额
|
||||
BigDecimal settleAmount = orderBasicInfo.getSettleAmount();
|
||||
// 订单编号
|
||||
String orderCode = orderBasicInfo.getOrderCode();
|
||||
|
||||
BigDecimal confirmAmt = BigDecimal.ZERO;
|
||||
BigDecimal feeAmt = BigDecimal.ZERO;
|
||||
String status = null;
|
||||
BigDecimal confirmAmt = BigDecimal.ZERO; // 消费金额
|
||||
BigDecimal feeAmt = BigDecimal.ZERO; // 手续费金额
|
||||
String status = null; // 状态
|
||||
|
||||
// 获取余额支付扣除金额 也许存在一笔不够扣,需要扣多笔的情况
|
||||
List<BalanceDeductionAmountVO> list = calculateTheBalanceDeductionAmount(orderBasicInfo.getMemberId(), settleAmount);
|
||||
@@ -1269,9 +1291,17 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
BigDecimal deductionAmount = vo.getDeductionAmount();
|
||||
|
||||
// 延时分账,使用确认交易API
|
||||
PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequest(paymentId, adapayMemberAccount, deductionAmount, orderCode, wechatAppId);
|
||||
PaymentConfirmOperation operation = new PaymentConfirmOperation();
|
||||
operation.setPaymentId(paymentId);
|
||||
operation.setConfirmAmt(deductionAmount);
|
||||
operation.setOrderCode(orderCode);
|
||||
operation.setAdapayMemberId(adapayMemberAccount.getAdapayMemberId());
|
||||
operation.setMerchantKey(wechatAppId);
|
||||
PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequest(operation);
|
||||
|
||||
// PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequest(paymentId, adapayMemberAccount, deductionAmount, orderCode, wechatAppId);
|
||||
if (paymentConfirmResponse != null && paymentConfirmResponse.isNotFailed()) {
|
||||
confirmAmt = confirmAmt.add(new BigDecimal(paymentConfirmResponse.getConfirmed_amt()));
|
||||
confirmAmt = confirmAmt.add(new BigDecimal(paymentConfirmResponse.getConfirm_amt()));
|
||||
feeAmt = feeAmt.add(new BigDecimal(paymentConfirmResponse.getFee_amt()));
|
||||
status = paymentConfirmResponse.getStatus();
|
||||
memberAdapayRecordService.updateSpendAmount(paymentId, deductionAmount);
|
||||
@@ -1347,27 +1377,36 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
* @param adapayMemberAccount 结算账户
|
||||
*/
|
||||
public OrderSettleResult doPaymentConfirmWithDelay(OrderBasicInfo orderBasicInfo, AdapayMemberAccount adapayMemberAccount, String wechatAppId) {
|
||||
// 查询订单的交易id
|
||||
String orderCode = orderBasicInfo.getOrderCode();
|
||||
// 查询该笔订单的支付交易回调
|
||||
AdapayCallbackRecord adapayCallbackRecord = adapayCallbackRecordService.selectByOrderCode(orderCode);
|
||||
if (adapayCallbackRecord == null) {
|
||||
logger.error("根据订单号:{}, 未查询到汇付支付回调信息", orderCode);
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CALLBACK_IS_NULL_ERROR);
|
||||
}
|
||||
// 支付id
|
||||
String paymentId = adapayCallbackRecord.getPaymentId();
|
||||
|
||||
// 金额
|
||||
// 订单结算金额
|
||||
BigDecimal settleAmount = orderBasicInfo.getSettleAmount();
|
||||
|
||||
// 调汇付的分账接口 确认交易
|
||||
PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequest(paymentId, adapayMemberAccount, settleAmount, orderCode, wechatAppId);
|
||||
// PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequest(paymentId, adapayMemberAccount, settleAmount, orderCode, wechatAppId);
|
||||
|
||||
PaymentConfirmOperation operation = new PaymentConfirmOperation();
|
||||
operation.setPaymentId(paymentId);
|
||||
operation.setConfirmAmt(settleAmount);
|
||||
operation.setOrderCode(orderCode);
|
||||
operation.setAdapayMemberId(adapayMemberAccount.getAdapayMemberId());
|
||||
operation.setMerchantKey(wechatAppId);
|
||||
PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequest(operation);
|
||||
|
||||
|
||||
// 分账接口返回的信息
|
||||
OrderSettleResult result = new OrderSettleResult();
|
||||
result.setConfirmAmt(paymentConfirmResponse.getConfirm_amt());
|
||||
result.setStatus(paymentConfirmResponse.getStatus());
|
||||
result.setFeeAmt(paymentConfirmResponse.getFee_amt());
|
||||
// result.setDescription(paymentConfirmResponse.getDescription());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user