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