Files
KJD/Store.Product/Publish/Steps/Wx/SubmitProductDraftStep.cs
T
2026-09-11 19:11:12 +08:00

108 lines
3.9 KiB
C#

using AllBase;
using AllBase.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 System.Windows.Forms;
using Work;
namespace Store.Product.Publish.Steps.Wx;
/// <summary>
/// 由 WXDBProdUploadForm.UploadProduct 的“保存商品草稿”区段迁移。
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
/// </summary>
public sealed class SubmitProductDraftStep : WxProductPublishStepBase
{
public override string Description => "保存商品草稿";
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
{
// 直接使用微信回采情趣商品品牌
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采") && chkUseWXComplateProd.Checked &&
upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
{
if (DefaultAdultBrandId.ParseToLong() > 0)
upProdParam.product.info.brandId = DefaultAdultBrandId.ParseToLong();
}
// 情趣内衣等类目禁止设置运费险
//if (upProdParam.product.info.category[1].name == "情趣内衣" ||
// upProdParam.product.info.category[1].name == "水果")
if (chkFreightInsurance.Checked)
{
upProdParam.product.info.extraService.freightInsurance = 1;
}
else
{
upProdParam.product.info.extraService.freightInsurance = 0;
}
// 假1赔3
if (upProdParam.product.info.category[0].name == "珠宝首饰" || upProdParam.product.info.category[1].name == "时尚饰品")
{
upProdParam.product.info.extraService.fakeOnePayFour = 1;
}
// 坏损包退 damageGuarantee
if (upProdParam.product.info.category[0].name == "生鲜" || upProdParam.product.info.category[0].name == "酒类" ||
upProdParam.product.info.category[0].name == "食品饮料" || upProdParam.product.info.category[0].name == "保健食品/膳食营养补充食品" ||
(upProdParam.product.info.category[0].name == "农资园艺" && upProdParam.product.info.category[1].name == "花卉绿植"))
{
upProdParam.product.info.extraService.damageGuarantee = 1;
}
// 生鲜不支持换货,关闭
if (upProdParam.product.info.category[0].name == "生鲜")
{
upProdParam.product.info.extraService.exchangeSupport = 0;
}
if (cell != null)
{
Invoke(new Action(() =>
{
cell.Value = "正在提交商品";
}));
}
Thread.Sleep(Randomx.GetId(1000, 2000));
uploadDraftRst = WXUpload.uploadProductDraft(shop, upProdParam);
if (!uploadDraftRst.Contains("\"code\":0") && !uploadDraftRst.Contains("\"success\":true"))
{
var error = BaseRegex.GetStringJson(ref uploadDraftRst, "msg");
if (string.IsNullOrEmpty(error))
{
if (uploadDraftRst.Contains("\"errcode\":9401043"))
error = "sku价格异常,请检查加价比例";
else
error = uploadDraftRst;
}
var draftId = BaseRegex.GetStringJson(ref uploadDraftRst, "productId").ParseToLong();
throw new Exception("草稿保存失败 " + GetHtml.UrlEncodeUtf8(error));
}
if (cell != null)
{
Invoke(new Action(() =>
{
var timeSpan = DateTime.Now - startTime;
var duration = timeSpan.TotalSeconds;
cell.Value = "商品已保存草稿,正在提交上架" + " " + duration.ParseToInt() + "秒";
}));
}
}
}