feat 分账接口调试

This commit is contained in:
xxm1995
2024-04-15 18:30:38 +08:00
parent 1deee49edb
commit e0c495d94b
12 changed files with 139 additions and 14 deletions

View File

@@ -179,15 +179,21 @@ public class SimplePayOrderTest {
## 🥪 关于我们
钉钉扫码加入钉钉交流群(推荐)
扫码加入QQ交流群
<p>
<img src="https://jsd.cdn.zzko.cn/gh/xxm1995/picx-images-hosting@master/connect/微信图片_20240412132238.3rb0hgrf2z.webp" width = "330" height = "500"/>
</p>
扫码加入钉钉交流群
<p>
<img src="https://jsd.cdn.zzko.cn/gh/xxm1995/picx-images-hosting@master/connect/png-(1).7egk526qnp.webp" width = "400" height = "400"/>
</p>
QQ扫码加入QQ交流群
扫码加入飞书交流群
<p>
<img src="https://jsd.cdn.zzko.cn/gh/xxm1995/picx-images-hosting@master/connect/微信图片_20240412132238.3rb0hgrf2z.webp" width = "330" height = "500"/>
<img src="https://jsd.cdn.zzko.cn/gh/xxm1995/picx-images-hosting@master/connect/微信图片_20240415124136.231noivcuz.webp" width = "390" height = "500"/>
</p>

View File

@@ -6,7 +6,9 @@ import cn.bootx.platform.common.core.rest.ResResult;
import cn.bootx.platform.common.core.rest.dto.LabelValue;
import cn.bootx.platform.common.core.rest.param.PageParam;
import cn.bootx.platform.daxpay.param.pay.AllocationSyncParam;
import cn.bootx.platform.daxpay.param.pay.allocation.AllocationFinishParam;
import cn.bootx.platform.daxpay.service.core.order.allocation.service.AllocationOrderService;
import cn.bootx.platform.daxpay.service.core.payment.allocation.service.AllocationService;
import cn.bootx.platform.daxpay.service.core.payment.allocation.service.AllocationSyncService;
import cn.bootx.platform.daxpay.service.dto.order.allocation.AllocationOrderDetailDto;
import cn.bootx.platform.daxpay.service.dto.order.allocation.AllocationOrderDto;
@@ -35,6 +37,7 @@ public class AllocationOrderController {
private final AllocationOrderService allocationOrderService;
private final AllocationSyncService allocationSyncService;
private final AllocationService allocationService;
@Operation(summary = "分页")
@GetMapping("/page")
@@ -75,4 +78,13 @@ public class AllocationOrderController {
allocationSyncService.sync(param);
return Res.ok();
}
@Operation(summary = "分账完结")
@PostMapping("/finish")
public ResResult<Void> finish(Long id){
AllocationFinishParam param = new AllocationFinishParam();
param.setOrderId(id);
allocationService.finish(param);
return Res.ok();
}
}

View File

@@ -0,0 +1,22 @@
package cn.bootx.platform.daxpay.param.pay.allocation;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 重新分账参数
* @author xxm
* @since 2024/4/15
*/
@Data
@Accessors(chain = true)
@Schema(title = "重新分账参数")
public class AllocationResetParam {
@Schema(description = "分账订单ID")
private Long orderId;
@Schema(description = "分账单号")
private String allocationNo;
}

View File

@@ -102,4 +102,7 @@ public interface AliPayCode {
/** 分账接收方不存在 */
String USER_NOT_EXIST = "USER_NOT_EXIST";
/** 分账金额超过最大可分账金额 */
String ALLOC_AMOUNT_VALIDATE_ERROR = "ACQ.ALLOC_AMOUNT_VALIDATE_ERROR";
}

View File

@@ -0,0 +1,17 @@
package cn.bootx.platform.daxpay.service.common.context;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 分账上下文
* @author xxm
* @since 2024/4/15
*/
@Data
@Accessors(chain = true)
public class AllocationLocal {
/** 网关分账号 */
private String gatewayNo;
}

View File

@@ -42,4 +42,7 @@ public class PaymentContext {
/** 对账相关信息 */
private final ReconcileLocal reconcileInfo = new ReconcileLocal();
/** 分账相关信息 */
private final AllocationLocal allocationInfo = new AllocationLocal();
}

View File

@@ -2,6 +2,7 @@ package cn.bootx.platform.daxpay.service.core.channel.alipay.service;
import cn.bootx.platform.daxpay.exception.pay.PayFailureException;
import cn.bootx.platform.daxpay.service.code.AliPayCode;
import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal;
import cn.bootx.platform.daxpay.service.core.order.allocation.entity.AllocationOrder;
import cn.bootx.platform.daxpay.service.core.order.allocation.entity.AllocationOrderDetail;
import cn.hutool.core.util.StrUtil;
@@ -35,7 +36,6 @@ public class AliPayAllocationService {
*/
@SneakyThrows
public void allocation(AllocationOrder allocationOrder, List<AllocationOrderDetail> orderDetails){
// 分账主体参数
AlipayTradeOrderSettleModel model = new AlipayTradeOrderSettleModel();
model.setOutRequestNo(String.valueOf(allocationOrder.getOrderNo()));
@@ -54,26 +54,38 @@ public class AliPayAllocationService {
model.setRoyaltyParameters(royaltyParameters);
AlipayTradeOrderSettleResponse response = AliPayApi.tradeOrderSettleToResponse(model);
// TODO 需要写入到分账订单中
// 需要写入到分账订单中
String settleNo = response.getSettleNo();
PaymentContextLocal.get().getAllocationInfo().setGatewayNo(settleNo);
this.verifyErrorMsg(response);
}
/**
* 分账完结
*/
@SneakyThrows
public void finish(AllocationOrder allocationOrder){
public void finish(AllocationOrder allocationOrder, List<AllocationOrderDetail> orderDetails ){
// 分账主体参数
AlipayTradeOrderSettleModel model = new AlipayTradeOrderSettleModel();
model.setOutRequestNo(String.valueOf(allocationOrder.getOrderNo()));
model.setTradeNo(allocationOrder.getGatewayPayOrderNo());
model.setRoyaltyMode("async");
// 分账完结参数
SettleExtendParams extendParams = new SettleExtendParams();
extendParams.setRoyaltyFinish("true");
model.setExtendParams(extendParams);
// 分账子参数
List<OpenApiRoyaltyDetailInfoPojo> royaltyParameters = orderDetails.stream()
.map(o -> {
OpenApiRoyaltyDetailInfoPojo infoPojo = new OpenApiRoyaltyDetailInfoPojo();
infoPojo.setAmount(String.valueOf(o.getAmount() / 100.0));
infoPojo.setTransIn(o.getReceiverAccount());
return infoPojo;
})
.collect(Collectors.toList());
model.setRoyaltyParameters(royaltyParameters);
AlipayTradeOrderSettleResponse response = AliPayApi.tradeOrderSettleToResponse(model);
this.verifyErrorMsg(response);
}

View File

@@ -59,7 +59,7 @@ public class WeChatPayAllocationService {
.appid(config.getWxAppId())
.nonce_str(WxPayKit.generateStr())
.transaction_id(allocationOrder.getGatewayPayOrderNo())
.out_order_no(WxPayKit.generateStr())
.out_order_no(allocationOrder.getOrderNo())
.receivers(JSON.toJSONString(list))
.build()
.createSign(config.getApiKeyV2(), SignType.HMACSHA256);
@@ -74,7 +74,7 @@ public class WeChatPayAllocationService {
/**
* 完成分账
*/
public void finish(AllocationOrder allocationOrder, WeChatPayConfig config){
public void finish(AllocationOrder allocationOrder, List<AllocationOrderDetail> allocationOrderDetails, WeChatPayConfig config){
Map<String, String> params = ProfitSharingModel.builder()
.mch_id(config.getWxMchId())
.appid(config.getWxAppId())

View File

@@ -0,0 +1,17 @@
package cn.bootx.platform.daxpay.service.core.payment.allocation.result;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 分账网关同步结果
* @author xxm
* @since 2024/4/15
*/
@Data
@Accessors(chain = true)
@Schema(title = "分账网关同步结果")
public class AllocationGatewaySyncResult {
}

View File

@@ -1,11 +1,13 @@
package cn.bootx.platform.daxpay.service.core.payment.allocation.service;
import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.bootx.platform.daxpay.code.AllocationStatusEnum;
import cn.bootx.platform.daxpay.exception.pay.PayFailureException;
import cn.bootx.platform.daxpay.param.pay.allocation.AllocationFinishParam;
import cn.bootx.platform.daxpay.param.pay.allocation.AllocationResetParam;
import cn.bootx.platform.daxpay.param.pay.allocation.AllocationStartParam;
import cn.bootx.platform.daxpay.result.allocation.AllocationResult;
import cn.bootx.platform.daxpay.code.AllocationStatusEnum;
import cn.bootx.platform.daxpay.service.core.order.allocation.dao.AllocationOrderDetailManager;
import cn.bootx.platform.daxpay.service.core.order.allocation.dao.AllocationOrderManager;
import cn.bootx.platform.daxpay.service.core.order.allocation.entity.AllocationOrder;
import cn.bootx.platform.daxpay.service.core.order.allocation.entity.AllocationOrderDetail;
@@ -50,6 +52,8 @@ public class AllocationService {
private final AllocationOrderService allocationOrderService;
private final AllocationOrderDetailManager allocationOrderDetailManager;
/**
* 开启分账, 使用分账组进行分账
*/
@@ -99,6 +103,34 @@ public class AllocationService {
.setStatus(order.getStatus());
}
/**
* 重新分账
*/
public void resetAllocation(AllocationResetParam param){
AllocationOrder allocationOrder;
if (Objects.nonNull(param.getOrderId())){
allocationOrder = allocationOrderManager.findById(param.getOrderId())
.orElseThrow(() -> new DataNotExistException("未查询到分账单信息"));
} else {
allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocationNo())
.orElseThrow(() -> new DataNotExistException("未查询到分账单信息"));
}
List<AllocationOrderDetail> details = allocationOrderDetailManager.findAllByOrderId(allocationOrder.getId());
// 创建分账策略并初始化
AbsAllocationStrategy allocationStrategy = AllocationFactory.create(allocationOrder.getChannel());
allocationStrategy.initParam(allocationOrder, details);
// 分账预处理
allocationStrategy.doBeforeHandler();
try {
// 重复分账处理
allocationStrategy.allocation();
} catch (Exception e) {
// 失败
}
}
/**
* 分账完结
*/
@@ -111,10 +143,11 @@ public class AllocationService {
allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocationNo())
.orElseThrow(() -> new DataNotExistException("未查询到分账单信息"));
}
List<AllocationOrderDetail> details = allocationOrderDetailManager.findAllByOrderId(allocationOrder.getId());
// 创建分账策略并初始化
AbsAllocationStrategy allocationStrategy = AllocationFactory.create(allocationOrder.getChannel());
allocationStrategy.initParam(allocationOrder, null);
allocationStrategy.initParam(allocationOrder, details);
// 分账完结预处理
allocationStrategy.doBeforeHandler();

View File

@@ -67,7 +67,7 @@ public class AliPayAllocationStrategy extends AbsAllocationStrategy {
*/
@Override
public void finish() {
aliPayAllocationService.finish(this.getAllocationOrder());
aliPayAllocationService.finish(this.getAllocationOrder(), this.getAllocationOrderDetails());
}
}

View File

@@ -57,7 +57,7 @@ public class WeChatPayAllocationStrategy extends AbsAllocationStrategy {
*/
@Override
public void allocation() {
weChatPayAllocationService.allocation(getAllocationOrder(), getAllocationOrderDetails(), weChatPayConfig);
weChatPayAllocationService.allocation(getAllocationOrder(), this.getAllocationOrderDetails(), weChatPayConfig);
}
/**
@@ -65,7 +65,7 @@ public class WeChatPayAllocationStrategy extends AbsAllocationStrategy {
*/
@Override
public void finish() {
weChatPayAllocationService.finish(getAllocationOrder(), weChatPayConfig);
weChatPayAllocationService.finish(getAllocationOrder(), this.getAllocationOrderDetails(), weChatPayConfig);
}