using Fake.Application; using Fake.Domain.Exceptions; using Fake.Users; using Oms.Domain.CustomersAggregate.Entities; using Oms.Domain.CustomersAggregate.Repositories; namespace Oms.Application.Shared; /// /// 营销门户会话解析。 /// public static class MarketingPortalSessionHelper { public static void EnsureCustomerLogin(ICurrentUser currentUser) { if (!OmsSessionHelper.IsCustomerLogin(currentUser)) { throw new BusinessException("仅客户门户可访问"); } } public static async Task ResolveMainCustomerAsync( ICustomerRepository customerRepository, ICurrentUser currentUser, CancellationToken cancellationToken = default) { EnsureCustomerLogin(currentUser); var sessionCustomer = await OmsSessionHelper.ResolveSessionCustomerAsync( customerRepository, currentUser); return await MarketingCustomerHelper.ResolveMarketingMainCustomerAsync( customerRepository, sessionCustomer, cancellationToken); } public static string MaskPhone(string? phone) { if (string.IsNullOrWhiteSpace(phone) || phone.Length < 7) { return phone ?? string.Empty; } return phone[..3] + "****" + phone[^4..]; } public static string MaskName(string? name) { if (string.IsNullOrWhiteSpace(name)) { return string.Empty; } if (name.Length == 1) { return "*"; } if (name.Length == 2) { return name[0] + "*"; } return name[0] + new string('*', name.Length - 2) + name[^1]; } }