mirror of
https://gitee.com/dromara/dax-pay
synced 2026-08-15 09:46:17 +08:00
feat(merchant): 默认应用/门店策略统一治理(唯一约束/删除阻挡/异常分类)
- 数据库加部分唯一索引 uk_mch_app_info_default / uk_mch_store_info_default 兜底 - Service.delete 检查默认项, 禁止删除默认应用/门店 - MchAppInfoService.add 首应用自动默认, 与 MchStoreInfoService 对齐 - resolveApp 异常分类: 默认应用不存在 vs 已停用 vs 指定应用异常 - resolveStoreNo 改抛异常 (替代返回 null), 与 resolveApp 策略对齐 - update-datas.sql 提供脏数据/缺默认项诊断查询 - 6 语种 i18n 新增 5 个错误 key
This commit is contained in:
@@ -1,112 +1,62 @@
|
||||
-- ============================================================
|
||||
-- 门店/应用默认项数据迁移诊断(升级脚本)
|
||||
-- ============================================================
|
||||
-- 背景:
|
||||
-- 本次升级后, 支付下单若未显式传 appId / storeNo,
|
||||
-- 系统会回落到商户的默认应用/默认门店;
|
||||
-- 若默认项不存在或已停用, 将直接抛异常阻断下单(对齐 MchApp 既有策略)。
|
||||
-- 风险:
|
||||
-- 历史数据中可能存在「从未创建默认应用/默认门店」的商户(如 SQL 直接导入未走入驻流程),
|
||||
-- 升级后这些商户的下单会被阻断。
|
||||
-- 迁移策略:
|
||||
-- 主键(id)与应用号(appId)/门店号(storeNo)由应用层(MyBatis-Plus 雪花 ID / RandomUtil)生成,
|
||||
-- SQL 层难以精确复现; 且每个商户的默认应用名/门店名应按当前请求语言生成,
|
||||
-- 不适合在 SQL 中硬编码。
|
||||
-- 因此本脚本不自动执行数据补建, 仅提供诊断查询, 由运维确认后处理。
|
||||
-- ============================================================
|
||||
|
||||
-- ----------------------------
|
||||
-- 收银台模拟配置: 商户 M1781861282382 / 应用 A7846150576259390
|
||||
-- H5(五环境 browser/wechat/alipay/union_pay/douyin) + WEB + MINI(四环境)
|
||||
-- resolve_mode 全部 method; 固定 ID 段 9100000000000100001~026, 可重复执行
|
||||
-- ----------------------------
|
||||
DELETE FROM "public"."pay_gateway_cashier_item"
|
||||
WHERE "mch_no" = 'M1781861282382'
|
||||
AND "app_id" = 'A7846150576259390';
|
||||
-- 诊断 1: 查询没有默认应用的商户(升级后这些商户未传 appId 的下单会失败)
|
||||
-- SELECT mch.mch_no, mch.mch_name
|
||||
-- FROM merchant_info mch
|
||||
-- WHERE NOT EXISTS (
|
||||
-- SELECT 1 FROM mch_app_info app
|
||||
-- WHERE app.mch_no = mch.mch_no
|
||||
-- AND app.default_app = TRUE
|
||||
-- AND app.deleted = FALSE
|
||||
-- )
|
||||
-- AND mch.deleted = FALSE;
|
||||
|
||||
INSERT INTO "public"."pay_gateway_cashier_item" (
|
||||
"id", "mch_no", "app_id", "cashier_type", "client_env",
|
||||
"name", "icon", "recommend", "sort_no",
|
||||
"resolve_mode", "method", "channel_mch_no", "capability",
|
||||
"creator", "create_time", "last_modifier", "last_modified_time",
|
||||
"version", "deleted"
|
||||
) VALUES
|
||||
-- H5 · browser
|
||||
(9100000000000100001, 'M1781861282382', 'A7846150576259390', 'h5', 'browser',
|
||||
'微信支付', 'wechat', 't', 1, 'method', 'wechat_h5', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100002, 'M1781861282382', 'A7846150576259390', 'h5', 'browser',
|
||||
'支付宝', 'alipay', 'f', 2, 'method', 'alipay_h5', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100003, 'M1781861282382', 'A7846150576259390', 'h5', 'browser',
|
||||
'云闪付', 'union_pay', 'f', 3, 'method', 'union_h5', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100004, 'M1781861282382', 'A7846150576259390', 'h5', 'browser',
|
||||
'抖音支付', 'douyin', 'f', 4, 'method', 'douyin_h5', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
-- H5 · wechat
|
||||
(9100000000000100005, 'M1781861282382', 'A7846150576259390', 'h5', 'wechat',
|
||||
'微信支付', 'wechat', 't', 1, 'method', 'wechat_jsapi', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100006, 'M1781861282382', 'A7846150576259390', 'h5', 'wechat',
|
||||
'微信扫码', 'wechat', 'f', 2, 'method', 'wechat_qr', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
-- H5 · alipay
|
||||
(9100000000000100007, 'M1781861282382', 'A7846150576259390', 'h5', 'alipay',
|
||||
'支付宝', 'alipay', 't', 1, 'method', 'alipay_jsapi', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100008, 'M1781861282382', 'A7846150576259390', 'h5', 'alipay',
|
||||
'支付宝扫码', 'alipay', 'f', 2, 'method', 'alipay_qr', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
-- H5 · union_pay
|
||||
(9100000000000100009, 'M1781861282382', 'A7846150576259390', 'h5', 'union_pay',
|
||||
'云闪付', 'union_pay', 't', 1, 'method', 'union_jsapi', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100010, 'M1781861282382', 'A7846150576259390', 'h5', 'union_pay',
|
||||
'银联扫码', 'union_pay', 'f', 2, 'method', 'union_qr', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
-- H5 · douyin
|
||||
(9100000000000100011, 'M1781861282382', 'A7846150576259390', 'h5', 'douyin',
|
||||
'抖音支付', 'douyin', 't', 1, 'method', 'douyin_jsapi', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100012, 'M1781861282382', 'A7846150576259390', 'h5', 'douyin',
|
||||
'抖音扫码', 'douyin', 'f', 2, 'method', 'douyin_qr', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
-- MINI · wechat
|
||||
(9100000000000100013, 'M1781861282382', 'A7846150576259390', 'mini', 'wechat',
|
||||
'微信支付', 'wechat', 't', 1, 'method', 'wechat_mini', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100014, 'M1781861282382', 'A7846150576259390', 'mini', 'wechat',
|
||||
'微信扫码', 'wechat', 'f', 2, 'method', 'wechat_qr', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
-- MINI · alipay
|
||||
(9100000000000100015, 'M1781861282382', 'A7846150576259390', 'mini', 'alipay',
|
||||
'支付宝', 'alipay', 't', 1, 'method', 'alipay_jsapi', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100016, 'M1781861282382', 'A7846150576259390', 'mini', 'alipay',
|
||||
'支付宝扫码', 'alipay', 'f', 2, 'method', 'alipay_qr', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
-- MINI · union_pay
|
||||
(9100000000000100017, 'M1781861282382', 'A7846150576259390', 'mini', 'union_pay',
|
||||
'云闪付', 'union_pay', 't', 1, 'method', 'union_jsapi', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100018, 'M1781861282382', 'A7846150576259390', 'mini', 'union_pay',
|
||||
'银联扫码', 'union_pay', 'f', 2, 'method', 'union_qr', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
-- MINI · douyin
|
||||
(9100000000000100019, 'M1781861282382', 'A7846150576259390', 'mini', 'douyin',
|
||||
'抖音支付', 'douyin', 't', 1, 'method', 'douyin_jsapi', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100020, 'M1781861282382', 'A7846150576259390', 'mini', 'douyin',
|
||||
'抖音扫码', 'douyin', 'f', 2, 'method', 'douyin_qr', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
-- WEB · 扁平(client_env 为空)
|
||||
(9100000000000100021, 'M1781861282382', 'A7846150576259390', 'web', NULL,
|
||||
'微信扫码', 'wechat', 't', 1, 'method', 'wechat_qr', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100022, 'M1781861282382', 'A7846150576259390', 'web', NULL,
|
||||
'支付宝扫码', 'alipay', 'f', 2, 'method', 'alipay_qr', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100023, 'M1781861282382', 'A7846150576259390', 'web', NULL,
|
||||
'支付宝电脑', 'alipay', 'f', 3, 'method', 'alipay_pc', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100024, 'M1781861282382', 'A7846150576259390', 'web', NULL,
|
||||
'银联扫码', 'union_pay', 'f', 4, 'method', 'union_qr', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100025, 'M1781861282382', 'A7846150576259390', 'web', NULL,
|
||||
'抖音扫码', 'douyin', 'f', 5, 'method', 'douyin_qr', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f'),
|
||||
(9100000000000100026, 'M1781861282382', 'A7846150576259390', 'web', NULL,
|
||||
'微信 H5', 'wechat', 'f', 6, 'method', 'wechat_h5', NULL, NULL,
|
||||
1, '2026-07-17 00:00:00+00', 1, '2026-07-17 00:00:00+00', 0, 'f');
|
||||
-- 诊断 2: 查询没有默认门店的商户(升级后这些商户未传 storeNo 的下单会失败)
|
||||
-- SELECT mch.mch_no, mch.mch_name
|
||||
-- FROM merchant_info mch
|
||||
-- WHERE NOT EXISTS (
|
||||
-- SELECT 1 FROM mch_store_info s
|
||||
-- WHERE s.mch_no = mch.mch_no
|
||||
-- AND s.default_store = TRUE
|
||||
-- AND s.deleted = FALSE
|
||||
-- )
|
||||
-- AND mch.deleted = FALSE;
|
||||
|
||||
-- ----------------------------
|
||||
-- 日志管理:支付接口审计菜单 system:log:unipay
|
||||
-- ----------------------------
|
||||
DELETE FROM "public"."iam_perm_menu" WHERE "id" = 30203;
|
||||
INSERT INTO "public"."iam_perm_menu" VALUES (30203, 302, 'system:log:unipay', 'admin', 'SystemUnipayApiLog', 'menu.system.log.unipay', 'lucide:webhook', 'f', 'f', '/system/log/unipay/UnipayApiLogList', '/system/log/unipay', NULL, 3, 'f', 't', 'f', 0, 1, 1, 'f', 'menu', NULL, NULL, NULL, NULL, NULL, NULL, '2026-07-17 00:00:00+00', '2026-07-17 00:00:00+00');
|
||||
-- 诊断 3: 查询同商户存在多个默认应用的脏数据(会导致 uk_mch_app_info_default 索引创建失败)
|
||||
-- SELECT mch_no, COUNT(*)
|
||||
-- FROM mch_app_info
|
||||
-- WHERE default_app = TRUE AND deleted = FALSE
|
||||
-- GROUP BY mch_no
|
||||
-- HAVING COUNT(*) > 1;
|
||||
|
||||
-- 诊断 4: 查询同商户存在多个默认门店的脏数据(会导致 uk_mch_store_info_default 索引创建失败)
|
||||
-- SELECT mch_no, COUNT(*)
|
||||
-- FROM mch_store_info
|
||||
-- WHERE default_store = TRUE AND deleted = FALSE
|
||||
-- GROUP BY mch_no
|
||||
-- HAVING COUNT(*) > 1;
|
||||
|
||||
-- ============================================================
|
||||
-- 修复指引(诊断查询有结果时按以下方式处理):
|
||||
-- 1. 诊断 3/4 命中(脏数据):
|
||||
-- 手动 UPDATE 保留其中一条 default_app/default_store = TRUE, 其余置 FALSE。
|
||||
-- 2. 诊断 1/2 命中(缺默认项):
|
||||
-- 登录运营端 -> 商户管理 -> 选择对应商户 -> 应用管理/门店管理 ->
|
||||
-- 新增应用/门店后调用「设为默认」接口(set-default);
|
||||
-- 或通过 MerchantAdminService.createDefaultApp / MchStoreInfoService.createDefaultStore 触发。
|
||||
-- ============================================================
|
||||
|
||||
Reference in New Issue
Block a user