feat(payment): 优化支付方式并确保系统平滑迁移
-将19种复杂支付方式简化为8种核心支付方式 - 更新PaymentType枚举,添加废弃支付方式的兼容处理 - 新增PaymentTypeCompatibilityUtil工具类,用于支付方式迁移 - 更新ShopOrder和ShopOrderParam的支付方式描述 - 修改ShopOrderServiceImpl中的支付处理逻辑 - 添加单元测试,验证支付方式优化后的功能正确性
This commit is contained in:
@@ -8,69 +8,100 @@ package com.gxwebsoft.payment.enums;
|
||||
* @since 2025-01-26
|
||||
*/
|
||||
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"),
|
||||
|
||||
|
||||
/** 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"),
|
||||
|
||||
/** VIP季卡 */
|
||||
POINTS(7, "积分支付", "points"),
|
||||
|
||||
// ========== 已废弃的支付方式(保留用于数据兼容) ==========
|
||||
|
||||
/** @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"),
|
||||
|
||||
/** 代付 */
|
||||
PROXY_PAY(18, "代付", "proxy_pay"),
|
||||
|
||||
/** 银联支付 */
|
||||
UNION_PAY(19, "银联支付", "union_pay");
|
||||
|
||||
/** @deprecated IC月卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
IC_MONTHLY(17, "IC月卡", "ic_monthly"),
|
||||
|
||||
/** @deprecated IC年卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
IC_YEARLY(18, "IC年卡", "ic_yearly"),
|
||||
|
||||
/** @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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user