using Store.Users.Contracts.Enums; using Store.Users.Entities; namespace Store.Users.Services; /// 统一账户管理范围:管理员管理全部,主账号管理本人及直属子账号。 internal static class UserAccessPolicy { public static bool IsAdmin(UserEntity actor) => actor.SaLevel == UserAdminLevel.SuperAdmin; public static bool Owns(UserEntity actor, UserEntity target) => actor.IsMainUser && string.Equals(target.ParentUserName, actor.UserName, StringComparison.OrdinalIgnoreCase); /// 子账号可查询本人、修改本人密码、提交充值备注和为本人店铺续费。 public static bool CanUseSelfService(UserEntity actor, UserEntity target) => actor.Id == target.Id || CanManage(actor, target); /// 管理员不受归属限制;普通主账号不能接管具有管理员身份的子账号。 public static bool CanManage(UserEntity actor, UserEntity target) => IsAdmin(actor) || (!IsAdmin(target) && actor.IsMainUser && (actor.Id == target.Id || Owns(actor, target))); }