142 lines
5.8 KiB
C#
142 lines
5.8 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 CalculateShippingTemplateStep : WxProductPublishStepBase
|
|
{
|
|
public override string Description => "获取推单运费模板并计算运费";
|
|
|
|
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
|
{
|
|
if (context.Progress != null)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
context.Progress.Report("正在选取运费模板");
|
|
}));
|
|
}
|
|
|
|
context.Parameters.ShippingTemplateJson = "";
|
|
context.Parameters.ShipPrice = 0;
|
|
|
|
if (context.Product.ProductGetTypeText == "厂商直采")
|
|
{
|
|
var urlShipping = BaseClass.BuildObjString("product/wx_get_shipping_template");
|
|
var dataShipping = Work.UserLogin.GetSignaturex() +
|
|
"&coid=" + context.Product.SkcId;
|
|
var htmlShipping = GetHtml.PostUtf8(urlShipping, dataShipping);
|
|
if (string.IsNullOrEmpty(htmlShipping) || !htmlShipping.Contains("\"code\":200"))
|
|
htmlShipping = GetHtml.PostUtf8(urlShipping, dataShipping);
|
|
if (string.IsNullOrEmpty(htmlShipping) || !htmlShipping.Contains("\"code\":200"))
|
|
{
|
|
}
|
|
else
|
|
{
|
|
if (htmlShipping.Contains("\"data\":\"\""))
|
|
{
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
context.Parameters.ShippingTemplateJson = JsonHelper.SerializeObject(JsonHelper.JObjectParse(htmlShipping)["data"]);
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(context.Parameters.ShippingTemplateJson))
|
|
{
|
|
// 获取运费模板
|
|
var urlShip = BaseClass.BuildObjString("product/e57_get_freight_template");
|
|
var dataShip = Work.UserLogin.GetSignaturex() + "&coid=" + context.Product.SkcId;
|
|
var shipRst = GetHtml.PostUtf8(urlShip, dataShip);
|
|
if (string.IsNullOrEmpty(shipRst) || !shipRst.Contains("\"code\":0"))
|
|
shipRst = GetHtml.PostUtf8(urlShipping, dataShipping);
|
|
if (!shipRst.Contains("\"code\":0"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref shipRst, "msg");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = shipRst;
|
|
throw new Exception("运费模板获取失败 " + errMsg);
|
|
}
|
|
try
|
|
{
|
|
//[{"id":"204","warehouseNum":"15016108","freightType":0,"provinces":"香港特别行政区,台湾省,澳门特别行政区","freightPrice":9999900,"createBy":"vmslin","createTime":"2026-01-30T16:45:03+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:45:03+08:00"},{"id":"205","warehouseNum":"15016108","freightType":3,"provinces":"海南省,新疆维吾尔自治区,西藏自治区,内蒙古自治区","freightPrice":1530,"createBy":"vmslin","createTime":"2026-01-30T16:45:51+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:45:51+08:00"},{"id":"206","warehouseNum":"15016108","freightType":1,"provinces":"北京市,上海市","freightPrice":410,"createBy":"vmslin","createTime":"2026-01-30T16:46:04+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:46:04+08:00"},{"id":"207","warehouseNum":"15016108","freightType":1,"provinces":"安徽省,重庆市,福建省,广东省,甘肃省,广西壮族自治区,贵州省,河北省,湖北省,黑龙江省,河南省,湖南省,吉林省,江苏省,江西省,辽宁省,宁夏回族自治区,青海省,四川省,山东省,山西省,陕西省,天津市,云南省,浙江省","freightPrice":310,"createBy":"vmslin","createTime":"2026-01-30T16:46:17+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:46:17+08:00"}]
|
|
context.Parameters.ShippingTemplateJson = JsonHelper.SerializeObject(JsonHelper.JObjectParse(shipRst)["data"]);
|
|
if (shipRst.Contains("\"code\":0") && !string.IsNullOrEmpty(context.Parameters.ShippingTemplateJson))
|
|
{
|
|
urlShipping = BaseClass.BuildObjString("product/wx_add_mdy_shipping_template");
|
|
dataShipping = Work.UserLogin.GetSignaturex() +
|
|
"&coid=" + context.Product.SkcId +
|
|
"&shipping_template_json=" + context.Parameters.ShippingTemplateJson;
|
|
htmlShipping = GetHtml.PostUtf8(urlShipping, dataShipping);
|
|
if (string.IsNullOrEmpty(htmlShipping) || !htmlShipping.Contains("\"code\":200"))
|
|
htmlShipping = GetHtml.PostUtf8(urlShipping, dataShipping);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("运费模板解析失败 " + ex.Message);
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(context.Parameters.ShippingTemplateJson))
|
|
{
|
|
try
|
|
{
|
|
int count = 0;
|
|
var shipObjs = JArray.Parse(context.Parameters.ShippingTemplateJson);
|
|
foreach (var shipObj in shipObjs)
|
|
{
|
|
var provincesStr = shipObj["provinces"].ParseToString();
|
|
if (provincesStr.Split(',').Length > count)
|
|
{
|
|
count = provincesStr.Split(',').Length;
|
|
context.Parameters.ShipPrice = shipObj["freightPrice"].ParseToInt();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("运费模板获取失败 " + ex.Message);
|
|
}
|
|
}
|
|
if (context.Parameters.ShipPrice <= 0)
|
|
{
|
|
throw new Exception("运费模板获取失败 未获取到");
|
|
}
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|