Files
KJD/Store.Product/Publish/Steps/Wx/FillMainImagesStep.cs
T
2026-09-14 09:16:59 +08:00

79 lines
2.6 KiB
C#

using AllBase;
using AllBase.Extension;
using NaiBa.Util.Extension;
using AllBase.Helper;
using AllBase.Model.Config;
using AllBase.Model.DBModel;
using AllBase.Model.Param.WXParam;
using AllBase.Model.Result;
using AllBase.Model.Result.PDDResult;
using AllBase.Model.Result.WXResult;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Store.Product.Models.PublishParameters.Wx;
using Store.Product.Publish;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Work;
namespace Store.Product.Publish.Steps.Wx;
/// <summary>
/// 由 WXDBProdUploadForm.UploadProduct 的“主图不足时使用详情图补充”区段迁移。
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
/// </summary>
public sealed class FillMainImagesStep : WxProductPublishStepBase
{
public override string Description => "主图不足时使用详情图补充";
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
{
context.Parameters.MainImgCount = (context.Parameters.ProdInfo?.detail?.galleries?.Where(g => g.type == 1).Count()).ParseToInt();
if (context.Parameters.MainImgCount > 0 && context.Parameters.MainImgCount < 3)
{
var gallery1 = context.Parameters.ProdInfo?.detail?.galleries?.Where(g => g.type == 2).FirstOrDefault();
// 先补一张
if (gallery1 != null)
{
context.Parameters.ProdInfo.detail.galleries.Add(new gallery_item()
{
type = 1,
url = gallery1.url,
width = gallery1.width,
height = gallery1.height,
});
}
// 如果补了只有两张再补一张
if (context.Parameters.MainImgCount == 1 && (context.Parameters.ProdInfo?.detail?.galleries?.Where(g => g.type == 1).Count()).ParseToInt() > 1)
{
var gallery2 = context.Parameters.ProdInfo?.detail?.galleries?[1];
if (gallery2 != null)
{
context.Parameters.ProdInfo.detail.galleries.Add(new gallery_item()
{
type = 1,
url = gallery2.url,
width = gallery2.width,
height = gallery2.height,
});
}
}
}
if ((context.Parameters.ProdInfo?.detail?.galleries?.Where(g => g.type == 1).Count()).ParseToInt() < 3)
{
Invoke(new Action(() =>
{
context.Progress.Report("主图数量少于三张");
}));
throw new Exception("主图数量少于三张");
}
return Task.CompletedTask;
}
}