From 466b6e9149a75e98897e8b5241fcd5841f6ee2de Mon Sep 17 00:00:00 2001 From: DevDengChao <2325690622@qq.com> Date: Wed, 12 Jun 2024 13:37:26 +0800 Subject: [PATCH 1/9] feat: add user id to pay order do --- .../api/order/dto/PayOrderCreateReqDTO.java | 4 + .../pay/dal/dataobject/order/PayOrderDO.java | 22 +- .../service/demo/PayDemoOrderServiceImpl.java | 3 +- .../wallet/PayWalletRechargeServiceImpl.java | 3 +- .../src/test/resources/sql/create_tables.sql | 204 +++++++++--------- 5 files changed, 127 insertions(+), 109 deletions(-) diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/order/dto/PayOrderCreateReqDTO.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/order/dto/PayOrderCreateReqDTO.java index a960488281..6d4e01271f 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/order/dto/PayOrderCreateReqDTO.java +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/order/dto/PayOrderCreateReqDTO.java @@ -28,6 +28,10 @@ public class PayOrderCreateReqDTO implements Serializable { @NotEmpty(message = "用户 IP 不能为空") private String userIp; + + @NotEmpty(message = "用户 Id 不能为空") + private Long userId; + // ========== 商户相关字段 ========== /** diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/order/PayOrderDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/order/PayOrderDO.java index a51b875fd1..6cad230c39 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/order/PayOrderDO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/order/PayOrderDO.java @@ -32,19 +32,19 @@ public class PayOrderDO extends BaseDO { private Long id; /** * 应用编号 - * + *
* 关联 {@link PayAppDO#getId()} */ private Long appId; /** * 渠道编号 - * + *
* 关联 {@link PayChannelDO#getId()} */ private Long channelId; /** * 渠道编码 - * + *
* 枚举 {@link PayChannelEnum} */ private String channelCode; @@ -53,7 +53,7 @@ public class PayOrderDO extends BaseDO { /** * 商户订单编号 - * + *
* 例如说,内部系统 A 的订单号,需要保证每个 PayAppDO 唯一 */ private String merchantOrderId; @@ -78,7 +78,7 @@ public class PayOrderDO extends BaseDO { private Integer price; /** * 渠道手续费,单位:百分比 - * + *
* 冗余 {@link PayChannelDO#getFeeRate()} */ private Double channelFeeRate; @@ -88,7 +88,7 @@ public class PayOrderDO extends BaseDO { private Integer channelFeePrice; /** * 支付状态 - * + *
* 枚举 {@link PayOrderStatusEnum} */ private Integer status; @@ -96,6 +96,10 @@ public class PayOrderDO extends BaseDO { * 用户 IP */ private String userIp; + /** + * 用户 IP + */ + private Long userId; /** * 订单失效时间 */ @@ -106,13 +110,13 @@ public class PayOrderDO extends BaseDO { private LocalDateTime successTime; /** * 支付成功的订单拓展单编号 - * + *
* 关联 {@link PayOrderExtensionDO#getId()} */ private Long extensionId; /** * 支付成功的外部订单号 - * + *
* 关联 {@link PayOrderExtensionDO#getNo()} */ private String no; @@ -126,7 +130,7 @@ public class PayOrderDO extends BaseDO { // ========== 渠道相关字段 ========== /** * 渠道用户编号 - * + *
* 例如说,微信 openid、支付宝账号
*/
private String channelUserId;
diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/demo/PayDemoOrderServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/demo/PayDemoOrderServiceImpl.java
index 8173905373..76b77396d8 100644
--- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/demo/PayDemoOrderServiceImpl.java
+++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/demo/PayDemoOrderServiceImpl.java
@@ -88,7 +88,8 @@ public Long createDemoOrder(Long userId, PayDemoOrderCreateReqVO createReqVO) {
// 2.1 创建支付单
Long payOrderId = payOrderApi.createOrder(new PayOrderCreateReqDTO()
- .setAppId(PAY_APP_ID).setUserIp(getClientIP()) // 支付应用
+ .setAppId(PAY_APP_ID) // 支付应用
+ .setUserIp(getClientIP()).setUserId(userId)
.setMerchantOrderId(demoOrder.getId().toString()) // 业务的订单编号
.setSubject(spuName).setBody("").setPrice(price) // 价格信息
.setExpireTime(addTime(Duration.ofHours(2L)))); // 支付的过期时间
diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java
index b263189222..f27a14943a 100644
--- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java
+++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java
@@ -83,7 +83,8 @@ public PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, S
// 2.1 创建支付单
Long payOrderId = payOrderService.createOrder(new PayOrderCreateReqDTO()
- .setAppId(WALLET_PAY_APP_ID).setUserIp(userIp)
+ .setAppId(WALLET_PAY_APP_ID)
+ .setUserIp(userIp).setUserId(userId)
.setMerchantOrderId(recharge.getId().toString()) // 业务的订单编号
.setSubject(WALLET_RECHARGE_ORDER_SUBJECT).setBody("")
.setPrice(recharge.getPayPrice())
diff --git a/yudao-module-pay/yudao-module-pay-biz/src/test/resources/sql/create_tables.sql b/yudao-module-pay/yudao-module-pay-biz/src/test/resources/sql/create_tables.sql
index 6ae2ce2d44..ea639ed002 100644
--- a/yudao-module-pay/yudao-module-pay-biz/src/test/resources/sql/create_tables.sql
+++ b/yudao-module-pay/yudao-module-pay-biz/src/test/resources/sql/create_tables.sql
@@ -1,9 +1,10 @@
-CREATE TABLE IF NOT EXISTS "pay_app" (
+CREATE TABLE IF NOT EXISTS "pay_app"
+(
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar(64) NOT NULL,
"status" tinyint NOT NULL,
"remark" varchar(255) DEFAULT NULL,
- `order_notify_url` varchar(1024) NOT NULL,
+ `order_notify_url` varchar(1024) NOT NULL,
`refund_notify_url` varchar(1024) NOT NULL,
"creator" varchar(64) DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -13,7 +14,8 @@ CREATE TABLE IF NOT EXISTS "pay_app" (
PRIMARY KEY ("id")
) COMMENT = '支付应用';
-CREATE TABLE IF NOT EXISTS "pay_channel" (
+CREATE TABLE IF NOT EXISTS "pay_channel"
+(
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"code" varchar(32) NOT NULL,
"status" tinyint(4) NOT NULL,
@@ -26,121 +28,127 @@ CREATE TABLE IF NOT EXISTS "pay_channel" (
"updater" varchar(64) NULL DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit(1) NOT NULL DEFAULT FALSE,
- "tenant_id" bigint not null default '0',
+ "tenant_id" bigint not null default '0',
PRIMARY KEY ("id")
) COMMENT = '支付渠道';
-CREATE TABLE IF NOT EXISTS `pay_order` (
+CREATE TABLE IF NOT EXISTS `pay_order`
+(
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
- `app_id` bigint(20) NOT NULL,
- `channel_id` bigint(20) DEFAULT NULL,
- `channel_code` varchar(32) DEFAULT NULL,
- `merchant_order_id` varchar(64) NOT NULL,
- `subject` varchar(32) NOT NULL,
- `body` varchar(128) NOT NULL,
- `notify_url` varchar(1024) NOT NULL,
- `price` bigint(20) NOT NULL,
- `channel_fee_rate` double DEFAULT 0,
- `channel_fee_price` bigint(20) DEFAULT 0,
- `status` tinyint(4) NOT NULL,
- `user_ip` varchar(50) NOT NULL,
- `expire_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `success_time` datetime(0) DEFAULT CURRENT_TIMESTAMP,
- `notify_time` datetime(0) DEFAULT CURRENT_TIMESTAMP,
- `extension_id` bigint(20) DEFAULT NULL,
- `no` varchar(64) NULL,
- `refund_price` bigint(20) NOT NULL,
- `channel_user_id` varchar(255) DEFAULT NULL,
- `channel_order_no` varchar(64) DEFAULT NULL,
- `creator` varchar(64) DEFAULT '',
- `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `updater` varchar(64) DEFAULT '',
- `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `deleted` bit(1) NOT NULL DEFAULT FALSE,
+ `app_id` bigint(20) NOT NULL,
+ `channel_id` bigint(20) DEFAULT NULL,
+ `channel_code` varchar(32) DEFAULT NULL,
+ `merchant_order_id` varchar(64) NOT NULL,
+ `subject` varchar(32) NOT NULL,
+ `body` varchar(128) NOT NULL,
+ `notify_url` varchar(1024) NOT NULL,
+ `price` bigint(20) NOT NULL,
+ `channel_fee_rate` double DEFAULT 0,
+ `channel_fee_price` bigint(20) DEFAULT 0,
+ `status` tinyint(4) NOT NULL,
+ `user_ip` varchar(50) NOT NULL,
+ `user_id` bigint(20) NOT NULL,
+ `expire_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `success_time` datetime(0) DEFAULT CURRENT_TIMESTAMP,
+ `notify_time` datetime(0) DEFAULT CURRENT_TIMESTAMP,
+ `extension_id` bigint(20) DEFAULT NULL,
+ `no` varchar(64) NULL,
+ `refund_price` bigint(20) NOT NULL,
+ `channel_user_id` varchar(255) DEFAULT NULL,
+ `channel_order_no` varchar(64) DEFAULT NULL,
+ `creator` varchar(64) DEFAULT '',
+ `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `updater` varchar(64) DEFAULT '',
+ `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `deleted` bit(1) NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT = '支付订单';
-CREATE TABLE IF NOT EXISTS `pay_order_extension` (
+CREATE TABLE IF NOT EXISTS `pay_order_extension`
+(
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
- `no` varchar(64) NOT NULL,
- `order_id` bigint(20) NOT NULL,
- `channel_id` bigint(20) NOT NULL,
- `channel_code` varchar(32) NOT NULL,
- `user_ip` varchar(50) NULL DEFAULT NULL,
- `status` tinyint(4) NOT NULL,
- `channel_extras` varchar(1024) NULL DEFAULT NULL,
- `channel_error_code` varchar(64) NULL,
- `channel_error_msg` varchar(64) NULL,
- `channel_notify_data` varchar(1024) NULL,
- `creator` varchar(64) NULL DEFAULT '',
- `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `updater` varchar(64) NULL DEFAULT '',
- `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `deleted` bit(1) NOT NULL DEFAULT FALSE,
+ `no` varchar(64) NOT NULL,
+ `order_id` bigint(20) NOT NULL,
+ `channel_id` bigint(20) NOT NULL,
+ `channel_code` varchar(32) NOT NULL,
+ `user_ip` varchar(50) NULL DEFAULT NULL,
+ `status` tinyint(4) NOT NULL,
+ `channel_extras` varchar(1024) NULL DEFAULT NULL,
+ `channel_error_code` varchar(64) NULL,
+ `channel_error_msg` varchar(64) NULL,
+ `channel_notify_data` varchar(1024) NULL,
+ `creator` varchar(64) NULL DEFAULT '',
+ `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `updater` varchar(64) NULL DEFAULT '',
+ `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `deleted` bit(1) NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT = '支付订单拓展';
-CREATE TABLE IF NOT EXISTS `pay_refund` (
+CREATE TABLE IF NOT EXISTS `pay_refund`
+(
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
- `no` varchar(64) NOT NULL,
- `app_id` bigint(20) NOT NULL,
- `channel_id` bigint(20) NOT NULL,
- `channel_code` varchar(32) NOT NULL,
- `order_id` bigint(20) NOT NULL,
- `order_no` varchar(64) NOT NULL,
- `merchant_order_id` varchar(64) NOT NULL,
- `merchant_refund_id` varchar(64) NOT NULL,
- `notify_url` varchar(1024) NOT NULL,
- `status` tinyint(4) NOT NULL,
- `pay_price` bigint(20) NOT NULL,
- `refund_price` bigint(20) NOT NULL,
- `reason` varchar(256) NOT NULL,
- `user_ip` varchar(50) NULL DEFAULT NULL,
- `channel_order_no` varchar(64) NOT NULL,
- `channel_refund_no` varchar(64) NULL DEFAULT NULL,
- `success_time` datetime(0) NULL DEFAULT NULL,
- `channel_error_code` varchar(128) NULL DEFAULT NULL,
- `channel_error_msg` varchar(256) NULL DEFAULT NULL,
- `channel_notify_data` varchar(1024) NULL,
- `creator` varchar(64) NULL DEFAULT '',
- `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `updater` varchar(64) NULL DEFAULT '',
- `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `deleted` bit(1) NOT NULL DEFAULT FALSE,
+ `no` varchar(64) NOT NULL,
+ `app_id` bigint(20) NOT NULL,
+ `channel_id` bigint(20) NOT NULL,
+ `channel_code` varchar(32) NOT NULL,
+ `order_id` bigint(20) NOT NULL,
+ `order_no` varchar(64) NOT NULL,
+ `merchant_order_id` varchar(64) NOT NULL,
+ `merchant_refund_id` varchar(64) NOT NULL,
+ `notify_url` varchar(1024) NOT NULL,
+ `status` tinyint(4) NOT NULL,
+ `pay_price` bigint(20) NOT NULL,
+ `refund_price` bigint(20) NOT NULL,
+ `reason` varchar(256) NOT NULL,
+ `user_ip` varchar(50) NULL DEFAULT NULL,
+ `channel_order_no` varchar(64) NOT NULL,
+ `channel_refund_no` varchar(64) NULL DEFAULT NULL,
+ `success_time` datetime(0) NULL DEFAULT NULL,
+ `channel_error_code` varchar(128) NULL DEFAULT NULL,
+ `channel_error_msg` varchar(256) NULL DEFAULT NULL,
+ `channel_notify_data` varchar(1024) NULL,
+ `creator` varchar(64) NULL DEFAULT '',
+ `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `updater` varchar(64) NULL DEFAULT '',
+ `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `deleted` bit(1) NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT = '退款订单';
-CREATE TABLE IF NOT EXISTS `pay_notify_task` (
+CREATE TABLE IF NOT EXISTS `pay_notify_task`
+(
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
- `app_id` bigint(20) NOT NULL,
- `type` tinyint(4) NOT NULL,
+ `app_id` bigint(20) NOT NULL,
+ `type` tinyint(4) NOT NULL,
`data_id` bigint(20) NOT NULL,
- `merchant_order_id` varchar(64) NOT NULL,
- `status` tinyint(4) NOT NULL,
- `next_notify_time` datetime(0) NULL DEFAULT NULL,
- `last_execute_time` datetime(0) NULL DEFAULT NULL,
- `notify_times` int NOT NULL,
- `max_notify_times` int NOT NULL,
- `notify_url` varchar(1024) NOT NULL,
- `creator` varchar(64) NULL DEFAULT '',
- `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `updater` varchar(64) NULL DEFAULT '',
- `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `deleted` bit(1) NOT NULL DEFAULT FALSE,
- `tenant_id` bigint(20) NOT NULL DEFAULT 0,
+ `merchant_order_id` varchar(64) NOT NULL,
+ `status` tinyint(4) NOT NULL,
+ `next_notify_time` datetime(0) NULL DEFAULT NULL,
+ `last_execute_time` datetime(0) NULL DEFAULT NULL,
+ `notify_times` int NOT NULL,
+ `max_notify_times` int NOT NULL,
+ `notify_url` varchar(1024) NOT NULL,
+ `creator` varchar(64) NULL DEFAULT '',
+ `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `updater` varchar(64) NULL DEFAULT '',
+ `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `deleted` bit(1) NOT NULL DEFAULT FALSE,
+ `tenant_id` bigint(20) NOT NULL DEFAULT 0,
PRIMARY KEY ("id")
) COMMENT = '支付通知任务';
-CREATE TABLE IF NOT EXISTS `pay_notify_log` (
+CREATE TABLE IF NOT EXISTS `pay_notify_log`
+(
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
- `task_id` bigint(20) NOT NULL,
- `notify_times` int NOT NULL,
- `response` varchar(1024) NOT NULL,
- `status` tinyint(4) NOT NULL,
- `creator` varchar(64) NULL DEFAULT '',
- `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `updater` varchar(64) NULL DEFAULT '',
- `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `deleted` bit(1) NOT NULL DEFAULT FALSE,
+ `task_id` bigint(20) NOT NULL,
+ `notify_times` int NOT NULL,
+ `response` varchar(1024) NOT NULL,
+ `status` tinyint(4) NOT NULL,
+ `creator` varchar(64) NULL DEFAULT '',
+ `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `updater` varchar(64) NULL DEFAULT '',
+ `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `deleted` bit(1) NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT = '支付通知日志';
From 0ebd8b5b7bbb149b68bed5713f0f19fc2bfc8e05 Mon Sep 17 00:00:00 2001
From: DevDengChao <2325690622@qq.com>
Date: Wed, 12 Jun 2024 14:03:30 +0800
Subject: [PATCH 2/9] feat: query pay order page by user id
---
.../pay/controller/admin/order/vo/PayOrderPageReqVO.java | 3 +++
.../yudao/module/pay/dal/mysql/order/PayOrderMapper.java | 1 +
2 files changed, 4 insertions(+)
diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderPageReqVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderPageReqVO.java
index f7ff801cb3..74a5f44ff9 100755
--- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderPageReqVO.java
+++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderPageReqVO.java
@@ -20,6 +20,9 @@ public class PayOrderPageReqVO extends PageParam {
@Schema(description = "应用编号", example = "1024")
private Long appId;
+ @Schema(description = "用户 id", example = "1024")
+ private Long userId;
+
@Schema(description = "渠道编码", example = "wx_app")
private String channelCode;
diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/order/PayOrderMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/order/PayOrderMapper.java
index 95510d5f7e..bdb3bc06db 100755
--- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/order/PayOrderMapper.java
+++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/order/PayOrderMapper.java
@@ -18,6 +18,7 @@ public interface PayOrderMapper extends BaseMapperX