diff --git a/db.sql b/db.sql index 2288bd6..82f6a29 100644 --- a/db.sql +++ b/db.sql @@ -584,6 +584,7 @@ CREATE TABLE `t_sales_product` ( `WeightRuleId` INT NULL COMMENT '计重规则ID', `WeightRoundingId` INT NULL COMMENT '计重进位ID', `ProductDescription` TEXT COMMENT '产品描述', + `CoverImage` VARCHAR(512) NULL COMMENT '官网线路封面图 object key', `PreStorageScript` TEXT COMMENT '入库前脚本', `CustomerGuideMarkdown` MEDIUMTEXT COMMENT '对客说明 Markdown', `IsActive` TINYINT NOT NULL DEFAULT 2 COMMENT 'EnableStatus:0=None未设置,1=Disabled禁用,2=Enabled启用', diff --git a/sql/migrate_sales_product_cover_image_20261126.sql b/sql/migrate_sales_product_cover_image_20261126.sql new file mode 100644 index 0000000..02226d2 --- /dev/null +++ b/sql/migrate_sales_product_cover_image_20261126.sql @@ -0,0 +1,20 @@ +-- 销售产品:官网线路封面图(产品配置可上传;门户精选线路卡片背景) +-- 可重复执行 + +SET @db := DATABASE(); + +SET @exists := ( + SELECT COUNT(1) + FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = @db + AND TABLE_NAME = 't_sales_product' + AND COLUMN_NAME = 'CoverImage' +); +SET @sql := IF( + @exists = 0, + 'ALTER TABLE `t_sales_product` ADD COLUMN `CoverImage` VARCHAR(512) NULL COMMENT ''官网线路封面图 object key'' AFTER `ProductDescription`', + 'SELECT ''t_sales_product.CoverImage already exists'' AS info' +); +PREPARE stmt FROM @sql; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; diff --git a/src/Oms.Application/Dtos/Channels/SalesProductDetailOutput.cs b/src/Oms.Application/Dtos/Channels/SalesProductDetailOutput.cs index 2ddcfa8..5e423cf 100644 --- a/src/Oms.Application/Dtos/Channels/SalesProductDetailOutput.cs +++ b/src/Oms.Application/Dtos/Channels/SalesProductDetailOutput.cs @@ -90,6 +90,16 @@ public class SalesProductDetailOutput /// public string? ProductDescription { get; set; } + /// + /// 官网线路封面图 object key(保存用)。 + /// + public string? CoverImage { get; set; } + + /// + /// 官网线路封面图可访问 URL(预览用)。 + /// + public string? CoverImageUrl { get; set; } + /// /// 预入库脚本。 /// diff --git a/src/Oms.Application/Dtos/Channels/SalesProductPortalCatalogOutput.cs b/src/Oms.Application/Dtos/Channels/SalesProductPortalCatalogOutput.cs index 840ca84..78d7874 100644 --- a/src/Oms.Application/Dtos/Channels/SalesProductPortalCatalogOutput.cs +++ b/src/Oms.Application/Dtos/Channels/SalesProductPortalCatalogOutput.cs @@ -103,6 +103,11 @@ public class SalesProductPortalItemOutput /// public string? ProductDescription { get; set; } + /// + /// 官网线路封面图可访问 URL(无图时为空)。 + /// + public string? CoverImageUrl { get; set; } + /// /// 官网目的地区域编码:us / eu / sea / ca_mx / au / global。 /// 优先由价格分区国家推导;国际快递跨区时含 global。 diff --git a/src/Oms.Application/Dtos/Channels/SalesProductSaveInput.cs b/src/Oms.Application/Dtos/Channels/SalesProductSaveInput.cs index 7cb0f1f..aa937aa 100644 --- a/src/Oms.Application/Dtos/Channels/SalesProductSaveInput.cs +++ b/src/Oms.Application/Dtos/Channels/SalesProductSaveInput.cs @@ -92,6 +92,11 @@ public class SalesProductSaveInput /// public string? ProductDescription { get; set; } + /// + /// 官网线路封面图 object key。 + /// + public string? CoverImage { get; set; } + /// /// 预入库脚本。 /// diff --git a/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs b/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs index 6c68753..8e9e203 100644 --- a/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs +++ b/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs @@ -3,6 +3,7 @@ using Oms.Application.Dtos.Orders; using Oms.Application.Dtos.Shared; using Oms.Application.Services.Approval.Contracts; using Oms.Application.Shared; +using Oms.Application.Storage; using Oms.Domain.ApprovalAggregate.Consts; using Oms.Domain.ChannelsAggregate.Consts; using Oms.Domain.ChannelsAggregate.Entities; @@ -615,6 +616,9 @@ public partial class SalesProductService entity.WeightRuleId = input.WeightRuleId; entity.WeightRoundingId = input.WeightRoundingId; entity.ProductDescription = input.ProductDescription; + entity.CoverImage = string.IsNullOrWhiteSpace(input.CoverImage) + ? null + : OmsObjectStorageExtensions.ToStorageKey(input.CoverImage.Trim()); entity.PreStorageScript = input.PreStorageScript; // 对客说明仅通过 /customer-guide/save 维护,产品配置保存/发布不覆盖 entity.IsActive = input.IsActive; @@ -857,6 +861,7 @@ public partial class SalesProductService WeightRuleId = entity.WeightRuleId, WeightRoundingId = entity.WeightRoundingId, ProductDescription = entity.ProductDescription, + CoverImage = entity.CoverImage, PreStorageScript = entity.PreStorageScript, CustomerGuideMarkdown = entity.CustomerGuideMarkdown, IsActive = (byte)entity.IsActive, diff --git a/src/Oms.Application/Services/Channels/SalesProductService.Portal.cs b/src/Oms.Application/Services/Channels/SalesProductService.Portal.cs index 5599706..c22da94 100644 --- a/src/Oms.Application/Services/Channels/SalesProductService.Portal.cs +++ b/src/Oms.Application/Services/Channels/SalesProductService.Portal.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Oms.Application.Dtos.Channels; +using Oms.Application.Storage; using Oms.Domain.ChannelsAggregate.Entities; using Oms.Domain.Shared.Enums; using Oms.Domain.SystemAggregate.Repositories; @@ -119,6 +120,9 @@ public partial class SalesProductService TradeTerms = string.IsNullOrWhiteSpace(p.TradeTerms) ? null : p.TradeTerms.Trim().ToUpperInvariant(), RouteSort = p.RouteSort, ProductDescription = p.ProductDescription, + CoverImageUrl = string.IsNullOrWhiteSpace(p.CoverImage) + ? null + : FileStorage.GetPublicUrl(p.CoverImage), DestRegions = destRegions, CoverageCountries = coverageCountries.Take(PortalCoverageCountryLimit).ToList(), CargoTags = cargoTags diff --git a/src/Oms.Application/Services/Channels/SalesProductService.cs b/src/Oms.Application/Services/Channels/SalesProductService.cs index fccb185..4037854 100644 --- a/src/Oms.Application/Services/Channels/SalesProductService.cs +++ b/src/Oms.Application/Services/Channels/SalesProductService.cs @@ -1,10 +1,13 @@ using System.Linq.Expressions; using Fake.Application; +using Fake.ObjectStorage; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Oms.Application.Dtos.Channels; using Oms.Application.Dtos.Shared; using Oms.Application.Services.Approval.Contracts; using Oms.Application.Shared; +using Oms.Application.Storage; using Oms.Domain.ApprovalAggregate.Consts; using Oms.Domain.ApprovalAggregate.Enums; using Oms.Domain.ApprovalAggregate.Repositories; @@ -41,6 +44,21 @@ public partial class SalesProductService : ApplicationService private IApprovalDefinitionRepository ApprovalDefinitionRepository => LazyServiceProvider.GetRequiredService(); + private IObjectStorage FileStorage => LazyServiceProvider.GetRequiredService(); + + /// + /// 上传销售产品官网封面图,返回 object key 与可访问 URL(落库存 key)。 + /// + /// 入参:封面图片文件(jpg/png/webp 等,≤5MB)。 + [HttpPost("/channel/sales-product/upload-cover")] + [Consumes("multipart/form-data")] + public async Task UploadCoverImageAsync(IFormFile file) + { + var key = await OmsFileUploadHelper.SaveSalesProductCoverAsync(file, FileStorage); + var url = FileStorage.GetPublicUrl(key); + return new { key, url, fileUrl = key }; + } + /// /// 查询销售产品列表。 /// @@ -78,7 +96,11 @@ public partial class SalesProductService : ApplicationService var entity = await GetProductOrThrowAsync(id); var auditUserNameMap = await UserDisplayNameResolver.ResolveManyAsync( [entity.CreateUserId, entity.UpdateUserId]); - return MapDetailOutput(entity, auditUserNameMap); + var detail = MapDetailOutput(entity, auditUserNameMap); + detail.CoverImageUrl = string.IsNullOrWhiteSpace(entity.CoverImage) + ? null + : FileStorage.GetPublicUrl(entity.CoverImage); + return detail; } /// diff --git a/src/Oms.Application/Shared/OmsFileUploadHelper.cs b/src/Oms.Application/Shared/OmsFileUploadHelper.cs index f7a169d..52abc7d 100644 --- a/src/Oms.Application/Shared/OmsFileUploadHelper.cs +++ b/src/Oms.Application/Shared/OmsFileUploadHelper.cs @@ -32,6 +32,9 @@ public static class OmsFileUploadHelper public static Task SaveBrandLogoAsync(IFormFile file, IObjectStorage storage) => SaveImageAsync(file, storage, "brand-logo", "品牌 Logo"); + public static Task SaveSalesProductCoverAsync(IFormFile file, IObjectStorage storage) => + SaveImageAsync(file, storage, "sales-product-cover", "销售产品封面图"); + private static async Task SaveImageAsync( IFormFile? file, IObjectStorage storage, diff --git a/src/Oms.Domain/ChannelsAggregate/Entities/SalesProduct.cs b/src/Oms.Domain/ChannelsAggregate/Entities/SalesProduct.cs index a6a65ec..bf9e043 100644 --- a/src/Oms.Domain/ChannelsAggregate/Entities/SalesProduct.cs +++ b/src/Oms.Domain/ChannelsAggregate/Entities/SalesProduct.cs @@ -51,6 +51,11 @@ public class SalesProduct : OmsAuditedAggregateRoot public string? ProductDescription { get; set; } + /// + /// 官网线路封面图 object key(如 uploads/sales-product-cover/...)。 + /// + public string? CoverImage { get; set; } + public string? PreStorageScript { get; set; } public string? CustomerGuideMarkdown { get; set; }