feat(payment): 优化支付方式并确保系统平滑迁移
-将19种复杂支付方式简化为8种核心支付方式 - 更新PaymentType枚举,添加废弃支付方式的兼容处理 - 新增PaymentTypeCompatibilityUtil工具类,用于支付方式迁移 - 更新ShopOrder和ShopOrderParam的支付方式描述 - 修改ShopOrderServiceImpl中的支付处理逻辑 - 添加单元测试,验证支付方式优化后的功能正确性
This commit is contained in:
210
docs/支付方式优化迁移指南.md
Normal file
210
docs/支付方式优化迁移指南.md
Normal file
@@ -0,0 +1,210 @@
|
||||
# 支付方式优化迁移指南
|
||||
|
||||
## 📋 概述
|
||||
|
||||
本文档说明如何将现有的复杂支付方式(19种)简化为8种核心支付方式,提高系统的可维护性和用户体验。
|
||||
|
||||
## 🎯 优化目标
|
||||
|
||||
- **简化支付方式**:从19种减少到8种核心支付方式
|
||||
- **提高可维护性**:减少代码复杂度和维护成本
|
||||
- **保持兼容性**:确保现有数据和业务逻辑正常运行
|
||||
- **改善用户体验**:简化支付选择,提高支付成功率
|
||||
|
||||
## 📊 支付方式映射表
|
||||
|
||||
### ✅ 保留的核心支付方式(8种)
|
||||
|
||||
| 代码 | 名称 | 渠道 | 说明 |
|
||||
|------|------|------|------|
|
||||
| 0 | 余额支付 | balance | 用户账户余额扣减 |
|
||||
| 1 | 微信支付 | wechat | 包含JSAPI和Native两种模式 |
|
||||
| 2 | 支付宝支付 | alipay | 支付宝在线支付 |
|
||||
| 3 | 银联支付 | union_pay | 银联在线支付 |
|
||||
| 4 | 现金支付 | cash | 线下现金收款 |
|
||||
| 5 | POS机支付 | pos | 线下刷卡支付 |
|
||||
| 6 | 免费 | free | 免费商品或活动 |
|
||||
| 7 | 积分支付 | points | 用户积分兑换 |
|
||||
|
||||
### ⚠️ 废弃的支付方式映射
|
||||
|
||||
| 原代码 | 原名称 | 建议迁移到 | 迁移说明 |
|
||||
|--------|--------|------------|----------|
|
||||
| 2 | 会员卡支付 | 0 (余额支付) | 会员卡余额转为用户余额 |
|
||||
| 3 | 支付宝支付(旧) | 2 (支付宝支付) | 编号调整:3→2 |
|
||||
| 6 | VIP月卡 | 0 (余额支付) | VIP卡余额转为用户余额 |
|
||||
| 7 | VIP年卡 | 0 (余额支付) | VIP卡余额转为用户余额 |
|
||||
| 8 | VIP次卡 | 0 (余额支付) | VIP卡余额转为用户余额 |
|
||||
| 9 | IC月卡 | 0 (余额支付) | IC卡余额转为用户余额 |
|
||||
| 10 | IC年卡 | 0 (余额支付) | IC卡余额转为用户余额 |
|
||||
| 11 | IC次卡 | 0 (余额支付) | IC卡余额转为用户余额 |
|
||||
| 12 | 免费(旧) | 6 (免费) | 编号调整:12→6 |
|
||||
| 13 | VIP充值卡 | 0 (余额支付) | 充值卡余额转为用户余额 |
|
||||
| 14 | IC充值卡 | 0 (余额支付) | 充值卡余额转为用户余额 |
|
||||
| 15 | 积分支付(旧) | 7 (积分支付) | 编号调整:15→7 |
|
||||
| 16 | VIP季卡 | 0 (余额支付) | VIP卡余额转为用户余额 |
|
||||
| 17 | IC季卡 | 0 (余额支付) | IC卡余额转为用户余额 |
|
||||
| 18 | 代付 | 1 (微信支付) | 通过代付字段记录代付信息 |
|
||||
| 19 | 银联支付(旧) | 3 (银联支付) | 编号调整:19→3 |
|
||||
| 102 | 微信Native | 1 (微信支付) | 合并到微信支付,自动选择支付模式 |
|
||||
|
||||
## 🔧 技术实现
|
||||
|
||||
### 1. 枚举类更新
|
||||
|
||||
已更新 `PaymentType.java`:
|
||||
- 保留8种核心支付方式
|
||||
- 废弃的支付方式标记为 `@Deprecated`
|
||||
- 添加兼容性方法:`isCorePaymentType()`, `isDeprecated()`
|
||||
|
||||
### 2. 业务逻辑兼容
|
||||
|
||||
已更新 `ShopOrderServiceImpl.java`:
|
||||
- 微信支付(1)自动根据openid选择JSAPI或Native模式
|
||||
- 保持对旧的微信Native(102)的兼容支持
|
||||
- 添加废弃支付方式的警告日志
|
||||
|
||||
### 3. 实体类注释更新
|
||||
|
||||
已更新相关实体类的Schema描述:
|
||||
- `ShopOrder.java`
|
||||
- `ShopOrderParam.java`
|
||||
|
||||
## 📝 数据迁移SQL
|
||||
|
||||
### 3.1 查看现有支付方式分布
|
||||
|
||||
```sql
|
||||
-- 查看当前系统中各支付方式的使用情况
|
||||
SELECT
|
||||
pay_type,
|
||||
COUNT(*) as order_count,
|
||||
SUM(total_price) as total_amount
|
||||
FROM shop_order
|
||||
WHERE pay_status = 1
|
||||
GROUP BY pay_type
|
||||
ORDER BY order_count DESC;
|
||||
```
|
||||
|
||||
### 3.2 迁移废弃的支付方式
|
||||
|
||||
```sql
|
||||
-- 第一步:调整编号映射(旧编号到新编号)
|
||||
UPDATE shop_order SET pay_type = 2, comments = CONCAT(IFNULL(comments, ''), ' [支付宝编号调整: 3→2]') WHERE pay_type = 3;
|
||||
UPDATE shop_order SET pay_type = 6, comments = CONCAT(IFNULL(comments, ''), ' [免费编号调整: 12→6]') WHERE pay_type = 12;
|
||||
UPDATE shop_order SET pay_type = 7, comments = CONCAT(IFNULL(comments, ''), ' [积分支付编号调整: 15→7]') WHERE pay_type = 15;
|
||||
UPDATE shop_order SET pay_type = 3, comments = CONCAT(IFNULL(comments, ''), ' [银联支付编号调整: 19→3]') WHERE pay_type = 19;
|
||||
|
||||
-- 第二步:将会员卡类支付迁移为余额支付
|
||||
UPDATE shop_order
|
||||
SET pay_type = 0,
|
||||
comments = CONCAT(IFNULL(comments, ''), ' [原支付方式: ',
|
||||
CASE pay_type
|
||||
WHEN 2 THEN '会员卡支付'
|
||||
WHEN 6 THEN 'VIP月卡'
|
||||
WHEN 7 THEN 'VIP年卡'
|
||||
WHEN 8 THEN 'VIP次卡'
|
||||
WHEN 9 THEN 'IC月卡'
|
||||
WHEN 10 THEN 'IC年卡'
|
||||
WHEN 11 THEN 'IC次卡'
|
||||
WHEN 13 THEN 'VIP充值卡'
|
||||
WHEN 14 THEN 'IC充值卡'
|
||||
WHEN 16 THEN 'VIP季卡'
|
||||
WHEN 17 THEN 'IC季卡'
|
||||
END, ']')
|
||||
WHERE pay_type IN (2, 6, 7, 8, 9, 10, 11, 13, 14, 16, 17);
|
||||
|
||||
-- 第三步:将微信Native支付迁移为微信支付
|
||||
UPDATE shop_order
|
||||
SET pay_type = 1,
|
||||
comments = CONCAT(IFNULL(comments, ''), ' [原支付方式: 微信Native支付]')
|
||||
WHERE pay_type = 102;
|
||||
|
||||
-- 第四步:处理代付支付方式
|
||||
UPDATE shop_order
|
||||
SET pay_type = IFNULL(friend_pay_type, 1),
|
||||
comments = CONCAT(IFNULL(comments, ''), ' [原为代付支付]')
|
||||
WHERE pay_type = 18;
|
||||
```
|
||||
|
||||
## ⚡ 部署步骤
|
||||
|
||||
### 1. 预部署检查
|
||||
|
||||
```bash
|
||||
# 1. 备份数据库
|
||||
mysqldump -u username -p database_name > backup_before_payment_migration.sql
|
||||
|
||||
# 2. 检查当前支付方式分布
|
||||
mysql -u username -p -e "
|
||||
SELECT pay_type, COUNT(*) as count
|
||||
FROM shop_order
|
||||
GROUP BY pay_type
|
||||
ORDER BY count DESC;"
|
||||
```
|
||||
|
||||
### 2. 代码部署
|
||||
|
||||
1. 部署更新后的代码
|
||||
2. 重启应用服务
|
||||
3. 验证支付功能正常
|
||||
|
||||
### 3. 数据迁移
|
||||
|
||||
1. 执行上述迁移SQL
|
||||
2. 验证数据迁移结果
|
||||
3. 清理废弃的支付配置
|
||||
|
||||
### 4. 后续清理
|
||||
|
||||
等待1-2个版本后,可以完全移除废弃的枚举值:
|
||||
|
||||
```java
|
||||
// 最终版本的PaymentType枚举(移除所有@Deprecated项)
|
||||
public enum PaymentType {
|
||||
BALANCE(0, "余额支付", "balance"),
|
||||
WECHAT(1, "微信支付", "wechat"),
|
||||
ALIPAY(3, "支付宝支付", "alipay"),
|
||||
CASH(4, "现金支付", "cash"),
|
||||
POS(5, "POS机支付", "pos"),
|
||||
FREE(12, "免费", "free"),
|
||||
POINTS(15, "积分支付", "points"),
|
||||
UNION_PAY(19, "银联支付", "union_pay");
|
||||
}
|
||||
```
|
||||
|
||||
## 🧪 测试建议
|
||||
|
||||
### 1. 功能测试
|
||||
|
||||
- [ ] 测试8种核心支付方式的正常流程
|
||||
- [ ] 测试废弃支付方式的兼容性
|
||||
- [ ] 测试支付回调处理
|
||||
- [ ] 测试退款功能
|
||||
|
||||
### 2. 数据验证
|
||||
|
||||
- [ ] 验证迁移后的订单数据完整性
|
||||
- [ ] 验证支付统计报表的准确性
|
||||
- [ ] 验证用户余额的正确性
|
||||
|
||||
## 📈 预期收益
|
||||
|
||||
1. **代码简化**:减少50%以上的支付相关代码复杂度
|
||||
2. **维护成本降低**:减少支付方式维护工作量
|
||||
3. **用户体验提升**:简化支付选择,提高转化率
|
||||
4. **系统稳定性**:减少支付相关的bug和异常
|
||||
|
||||
## ⚠️ 注意事项
|
||||
|
||||
1. **数据备份**:迁移前务必备份数据库
|
||||
2. **分步实施**:建议分阶段实施,先标记废弃,后续版本再移除
|
||||
3. **监控告警**:部署后密切监控支付成功率和异常情况
|
||||
4. **用户通知**:如有必要,提前通知用户支付方式的变更
|
||||
|
||||
## 🔗 相关文件
|
||||
|
||||
- `src/main/java/com/gxwebsoft/payment/enums/PaymentType.java` - 支付类型枚举
|
||||
- `src/main/java/com/gxwebsoft/shop/entity/ShopOrder.java` - 订单实体
|
||||
- `src/main/java/com/gxwebsoft/shop/service/impl/ShopOrderServiceImpl.java` - 订单服务实现
|
||||
- `src/main/java/com/gxwebsoft/payment/strategy/` - 支付策略实现目录
|
||||
@@ -12,17 +12,14 @@ public enum PaymentType {
|
||||
/** 余额支付 */
|
||||
BALANCE(0, "余额支付", "balance"),
|
||||
|
||||
/** 微信支付 */
|
||||
/** 微信支付(包含JSAPI和Native) */
|
||||
WECHAT(1, "微信支付", "wechat"),
|
||||
|
||||
/** 微信Native支付 */
|
||||
WECHAT_NATIVE(102, "微信Native支付", "wechat_native"),
|
||||
|
||||
/** 会员卡支付 */
|
||||
MEMBER_CARD(2, "会员卡支付", "member_card"),
|
||||
|
||||
/** 支付宝支付 */
|
||||
ALIPAY(3, "支付宝支付", "alipay"),
|
||||
ALIPAY(2, "支付宝支付", "alipay"),
|
||||
|
||||
/** 银联支付 */
|
||||
UNION_PAY(3, "银联支付", "union_pay"),
|
||||
|
||||
/** 现金支付 */
|
||||
CASH(4, "现金支付", "cash"),
|
||||
@@ -30,47 +27,81 @@ public enum PaymentType {
|
||||
/** POS机支付 */
|
||||
POS(5, "POS机支付", "pos"),
|
||||
|
||||
/** VIP月卡 */
|
||||
VIP_MONTHLY(6, "VIP月卡", "vip_monthly"),
|
||||
|
||||
/** VIP年卡 */
|
||||
VIP_YEARLY(7, "VIP年卡", "vip_yearly"),
|
||||
|
||||
/** VIP次卡 */
|
||||
VIP_COUNT(8, "VIP次卡", "vip_count"),
|
||||
|
||||
/** IC月卡 */
|
||||
IC_MONTHLY(9, "IC月卡", "ic_monthly"),
|
||||
|
||||
/** IC年卡 */
|
||||
IC_YEARLY(10, "IC年卡", "ic_yearly"),
|
||||
|
||||
/** IC次卡 */
|
||||
IC_COUNT(11, "IC次卡", "ic_count"),
|
||||
|
||||
/** 免费 */
|
||||
FREE(12, "免费", "free"),
|
||||
|
||||
/** VIP充值卡 */
|
||||
VIP_RECHARGE(13, "VIP充值卡", "vip_recharge"),
|
||||
|
||||
/** IC充值卡 */
|
||||
IC_RECHARGE(14, "IC充值卡", "ic_recharge"),
|
||||
FREE(6, "免费", "free"),
|
||||
|
||||
/** 积分支付 */
|
||||
POINTS(15, "积分支付", "points"),
|
||||
POINTS(7, "积分支付", "points"),
|
||||
|
||||
/** VIP季卡 */
|
||||
// ========== 已废弃的支付方式(保留用于数据兼容) ==========
|
||||
|
||||
/** @deprecated 微信Native支付 - 已合并到WECHAT */
|
||||
@Deprecated
|
||||
WECHAT_NATIVE(102, "微信Native支付", "wechat_native"),
|
||||
|
||||
/** @deprecated 会员卡支付 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
MEMBER_CARD_OLD(8, "会员卡支付", "member_card"),
|
||||
|
||||
/** @deprecated VIP月卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
VIP_MONTHLY(9, "VIP月卡", "vip_monthly"),
|
||||
|
||||
/** @deprecated VIP年卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
VIP_YEARLY(10, "VIP年卡", "vip_yearly"),
|
||||
|
||||
/** @deprecated VIP次卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
VIP_COUNT(11, "VIP次卡", "vip_count"),
|
||||
|
||||
/** @deprecated 免费(旧编号) - 已迁移到新编号6 */
|
||||
@Deprecated
|
||||
FREE_OLD(12, "免费", "free"),
|
||||
|
||||
/** @deprecated VIP充值卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
VIP_RECHARGE(13, "VIP充值卡", "vip_recharge"),
|
||||
|
||||
/** @deprecated IC充值卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
IC_RECHARGE(14, "IC充值卡", "ic_recharge"),
|
||||
|
||||
/** @deprecated 积分支付(旧编号) - 已迁移到新编号7 */
|
||||
@Deprecated
|
||||
POINTS_OLD(15, "积分支付", "points"),
|
||||
|
||||
/** @deprecated VIP季卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
VIP_QUARTERLY(16, "VIP季卡", "vip_quarterly"),
|
||||
|
||||
/** IC季卡 */
|
||||
IC_QUARTERLY(17, "IC季卡", "ic_quarterly"),
|
||||
/** @deprecated IC月卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
IC_MONTHLY(17, "IC月卡", "ic_monthly"),
|
||||
|
||||
/** 代付 */
|
||||
PROXY_PAY(18, "代付", "proxy_pay"),
|
||||
/** @deprecated IC年卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
IC_YEARLY(18, "IC年卡", "ic_yearly"),
|
||||
|
||||
/** 银联支付 */
|
||||
UNION_PAY(19, "银联支付", "union_pay");
|
||||
/** @deprecated IC次卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
IC_COUNT(19, "IC次卡", "ic_count"),
|
||||
|
||||
/** @deprecated IC季卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
IC_QUARTERLY(20, "IC季卡", "ic_quarterly"),
|
||||
|
||||
/** @deprecated 代付 - 建议通过业务逻辑实现 */
|
||||
@Deprecated
|
||||
PROXY_PAY(21, "代付", "proxy_pay"),
|
||||
|
||||
/** @deprecated 支付宝(旧编号) - 已迁移到新编号2 */
|
||||
@Deprecated
|
||||
ALIPAY_OLD(22, "支付宝支付", "alipay"),
|
||||
|
||||
/** @deprecated 银联支付(旧编号) - 已迁移到新编号3 */
|
||||
@Deprecated
|
||||
UNION_PAY_OLD(23, "银联支付", "union_pay");
|
||||
|
||||
private final Integer code;
|
||||
private final String name;
|
||||
@@ -146,13 +177,30 @@ public enum PaymentType {
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为卡类支付
|
||||
* 是否为卡类支付(已废弃的支付方式)
|
||||
* @deprecated 卡类支付已废弃,建议使用余额支付
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isCardPay() {
|
||||
return this == MEMBER_CARD ||
|
||||
return this == MEMBER_CARD_OLD ||
|
||||
this == VIP_MONTHLY || this == VIP_YEARLY || this == VIP_COUNT || this == VIP_QUARTERLY ||
|
||||
this == IC_MONTHLY || this == IC_YEARLY || this == IC_COUNT || this == IC_QUARTERLY ||
|
||||
this == VIP_RECHARGE || this == IC_RECHARGE;
|
||||
this == VIP_RECHARGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为推荐使用的核心支付方式
|
||||
*/
|
||||
public boolean isCorePaymentType() {
|
||||
return this == BALANCE || this == WECHAT || this == ALIPAY || this == UNION_PAY ||
|
||||
this == CASH || this == POS || this == FREE || this == POINTS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为已废弃的支付方式
|
||||
*/
|
||||
public boolean isDeprecated() {
|
||||
return !isCorePaymentType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
package com.gxwebsoft.payment.utils;
|
||||
|
||||
import com.gxwebsoft.payment.enums.PaymentType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 支付方式兼容性处理工具类
|
||||
* 处理废弃支付方式到核心支付方式的映射转换
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2025-08-30
|
||||
*/
|
||||
@Slf4j
|
||||
public class PaymentTypeCompatibilityUtil {
|
||||
|
||||
/**
|
||||
* 废弃支付方式到核心支付方式的映射表
|
||||
*/
|
||||
private static final Map<Integer, Integer> DEPRECATED_TO_CORE_MAPPING = new HashMap<>();
|
||||
|
||||
static {
|
||||
// 旧编号到新编号的映射
|
||||
DEPRECATED_TO_CORE_MAPPING.put(3, 2); // 支付宝(旧3) -> 支付宝(新2)
|
||||
DEPRECATED_TO_CORE_MAPPING.put(12, 6); // 免费(旧12) -> 免费(新6)
|
||||
DEPRECATED_TO_CORE_MAPPING.put(15, 7); // 积分支付(旧15) -> 积分支付(新7)
|
||||
DEPRECATED_TO_CORE_MAPPING.put(19, 3); // 银联支付(旧19) -> 银联支付(新3)
|
||||
|
||||
// 会员卡类支付 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(2, 0); // 会员卡支付 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(6, 0); // VIP月卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(7, 0); // VIP年卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(8, 0); // VIP次卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(9, 0); // IC月卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(10, 0); // IC年卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(11, 0); // IC次卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(13, 0); // VIP充值卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(14, 0); // IC充值卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(16, 0); // VIP季卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(17, 0); // IC季卡 -> 余额支付
|
||||
|
||||
// 微信Native -> 微信支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(102, 1); // 微信Native -> 微信支付
|
||||
|
||||
// 代付 -> 微信支付(默认)
|
||||
DEPRECATED_TO_CORE_MAPPING.put(18, 1); // 代付 -> 微信支付
|
||||
}
|
||||
|
||||
/**
|
||||
* 将废弃的支付方式转换为核心支付方式
|
||||
*
|
||||
* @param originalPayType 原始支付方式代码
|
||||
* @return 转换后的核心支付方式代码
|
||||
*/
|
||||
public static Integer convertToCore(Integer originalPayType) {
|
||||
if (originalPayType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 检查是否为废弃的支付方式
|
||||
if (DEPRECATED_TO_CORE_MAPPING.containsKey(originalPayType)) {
|
||||
Integer corePayType = DEPRECATED_TO_CORE_MAPPING.get(originalPayType);
|
||||
log.warn("检测到废弃的支付方式: {} -> {},建议升级到核心支付方式",
|
||||
originalPayType, corePayType);
|
||||
return corePayType;
|
||||
}
|
||||
|
||||
// 如果是核心支付方式,直接返回
|
||||
return originalPayType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查支付方式是否已废弃
|
||||
*
|
||||
* @param payType 支付方式代码
|
||||
* @return true表示已废弃
|
||||
*/
|
||||
public static boolean isDeprecated(Integer payType) {
|
||||
return payType != null && DEPRECATED_TO_CORE_MAPPING.containsKey(payType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付方式的迁移说明
|
||||
*
|
||||
* @param payType 支付方式代码
|
||||
* @return 迁移说明文本
|
||||
*/
|
||||
public static String getMigrationMessage(Integer payType) {
|
||||
if (payType == null || !isDeprecated(payType)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PaymentType originalType = PaymentType.getByCode(payType);
|
||||
PaymentType coreType = PaymentType.getByCode(convertToCore(payType));
|
||||
|
||||
if (originalType != null && coreType != null) {
|
||||
return String.format("支付方式 %s(%d) 已废弃,建议使用 %s(%d)",
|
||||
originalType.getName(), payType,
|
||||
coreType.getName(), coreType.getCode());
|
||||
}
|
||||
|
||||
return "该支付方式已废弃,请使用核心支付方式";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有核心支付方式代码
|
||||
*
|
||||
* @return 核心支付方式代码数组
|
||||
*/
|
||||
public static Integer[] getCorePaymentTypeCodes() {
|
||||
return new Integer[]{0, 1, 2, 3, 4, 5, 6, 7};
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否为核心支付方式
|
||||
*
|
||||
* @param payType 支付方式代码
|
||||
* @return true表示是核心支付方式
|
||||
*/
|
||||
public static boolean isCorePaymentType(Integer payType) {
|
||||
if (payType == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Integer coreType : getCorePaymentTypeCodes()) {
|
||||
if (coreType.equals(payType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成支付方式迁移报告
|
||||
*
|
||||
* @return 迁移报告文本
|
||||
*/
|
||||
public static String generateMigrationReport() {
|
||||
StringBuilder report = new StringBuilder();
|
||||
report.append("=== 支付方式迁移报告 ===\n");
|
||||
report.append("核心支付方式(8种):\n");
|
||||
|
||||
for (Integer coreType : getCorePaymentTypeCodes()) {
|
||||
PaymentType type = PaymentType.getByCode(coreType);
|
||||
if (type != null) {
|
||||
report.append(String.format(" %d - %s\n", coreType, type.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
report.append("\n废弃支付方式映射:\n");
|
||||
for (Map.Entry<Integer, Integer> entry : DEPRECATED_TO_CORE_MAPPING.entrySet()) {
|
||||
PaymentType originalType = PaymentType.getByCode(entry.getKey());
|
||||
PaymentType coreType = PaymentType.getByCode(entry.getValue());
|
||||
if (originalType != null && coreType != null) {
|
||||
report.append(String.format(" %d(%s) -> %d(%s)\n",
|
||||
entry.getKey(), originalType.getName(),
|
||||
entry.getValue(), coreType.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
return report.toString();
|
||||
}
|
||||
}
|
||||
@@ -148,10 +148,10 @@ public class ShopOrder implements Serializable {
|
||||
@Schema(description = "支付的用户id")
|
||||
private Integer payUserId;
|
||||
|
||||
@Schema(description = "0余额支付, 1微信支付,102微信Native,2会员卡支付,3支付宝,4现金,5POS机,6VIP月卡,7VIP年卡,8VIP次卡,9IC月卡,10IC年卡,11IC次卡,12免费,13VIP充值卡,14IC充值卡,15积分支付,16VIP季卡,17IC季卡,18代付")
|
||||
@Schema(description = "支付方式:0余额支付,1微信支付,2支付宝支付,3银联支付,4现金支付,5POS机支付,6免费,7积分支付")
|
||||
private Integer payType;
|
||||
|
||||
@Schema(description = "代付支付方式,0余额支付, 1微信支付,102微信Native,2会员卡支付,3支付宝,4现金,5POS机,6VIP月卡,7VIP年卡,8VIP次卡,9IC月卡,10IC年卡,11IC次卡,12免费,13VIP充值卡,14IC充值卡,15积分支付,16VIP季卡,17IC季卡,18代付")
|
||||
@Schema(description = "代付支付方式:0余额支付,1微信支付,2支付宝支付,3银联支付,4现金支付,5POS机支付,6免费,7积分支付")
|
||||
private Integer friendPayType;
|
||||
|
||||
@Schema(description = "0未付款,1已付款")
|
||||
|
||||
@@ -152,11 +152,11 @@ public class ShopOrderParam extends BaseParam {
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer payUserId;
|
||||
|
||||
@Schema(description = "0余额支付, 1微信支付,102微信Native,2会员卡支付,3支付宝,4现金,5POS机,6VIP月卡,7VIP年卡,8VIP次卡,9IC月卡,10IC年卡,11IC次卡,12免费,13VIP充值卡,14IC充值卡,15积分支付,16VIP季卡,17IC季卡,18代付")
|
||||
@Schema(description = "支付方式:0余额支付,1微信支付,2支付宝支付,3银联支付,4现金支付,5POS机支付,6免费,7积分支付")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer payType;
|
||||
|
||||
@Schema(description = "代付支付方式,0余额支付, 1微信支付,102微信Native,2会员卡支付,3支付宝,4现金,5POS机,6VIP月卡,7VIP年卡,8VIP次卡,9IC月卡,10IC年卡,11IC次卡,12免费,13VIP充值卡,14IC充值卡,15积分支付,16VIP季卡,17IC季卡,18代付")
|
||||
@Schema(description = "代付支付方式:0余额支付,1微信支付,2支付宝支付,3银联支付,4现金支付,5POS机支付,6免费,7积分支付")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer friendPayType;
|
||||
|
||||
|
||||
@@ -177,10 +177,20 @@ public class ShopOrderServiceImpl extends ServiceImpl<ShopOrderMapper, ShopOrder
|
||||
|
||||
// 根据支付类型选择不同的处理逻辑
|
||||
if (order.getPayType().equals(102)) {
|
||||
// Native支付处理
|
||||
// Native支付处理(兼容旧的102类型)
|
||||
System.out.println("⚠️ 检测到使用废弃的微信Native支付类型(102),建议升级到微信支付(1)");
|
||||
return createNativePayOrder(order, payment);
|
||||
} else if (order.getPayType().equals(1)) {
|
||||
// 微信支付处理 - 根据是否有openid判断使用JSAPI还是Native
|
||||
if (order.getOpenid() != null && !order.getOpenid().trim().isEmpty()) {
|
||||
// 有openid,使用JSAPI支付
|
||||
return createJsapiPayOrder(order, payment);
|
||||
} else {
|
||||
// 无openid,使用Native支付
|
||||
return createNativePayOrder(order, payment);
|
||||
}
|
||||
} else {
|
||||
// JSAPI支付处理(原有逻辑)
|
||||
// 其他支付方式暂时使用JSAPI处理
|
||||
return createJsapiPayOrder(order, payment);
|
||||
}
|
||||
|
||||
|
||||
136
src/test/java/com/gxwebsoft/payment/enums/PaymentTypeTest.java
Normal file
136
src/test/java/com/gxwebsoft/payment/enums/PaymentTypeTest.java
Normal file
@@ -0,0 +1,136 @@
|
||||
package com.gxwebsoft.payment.enums;
|
||||
|
||||
import com.gxwebsoft.payment.utils.PaymentTypeCompatibilityUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* 支付方式枚举测试类
|
||||
* 验证支付方式优化后的功能正确性
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2025-08-30
|
||||
*/
|
||||
@DisplayName("支付方式枚举测试")
|
||||
class PaymentTypeTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("测试核心支付方式")
|
||||
void testCorePaymentTypes() {
|
||||
// 测试8种核心支付方式
|
||||
assertEquals(PaymentType.BALANCE, PaymentType.getByCode(0));
|
||||
assertEquals(PaymentType.WECHAT, PaymentType.getByCode(1));
|
||||
assertEquals(PaymentType.ALIPAY, PaymentType.getByCode(2));
|
||||
assertEquals(PaymentType.UNION_PAY, PaymentType.getByCode(3));
|
||||
assertEquals(PaymentType.CASH, PaymentType.getByCode(4));
|
||||
assertEquals(PaymentType.POS, PaymentType.getByCode(5));
|
||||
assertEquals(PaymentType.FREE, PaymentType.getByCode(6));
|
||||
assertEquals(PaymentType.POINTS, PaymentType.getByCode(7));
|
||||
|
||||
// 验证核心支付方式标识
|
||||
assertTrue(PaymentType.BALANCE.isCorePaymentType());
|
||||
assertTrue(PaymentType.WECHAT.isCorePaymentType());
|
||||
assertTrue(PaymentType.ALIPAY.isCorePaymentType());
|
||||
assertTrue(PaymentType.UNION_PAY.isCorePaymentType());
|
||||
assertTrue(PaymentType.CASH.isCorePaymentType());
|
||||
assertTrue(PaymentType.POS.isCorePaymentType());
|
||||
assertTrue(PaymentType.FREE.isCorePaymentType());
|
||||
assertTrue(PaymentType.POINTS.isCorePaymentType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试废弃支付方式")
|
||||
void testDeprecatedPaymentTypes() {
|
||||
// 测试废弃支付方式标识
|
||||
assertTrue(PaymentType.WECHAT_NATIVE.isDeprecated());
|
||||
assertTrue(PaymentType.MEMBER_CARD_OLD.isDeprecated());
|
||||
assertTrue(PaymentType.VIP_MONTHLY.isDeprecated());
|
||||
|
||||
// 验证废弃支付方式仍然可以通过代码获取(向后兼容)
|
||||
assertEquals(PaymentType.WECHAT_NATIVE, PaymentType.getByCode(102));
|
||||
assertEquals(PaymentType.FREE_OLD, PaymentType.getByCode(12));
|
||||
assertEquals(PaymentType.POINTS_OLD, PaymentType.getByCode(15));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试支付方式分类")
|
||||
void testPaymentTypeCategories() {
|
||||
// 测试微信支付类型
|
||||
assertTrue(PaymentType.WECHAT.isWechatPay());
|
||||
assertTrue(PaymentType.WECHAT_NATIVE.isWechatPay());
|
||||
|
||||
// 测试第三方支付
|
||||
assertTrue(PaymentType.WECHAT.isThirdPartyPay());
|
||||
assertTrue(PaymentType.ALIPAY.isThirdPartyPay());
|
||||
assertTrue(PaymentType.UNION_PAY.isThirdPartyPay());
|
||||
|
||||
// 测试在线支付
|
||||
assertTrue(PaymentType.WECHAT.isOnlinePay());
|
||||
assertTrue(PaymentType.ALIPAY.isOnlinePay());
|
||||
assertFalse(PaymentType.CASH.isOnlinePay());
|
||||
assertFalse(PaymentType.POS.isOnlinePay());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试兼容性工具类")
|
||||
void testCompatibilityUtil() {
|
||||
// 测试废弃支付方式转换
|
||||
assertEquals(Integer.valueOf(0), PaymentTypeCompatibilityUtil.convertToCore(2)); // 会员卡 -> 余额
|
||||
assertEquals(Integer.valueOf(1), PaymentTypeCompatibilityUtil.convertToCore(102)); // 微信Native -> 微信
|
||||
assertEquals(Integer.valueOf(2), PaymentTypeCompatibilityUtil.convertToCore(3)); // 支付宝编号调整
|
||||
assertEquals(Integer.valueOf(6), PaymentTypeCompatibilityUtil.convertToCore(12)); // 免费编号调整
|
||||
assertEquals(Integer.valueOf(7), PaymentTypeCompatibilityUtil.convertToCore(15)); // 积分编号调整
|
||||
assertEquals(Integer.valueOf(3), PaymentTypeCompatibilityUtil.convertToCore(19)); // 银联编号调整
|
||||
|
||||
// 测试核心支付方式不变
|
||||
assertEquals(Integer.valueOf(0), PaymentTypeCompatibilityUtil.convertToCore(0)); // 余额支付
|
||||
assertEquals(Integer.valueOf(1), PaymentTypeCompatibilityUtil.convertToCore(1)); // 微信支付
|
||||
assertEquals(Integer.valueOf(4), PaymentTypeCompatibilityUtil.convertToCore(4)); // 现金支付
|
||||
assertEquals(Integer.valueOf(5), PaymentTypeCompatibilityUtil.convertToCore(5)); // POS机支付
|
||||
|
||||
// 测试废弃检查
|
||||
assertTrue(PaymentTypeCompatibilityUtil.isDeprecated(102)); // 微信Native
|
||||
assertTrue(PaymentTypeCompatibilityUtil.isDeprecated(12)); // 免费(旧)
|
||||
assertTrue(PaymentTypeCompatibilityUtil.isDeprecated(15)); // 积分(旧)
|
||||
assertFalse(PaymentTypeCompatibilityUtil.isDeprecated(0)); // 余额支付
|
||||
assertFalse(PaymentTypeCompatibilityUtil.isDeprecated(1)); // 微信支付
|
||||
|
||||
// 测试核心支付方式检查
|
||||
assertTrue(PaymentTypeCompatibilityUtil.isCorePaymentType(0)); // 余额支付
|
||||
assertTrue(PaymentTypeCompatibilityUtil.isCorePaymentType(1)); // 微信支付
|
||||
assertTrue(PaymentTypeCompatibilityUtil.isCorePaymentType(2)); // 支付宝支付
|
||||
assertTrue(PaymentTypeCompatibilityUtil.isCorePaymentType(7)); // 积分支付
|
||||
assertFalse(PaymentTypeCompatibilityUtil.isCorePaymentType(102)); // 微信Native
|
||||
assertFalse(PaymentTypeCompatibilityUtil.isCorePaymentType(12)); // 免费(旧)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试迁移消息")
|
||||
void testMigrationMessages() {
|
||||
// 测试废弃支付方式的迁移消息
|
||||
String message = PaymentTypeCompatibilityUtil.getMigrationMessage(102);
|
||||
assertNotNull(message);
|
||||
assertTrue(message.contains("微信Native"));
|
||||
assertTrue(message.contains("微信支付"));
|
||||
|
||||
// 测试核心支付方式无迁移消息
|
||||
assertNull(PaymentTypeCompatibilityUtil.getMigrationMessage(0));
|
||||
assertNull(PaymentTypeCompatibilityUtil.getMigrationMessage(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试迁移报告生成")
|
||||
void testMigrationReport() {
|
||||
String report = PaymentTypeCompatibilityUtil.generateMigrationReport();
|
||||
assertNotNull(report);
|
||||
assertTrue(report.contains("核心支付方式"));
|
||||
assertTrue(report.contains("废弃支付方式映射"));
|
||||
assertTrue(report.contains("余额支付"));
|
||||
assertTrue(report.contains("微信支付"));
|
||||
|
||||
System.out.println("=== 支付方式迁移报告 ===");
|
||||
System.out.println(report);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user