mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-09-06 20:47:46 +00:00
feat 订单增加分账状态
This commit is contained in:
@@ -33,7 +33,7 @@ public class AliPayAllocationService {
|
||||
|
||||
// 分账主体参数
|
||||
AlipayTradeOrderSettleModel model = new AlipayTradeOrderSettleModel();
|
||||
model.setOutRequestNo(String.valueOf(allocationOrder.getOutReqNo()));
|
||||
model.setOutRequestNo(String.valueOf(allocationOrder.getOrderNo()));
|
||||
model.setTradeNo(allocationOrder.getGatewayPayOrderNo());
|
||||
model.setRoyaltyMode("async");
|
||||
|
||||
@@ -59,7 +59,7 @@ public class AliPayAllocationService {
|
||||
public void finish(AllocationOrder allocationOrder){
|
||||
// 分账主体参数
|
||||
AlipayTradeOrderSettleModel model = new AlipayTradeOrderSettleModel();
|
||||
model.setOutRequestNo(String.valueOf(allocationOrder.getOutReqNo()));
|
||||
model.setOutRequestNo(String.valueOf(allocationOrder.getOrderNo()));
|
||||
model.setTradeNo(allocationOrder.getGatewayPayOrderNo());
|
||||
// 分账完结参数
|
||||
SettleExtendParams extendParams = new SettleExtendParams();
|
||||
|
@@ -80,7 +80,7 @@ public class WeChatPayAllocationService {
|
||||
.appid(config.getWxAppId())
|
||||
.nonce_str(WxPayKit.generateStr())
|
||||
.transaction_id(allocationOrder.getGatewayPayOrderNo())
|
||||
.out_order_no(allocationOrder.getOutReqNo())
|
||||
.out_order_no(allocationOrder.getOrderNo())
|
||||
.description("分账完成")
|
||||
.build()
|
||||
.createSign(config.getApiKeyV2(), SignType.HMACSHA256);
|
||||
|
@@ -22,6 +22,6 @@ public class AllocationOrderDetailManager extends BaseManager<AllocationOrderDet
|
||||
* 根据订单ID查询
|
||||
*/
|
||||
public List<AllocationOrderDetail> findAllByOrderId(Long orderId) {
|
||||
return findAllByField(AllocationOrderDetail::getOrderId, orderId);
|
||||
return findAllByField(AllocationOrderDetail::getAllocationId, orderId);
|
||||
}
|
||||
}
|
||||
|
@@ -32,6 +32,12 @@ import java.time.LocalDateTime;
|
||||
@TableName("pay_allocation_order")
|
||||
public class AllocationOrder extends MpBaseEntity implements EntityBaseFunction<AllocationOrderDto> {
|
||||
|
||||
/**
|
||||
* 分账订单号
|
||||
*/
|
||||
@DbColumn(comment = "分账订单号")
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 支付订单ID
|
||||
*/
|
||||
@@ -64,12 +70,6 @@ public class AllocationOrder extends MpBaseEntity implements EntityBaseFunction<
|
||||
private String allocationNo;
|
||||
|
||||
|
||||
/**
|
||||
* 外部请求号
|
||||
*/
|
||||
@DbColumn(comment = "外部请求号")
|
||||
private String outReqNo;
|
||||
|
||||
/**
|
||||
* 所属通道
|
||||
* @see PayChannelEnum
|
||||
|
@@ -27,7 +27,7 @@ public class AllocationOrderDetail extends MpBaseEntity implements EntityBaseFun
|
||||
|
||||
/** 分账订单ID */
|
||||
@DbColumn(comment = "分账订单ID")
|
||||
private Long orderId;
|
||||
private Long allocationId;
|
||||
|
||||
/** 接收者ID */
|
||||
@DbColumn(comment = "接收者ID")
|
||||
|
@@ -19,6 +19,7 @@ import cn.bootx.platform.daxpay.service.dto.allocation.AllocationGroupReceiverRe
|
||||
import cn.bootx.platform.daxpay.service.dto.order.allocation.AllocationOrderDetailDto;
|
||||
import cn.bootx.platform.daxpay.service.dto.order.allocation.AllocationOrderDto;
|
||||
import cn.bootx.platform.daxpay.service.param.order.AllocationOrderQuery;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -87,7 +88,7 @@ public class AllocationOrderService {
|
||||
* 生成分账订单
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public OrderAndDetail create(AllocationStartParam param, PayOrder payOrder, int orderAmount, List<AllocationGroupReceiverResult> receiversByGroups){
|
||||
public OrderAndDetail createAndUpdate(AllocationStartParam param, PayOrder payOrder, int orderAmount, List<AllocationGroupReceiverResult> receiversByGroups){
|
||||
long orderId = IdUtil.getSnowflakeNextId();
|
||||
|
||||
// 请求号不存在使用订单ID
|
||||
@@ -103,7 +104,7 @@ public class AllocationOrderService {
|
||||
Integer rate = o.getRate();
|
||||
Integer amount = orderAmount * rate / 10000;
|
||||
AllocationOrderDetail detail = new AllocationOrderDetail();
|
||||
detail.setOrderId(orderId)
|
||||
detail.setAllocationId(orderId)
|
||||
.setReceiverId(o.getId())
|
||||
.setStatus(AllocationStatusEnum.WAITING.getCode())
|
||||
.setAmount(amount)
|
||||
@@ -125,16 +126,23 @@ public class AllocationOrderService {
|
||||
.setAllocationNo(allocationNo)
|
||||
.setChannel(payOrder.getAsyncChannel())
|
||||
.setGatewayPayOrderNo(payOrder.getGatewayOrderNo())
|
||||
.setOutReqNo(String.valueOf(orderId))
|
||||
.setOrderNo(String.valueOf(orderId))
|
||||
.setDescription(param.getDescription())
|
||||
.setStatus(AllocationStatusEnum.WAITING.getCode())
|
||||
.setAmount(sumAmount);
|
||||
allocationOrder.setId(orderId);
|
||||
// 保存
|
||||
// 因为加密后字段值会发生变更, 所以在保存前备份一下
|
||||
List<AllocationOrderDetail> detailsBack = details.stream()
|
||||
.map(o -> {
|
||||
AllocationOrderDetail allocationOrderDetail = new AllocationOrderDetail();
|
||||
BeanUtil.copyProperties(o, allocationOrderDetail);
|
||||
return allocationOrderDetail;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
allocationOrderDetailManager.saveAll(details);
|
||||
allocationOrderManager.save(allocationOrder);
|
||||
|
||||
return new OrderAndDetail().setOrder(allocationOrder).setDetails(details);
|
||||
return new OrderAndDetail().setOrder(allocationOrder).setDetails(detailsBack);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -56,6 +56,7 @@ public class PayBuilder {
|
||||
.setBusinessNo(payParam.getBusinessNo())
|
||||
.setTitle(payParam.getTitle())
|
||||
.setStatus(PayStatusEnum.PROGRESS.getCode())
|
||||
.setAllocation(payParam.isAllocation())
|
||||
.setAmount(sumAmount)
|
||||
.setExpiredTime(expiredTime)
|
||||
.setCombinationPay(payParam.getPayChannels().size() > 1)
|
||||
|
@@ -4,6 +4,7 @@ import cn.bootx.platform.common.core.function.EntityBaseFunction;
|
||||
import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity;
|
||||
import cn.bootx.platform.daxpay.code.PayChannelEnum;
|
||||
import cn.bootx.platform.daxpay.code.PayStatusEnum;
|
||||
import cn.bootx.platform.daxpay.service.code.AllocationStatusEnum;
|
||||
import cn.bootx.platform.daxpay.service.core.order.pay.convert.PayOrderConvert;
|
||||
import cn.bootx.platform.daxpay.service.dto.order.pay.PayOrderDto;
|
||||
import cn.bootx.table.modify.annotation.DbColumn;
|
||||
@@ -80,6 +81,13 @@ public class PayOrder extends MpBaseEntity implements EntityBaseFunction<PayOrde
|
||||
@DbColumn(comment = "支付状态")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 分账状态
|
||||
* @see AllocationStatusEnum
|
||||
*/
|
||||
@DbColumn(comment = "分账状态")
|
||||
private String allocationStatus;
|
||||
|
||||
/** 支付时间 */
|
||||
@DbColumn(comment = "支付时间")
|
||||
@TableField(updateStrategy = FieldStrategy.ALWAYS)
|
||||
|
@@ -2,6 +2,8 @@ package cn.bootx.platform.daxpay.service.core.payment.allocation.factory;
|
||||
|
||||
import cn.bootx.platform.daxpay.code.PayChannelEnum;
|
||||
import cn.bootx.platform.daxpay.exception.pay.PayUnsupportedMethodException;
|
||||
import cn.bootx.platform.daxpay.service.core.payment.allocation.strategy.allocation.AliPayAllocationStrategy;
|
||||
import cn.bootx.platform.daxpay.service.core.payment.allocation.strategy.allocation.WeChatPayAllocationStrategy;
|
||||
import cn.bootx.platform.daxpay.service.func.AbsAllocationStrategy;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import lombok.experimental.UtilityClass;
|
||||
@@ -24,10 +26,10 @@ public class AllocationFactory {
|
||||
AbsAllocationStrategy strategy;
|
||||
switch (channelEnum) {
|
||||
case ALI:
|
||||
strategy = SpringUtil.getBean(AbsAllocationStrategy.class);
|
||||
strategy = SpringUtil.getBean(AliPayAllocationStrategy.class);
|
||||
break;
|
||||
case WECHAT:
|
||||
strategy = SpringUtil.getBean(AbsAllocationStrategy.class);
|
||||
strategy = SpringUtil.getBean(WeChatPayAllocationStrategy.class);
|
||||
break;
|
||||
default:
|
||||
throw new PayUnsupportedMethodException();
|
||||
|
@@ -70,8 +70,8 @@ public class AllocationService {
|
||||
}
|
||||
List<AllocationGroupReceiverResult> receiversByGroups = allocationGroupService.findReceiversByGroups(allocationGroup.getId());
|
||||
|
||||
// 创建分账单和明细并保存, 使用事务
|
||||
OrderAndDetail orderAndDetail = allocationOrderService.create(param ,payOrder, channelOrder.getAmount(), receiversByGroups);
|
||||
// 创建分账单和明细并保存, 同时更新支付订单状态 使用事务
|
||||
OrderAndDetail orderAndDetail = allocationOrderService.createAndUpdate(param ,payOrder, channelOrder.getAmount(), receiversByGroups);
|
||||
|
||||
// 创建分账策略并初始化
|
||||
AbsAllocationStrategy allocationStrategy = AllocationFactory.create(payOrder.getAsyncChannel());
|
||||
@@ -120,7 +120,7 @@ public class AllocationService {
|
||||
allocationStrategy.doBeforeHandler();
|
||||
try {
|
||||
// 分账处理
|
||||
allocationStrategy.allocation();
|
||||
allocationStrategy.finish();
|
||||
// 执行中
|
||||
allocationOrder.setStatus(AllocationStatusEnum.FINISH_PROCESSING.getCode())
|
||||
.setErrorMsg(null);
|
||||
@@ -151,6 +151,10 @@ public class AllocationService {
|
||||
if (!payOrder.isAllocation()){
|
||||
throw new PayFailureException("该订单不允许分账");
|
||||
}
|
||||
// 判断分账状态
|
||||
if (Objects.equals(AllocationStatusEnum.FINISH_SUCCESS.getCode(), payOrder.getAllocationStatus())){
|
||||
throw new PayFailureException("该订单已分账完成");
|
||||
}
|
||||
return payOrder;
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,7 @@ import cn.bootx.platform.daxpay.param.pay.PayChannelParam;
|
||||
import cn.bootx.platform.daxpay.param.pay.PayParam;
|
||||
import cn.bootx.platform.daxpay.param.pay.SimplePayParam;
|
||||
import cn.bootx.platform.daxpay.result.pay.PayResult;
|
||||
import cn.bootx.platform.daxpay.service.code.AllocationStatusEnum;
|
||||
import cn.bootx.platform.daxpay.service.common.context.PayLocal;
|
||||
import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal;
|
||||
import cn.bootx.platform.daxpay.service.core.order.pay.builder.PayBuilder;
|
||||
@@ -270,6 +271,10 @@ public class PayService {
|
||||
payOrderExtraManager.update(payOrderExtra);
|
||||
// 如果支付完成 发送通知
|
||||
if (Objects.equals(payOrder.getStatus(), SUCCESS.getCode())){
|
||||
// 如果是是允许分账的订单, 设置为待分装
|
||||
if (payOrder.isAllocation()){
|
||||
payOrder.setAllocationStatus(AllocationStatusEnum.WAITING.getCode());
|
||||
}
|
||||
clientNoticeService.registerPayNotice(payOrder, payOrderExtra, payInfo.getPayChannelOrders());
|
||||
}
|
||||
return PayBuilder.buildPayResultByPayOrder(payOrder);
|
||||
@@ -368,6 +373,10 @@ public class PayService {
|
||||
payOrderExtraManager.update(payOrderExtra);
|
||||
// 如果支付完成 发送通知
|
||||
if (Objects.equals(payOrder.getStatus(), SUCCESS.getCode())){
|
||||
// 如果是是允许分账的订单, 设置为待分装
|
||||
if (payOrder.isAllocation()){
|
||||
payOrder.setAllocationStatus(AllocationStatusEnum.WAITING.getCode());
|
||||
}
|
||||
clientNoticeService.registerPayNotice(payOrder, payOrderExtra, payInfo.getPayChannelOrders());
|
||||
}
|
||||
return PayBuilder.buildPayResultByPayOrder(payOrder);
|
||||
|
@@ -8,14 +8,14 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
*
|
||||
* 分账组
|
||||
* @author xxm
|
||||
* @since 2024/4/1
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "")
|
||||
@Schema(title = "分账组")
|
||||
public class AllocationGroupDto extends BaseDto {
|
||||
|
||||
@Schema(description = "名称")
|
||||
|
@@ -11,14 +11,14 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 分账接收方参数
|
||||
* 分账接收方
|
||||
* @author xxm
|
||||
* @since 2024/3/28
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "分账接收方参数")
|
||||
@Schema(title = "分账接收方")
|
||||
public class AllocationReceiverDto extends BaseDto {
|
||||
|
||||
@Schema(description = "主键")
|
||||
|
@@ -22,7 +22,7 @@ public class AllocationOrderDetailDto extends BaseDto {
|
||||
|
||||
/** 分账订单ID */
|
||||
@Schema(description = "分账订单ID")
|
||||
private Long orderId;
|
||||
private Long allocationId;
|
||||
|
||||
/** 接收者ID */
|
||||
@Schema(description = "接收者ID")
|
||||
|
@@ -20,6 +20,13 @@ import java.time.LocalDateTime;
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "分账订单")
|
||||
public class AllocationOrderDto extends BaseDto {
|
||||
|
||||
/**
|
||||
* 分账订单号
|
||||
*/
|
||||
@Schema(description = "分账订单号")
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 支付订单ID
|
||||
*/
|
||||
@@ -50,13 +57,6 @@ public class AllocationOrderDto extends BaseDto {
|
||||
@Schema(description = "分账单号")
|
||||
private String allocationNo;
|
||||
|
||||
|
||||
/**
|
||||
* 外部请求号
|
||||
*/
|
||||
@Schema(description = "外部请求号")
|
||||
private String outReqNo;
|
||||
|
||||
/**
|
||||
* 所属通道
|
||||
*/
|
||||
|
@@ -3,6 +3,7 @@ package cn.bootx.platform.daxpay.service.dto.order.pay;
|
||||
import cn.bootx.platform.common.core.rest.dto.BaseDto;
|
||||
import cn.bootx.platform.daxpay.code.PayChannelEnum;
|
||||
import cn.bootx.platform.daxpay.code.PayStatusEnum;
|
||||
import cn.bootx.platform.daxpay.service.code.AllocationStatusEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -68,6 +69,13 @@ public class PayOrderDto extends BaseDto {
|
||||
@Schema(description = "支付状态")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 分账状态
|
||||
* @see AllocationStatusEnum
|
||||
*/
|
||||
@Schema(description = "分账状态")
|
||||
private String allocationStatus;
|
||||
|
||||
/** 支付时间 */
|
||||
@Schema(description = "支付时间")
|
||||
private LocalDateTime payTime;
|
||||
|
Reference in New Issue
Block a user