feat: 品牌 Logo 上传与匿名读取接口
All checks were successful
Build and Deploy / deploy (push) Successful in 1m21s

新增 brand_logo 配置及 portal/site 渠道上传,供系统顶栏与官网展示。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zzh 2026-11-19 16:03:34 +08:00
parent 2ced23e564
commit 8c1b7c0140
5 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,17 @@
namespace Oms.Application.Dtos.System;
/// <summary>
/// 品牌 Logo 展示输出。
/// </summary>
public class BrandLogoOutput
{
/// <summary>
/// 系统顶栏 Logo 可访问 URL;未配置时为空。
/// </summary>
public string PortalUrl { get; set; } = string.Empty;
/// <summary>
/// 官网 Logo 可访问 URL;未配置时为空。
/// </summary>
public string SiteUrl { get; set; } = string.Empty;
}

View File

@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Http;
namespace Oms.Application.Dtos.System;
/// <summary>
/// 上传品牌 Logo 入参(multipart/form-data:channel + file)。
/// </summary>
public class BrandLogoUploadInput
{
/// <summary>
/// 渠道:portal(系统顶栏)/ site(官网)。
/// </summary>
public string Channel { get; set; } = string.Empty;
/// <summary>
/// Logo 图片。
/// </summary>
public IFormFile File { get; set; } = null!;
}

View File

@ -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<ISystemOtherConfigRepository>();
@ -193,6 +196,54 @@ public class SystemOtherConfigService : ApplicationService
};
}
/// <summary>
/// 获取品牌 Logo(系统顶栏 / 官网)。未配置时对应 URL 为空(前端回退本地默认图)。匿名可读,供官网使用。
/// </summary>
[AllowAnonymous]
[HttpGet("/system/other-config/brand-logo")]
public async Task<BrandLogoOutput> GetBrandLogoAsync()
{
var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.BrandLogo);
return new BrandLogoOutput
{
PortalUrl = FileStorage.GetPublicUrl(entity?.AppKey),
SiteUrl = FileStorage.GetPublicUrl(entity?.Remark)
};
}
/// <summary>
/// 上传并替换品牌 Logo。Channel=portal|site;返回最新可访问 URL。
/// </summary>
/// <param name="input">入参:渠道 + 图片文件。</param>
[HttpPost("/system/other-config/brand-logo/upload")]
[Consumes("multipart/form-data")]
public async Task<BrandLogoOutput> 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<SystemOtherConfig> EnsurePaymentReceiveQrConfigAsync()
{
var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr);
@ -224,11 +275,43 @@ public class SystemOtherConfigService : ApplicationService
});
}
private async Task<SystemOtherConfig> 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<Func<SystemOtherConfig, bool>> 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));

View File

@ -29,6 +29,9 @@ public static class OmsFileUploadHelper
public static Task<string> SavePaymentReceiveQrAsync(IFormFile file, IObjectStorage storage) =>
SaveImageAsync(file, storage, "payment-qr", "收款码图片");
public static Task<string> SaveBrandLogoAsync(IFormFile file, IObjectStorage storage) =>
SaveImageAsync(file, storage, "brand-logo", "品牌 Logo");
private static async Task<string> SaveImageAsync(
IFormFile? file,
IObjectStorage storage,

View File

@ -64,4 +64,9 @@ public static class SystemOtherConfigCodes
/// 客户充值收款码(AppKey=支付宝收款码 object key,Remark=微信收款码 object key)。
/// </summary>
public const string PaymentReceiveQr = "payment_receive_qr";
/// <summary>
/// 品牌 Logo(AppKey=系统顶栏 Logo object key,Remark=官网 Logo object key)。
/// </summary>
public const string BrandLogo = "brand_logo";
}