diff --git a/src/Oms.Application/Dtos/System/BrandLogoOutput.cs b/src/Oms.Application/Dtos/System/BrandLogoOutput.cs new file mode 100644 index 0000000..a2478fa --- /dev/null +++ b/src/Oms.Application/Dtos/System/BrandLogoOutput.cs @@ -0,0 +1,17 @@ +namespace Oms.Application.Dtos.System; + +/// +/// 品牌 Logo 展示输出。 +/// +public class BrandLogoOutput +{ + /// + /// 系统顶栏 Logo 可访问 URL;未配置时为空。 + /// + public string PortalUrl { get; set; } = string.Empty; + + /// + /// 官网 Logo 可访问 URL;未配置时为空。 + /// + public string SiteUrl { get; set; } = string.Empty; +} diff --git a/src/Oms.Application/Dtos/System/BrandLogoUploadInput.cs b/src/Oms.Application/Dtos/System/BrandLogoUploadInput.cs new file mode 100644 index 0000000..ba54106 --- /dev/null +++ b/src/Oms.Application/Dtos/System/BrandLogoUploadInput.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Http; + +namespace Oms.Application.Dtos.System; + +/// +/// 上传品牌 Logo 入参(multipart/form-data:channel + file)。 +/// +public class BrandLogoUploadInput +{ + /// + /// 渠道:portal(系统顶栏)/ site(官网)。 + /// + public string Channel { get; set; } = string.Empty; + + /// + /// Logo 图片。 + /// + public IFormFile File { get; set; } = null!; +} diff --git a/src/Oms.Application/Services/System/SystemOtherConfigService.cs b/src/Oms.Application/Services/System/SystemOtherConfigService.cs index e8654b9..c24633a 100644 --- a/src/Oms.Application/Services/System/SystemOtherConfigService.cs +++ b/src/Oms.Application/Services/System/SystemOtherConfigService.cs @@ -1,6 +1,7 @@ using System.Linq.Expressions; using Fake.Application; using Fake.ObjectStorage; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Oms.Application.Dtos.Shared; using Oms.Application.Dtos.System; @@ -21,6 +22,8 @@ public class SystemOtherConfigService : ApplicationService private const string SecretMask = "******"; private const string PaymentQrChannelAlipay = "alipay"; private const string PaymentQrChannelWechat = "wechat"; + private const string BrandLogoChannelPortal = "portal"; + private const string BrandLogoChannelSite = "site"; private ISystemOtherConfigRepository SystemOtherConfigRepository => LazyServiceProvider.GetRequiredService(); @@ -193,6 +196,54 @@ public class SystemOtherConfigService : ApplicationService }; } + /// + /// 获取品牌 Logo(系统顶栏 / 官网)。未配置时对应 URL 为空(前端回退本地默认图)。匿名可读,供官网使用。 + /// + [AllowAnonymous] + [HttpGet("/system/other-config/brand-logo")] + public async Task GetBrandLogoAsync() + { + var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.BrandLogo); + return new BrandLogoOutput + { + PortalUrl = FileStorage.GetPublicUrl(entity?.AppKey), + SiteUrl = FileStorage.GetPublicUrl(entity?.Remark) + }; + } + + /// + /// 上传并替换品牌 Logo。Channel=portal|site;返回最新可访问 URL。 + /// + /// 入参:渠道 + 图片文件。 + [HttpPost("/system/other-config/brand-logo/upload")] + [Consumes("multipart/form-data")] + public async Task UploadBrandLogoAsync([FromForm] BrandLogoUploadInput input) + { + var channel = (input.Channel ?? string.Empty).Trim().ToLowerInvariant(); + if (channel is not (BrandLogoChannelPortal or BrandLogoChannelSite)) + { + throw new BusinessException("渠道仅支持 portal 或 site"); + } + + var key = await OmsFileUploadHelper.SaveBrandLogoAsync(input.File, FileStorage); + var entity = await EnsureBrandLogoConfigAsync(); + if (channel == BrandLogoChannelPortal) + { + entity.AppKey = key; + } + else + { + entity.Remark = key; + } + + await SystemOtherConfigRepository.UpdateAsync(entity); + return new BrandLogoOutput + { + PortalUrl = FileStorage.GetPublicUrl(entity.AppKey), + SiteUrl = FileStorage.GetPublicUrl(entity.Remark) + }; + } + private async Task EnsurePaymentReceiveQrConfigAsync() { var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr); @@ -224,11 +275,43 @@ public class SystemOtherConfigService : ApplicationService }); } + private async Task EnsureBrandLogoConfigAsync() + { + var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.BrandLogo); + if (entity != null) + { + return entity; + } + + var deleted = await SystemOtherConfigRepository.GetByConfigCodeIncludingDeletedAsync( + SystemOtherConfigCodes.BrandLogo); + if (deleted != null) + { + deleted.IsDeleted = false; + deleted.ConfigName = "品牌 Logo"; + deleted.Enabled = true; + deleted.TimeoutSeconds = 30; + deleted.BaseUrl = null; + deleted.AppSecret = null; + await SystemOtherConfigRepository.UpdateAsync(deleted); + return deleted; + } + + return await SystemOtherConfigRepository.InsertAsync(new SystemOtherConfig + { + ConfigCode = SystemOtherConfigCodes.BrandLogo, + ConfigName = "品牌 Logo", + Enabled = true, + TimeoutSeconds = 30 + }); + } + private static Expression> BuildListPredicate(SystemOtherConfigListInput input) { var keyword = input.Keyword?.Trim(); return x => x.ConfigCode != SystemOtherConfigCodes.PaymentReceiveQr + && x.ConfigCode != SystemOtherConfigCodes.BrandLogo && (string.IsNullOrWhiteSpace(keyword) || x.ConfigCode.Contains(keyword) || x.ConfigName.Contains(keyword)); diff --git a/src/Oms.Application/Shared/OmsFileUploadHelper.cs b/src/Oms.Application/Shared/OmsFileUploadHelper.cs index 4889596..f7a169d 100644 --- a/src/Oms.Application/Shared/OmsFileUploadHelper.cs +++ b/src/Oms.Application/Shared/OmsFileUploadHelper.cs @@ -29,6 +29,9 @@ public static class OmsFileUploadHelper public static Task SavePaymentReceiveQrAsync(IFormFile file, IObjectStorage storage) => SaveImageAsync(file, storage, "payment-qr", "收款码图片"); + public static Task SaveBrandLogoAsync(IFormFile file, IObjectStorage storage) => + SaveImageAsync(file, storage, "brand-logo", "品牌 Logo"); + private static async Task SaveImageAsync( IFormFile? file, IObjectStorage storage, diff --git a/src/Oms.Domain/SystemAggregate/Consts/SystemOtherConfigCodes.cs b/src/Oms.Domain/SystemAggregate/Consts/SystemOtherConfigCodes.cs index 7bc9f93..8116eae 100644 --- a/src/Oms.Domain/SystemAggregate/Consts/SystemOtherConfigCodes.cs +++ b/src/Oms.Domain/SystemAggregate/Consts/SystemOtherConfigCodes.cs @@ -64,4 +64,9 @@ public static class SystemOtherConfigCodes /// 客户充值收款码(AppKey=支付宝收款码 object key,Remark=微信收款码 object key)。 /// public const string PaymentReceiveQr = "payment_receive_qr"; + + /// + /// 品牌 Logo(AppKey=系统顶栏 Logo object key,Remark=官网 Logo object key)。 + /// + public const string BrandLogo = "brand_logo"; }