diff --git a/_doc/Task.md b/_doc/Task.md index 03091d6d..98a529e9 100644 --- a/_doc/Task.md +++ b/_doc/Task.md @@ -6,15 +6,20 @@ ## 3.0.0.bate3: 功能完善 - 优化: - [ ] 增加首页驾驶舱功能 -- [ ] 分账功能 +- [x] 分账界面功能 - [x] 分账接收方配置 - - [ ] 分账单管理 - - [ ] 分账接口开发 + - [x] 分账单管理 + - [x] 接口开发 开启/完结/用不 +- [ ] 分账接口开发 + - [x] 支付宝 + - [ ] 微信 +- [ ] 分账扩展能力 + - [ ] 自动分账 + - [ ] 自动完成 + - [ ] 自动同步状态 - [ ] 网关配套移动端开发 - [ ] 同步回调页 -- [ ] 分账接收方和分账组优化 - - [ ] 后台管理时, 编号自动生成 - - [ ] 显示数据 +- [x] 分账接收方和分账组优化, 后台管理时, 编号自动生成 - [x] 微信通道添加单独的认证跳转地址, 处理它的特殊情况 - [x] 支付订单新增待支付状态 ## 3.0.0.beta2 收银台 diff --git a/daxpay-single-channel/daxpay-single-alipay/src/main/java/org/dromara/daxpay/channel/alipay/service/allocation/AliPayAllocationService.java b/daxpay-single-channel/daxpay-single-alipay/src/main/java/org/dromara/daxpay/channel/alipay/service/allocation/AliPayAllocationService.java index dd87dd01..f9e2c6ef 100644 --- a/daxpay-single-channel/daxpay-single-alipay/src/main/java/org/dromara/daxpay/channel/alipay/service/allocation/AliPayAllocationService.java +++ b/daxpay-single-channel/daxpay-single-alipay/src/main/java/org/dromara/daxpay/channel/alipay/service/allocation/AliPayAllocationService.java @@ -142,7 +142,6 @@ public class AliPayAllocationService { var detail = detailMap.get(receiver.getTransIn()); if (Objects.nonNull(detail)) { detail.setResult(this.getDetailResultEnum(receiver.getState()).getCode()); - detail.setErrorCode(receiver.getErrorCode()); detail.setErrorMsg(receiver.getErrorDesc()); // 如果是完成, 更新时间 if (AllocDetailResultEnum.SUCCESS.getCode().equals(detail.getResult())){ diff --git a/daxpay-single-channel/daxpay-single-wechat/src/main/java/org/dromara/daxpay/channel/wechat/service/allocation/WeChatPayAllocationV2Service.java b/daxpay-single-channel/daxpay-single-wechat/src/main/java/org/dromara/daxpay/channel/wechat/service/allocation/WeChatPayAllocationV2Service.java index 4cce6cb3..dac162dc 100644 --- a/daxpay-single-channel/daxpay-single-wechat/src/main/java/org/dromara/daxpay/channel/wechat/service/allocation/WeChatPayAllocationV2Service.java +++ b/daxpay-single-channel/daxpay-single-wechat/src/main/java/org/dromara/daxpay/channel/wechat/service/allocation/WeChatPayAllocationV2Service.java @@ -2,8 +2,14 @@ package org.dromara.daxpay.channel.wechat.service.allocation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.dromara.daxpay.channel.wechat.entity.config.WechatPayConfig; +import org.dromara.daxpay.service.bo.allocation.AllocStartResultBo; +import org.dromara.daxpay.service.entity.allocation.transaction.AllocDetail; +import org.dromara.daxpay.service.entity.allocation.transaction.AllocOrder; import org.springframework.stereotype.Service; +import java.util.List; + /** * 微信分账V2版本接口 * @author xxm @@ -13,4 +19,25 @@ import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor public class WeChatPayAllocationV2Service { + + /** + * 分账 + */ + public AllocStartResultBo start(AllocOrder order, List details, WechatPayConfig config) { + return null; + } + + /** + * 完结 + */ + public void finish(AllocOrder order, List details, WechatPayConfig config) { + + } + + /** + * 同步 + */ + public void sync(AllocOrder order, List details, WechatPayConfig config) { + + } } diff --git a/daxpay-single-channel/daxpay-single-wechat/src/main/java/org/dromara/daxpay/channel/wechat/service/allocation/WeChatPayAllocationV3Service.java b/daxpay-single-channel/daxpay-single-wechat/src/main/java/org/dromara/daxpay/channel/wechat/service/allocation/WeChatPayAllocationV3Service.java index b9a1bbb7..6bbb6bb2 100644 --- a/daxpay-single-channel/daxpay-single-wechat/src/main/java/org/dromara/daxpay/channel/wechat/service/allocation/WeChatPayAllocationV3Service.java +++ b/daxpay-single-channel/daxpay-single-wechat/src/main/java/org/dromara/daxpay/channel/wechat/service/allocation/WeChatPayAllocationV3Service.java @@ -1,5 +1,6 @@ package org.dromara.daxpay.channel.wechat.service.allocation; +import com.github.binarywang.wxpay.bean.profitsharing.request.ProfitSharingQueryV3Request; import com.github.binarywang.wxpay.bean.profitsharing.request.ProfitSharingUnfreezeV3Request; import com.github.binarywang.wxpay.bean.profitsharing.request.ProfitSharingV3Request; import com.github.binarywang.wxpay.bean.profitsharing.result.ProfitSharingV3Result; @@ -36,7 +37,7 @@ public class WeChatPayAllocationV3Service { private final WechatPayConfigService wechatPayConfigService; /** - * 发起分账 + * 发起分账 使用分账号作为请求号4 */ public AllocStartResultBo start(AllocOrder allocOrder, List orderDetails, WechatPayConfig config){ @@ -44,9 +45,10 @@ public class WeChatPayAllocationV3Service { ProfitSharingService sharingService = wxPayService.getProfitSharingService(); ProfitSharingV3Request request = new ProfitSharingV3Request(); + request.setAppid(config.getWxAppId()); request.setOutOrderNo(allocOrder.getAllocNo()); request.setTransactionId(allocOrder.getOutOrderNo()); - request.setUnfreezeUnsplit(true); + request.setUnfreezeUnsplit(false); // 分账接收方信息 var receivers = orderDetails.stream() @@ -67,7 +69,6 @@ public class WeChatPayAllocationV3Service { request.setReceivers(receivers); try { ProfitSharingV3Result result = sharingService.profitSharingV3(request); - return new AllocStartResultBo().setOutAllocNo(result.getOrderId()); } catch (WxPayException e) { throw new OperationFailException("微信分账V3失败: "+e.getMessage()); @@ -75,22 +76,40 @@ public class WeChatPayAllocationV3Service { } /** - * 分账完结 + * 分账完结 使用ID作为请求号 */ - public void finish(AllocOrder allocOrder, List orderDetails, WechatPayConfig config){ + public void finish(AllocOrder allocOrder, List details, WechatPayConfig config){ WxPayService wxPayService = wechatPayConfigService.wxJavaSdk(config); ProfitSharingService sharingService = wxPayService.getProfitSharingService(); var request = new ProfitSharingUnfreezeV3Request(); - request.setOutOrderNo(allocOrder.getAllocNo()); + request.setOutOrderNo(String.valueOf(allocOrder.getId())); request.setTransactionId(allocOrder.getOutOrderNo()); request.setDescription("分账完结"); try { - sharingService.profitSharingUnfreeze(request); + var result = sharingService.profitSharingUnfreeze(request); } catch (WxPayException e) { throw new OperationFailException("微信分账V3失败: "+e.getMessage()); } } + /** + * 同步 + */ + public void sync(AllocOrder allocOrder, List details, WechatPayConfig config){ + WxPayService wxPayService = wechatPayConfigService.wxJavaSdk(config); + ProfitSharingService sharingService = wxPayService.getProfitSharingService(); + ProfitSharingQueryV3Request request = new ProfitSharingQueryV3Request(); + request.setOutOrderNo(allocOrder.getAllocNo()); + // 根据订单状态判断 + + request.setTransactionId(allocOrder.getOutOrderNo()); + try { + var result = sharingService.profitSharingQueryV3(request); + } catch (WxPayException e) { + throw new OperationFailException("微信分账订单查询V3失败: "+e.getMessage()); + } + } + /** * 获取分账接收方类型编码 */ @@ -103,4 +122,5 @@ public class WeChatPayAllocationV3Service { } throw new ConfigErrorException("分账接收方类型错误"); } + } diff --git a/daxpay-single-channel/daxpay-single-wechat/src/main/java/org/dromara/daxpay/channel/wechat/strategy/WechatAllocationStrategy.java b/daxpay-single-channel/daxpay-single-wechat/src/main/java/org/dromara/daxpay/channel/wechat/strategy/WechatAllocationStrategy.java index ebe43344..419a67f7 100644 --- a/daxpay-single-channel/daxpay-single-wechat/src/main/java/org/dromara/daxpay/channel/wechat/strategy/WechatAllocationStrategy.java +++ b/daxpay-single-channel/daxpay-single-wechat/src/main/java/org/dromara/daxpay/channel/wechat/strategy/WechatAllocationStrategy.java @@ -2,6 +2,11 @@ package org.dromara.daxpay.channel.wechat.strategy; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.dromara.daxpay.channel.wechat.code.WechatPayCode; +import org.dromara.daxpay.channel.wechat.entity.config.WechatPayConfig; +import org.dromara.daxpay.channel.wechat.service.allocation.WeChatPayAllocationV2Service; +import org.dromara.daxpay.channel.wechat.service.allocation.WeChatPayAllocationV3Service; +import org.dromara.daxpay.channel.wechat.service.config.WechatPayConfigService; import org.dromara.daxpay.core.enums.ChannelEnum; import org.dromara.daxpay.service.bo.allocation.AllocStartResultBo; import org.dromara.daxpay.service.bo.allocation.AllocSyncResultBo; @@ -9,6 +14,8 @@ import org.dromara.daxpay.service.strategy.AbsAllocationStrategy; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; +import java.util.Objects; + import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE; /** @@ -21,7 +28,11 @@ import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROT @Component @RequiredArgsConstructor public class WechatAllocationStrategy extends AbsAllocationStrategy { + private final WeChatPayAllocationV3Service weChatPayAllocationV3Service; + private final WeChatPayAllocationV2Service weChatPayAllocationV2Service; + private final WechatPayConfigService wechatPayConfigService; + private WechatPayConfig config; /** * 分账通道 @@ -31,20 +42,33 @@ public class WechatAllocationStrategy extends AbsAllocationStrategy { return ChannelEnum.WECHAT.getCode(); } + @Override + public void doBeforeHandler(){ + this.config = wechatPayConfigService.getAndCheckConfig(); + } + /** * 开始分账 */ @Override public AllocStartResultBo start() { - return null; + if (Objects.equals(config.getApiVersion(), WechatPayCode.API_V3)){ + return weChatPayAllocationV3Service.start(getOrder(), getDetails(), this.config); + } else { + return weChatPayAllocationV2Service.start(getOrder(), getDetails(), this.config); + } } /** - * + * 完结 */ @Override public void finish() { - + if (Objects.equals(config.getApiVersion(), WechatPayCode.API_V3)){ + weChatPayAllocationV3Service.finish(getOrder(), this.getDetails(), this.config); + } else { + weChatPayAllocationV2Service.finish(getOrder(), this.getDetails(), this.config); + } } /** @@ -52,6 +76,13 @@ public class WechatAllocationStrategy extends AbsAllocationStrategy { */ @Override public AllocSyncResultBo doSync() { + if (Objects.equals(config.getApiVersion(), WechatPayCode.API_V3)){ + weChatPayAllocationV3Service.finish(getOrder(), this.getDetails(), this.config); + + weChatPayAllocationV3Service.sync(getOrder(), this.getDetails(), this.config); + } else { + weChatPayAllocationV2Service.sync(getOrder(), this.getDetails(), this.config); + } return null; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/org/dromara/daxpay/service/entity/allocation/AllocConfig.java b/daxpay-single/daxpay-single-service/src/main/java/org/dromara/daxpay/service/entity/allocation/AllocConfig.java index 6ed19b71..426a6a0e 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/org/dromara/daxpay/service/entity/allocation/AllocConfig.java +++ b/daxpay-single/daxpay-single-service/src/main/java/org/dromara/daxpay/service/entity/allocation/AllocConfig.java @@ -26,9 +26,15 @@ public class AllocConfig extends MchAppBaseEntity implements ToResult