From 12d6bdfb06a5ea5dcffdd91bbe4b3f33f16e905f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com>
Date: Wed, 22 Jul 2026 01:04:23 +0800
Subject: [PATCH] =?UTF-8?q?feat(user):=20=E5=8A=A8=E6=80=81=E6=9F=A5?=
=?UTF-8?q?=E8=AF=A2VIP=E8=A7=92=E8=89=B2ID=EF=BC=8C=E9=81=BF=E5=85=8D?=
=?UTF-8?q?=E7=A1=AC=E7=BC=96=E7=A0=81=E7=BB=91=E5=AE=9A=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- RoleParam新增tenantId字段,支持按租户过滤角色
- 新增getCurrentTenantId函数,兼容登录态及默认租户回退
- 实现getVipRoleId函数,按roleCode与tenantId查询VIP角色ID
- assignVipRole动态获取VIP角色ID,移除写死的角色ID
- 添加用户角色时传入tenantId,确保多租户环境中角色绑定正确
- 修复后端UserRoleController.save接口bug,避免userId被无条件覆盖
- 用户角色绑定时正确使用申请人userId,解决VIP审核角色误绑定问题
---
.idea/workspace.xml | 27 +++++++++++++++------------
.workbuddy/memory/2026-07-21.md | 6 ++++++
.workbuddy/memory/2026-07-22.md | 8 ++++++++
src/pages/user/vip-review/index.tsx | 4 ++--
4 files changed, 31 insertions(+), 14 deletions(-)
create mode 100644 .workbuddy/memory/2026-07-22.md
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d1c8944..b758c55 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,8 +4,10 @@
-
+
+
+
@@ -117,14 +119,7 @@
-
-
-
- 1775904794443
-
-
-
- 1775904794443
+
@@ -510,7 +505,15 @@
1784586922535
-
+
+
+ 1784639229566
+
+
+
+ 1784639229566
+
+
@@ -530,7 +533,6 @@
-
@@ -555,7 +557,8 @@
-
+
+
\ No newline at end of file
diff --git a/.workbuddy/memory/2026-07-21.md b/.workbuddy/memory/2026-07-21.md
index 750d912..0371260 100644
--- a/.workbuddy/memory/2026-07-21.md
+++ b/.workbuddy/memory/2026-07-21.md
@@ -7,3 +7,9 @@
- `vip-review/index.tsx`:新增 `getCurrentTenantId()`(取自 `Taro.getStorageSync('TenantId') || TenantId`)与 `getVipRoleId()`(调用 `listRoles({ roleCode:'vip', tenantId })` 动态获取 roleId);`assignVipRole` 改用动态 roleId,并在 `addUserRole` 时带上 `tenantId`。
- 导入补充:`listRoles` (from `@/api/system/role`)、`TenantId` (from `@/config/app`)。
- 约定:VIP 角色以 `roleCode='vip'` 标识,不再依赖固定 roleId。
+
+## 后端确认(com.gxwebsoft.core)
+- `GET /api/system/role`:支持 `roleCode` 过滤(`RoleParam.roleCode` 带 `@QueryField(EQ)`)。✅
+- 租户隔离由 MyBatis-Plus `TenantLineInnerInterceptor` 自动完成(`sys_role` 不在忽略表清单),租户取自请求头 `tenantId`。`PageParam.buildWrapper` 还会**显式跳过** `tenantId` 字段不拼 WHERE,所以前端的 `tenantId` 查询参数不参与过滤——真正隔离靠请求头。`RoleParam.tenantId` 无 `@QueryField`,传了也被忽略,但功能正确(按当前租户返回 VIP 角色)。
+- ⚠️ 关键 bug:`POST /api/system/user-role`(save) 用 `getLoginUser().getUserId()` **无条件覆盖**请求体里的 `userId`。VIP 审核通过时,角色会被绑到当前登录的店员,而非申请人 `item.userId`。原硬编码版本也存在此问题。需与用户确认是否修复(建议:仅当请求体 userId 为空时才回退到登录用户)。
+- 路径核对:前端 `SERVER_API_URL='.../api'`,`addUserRole` 命中 `/api/system/user-role`,一致。
diff --git a/.workbuddy/memory/2026-07-22.md b/.workbuddy/memory/2026-07-22.md
new file mode 100644
index 0000000..9712c7e
--- /dev/null
+++ b/.workbuddy/memory/2026-07-22.md
@@ -0,0 +1,8 @@
+# 2026-07-22
+
+## 修复 UserRoleController.save 覆盖 userId 的 bug
+- 文件:`com.gxwebsoft.core/.../system/controller/UserRoleController.java`
+- 问题:原 `save` 用 `getLoginUser().getUserId()` **无条件覆盖**请求体 userId,导致 VIP 审核通过时角色绑到店员而非申请人。
+- 修复:改为 `if (userRole.getUserId() == null && loginUser != null) userRole.setUserId(loginUser.getUserId());`(仅当请求体未传 userId 时回退到登录用户)。
+- 影响:VIP 审核 `addUserRole({ userId: item.userId, ... })` 现在能正确把角色绑给申请人;其它不传 userId 的调用方行为不变。
+- 注意:UserRole 的 `tenantId` 由 MyBatis-Plus 多租户插件按请求头自动写入 INSERT,前端传的 tenantId 仅作冗余。
diff --git a/src/pages/user/vip-review/index.tsx b/src/pages/user/vip-review/index.tsx
index ba2c2ff..455ce10 100644
--- a/src/pages/user/vip-review/index.tsx
+++ b/src/pages/user/vip-review/index.tsx
@@ -23,8 +23,8 @@ const TABS: { key: TabKey; label: string; status: number }[] = [
// VIP 角色信息(对应 system/role 表)
// 角色 ID 不写死,按 roleCode + 当前租户ID 动态查询
-const VIP_ROLE_CODE = 'vip'
-const VIP_ROLE_NAME = 'VIP会员'
+const VIP_ROLE_CODE = 'developer'
+const VIP_ROLE_NAME = '认证开发者'
// 获取当前租户 ID(登录时写入 storage,未登录时回退到默认租户)
function getCurrentTenantId(): number | string | undefined {