Files
KJD/Store.Product/Models/PublishParameters/Wx/WxProductUploadParam.cs
T
2026-09-14 09:16:59 +08:00

281 lines
11 KiB
C#

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.Linq;
using Store.Framework.Extensions;
using Store.Product.Models.Product;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace Store.Product.Models.PublishParameters.Wx;
/// <summary>
/// Store.Product 新的微信商品上传参数实体。
/// 说明:这里不修改 AllBase 中已有上传参数实体,当前作为迁移期承载对象复用其字段结构。
/// </summary>
public class WxProductUploadParam
{
public WxProductUploadSource Source { get; set; } = new();
public WXUploadProductInitParam InitParameter { get; set; } = new();
public WXUploadProductParam ProductParameter { get; set; } = new();
public WxProductPublishState State { get; set; } = new();
public WxProductUploadOptions Options { get; set; } = new();
public WxProductUploadRuntime Runtime { get; set; } = new();
/// <summary>步骤正常提前结束或最终成功时写入的返回 JSON。</summary>
public string Result { get; set; }
/// <summary>正常提前结束发布时置为 true,流水线不再执行后续步骤。</summary>
public bool IsCompleted { get; set; }
}
public class WxProductUploadSource
{
public ShopLoginInfo Shop { get; set; }
/// <summary>已完成商品与选品定制组合后的商品数据。</summary>
public WxProductUploadProduct Product { get; set; } = new();
/// <summary>上传任务状态,仅用于结果回写,不作为商品数据源。</summary>
public WxProductPublishTask Task { get; set; } = new();
public DateTime StartTime { get; set; } = DateTime.Now;
}
/// <summary>
/// 上传任务结果。只保存任务状态和最终草稿参数,不保存原始商品数据。
/// </summary>
public class WxProductPublishTask
{
public long id { get; set; }
public string out_product_Id { get; set; }
public string shop_id { get; set; }
public string draft_id { get; set; }
public string status { get; set; }
public DateTime add_time { get; set; }
public WXUploadProductParam wxDraftProduct { get; set; }
}
/// <summary>
/// 原 UploadProduct 方法中跨 #region 使用的可变状态。
/// TODO(迁移): 个别字段当前为 dynamic,需按 Store.Product 最终 DTO 改为明确类型。
/// </summary>
public class WxProductPublishState
{
public int CommissionRate { get; set; }
public int MinCommissionRate { get; set; }
public int MaxCommissionRate { get; set; }
public int CommissionRateChange { get; set; }
public int? FromCommissionRate { get; set; }
public WXGetEditProductInfoLite WxEditProdInfo { get; set; }
public JObject ProdJObject { get; set; } = new();
public bool IsChangeImgDic { get; set; }
public Dictionary<string, string> WxImgMapDic { get; set; } = new();
public PDDProductInfo ProdInfo { get; set; }
public int MainImgCount { get; set; }
public bool NeedAddRandomBlock { get; set; }
public bool WantAddRandomBlock { get; set; }
public WXShopTokenInfo Token { get; set; }
public string ProdTitle { get; set; }
public string ExtCode { get; set; }
public List<gallery_item> MainGalleries { get; set; } = new();
public List<long> AiCateIdLst { get; set; } = new();
public string GetCateRst { get; set; }
public JObject JCateRst { get; set; }
public long LeafCatId { get; set; }
public WxCatBoundInfo Bound { get; set; }
public int MaxBound { get; set; }
public int MinBound { get; set; }
public string SpBrandId { get; set; }
public string SpBrandName { get; set; }
public string ShippingTemplateJson { get; set; }
public int ShipPrice { get; set; }
public string ExpressRst { get; set; }
public List<gallery_item> DetailGalleries { get; set; } = new();
public WXUploadProductInfoRecommendParam RecommendParamRst { get; set; } = new();
public allAttrParam ProductAttr { get; set; }
public int MaxSkuSpecCnt { get; set; }
public int SkuIndex { get; set; }
public int Id { get; set; }
public long CatId { get; set; }
public long FCatId { get; set; }
public long ValueCatId { get; set; }
public Dictionary<string, long> DicSpecParentNameId { get; set; } = new();
public Dictionary<string, long> DicSpecParentNameCatId { get; set; } = new();
public Dictionary<string, long> DicSpecNameFCatId { get; set; } = new();
public Dictionary<string, long> DicSpecNameCatId { get; set; } = new();
public string UploadDraftRst { get; set; }
public string CommissionRstStr { get; set; }
public string DefaultAdultBrandId { get; set; }
public bool IsWxNotUseSoftwareDefaultAddressOnce { get; set; }
public List<WXShopTokenInfo> WxShopTokenInfoList { get; set; } = new();
public List<wx_qualification_image_info> QualificationImages { get; set; } = new();
public List<string> ForceFilterKeywords { get; set; } = new();
public List<dynamic> AddPriceRules { get; set; } = new();
public dynamic WxUploadRule { get; set; }
public string PddProductCates { get; set; }
public List<WxProductPublishTask> UploadDraftProductList { get; set; } = new();
}
/// <summary>
/// UploadProduct 从窗体控件和配置读取的入参快照。
/// TODO(迁移): 后续可将这些字段逐步替换成 Store.Product 自己的发布规则模型。
/// </summary>
public class WxProductUploadOptions
{
public WxProductUploadFormState Form { get; set; } = new();
}
/// <summary>
/// 原方法依赖的窗体操作与通用上传能力适配入口。
/// </summary>
public class WxProductUploadRuntime
{
public object Host { get; set; }
public dynamic Cell { get; set; } = new WxUploadCellState();
public dynamic CancellationTokenSource { get; set; } = new WxUploadCancellationState();
public Func<string, string> GetAiImg { get; set; }
public Func<ShopLoginInfo, string, object, bool, string> UploadImgByUrl { get; set; }
public Func<ShopLoginInfo, Bitmap, object, string> UploadImgByBitmap { get; set; }
public GetImgBase64ForApiHandler GetImgBase64ForApi { get; set; }
public Action<string> SetStatus { get; set; }
public Action Cancel { get; set; }
public Action<string> ShowError { get; set; }
}
public delegate string GetImgBase64ForApiHandler(
out string errorMsg,
string imgUrl,
bool needAddRandomBlock,
bool wantAddRandomBlock,
int imgWidth = 0,
int imgHeight = 0,
bool wantAddRandomBorder = false);
public class WxUploadCellState
{
private object _value;
public object Value
{
get => _value;
set => _value = value;
}
}
public class WxUploadCancellationState
{
public Action CancelAction { get; set; }
public void Cancel()
{
CancelAction?.Invoke();
}
}
/// <summary>
/// 原窗体控件的状态代理,避免 Store.Product 直接引用 WinForms 控件类型。
/// </summary>
public class WxProductUploadFormState
{
public dynamic chkFissionGoodsName { get; set; } = new WxControlState();
public dynamic txtFissionTitle { get; set; } = new WxControlState();
public dynamic chkSkipUploaded { get; set; } = new WxControlState();
public dynamic chkCommission { get; set; } = new WxControlState();
public dynamic cmbCommissionAddOrReduce { get; set; } = new WxControlState();
public dynamic txtCommissionChangeValue { get; set; } = new WxControlState();
public dynamic txtMinUpCommission { get; set; } = new WxControlState();
public dynamic txtMaxUpCommission { get; set; } = new WxControlState();
public dynamic chkImgRandomBlock { get; set; } = new WxControlState();
public dynamic chkRandomMainImgOrder { get; set; } = new WxControlState();
public dynamic chkRandomDetailImgOrder { get; set; } = new WxControlState();
public dynamic chkFissionRandomPriceChange { get; set; } = new WxControlState();
public dynamic txtFissionRandomPriceChange { get; set; } = new WxControlState();
public dynamic chkHighestPriceSku { get; set; } = new WxControlState();
public dynamic chkLowestPriceSku { get; set; } = new WxControlState();
public dynamic chkSameSpecPriceUp { get; set; } = new WxControlState();
public dynamic chkSameSpecPriceDown { get; set; } = new WxControlState();
public dynamic txtMinPrice { get; set; } = new WxControlState();
public dynamic txtMaxPrice { get; set; } = new WxControlState();
public dynamic txtReplaceText { get; set; } = new WxControlState();
public dynamic chkSkipReplaceText { get; set; } = new WxControlState();
public dynamic chkRemoveSpecialChar { get; set; } = new WxControlState();
public dynamic chkUseWXComplateProd { get; set; } = new WxControlState();
public dynamic chkUseRecommand { get; set; } = new WxControlState();
public dynamic cmbSpBrandName { get; set; } = new WxControlState();
public dynamic txtFilterBoundMax { get; set; } = new WxControlState();
public dynamic txtFilterBoundMin { get; set; } = new WxControlState();
public dynamic txtMainBorderImgCount { get; set; } = new WxControlState();
public dynamic txtDetailBorderImgCount { get; set; } = new WxControlState();
public dynamic chkRandomImgBorder { get; set; } = new WxControlState();
public dynamic chkAiImage { get; set; } = new WxControlState();
public dynamic txtAiImgCount { get; set; } = new WxControlState();
public dynamic chkFreightInsurance { get; set; } = new WxControlState();
public dynamic chkUseShanghaiReturnOrderAddress { get; set; } = new WxControlState();
public dynamic chkPreSale { get; set; } = new WxControlState();
public dynamic chkDefaultBestBefore { get; set; } = new WxControlState();
public dynamic txtDefaultBestBefore { get; set; } = new WxControlState();
public dynamic chkTestNoAuditUpload { get; set; } = new WxControlState();
public dynamic chkUpDraft { get; set; } = new WxControlState();
public dynamic chkIsSubmitSuccess { get; set; } = new WxControlState();
public dynamic dgvShop { get; set; } = new WxControlState();
}
public class WxControlState
{
public bool Checked { get; set; }
public string Text { get; set; } = "";
public decimal Value { get; set; }
public object SelectedValue { get; set; }
public object SelectedItem { get; set; }
public int SelectedIndex { get; set; } = -1;
public dynamic Items { get; set; } = new List<object>();
public static WxControlState FromCheckBox(dynamic checkBox)
{
return new WxControlState
{
Checked = checkBox?.Checked == true,
Text = checkBox?.Text ?? ""
};
}
public static WxControlState FromTextBox(dynamic textBox)
{
return new WxControlState
{
Text = textBox?.Text ?? ""
};
}
public static WxControlState FromComboBox(dynamic comboBox)
{
if (comboBox == null)
{
return new WxControlState();
}
return new WxControlState
{
Text = comboBox.Text ?? "",
SelectedValue = comboBox.SelectedValue,
SelectedItem = comboBox.SelectedItem,
SelectedIndex = comboBox.SelectedIndex
};
}
public static WxControlState FromNumericUpDown(dynamic numericUpDown)
{
return new WxControlState
{
Value = numericUpDown?.Value ?? 0m,
Text = numericUpDown?.Text ?? ""
};
}
}