feat:发起分账
This commit is contained in:
1 parent
e00e69ccbb
commit
e19bc4a7ef
11 files changed
+388
-7
No files matched your search
@@ -143,7 +143,6 @@ DROP TABLE IF EXISTS `third_pay_order`;
|
||||
CREATE TABLE `third_pay_order`
|
||||
(
|
||||
`id` bigint NOT NULL COMMENT '主键',
|
||||
|
||||
`pay_platform_type` varchar(32) NOT NULL COMMENT '支付平台类型',
|
||||
`biz_type` varchar(32) NOT NULL COMMENT '支付类型',
|
||||
`biz_id` varchar(128) NOT NULL COMMENT '支付相关id',
|
||||
@@ -151,17 +150,13 @@ CREATE TABLE `third_pay_order`
|
||||
`user_code` varchar(64) DEFAULT NULL COMMENT '用户code',
|
||||
`price` int NOT NULL COMMENT '支付金额(分)',
|
||||
`status` varchar(128) DEFAULT NULL COMMENT '支付状态',
|
||||
|
||||
`pay_no` varchar(128) DEFAULT NULL COMMENT '支付订单号',
|
||||
`pay_time` datetime DEFAULT NULL COMMENT '支付时间',
|
||||
`pay_res` text DEFAULT NULL COMMENT '支付返回',
|
||||
|
||||
`refund_no` varchar(128) DEFAULT NULL COMMENT '退款订单号',
|
||||
`refund_time` datetime DEFAULT NULL COMMENT '退款时间',
|
||||
`refund_res` text DEFAULT NULL COMMENT '退款返回',
|
||||
|
||||
`expire_time` datetime DEFAULT NULL COMMENT '订单过期时间',
|
||||
|
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
||||
`create_by` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
|
||||
@@ -173,3 +168,34 @@ CREATE TABLE `third_pay_order`
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci
|
||||
ROW_FORMAT = DYNAMIC COMMENT ='第三方支付订单';
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for third_fz_order
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `third_fz_order`;
|
||||
CREATE TABLE `third_fz_order`
|
||||
(
|
||||
`id` bigint NOT NULL COMMENT '主键',
|
||||
`pay_no` varchar(128) DEFAULT NULL COMMENT '支付订单号',
|
||||
`fz_no` varchar(128) DEFAULT NULL COMMENT '分账订单号',
|
||||
`create_req` text DEFAULT NULL COMMENT '发起分账req',
|
||||
`create_res` text DEFAULT NULL COMMENT '发起分账res',
|
||||
`create_error` text DEFAULT NULL COMMENT '发起分账error',
|
||||
`status` varchar(128) DEFAULT NULL COMMENT '支付状态',
|
||||
`fz_time` datetime DEFAULT NULL COMMENT '分账时间',
|
||||
`fz_refund_no` varchar(128) DEFAULT NULL COMMENT '分账退款订单号',
|
||||
`fz_refund_time` datetime DEFAULT NULL COMMENT '分账退款时间',
|
||||
`fz_refund_req` text DEFAULT NULL COMMENT '分账退款req',
|
||||
`fz_refund_res` text DEFAULT NULL COMMENT '分账退款res',
|
||||
`fz_refund_error` text DEFAULT NULL COMMENT '分账退款error',
|
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
||||
`create_by` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
|
||||
`update_by` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '更新人',
|
||||
`del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '删除时间',
|
||||
`tenant_id` bigint(20) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci
|
||||
ROW_FORMAT = DYNAMIC COMMENT ='第三方支付分账';
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.bsd.pjcloud.thirdparty.constant.fz;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderStatusEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 第三方支付分账状态
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ThirdFzOrderStatusEnum {
|
||||
FZ_UNPAID("10", "发起分账"),
|
||||
FZ_SUCCESS("20", "分账成功"),
|
||||
FZ_FAILED("30", "分账失败"),
|
||||
|
||||
FZ_REFUNDING("100", "分账退款中"),
|
||||
FZ_REFUND_SUCCESS("200", "分账退款成功"),
|
||||
FZ_REFUND_FAILED("300", "分账退款失败"),
|
||||
;
|
||||
|
||||
private final String type;
|
||||
private final String description;
|
||||
|
||||
public static ThirdFzOrderStatusEnum valueOfByType(String type) {
|
||||
if (ObjectUtil.isEmpty(type)) return null;
|
||||
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.bsd.pjcloud.thirdparty.dto.pay;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThirdFzOrderDto extends ThirdFzOrderEntity {
|
||||
|
||||
}
|
||||
Vendored
Executable
+142
@@ -0,0 +1,142 @@
|
||||
package com.bsd.pjcloud.thirdparty.entity.pay;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.bsd.pjcloud.common.core.util.TenantTable;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 第三方支付分账
|
||||
*/
|
||||
@Data
|
||||
@TenantTable
|
||||
@TableName("third_fz_order")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(description = "第三方支付分账")
|
||||
public class ThirdFzOrderEntity extends Model<ThirdFzOrderEntity> {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "主键")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 支付订单号
|
||||
*/
|
||||
@Schema(description = "支付订单号")
|
||||
private String payNo;
|
||||
|
||||
/**
|
||||
* 分账订单号
|
||||
*/
|
||||
@Schema(description = "分账订单号")
|
||||
private String fzNo;
|
||||
|
||||
/**
|
||||
* 发起分账req
|
||||
*/
|
||||
@Schema(description = "发起分账req")
|
||||
private String createReq;
|
||||
|
||||
/**
|
||||
* 发起分账res
|
||||
*/
|
||||
@Schema(description = "发起分账res")
|
||||
private String createRes;
|
||||
|
||||
/**
|
||||
* 发起分账error
|
||||
*/
|
||||
@Schema(description = "发起分账error")
|
||||
private String createError;
|
||||
|
||||
/**
|
||||
* 支付状态
|
||||
*/
|
||||
@Schema(description = "支付状态")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 分账时间
|
||||
*/
|
||||
@Schema(description = "分账时间")
|
||||
private LocalDateTime fzTime;
|
||||
|
||||
/**
|
||||
* 分账退款订单号
|
||||
*/
|
||||
@Schema(description = "分账退款订单号")
|
||||
private String fzRefundNo;
|
||||
|
||||
/**
|
||||
* 分账退款时间
|
||||
*/
|
||||
@Schema(description = "分账退款时间")
|
||||
private LocalDateTime fzRefundTime;
|
||||
|
||||
/**
|
||||
* 分账退款req
|
||||
*/
|
||||
@Schema(description = "分账退款req")
|
||||
private String fzRefundReq;
|
||||
|
||||
/**
|
||||
* 分账退款res
|
||||
*/
|
||||
@Schema(description = "分账退款res")
|
||||
private String fzRefundRes;
|
||||
|
||||
/**
|
||||
* 分账退款error
|
||||
*/
|
||||
@Schema(description = "分账退款error")
|
||||
private String fzRefundError;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建人")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新人")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 删除时间
|
||||
*/
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "删除时间")
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* tenantId
|
||||
*/
|
||||
@Schema(description = "tenantId")
|
||||
private Long tenantId;
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.bsd.pjcloud.thirdparty.vo.pay;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThirdFzOrderVo extends ThirdFzOrderEntity {
|
||||
|
||||
}
|
||||
Vendored
Executable
+48
@@ -0,0 +1,48 @@
|
||||
package com.bsd.pjcloud.thirdparty.controller.pay;
|
||||
;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdFzOrderService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 第三方支付分账
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/third-fz-order")
|
||||
@Tag(description = "thirdFzOrder", name = "第三方支付分账管理")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class ThirdFzOrderController {
|
||||
|
||||
private final ThirdFzOrderService thirdFzOrderService;
|
||||
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdFzOrder_view')")
|
||||
public R getThirdFzOrderPage(@ParameterObject Page page, @ParameterObject ThirdFzOrderEntity thirdFzOrder) {
|
||||
LambdaQueryWrapper<ThirdFzOrderEntity> wrapper = Wrappers.lambdaQuery();
|
||||
return R.ok(thirdFzOrderService.page(page, wrapper));
|
||||
}
|
||||
|
||||
@Operation(summary = "通过id查询", description = "通过id查询")
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdFzOrder_view')")
|
||||
public R getById(@PathVariable("id") Long id) {
|
||||
return R.ok(thirdFzOrderService.getById(id));
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
Executable
+11
@@ -0,0 +1,11 @@
|
||||
package com.bsd.pjcloud.thirdparty.mapper.pay;
|
||||
|
||||
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ThirdFzOrderMapper extends PjcloudBaseMapper<ThirdFzOrderEntity> {
|
||||
|
||||
|
||||
}
|
||||
Vendored
Executable
+8
@@ -0,0 +1,8 @@
|
||||
package com.bsd.pjcloud.thirdparty.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
|
||||
public interface ThirdFzOrderService extends IService<ThirdFzOrderEntity> {
|
||||
|
||||
}
|
||||
+76
-2
@@ -1,14 +1,28 @@
|
||||
package com.bsd.pjcloud.thirdparty.service.impl.appplus.fz;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.thirdparty.config.AppPlusPayConfig;
|
||||
import com.bsd.pjcloud.thirdparty.constant.fz.ThirdFzOrderStatusEnum;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.mapper.pay.ThirdFzOrderMapper;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdAppPlusWechatFzService;
|
||||
import com.bsd.pjcloud.wallet.api.entity.mch.MchPaySettingEntity;
|
||||
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
||||
import com.wechat.pay.java.service.profitsharing.model.CreateOrderReceiver;
|
||||
import com.wechat.pay.java.service.profitsharing.model.CreateOrderRequest;
|
||||
import com.wechat.pay.java.service.profitsharing.model.OrdersEntity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 微信分账
|
||||
*/
|
||||
@@ -18,20 +32,80 @@ import org.springframework.validation.annotation.Validated;
|
||||
@RequiredArgsConstructor
|
||||
public class ThirdAppPlusWechatFzServiceImpl implements ThirdAppPlusWechatFzService {
|
||||
|
||||
private final String TAG = "微信分账(app版本)";
|
||||
|
||||
private final AppPlusPayConfig appPlusPayConfig;
|
||||
|
||||
private final ProfitsharingService profitsharingService;
|
||||
|
||||
private final ThirdFzOrderMapper thirdFzOrderMapper;
|
||||
|
||||
/**
|
||||
* 发起分账
|
||||
*/
|
||||
@Override
|
||||
public void create(ThirdPayOrderEntity orderEntity) {
|
||||
String outOrderNo = "fz" + orderEntity.getPayNo();
|
||||
// 获取配置
|
||||
if (ObjectUtil.isEmpty(orderEntity.getMchPaySettingJson())) {
|
||||
throw new RuntimeException("支付配置不存在");
|
||||
}
|
||||
ThirdFzOrderEntity fzOrderEntity = new ThirdFzOrderEntity();
|
||||
fzOrderEntity.setFzTime(LocalDateTime.now());
|
||||
fzOrderEntity.setStatus(ThirdFzOrderStatusEnum.FZ_UNPAID.getType());
|
||||
|
||||
MchPaySettingEntity mchPaySetting = JSONUtil.toBean(orderEntity.getMchPaySettingJson(), MchPaySettingEntity.class);
|
||||
MchPaySettingEntity.WechatPaySetting wechatPaySetting = JSONUtil.toBean(mchPaySetting.getSettingJson(), MchPaySettingEntity.WechatPaySetting.class);
|
||||
|
||||
AppPlusPayConfig.WechatConfig wechatConfig = appPlusPayConfig.getWechatConfig();
|
||||
|
||||
String outOrderNo = "fz" + orderEntity.getPayNo();
|
||||
// 最少分账1分
|
||||
Long amount = BigDecimal.valueOf(orderEntity.getPrice())
|
||||
.divide(BigDecimal.valueOf(100))
|
||||
.multiply(BigDecimal.valueOf(mchPaySetting.getFzRatio()))
|
||||
.setScale(2, RoundingMode.HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100))
|
||||
.longValue();
|
||||
// 确保至少1分
|
||||
if (amount < 1L) {
|
||||
amount = 1L;
|
||||
}
|
||||
// 请求参数
|
||||
CreateOrderRequest createDto = new CreateOrderRequest();
|
||||
createDto.setSubAppid(wechatPaySetting.getSubMchid());
|
||||
createDto.setTransactionId("");
|
||||
createDto.setOutOrderNo(outOrderNo);
|
||||
CreateOrderReceiver zaxReceiver = new CreateOrderReceiver();
|
||||
zaxReceiver.setType("MERCHANT_ID");
|
||||
zaxReceiver.setAccount(wechatConfig.getMerchantId());
|
||||
zaxReceiver.setName("浙江资安信信息科技有限公司");
|
||||
zaxReceiver.setAmount(amount);
|
||||
zaxReceiver.setDescription(getDescription(mchPaySetting, amount));
|
||||
createDto.setReceivers(List.of(zaxReceiver));
|
||||
createDto.setUnfreezeUnsplit(true);
|
||||
try {
|
||||
fzOrderEntity.setCreateReq(JSONUtil.toJsonStr(createDto));
|
||||
OrdersEntity orderRes = profitsharingService.createOrder(createDto);
|
||||
fzOrderEntity.setCreateRes(JSONUtil.toJsonStr(createDto));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fzOrderEntity.setCreateError(JSONUtil.toJsonStr(e));
|
||||
log.error("|{}|发起分账意外的错误,error:|{}|", TAG, e.getMessage());
|
||||
} finally {
|
||||
thirdFzOrderMapper.insert(fzOrderEntity);
|
||||
}
|
||||
}
|
||||
|
||||
profitsharingService.createOrder(createDto);
|
||||
// 分账描述,最多80个字
|
||||
private String getDescription(MchPaySettingEntity mchPaySetting, Long amount) {
|
||||
return "商户id:" + mchPaySetting.getMchId() + "分账" + mchPaySetting.getFzRatio() + "%即" + fenToYuan(BigDecimal.valueOf(amount)) + "元,到平台";
|
||||
}
|
||||
|
||||
public String fenToYuan(BigDecimal fen) {
|
||||
if (ObjectUtil.isEmpty(fen)) {
|
||||
return "0";
|
||||
}
|
||||
return fen.divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString();
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
Executable
+15
@@ -0,0 +1,15 @@
|
||||
package com.bsd.pjcloud.thirdparty.service.impl.pay;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.mapper.pay.ThirdFzOrderMapper;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdFzOrderService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 第三方支付分账
|
||||
*/
|
||||
@Service
|
||||
public class ThirdFzOrderServiceImpl extends ServiceImpl<ThirdFzOrderMapper, ThirdFzOrderEntity> implements ThirdFzOrderService {
|
||||
|
||||
}
|
||||
Vendored
Executable
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.bsd.pjcloud.thirdparty.mapper.pay.ThirdFzOrderMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in new issue
Block a user