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