mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-09-06 04:27:55 +00:00
feat 分账同步信息保存
This commit is contained in:
@@ -8,9 +8,11 @@ import cn.daxpay.single.service.code.AliPayCode;
|
||||
import cn.daxpay.single.service.common.local.PaymentContextLocal;
|
||||
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrder;
|
||||
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrderDetail;
|
||||
import cn.daxpay.single.service.core.payment.sync.result.AllocSyncResult;
|
||||
import cn.daxpay.single.util.PayUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alipay.api.AlipayResponse;
|
||||
import com.alipay.api.domain.*;
|
||||
import com.alipay.api.request.AlipayTradeOrderSettleQueryRequest;
|
||||
@@ -104,7 +106,7 @@ public class AliPayAllocationService {
|
||||
* 分账状态同步
|
||||
*/
|
||||
@SneakyThrows
|
||||
public void sync(AllocationOrder allocationOrder, List<AllocationOrderDetail> allocationOrderDetails){
|
||||
public AllocSyncResult sync(AllocationOrder allocationOrder, List<AllocationOrderDetail> allocationOrderDetails){
|
||||
AlipayTradeOrderSettleQueryModel model = new AlipayTradeOrderSettleQueryModel();
|
||||
model.setTradeNo(allocationOrder.getOutOrderNo());
|
||||
model.setOutRequestNo(allocationOrder.getOrderNo());
|
||||
@@ -132,6 +134,7 @@ public class AliPayAllocationService {
|
||||
}
|
||||
}
|
||||
}
|
||||
return new AllocSyncResult().setSyncInfo(JSONUtil.toJsonStr(response));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -9,6 +9,7 @@ import cn.daxpay.single.service.code.WeChatPayCode;
|
||||
import cn.daxpay.single.service.core.channel.wechat.entity.WeChatPayConfig;
|
||||
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrder;
|
||||
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrderDetail;
|
||||
import cn.daxpay.single.service.core.payment.sync.result.AllocSyncResult;
|
||||
import cn.daxpay.single.service.dto.channel.wechat.WeChatPayAllocationReceiver;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
@@ -108,7 +109,7 @@ public class WeChatPayAllocationService {
|
||||
/**
|
||||
* 同步分账状态
|
||||
*/
|
||||
public void sync(AllocationOrder allocationOrder, List<AllocationOrderDetail> allocationOrderDetails, WeChatPayConfig config){
|
||||
public AllocSyncResult sync(AllocationOrder allocationOrder, List<AllocationOrderDetail> allocationOrderDetails, WeChatPayConfig config){
|
||||
// 不要传输AppId参数, 否则会失败
|
||||
Map<String, String> params = ProfitSharingModel.builder()
|
||||
.mch_id(config.getWxMchId())
|
||||
@@ -137,6 +138,7 @@ public class WeChatPayAllocationService {
|
||||
}
|
||||
}
|
||||
}
|
||||
return new AllocSyncResult().setSyncInfo(JSONUtil.toJsonStr(receivers));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -133,10 +133,10 @@ public class AllocationService {
|
||||
// TODO 返回异常处理
|
||||
}
|
||||
// 网关分账号
|
||||
String gatewayNo = PaymentContextLocal.get()
|
||||
String outAllocationNo = PaymentContextLocal.get()
|
||||
.getAllocationInfo()
|
||||
.getOutAllocationNo();
|
||||
order.setOutAllocationNo(gatewayNo);
|
||||
order.setOutAllocationNo(outAllocationNo);
|
||||
allocationOrderManager.updateById(order);
|
||||
return new AllocationResult()
|
||||
.setAllocationNo(order.getAllocationNo())
|
||||
|
@@ -7,12 +7,17 @@ import cn.daxpay.single.code.AllocOrderResultEnum;
|
||||
import cn.daxpay.single.code.AllocOrderStatusEnum;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocSyncParam;
|
||||
import cn.daxpay.single.result.allocation.AllocationSyncResult;
|
||||
import cn.daxpay.single.service.code.PaymentTypeEnum;
|
||||
import cn.daxpay.single.service.common.local.PaymentContextLocal;
|
||||
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderDetailManager;
|
||||
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderManager;
|
||||
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrder;
|
||||
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrderDetail;
|
||||
import cn.daxpay.single.service.core.payment.allocation.factory.AllocationFactory;
|
||||
import cn.daxpay.single.service.core.payment.notice.service.ClientNoticeService;
|
||||
import cn.daxpay.single.service.core.payment.sync.result.AllocSyncResult;
|
||||
import cn.daxpay.single.service.core.record.sync.entity.PaySyncRecord;
|
||||
import cn.daxpay.single.service.core.record.sync.service.PaySyncRecordService;
|
||||
import cn.daxpay.single.service.func.AbsAllocationStrategy;
|
||||
import com.baomidou.lock.LockInfo;
|
||||
import com.baomidou.lock.LockTemplate;
|
||||
@@ -37,11 +42,14 @@ import java.util.Objects;
|
||||
public class AllocationSyncService {
|
||||
|
||||
private final ClientNoticeService clientNoticeService;
|
||||
|
||||
private final AllocationOrderManager allocationOrderManager;
|
||||
|
||||
private final LockTemplate lockTemplate;
|
||||
private final AllocationOrderDetailManager allocationOrderDetailManager;
|
||||
|
||||
private final PaySyncRecordService paySyncRecordService;
|
||||
|
||||
private final LockTemplate lockTemplate;
|
||||
|
||||
/**
|
||||
* 分账同步, 开启一个新的事务, 不受外部抛出异常的影响
|
||||
@@ -77,9 +85,9 @@ public class AllocationSyncService {
|
||||
allocationStrategy.initParam(allocationOrder, detailList);
|
||||
// 分账完结预处理
|
||||
allocationStrategy.doBeforeHandler();
|
||||
allocationStrategy.doSync();
|
||||
// TODO 保存分账同步记录
|
||||
|
||||
AllocSyncResult allocSyncResult = allocationStrategy.doSync();
|
||||
// 保存分账同步记录
|
||||
this.saveRecord(allocationOrder, allocSyncResult,null,null);
|
||||
// 根据订单明细更新订单的状态和处理结果
|
||||
this.updateOrderStatus(allocationOrder, detailList);
|
||||
} finally {
|
||||
@@ -138,4 +146,21 @@ public class AllocationSyncService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存同步记录
|
||||
*/
|
||||
private void saveRecord(AllocationOrder order, AllocSyncResult syncResult, String errorCode, String errorMsg){
|
||||
PaySyncRecord paySyncRecord = new PaySyncRecord()
|
||||
.setBizTradeNo(order.getBizAllocationNo())
|
||||
.setTradeNo(order.getAllocationNo())
|
||||
.setOutTradeNo(order.getOutAllocationNo())
|
||||
.setSyncType(PaymentTypeEnum.ALLOCATION.getCode())
|
||||
.setChannel(order.getChannel())
|
||||
.setSyncInfo(syncResult.getSyncInfo())
|
||||
.setErrorCode(errorCode)
|
||||
.setErrorMsg(errorMsg)
|
||||
.setClientIp(PaymentContextLocal.get().getRequestInfo().getClientIp());
|
||||
paySyncRecordService.saveRecord(paySyncRecord);
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import cn.daxpay.single.exception.pay.PayFailureException;
|
||||
import cn.daxpay.single.service.core.channel.alipay.entity.AliPayConfig;
|
||||
import cn.daxpay.single.service.core.channel.alipay.service.AliPayAllocationService;
|
||||
import cn.daxpay.single.service.core.channel.alipay.service.AliPayConfigService;
|
||||
import cn.daxpay.single.service.core.payment.sync.result.AllocSyncResult;
|
||||
import cn.daxpay.single.service.func.AbsAllocationStrategy;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -74,8 +75,8 @@ public class AliPayAllocationStrategy extends AbsAllocationStrategy {
|
||||
* 同步状态
|
||||
*/
|
||||
@Override
|
||||
public void doSync() {
|
||||
aliPayAllocationService.sync(this.getAllocationOrder(), this.getAllocationOrderDetails());
|
||||
public AllocSyncResult doSync() {
|
||||
return aliPayAllocationService.sync(this.getAllocationOrder(), this.getAllocationOrderDetails());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import cn.daxpay.single.exception.pay.PayFailureException;
|
||||
import cn.daxpay.single.service.core.channel.wechat.entity.WeChatPayConfig;
|
||||
import cn.daxpay.single.service.core.channel.wechat.service.WeChatPayAllocationService;
|
||||
import cn.daxpay.single.service.core.channel.wechat.service.WeChatPayConfigService;
|
||||
import cn.daxpay.single.service.core.payment.sync.result.AllocSyncResult;
|
||||
import cn.daxpay.single.service.func.AbsAllocationStrategy;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -72,8 +73,8 @@ public class WeChatPayAllocationStrategy extends AbsAllocationStrategy {
|
||||
* 同步状态
|
||||
*/
|
||||
@Override
|
||||
public void doSync() {
|
||||
weChatPayAllocationService.sync(this.getAllocationOrder(),this.getAllocationOrderDetails(),weChatPayConfig);
|
||||
public AllocSyncResult doSync() {
|
||||
return weChatPayAllocationService.sync(this.getAllocationOrder(),this.getAllocationOrderDetails(),weChatPayConfig);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,16 @@
|
||||
package cn.daxpay.single.service.core.payment.sync.result;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 分账同步结果
|
||||
* @author xxm
|
||||
* @since 2024/5/23
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class AllocSyncResult {
|
||||
/** 同步时网关返回的对象, 序列化为json字符串 */
|
||||
private String syncInfo;
|
||||
}
|
@@ -47,7 +47,6 @@ public class PaySyncRecord extends MpCreateEntity implements EntityBaseFunction<
|
||||
* 三方支付返回状态
|
||||
* @see PaySyncStatusEnum
|
||||
* @see RefundSyncStatusEnum
|
||||
* @see AllocOrderStatusEnum
|
||||
*/
|
||||
@DbColumn(comment = "网关返回状态")
|
||||
private String outTradeStatus;
|
||||
|
@@ -16,7 +16,7 @@ import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 支付同步记录
|
||||
* 支付同步记录, 包括支付/退款/分账
|
||||
* @author xxm
|
||||
* @since 2023/7/14
|
||||
*/
|
||||
|
@@ -2,6 +2,7 @@ package cn.daxpay.single.service.func;
|
||||
|
||||
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrder;
|
||||
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrderDetail;
|
||||
import cn.daxpay.single.service.core.payment.sync.result.AllocSyncResult;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -48,5 +49,5 @@ public abstract class AbsAllocationStrategy implements PayStrategy{
|
||||
/**
|
||||
* 同步状态
|
||||
*/
|
||||
public abstract void doSync();
|
||||
public abstract AllocSyncResult doSync();
|
||||
}
|
||||
|
Reference in New Issue
Block a user