feat: 品牌 Logo 上传与匿名读取接口
All checks were successful
Build and Deploy / deploy (push) Successful in 1m21s
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:
parent
2ced23e564
commit
8c1b7c0140
17
src/Oms.Application/Dtos/System/BrandLogoOutput.cs
Normal file
17
src/Oms.Application/Dtos/System/BrandLogoOutput.cs
Normal 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;
|
||||||
|
}
|
||||||
19
src/Oms.Application/Dtos/System/BrandLogoUploadInput.cs
Normal file
19
src/Oms.Application/Dtos/System/BrandLogoUploadInput.cs
Normal 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!;
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using Fake.Application;
|
using Fake.Application;
|
||||||
using Fake.ObjectStorage;
|
using Fake.ObjectStorage;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Oms.Application.Dtos.Shared;
|
using Oms.Application.Dtos.Shared;
|
||||||
using Oms.Application.Dtos.System;
|
using Oms.Application.Dtos.System;
|
||||||
@ -21,6 +22,8 @@ public class SystemOtherConfigService : ApplicationService
|
|||||||
private const string SecretMask = "******";
|
private const string SecretMask = "******";
|
||||||
private const string PaymentQrChannelAlipay = "alipay";
|
private const string PaymentQrChannelAlipay = "alipay";
|
||||||
private const string PaymentQrChannelWechat = "wechat";
|
private const string PaymentQrChannelWechat = "wechat";
|
||||||
|
private const string BrandLogoChannelPortal = "portal";
|
||||||
|
private const string BrandLogoChannelSite = "site";
|
||||||
|
|
||||||
private ISystemOtherConfigRepository SystemOtherConfigRepository =>
|
private ISystemOtherConfigRepository SystemOtherConfigRepository =>
|
||||||
LazyServiceProvider.GetRequiredService<ISystemOtherConfigRepository>();
|
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()
|
private async Task<SystemOtherConfig> EnsurePaymentReceiveQrConfigAsync()
|
||||||
{
|
{
|
||||||
var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr);
|
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)
|
private static Expression<Func<SystemOtherConfig, bool>> BuildListPredicate(SystemOtherConfigListInput input)
|
||||||
{
|
{
|
||||||
var keyword = input.Keyword?.Trim();
|
var keyword = input.Keyword?.Trim();
|
||||||
return x =>
|
return x =>
|
||||||
x.ConfigCode != SystemOtherConfigCodes.PaymentReceiveQr
|
x.ConfigCode != SystemOtherConfigCodes.PaymentReceiveQr
|
||||||
|
&& x.ConfigCode != SystemOtherConfigCodes.BrandLogo
|
||||||
&& (string.IsNullOrWhiteSpace(keyword)
|
&& (string.IsNullOrWhiteSpace(keyword)
|
||||||
|| x.ConfigCode.Contains(keyword)
|
|| x.ConfigCode.Contains(keyword)
|
||||||
|| x.ConfigName.Contains(keyword));
|
|| x.ConfigName.Contains(keyword));
|
||||||
|
|||||||
@ -29,6 +29,9 @@ public static class OmsFileUploadHelper
|
|||||||
public static Task<string> SavePaymentReceiveQrAsync(IFormFile file, IObjectStorage storage) =>
|
public static Task<string> SavePaymentReceiveQrAsync(IFormFile file, IObjectStorage storage) =>
|
||||||
SaveImageAsync(file, storage, "payment-qr", "收款码图片");
|
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(
|
private static async Task<string> SaveImageAsync(
|
||||||
IFormFile? file,
|
IFormFile? file,
|
||||||
IObjectStorage storage,
|
IObjectStorage storage,
|
||||||
|
|||||||
@ -64,4 +64,9 @@ public static class SystemOtherConfigCodes
|
|||||||
/// 客户充值收款码(AppKey=支付宝收款码 object key,Remark=微信收款码 object key)。
|
/// 客户充值收款码(AppKey=支付宝收款码 object key,Remark=微信收款码 object key)。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string PaymentReceiveQr = "payment_receive_qr";
|
public const string PaymentReceiveQr = "payment_receive_qr";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 品牌 Logo(AppKey=系统顶栏 Logo object key,Remark=官网 Logo object key)。
|
||||||
|
/// </summary>
|
||||||
|
public const string BrandLogo = "brand_logo";
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user