From c38ccd8ccb0e8cd4e25a19c7be5765076666c844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Tue, 16 Jun 2026 13:44:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=B5=9B=E4=BA=8B=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E4=B9=9F=E5=8F=AF=E4=BB=A5=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E5=85=A8=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YD_Event.Application/Order/OrderService.cs | 33 +++++++++++++++---- YD_Event.Application/YD_Event.Application.xml | 5 +++ YD_Event.Application/applicationsettings.json | 1 + YD_Event.Core/Options/RoleOptions.cs | 5 +++ YD_Event.Core/YD_Event.Core.xml | 5 +++ 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/YD_Event.Application/Order/OrderService.cs b/YD_Event.Application/Order/OrderService.cs index 02fc50c..d4bea45 100644 --- a/YD_Event.Application/Order/OrderService.cs +++ b/YD_Event.Application/Order/OrderService.cs @@ -7,7 +7,9 @@ using YD_Event.Application.Event; using YD_Event.Application.Order.Dtos; using YD_Event.Core.Entities; using YD_Event.Core.Enum; +using YD_Event.Core.Options; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using YD_Event.Core.Domain; namespace YD_Event.Application.Order; @@ -27,6 +29,8 @@ public class OrderService : BaseService, ITransien private readonly IIdGenerator _idGenerator; private readonly AuthManager _authManager; private readonly ISqlSugarClient _db; + private readonly ISqlSugarRepository _sysUserRoleRepository; + private readonly IOptionsMonitor _roleOptionsMonitor; private readonly OrderNoGeneratorService _orderNoGeneratorService; private readonly ILogger _logger; private readonly UnifiedRegistrationService _unifiedRegistrationService; @@ -42,6 +46,8 @@ public class OrderService : BaseService, ITransien IIdGenerator idGenerator, AuthManager authManager, ISqlSugarClient db, + ISqlSugarRepository sysUserRoleRepository, + IOptionsMonitor roleOptionsMonitor, OrderNoGeneratorService orderNoGeneratorService, ILogger logger, UnifiedRegistrationService unifiedRegistrationService) : base(orderRepository) @@ -56,11 +62,26 @@ public class OrderService : BaseService, ITransien _idGenerator = idGenerator; _authManager = authManager; _db = db; + _sysUserRoleRepository = sysUserRoleRepository; + _roleOptionsMonitor = roleOptionsMonitor; _orderNoGeneratorService = orderNoGeneratorService; _logger = logger; _unifiedRegistrationService = unifiedRegistrationService; } + /// + /// 判断当前用户是否是管理员(超级管理员、系统管理员或赛事管理员) + /// + private async Task IsCurrentUserAdminAsync() + { + if (_authManager.IsSuperAdmin) return true; + var userId = _authManager.UserId; + var roleOptions = _roleOptionsMonitor.CurrentValue; + return await _sysUserRoleRepository.IsAnyAsync(x => + x.UserId == userId && + (x.RoleId == roleOptions.AdminRoleId || x.RoleId == roleOptions.EventManagerRoleId)); + } + /// /// 创建订单 /// @@ -194,8 +215,8 @@ public class OrderService : BaseService, ITransien .WhereIF(input.EndTime.HasValue, (o, e, m, r, ro) => o.PaymentTime <= input.EndTime) .OrderByDescending((o, e, m, r, ro) => o.CreatedTime); - // 权限判断:非超级管理员必须过滤订单 - if (!_authManager.IsSuperAdmin) + // 权限判断:非管理员(超级管理员或系统管理员)必须过滤订单 + if (!await IsCurrentUserAdminAsync()) { if (certification != null) { @@ -602,8 +623,8 @@ public class OrderService : BaseService, ITransien .WhereIF(input.EndTime.HasValue, (o, e, m, r, ro) => o.CreatedTime <= input.EndTime) .OrderByDescending((o, e, m, r, ro) => o.CreatedTime); - // 权限判断:非超级管理员必须过滤订单 - if (!_authManager.IsSuperAdmin) + // 权限判断:非管理员(超级管理员或系统管理员)必须过滤订单 + if (!await IsCurrentUserAdminAsync()) { if (certification != null) { @@ -864,8 +885,8 @@ public class OrderService : BaseService, ITransien .WhereIF(input.StartTime.HasValue, (o, e, m, r, ro) => o.CreatedTime >= input.StartTime) .WhereIF(input.EndTime.HasValue, (o, e, m, r, ro) => o.CreatedTime <= input.EndTime); - // 权限判断:非超级管理员必须过滤订单 - if (!_authManager.IsSuperAdmin) + // 权限判断:非管理员(超级管理员或系统管理员)必须过滤订单 + if (!await IsCurrentUserAdminAsync()) { if (certification != null) { diff --git a/YD_Event.Application/YD_Event.Application.xml b/YD_Event.Application/YD_Event.Application.xml index 3c96ed7..90c9c19 100644 --- a/YD_Event.Application/YD_Event.Application.xml +++ b/YD_Event.Application/YD_Event.Application.xml @@ -11464,6 +11464,11 @@ 订单管理服务 + + + 判断当前用户是否是管理员(超级管理员、系统管理员或赛事管理员) + + 创建订单 diff --git a/YD_Event.Application/applicationsettings.json b/YD_Event.Application/applicationsettings.json index 13f558e..b872025 100644 --- a/YD_Event.Application/applicationsettings.json +++ b/YD_Event.Application/applicationsettings.json @@ -167,6 +167,7 @@ // 角色配置 "RoleSettings": { "AdminRoleId": 1000, + "EventManagerRoleId": 1002, "UnitUserRoleId": 1001, "HiddenMenuIds": [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009] } diff --git a/YD_Event.Core/Options/RoleOptions.cs b/YD_Event.Core/Options/RoleOptions.cs index 0a806af..6a5e3c3 100644 --- a/YD_Event.Core/Options/RoleOptions.cs +++ b/YD_Event.Core/Options/RoleOptions.cs @@ -13,6 +13,11 @@ public class RoleOptions : IConfigurableOptions /// public long AdminRoleId { get; set; } + /// + /// 赛事管理员角色ID + /// + public long EventManagerRoleId { get; set; } + /// /// 单位用户角色ID /// diff --git a/YD_Event.Core/YD_Event.Core.xml b/YD_Event.Core/YD_Event.Core.xml index c037a07..393dc29 100644 --- a/YD_Event.Core/YD_Event.Core.xml +++ b/YD_Event.Core/YD_Event.Core.xml @@ -5968,6 +5968,11 @@ 系统管理员角色ID + + + 赛事管理员角色ID + + 单位用户角色ID