增加项目,分层
This commit is contained in:
1 parent
6e995a5bdb
commit
0a3e5af6a9
234 files changed
+26994
-1
No files matched your search
@@ -0,0 +1,18 @@
|
||||
using Store.Product.Publish.Steps.Wx;
|
||||
|
||||
namespace Store.Product;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
public Class1()
|
||||
{
|
||||
var p = new Progress<string>(P_ProgressChanged);
|
||||
new WXPublishContext().Progress = p;
|
||||
|
||||
}
|
||||
|
||||
private void P_ProgressChanged(string value)
|
||||
{
|
||||
// 更新 UI
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 封禁类型
|
||||
/// </summary>
|
||||
public enum BlockType
|
||||
{
|
||||
/// <summary>
|
||||
/// 根类目封禁
|
||||
/// </summary>
|
||||
CatgoryRoot,
|
||||
/// <summary>
|
||||
/// 当前类目封禁
|
||||
/// </summary>
|
||||
Category,
|
||||
/// <summary>
|
||||
/// 店铺封禁
|
||||
/// </summary>
|
||||
Shop,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 运费模板设置方式
|
||||
/// </summary>
|
||||
public enum FreightTemplateType
|
||||
{
|
||||
/// <summary>
|
||||
/// 复制上家模板
|
||||
/// </summary>
|
||||
[Description("复制上家模板")]
|
||||
Copy = 0,
|
||||
/// <summary>
|
||||
/// 随机本店模板
|
||||
/// </summary>
|
||||
[Description("随机本店模板")]
|
||||
Random = 1,
|
||||
/// <summary>
|
||||
/// 固定本店模板
|
||||
/// </summary>
|
||||
[Description("固定本店模板")]
|
||||
Fixed = 2,
|
||||
/// <summary>
|
||||
/// 指定模板
|
||||
/// </summary>
|
||||
[Description("指定本店模板")]
|
||||
Specified = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 上传结果状态
|
||||
/// </summary>
|
||||
public enum UpResultStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 继续下一个
|
||||
/// </summary>
|
||||
Next,
|
||||
/// <summary>
|
||||
/// 跳出本次上传
|
||||
/// </summary>
|
||||
Return,
|
||||
/// <summary>
|
||||
/// 结束所有上传
|
||||
/// </summary>
|
||||
Finished
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品存储状态
|
||||
/// </summary>
|
||||
public enum ProductStorageStatus
|
||||
{
|
||||
立刻上架 = 0,
|
||||
定时上架 = 1,
|
||||
放入仓库 = 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Store.Product.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品状态
|
||||
/// </summary>
|
||||
public enum StuffStatus
|
||||
{
|
||||
全新 = 5,
|
||||
二手 = 6
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Models.Product.Image
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品详情图片
|
||||
/// </summary>
|
||||
public class ContentImage : ProductImage
|
||||
{
|
||||
//public override ImageType ImageType => ImageType.Content;
|
||||
|
||||
public ContentImage(string url) : base(url)
|
||||
{
|
||||
Gid = Guid.NewGuid().ToString();
|
||||
}
|
||||
public string Gid { get; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Models.Product.Image
|
||||
{
|
||||
public class MainImage : ProductImage
|
||||
{
|
||||
public override ProductImageType ImageType => ProductImageType.Main;
|
||||
public MainImage()
|
||||
{
|
||||
|
||||
}
|
||||
public MainImage(string url) : base(url)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using Newtonsoft.Json;
|
||||
using Store.Management.Framework.Helpers;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Store.Product.Models.Product.Image
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品图片
|
||||
/// </summary>
|
||||
public class ProductImage
|
||||
{
|
||||
|
||||
public ProductImage()
|
||||
{
|
||||
|
||||
}
|
||||
public ProductImage(string url)
|
||||
{
|
||||
ImgUrl = url;
|
||||
}
|
||||
//public ProductImage(string url, ImageType type)
|
||||
//{
|
||||
// ImgUrl = url;
|
||||
// ImageType = type;
|
||||
//}
|
||||
/// <summary>
|
||||
/// 图片类型
|
||||
/// </summary>
|
||||
public virtual ProductImageType ImageType { get; protected set; } = ProductImageType.None;
|
||||
/// <summary>
|
||||
/// 文件名
|
||||
/// </summary>
|
||||
public string FileName { get; set; }
|
||||
/// <summary>
|
||||
/// 图片源路径
|
||||
/// </summary>
|
||||
public string ImgUrl { get; set; }
|
||||
|
||||
private byte[] _imgbyte;
|
||||
/// <summary>
|
||||
/// 图片流
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public byte[] ImgByte
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_imgbyte == null)
|
||||
{
|
||||
_imgbyte = ImageHelper.DownloadImage(ImgUrl);
|
||||
}
|
||||
return _imgbyte;
|
||||
}
|
||||
set
|
||||
{
|
||||
_imgbyte = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 上传后图片路径
|
||||
/// </summary>
|
||||
public string UploadImgUrl { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Store.Product.Models.Product.Image
|
||||
{
|
||||
/// <summary>
|
||||
/// 图片类型
|
||||
/// </summary>
|
||||
public enum ProductImageType
|
||||
{
|
||||
None,
|
||||
Main,
|
||||
Sku,
|
||||
Content
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Models.Product.Image
|
||||
{
|
||||
public class SkuImage : ProductImage
|
||||
{
|
||||
public override ProductImageType ImageType => ProductImageType.Sku;
|
||||
public SkuImage()
|
||||
{
|
||||
|
||||
}
|
||||
public SkuImage(string url) : base(url)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Store.Product.Models.Product.Image;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Models.Product
|
||||
{
|
||||
/// <summary>
|
||||
/// 主图集合
|
||||
/// </summary>
|
||||
public class MainImageCollection : List<ProductImage>
|
||||
{
|
||||
/// <summary>
|
||||
/// 随机排序
|
||||
/// </summary>
|
||||
public void RandomSort()
|
||||
{
|
||||
Random random = new Random();
|
||||
List<ProductImage> newList = new List<ProductImage>();
|
||||
foreach (ProductImage item in this.Take(4))
|
||||
{
|
||||
newList.Insert(random.Next(newList.Count + 1), item);
|
||||
}
|
||||
if (this.Count == 5)
|
||||
{
|
||||
newList.Add(this.Last());
|
||||
}
|
||||
this.Clear();
|
||||
this.AddRange(newList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
using Store.Product.Models.Product.Sku;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Models.Product;
|
||||
|
||||
/// <summary>
|
||||
/// 商品属性基类
|
||||
/// </summary>
|
||||
public class ProductBase
|
||||
{
|
||||
private string _gid = Guid.NewGuid().ToString();
|
||||
/// <summary>
|
||||
/// 唯一ID
|
||||
/// </summary>
|
||||
public string Gid
|
||||
{
|
||||
get
|
||||
{
|
||||
return _gid;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 商品ID
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商铺名称
|
||||
/// </summary>
|
||||
public string ShopName { get; set; }
|
||||
/// <summary>
|
||||
/// 类目ID
|
||||
/// </summary>
|
||||
public int CategoryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 销售数量
|
||||
/// </summary>
|
||||
public int SaleCount { get; set; }
|
||||
/// <summary>
|
||||
/// 库存数量
|
||||
/// </summary>
|
||||
public int StockCount { get; set; }
|
||||
/// <summary>
|
||||
/// 价格
|
||||
/// </summary>
|
||||
public decimal Price { get; set; }
|
||||
/// <summary>
|
||||
/// 以前价格 | 划线价格
|
||||
/// </summary>
|
||||
public decimal BeforePrice { get; set; }
|
||||
/// <summary>
|
||||
/// 邮费
|
||||
/// </summary>
|
||||
public decimal ExpressPrice { get; set; }
|
||||
/// <summary>
|
||||
/// 折扣
|
||||
/// </summary>
|
||||
public decimal Discount { get; set; }
|
||||
/// <summary>
|
||||
/// 折扣价格
|
||||
/// </summary>
|
||||
public decimal DiscountPrice { get; set; }
|
||||
/// <summary>
|
||||
/// 在线价格
|
||||
/// </summary>
|
||||
public decimal OnlinePrice { get; set; }
|
||||
/// <summary>
|
||||
/// 市场价格
|
||||
/// </summary>
|
||||
public decimal MarketPrice { get; set; }
|
||||
/// <summary>
|
||||
/// 主图
|
||||
/// </summary>
|
||||
public string MainImage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 品牌
|
||||
/// </summary>
|
||||
public string ShopBrand { get; set; }
|
||||
/// <summary>
|
||||
/// 是否是促销品
|
||||
/// </summary>
|
||||
public bool IsPromotion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 省
|
||||
/// </summary>
|
||||
public string State { get; set; }
|
||||
/// <summary>
|
||||
/// 市
|
||||
/// </summary>
|
||||
public string City { get; set; }
|
||||
/// <summary>
|
||||
/// 内容
|
||||
/// </summary>
|
||||
public ProductContent Content { get; set; } = new ProductContent("");
|
||||
/// <summary>
|
||||
/// 来源地址
|
||||
/// </summary>
|
||||
public virtual string SourceUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品主图视频Id
|
||||
/// </summary>
|
||||
public long VideoId { get; set; }
|
||||
/// <summary>
|
||||
/// 重量
|
||||
/// </summary>
|
||||
public int Weight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品特性
|
||||
/// </summary>
|
||||
public ProductPropertys Propertys { get; set; } = new ProductPropertys();
|
||||
|
||||
/// <summary>
|
||||
/// SKU 属性值
|
||||
/// </summary>
|
||||
public SkuPropertys SkuProperty { get; set; } = new SkuPropertys();
|
||||
|
||||
/// <summary>
|
||||
/// Sku 属性映射
|
||||
/// </summary>
|
||||
public SkuMaps SkuMaps { get; set; } = new SkuMaps();
|
||||
/// <summary>
|
||||
/// 主图列表
|
||||
/// </summary>
|
||||
public MainImageCollection MainImages { get; set; } = new MainImageCollection();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
using Store.Product.Models.Product.Image;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Models.Product
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品详情
|
||||
/// </summary>
|
||||
public class ProductContent
|
||||
{
|
||||
/// <summary>
|
||||
/// 备份数据
|
||||
/// </summary>
|
||||
private string _backcontent = "";
|
||||
public ProductContent(string content)
|
||||
{
|
||||
_backcontent = content;
|
||||
_content = content;
|
||||
ConvertContent();
|
||||
}
|
||||
|
||||
|
||||
private string _content = "";
|
||||
public override string ToString()
|
||||
{
|
||||
return GetContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 详情图片集合
|
||||
/// </summary>
|
||||
public List<ContentImage> Images { get; } = new List<ContentImage>();
|
||||
|
||||
/// <summary>
|
||||
/// 删除详情图片
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
public void DelImage(ContentImage image)
|
||||
{
|
||||
var item = Images.FirstOrDefault(a => a.Gid == image.Gid);
|
||||
if (item != null)
|
||||
{
|
||||
string value = GetImgTag(item);
|
||||
_content.Replace(value, "");
|
||||
Images.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void ConvertContent()
|
||||
{
|
||||
Regex regImg = new Regex(@"<img\b[^>]*?\bsrc[\s]*=[\s]*[""']?[\s]*(?<imgUrl>[^""'>]*)[^>]*?/?[\s]*>");
|
||||
if (regImg.IsMatch(_backcontent))
|
||||
{
|
||||
MatchCollection matchs = regImg.Matches(_backcontent);
|
||||
int MatchMax = matchs.Count;
|
||||
for (int i = MatchMax - 1; i >=0; i--)
|
||||
{
|
||||
Match item = matchs[i];
|
||||
if (item.Success)
|
||||
{
|
||||
Group urlgroup = item.Groups["imgUrl"];
|
||||
if (urlgroup.Success)
|
||||
{
|
||||
var cimg = new ContentImage(urlgroup.Value);
|
||||
Images.Add(cimg);
|
||||
|
||||
_content = _content.Remove(item.Index, item.Length);
|
||||
_content = _content.Insert(item.Index, GetImgTag(cimg));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetContent()
|
||||
{
|
||||
var tempContent = _content;
|
||||
foreach (var item in Images)
|
||||
{
|
||||
string value = GetImgTag(item);
|
||||
string imgString = $"<img src=\"{item.UploadImgUrl}\" width=\"100%\" />";
|
||||
tempContent = tempContent.Replace(value, imgString);
|
||||
}
|
||||
return tempContent;
|
||||
}
|
||||
/// <summary>
|
||||
/// 图片标记
|
||||
/// </summary>
|
||||
/// <param name="img"></param>
|
||||
/// <returns></returns>
|
||||
private string GetImgTag(ContentImage img)
|
||||
{
|
||||
return "${" + img.Gid + "}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using MAX.Core.Commons;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Models.Product
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品属性
|
||||
/// </summary>
|
||||
public partial class ProductPropertys : List<CommonKeyValue>
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否存在Key
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public bool ContainsKey(string key)
|
||||
{
|
||||
return Exists(a => a.Key == key);
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加数据
|
||||
/// </summary>
|
||||
/// <param name="Key"></param>
|
||||
/// <param name="Value"></param>
|
||||
public void Add(string Key, string Value)
|
||||
{
|
||||
if (!ContainsKey(Key))
|
||||
{
|
||||
Add(new CommonKeyValue() { Key = Key, Value = Value });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public string GetValue(string key)
|
||||
{
|
||||
if (ContainsKey(key))
|
||||
{
|
||||
CommonKeyValue p = this.FirstOrDefault(a => a.Key == key);
|
||||
return p.Value;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace Store.Product.Models.Product.Sku
|
||||
{
|
||||
/// <summary>
|
||||
/// 属性值
|
||||
/// </summary>
|
||||
public class Property
|
||||
{
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Store.Product.Models.Product.Sku
|
||||
{
|
||||
/// <summary>
|
||||
/// Sku Map Item
|
||||
/// </summary>
|
||||
public class SkuMapItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 库存数量
|
||||
/// </summary>
|
||||
public int StockCount { get; set; }
|
||||
/// <summary>
|
||||
/// 价格
|
||||
/// </summary>
|
||||
public decimal Price { get; set; }
|
||||
/// <summary>
|
||||
/// 划线价格
|
||||
/// </summary>
|
||||
public decimal MarketPrice { get; set; }
|
||||
/// <summary>
|
||||
/// SkuId
|
||||
/// </summary>
|
||||
public long SkuId { get; set; }
|
||||
/// <summary>
|
||||
/// Sku 属性值
|
||||
/// </summary>
|
||||
public List<SkuMapProperty> Properties { get; set; } = new List<SkuMapProperty>();
|
||||
|
||||
/// <summary>
|
||||
/// Sku 属性标题集合
|
||||
/// </summary>
|
||||
public string SkuPropertyTitles
|
||||
{
|
||||
get
|
||||
{
|
||||
string title = string.Join("},{", Properties.Select(a => a.ToString()));
|
||||
title = "{" + title + "}";
|
||||
return title;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Sku属性Keyu
|
||||
/// </summary>
|
||||
public string SalePropKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Join("_", Properties.Select(a => a.SalePropKey));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace Store.Product.Models.Product.Sku
|
||||
{
|
||||
/// <summary>
|
||||
/// SkuMap 属性
|
||||
/// </summary>
|
||||
public class SkuMapProperty : Property
|
||||
{
|
||||
public SkuPropertyItem Item { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Name}:{Item.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// 属性Key
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string SalePropKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Id + "-" + Item.Id).Replace("p-", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
namespace Store.Product.Models.Product.Sku
|
||||
{
|
||||
/// <summary>
|
||||
/// Sku Map映射
|
||||
/// </summary>
|
||||
public class SkuMaps : List<SkuMapItem>
|
||||
{
|
||||
/// <summary>
|
||||
/// 最低价位
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SkuMapItem SkuLowItem
|
||||
{
|
||||
get
|
||||
{
|
||||
var price = this.Min(a => a.Price);
|
||||
return this.FirstOrDefault(a => a.Price == price);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 最高价位
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SkuMapItem SkuHighItem
|
||||
{
|
||||
get
|
||||
{
|
||||
var price = this.Max(a => a.Price);
|
||||
return this.FirstOrDefault(a => a.Price == price);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Store.Product.Models.Product.Sku
|
||||
{
|
||||
/// <summary>
|
||||
/// SKU 属性值
|
||||
/// </summary>
|
||||
public class SkuProperty : Property
|
||||
{
|
||||
public List<SkuPropertyItem> Values { get; set; } = new List<SkuPropertyItem>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Store.Product.Models.Product.Image;
|
||||
|
||||
namespace Store.Product.Models.Product.Sku
|
||||
{
|
||||
/// <summary>
|
||||
/// Sku属性 values
|
||||
/// </summary>
|
||||
public class SkuPropertyItem : Property
|
||||
{
|
||||
/// <summary>
|
||||
/// 库存
|
||||
/// </summary>
|
||||
public int StockCount { get; set; }
|
||||
public ProductImage SkuImg { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Models.Product.Sku
|
||||
{
|
||||
/// <summary>
|
||||
/// Sku属性
|
||||
/// </summary>
|
||||
public class SkuPropertys : List<SkuProperty>
|
||||
{
|
||||
|
||||
public SkuPropertys()
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否存在Key
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public bool ContainsKey(string Id)
|
||||
{
|
||||
return Exists(a => a.Id == Id);
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加Sku属性
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="name"></param>
|
||||
public void AddSkuProperty(string id, string name)
|
||||
{
|
||||
if (!ContainsKey(id))
|
||||
{
|
||||
this.Add(new SkuProperty
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
Values = new List<SkuPropertyItem>()
|
||||
});
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加Sku属性 包含值
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="propertyItem"></param>
|
||||
public void AddSkuPropertyItem(string id, SkuPropertyItem propertyItem)
|
||||
{
|
||||
if (propertyItem != null)
|
||||
{
|
||||
var item = GetPropertyById(id);
|
||||
if (!item.Values.Exists(a => a.Id == propertyItem.Id))
|
||||
{
|
||||
item.Values.Add(propertyItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
//public void AddSkuProperty(string id, string name, SkuPropertyItem propertyItem)
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Sku属性值
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="itemname"></param>
|
||||
/// <returns></returns>
|
||||
public SkuMapProperty GetSkuMapProperty(string name, string itemname)
|
||||
{
|
||||
SkuProperty p = this.FirstOrDefault(a => a.Name == name);
|
||||
if (p != null)
|
||||
{
|
||||
var item = p.Values.FirstOrDefault(a => a.Name == itemname);
|
||||
return new SkuMapProperty()
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Name,
|
||||
Item = item
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public SkuProperty GetPropertyById(string Id)
|
||||
{
|
||||
if (ContainsKey(Id))
|
||||
{
|
||||
SkuProperty p = this.FirstOrDefault(a => a.Id == Id);
|
||||
return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System.IO;
|
||||
|
||||
namespace Store.Product.Models.PublishParameters.Image
|
||||
{
|
||||
/// <summary>
|
||||
/// 上传图片参数
|
||||
/// </summary>
|
||||
public class ImageParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否随机删除一张详情图
|
||||
/// </summary>
|
||||
public bool IsRandomDelDetailImg { get; set; }
|
||||
/// <summary>
|
||||
/// 是否随机主图
|
||||
/// </summary>
|
||||
public bool IsRandomMainImg { get; set; }
|
||||
/// <summary>
|
||||
/// 复制上家主图视频
|
||||
/// </summary>
|
||||
public bool IsUploadVideoByCopy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上传自己视频空间索引视频
|
||||
/// </summary>
|
||||
public SwitchParams<int> IsUploadVideoFromToIndex { get; set; }
|
||||
/// <summary>
|
||||
/// Logo水印
|
||||
/// </summary>
|
||||
public SwitchParams<System.Drawing.Image> IsLogoWaterMark { get; set; }
|
||||
/// <summary>
|
||||
/// 图片质量百分比
|
||||
/// </summary>
|
||||
public int PicQuality { get; set; }
|
||||
/// <summary>
|
||||
/// 商铺文字水印
|
||||
/// </summary>
|
||||
public bool IsShopNameWaterMark { get; set; }
|
||||
/// <summary>
|
||||
/// 是否随机属性图充当主图
|
||||
/// </summary>
|
||||
public bool IsRandomPropImgFillToMainImg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 简单的电脑详情图
|
||||
/// </summary>
|
||||
public bool IsSimpleContentPc { get; set; }
|
||||
/// <summary>
|
||||
/// 是否删除主图 索引
|
||||
/// </summary>
|
||||
public SwitchParams<int> IsDelMainImgByIndex { get; set; } = new SwitchParams<int>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否删除详情图 索引 在之前
|
||||
/// </summary>
|
||||
public SwitchParams<int> IsDelDetailImgByFromToIndex { get; set; } = new SwitchParams<int>();
|
||||
|
||||
/// <summary>
|
||||
/// 是否开启 详情图 最大上传
|
||||
/// </summary>
|
||||
public SwitchParams<int> IsOnlyUpDetailImgMaxCount { get; set; } = new SwitchParams<int>();
|
||||
|
||||
/// <summary>
|
||||
/// 主图 白底最后一张
|
||||
/// </summary>
|
||||
public bool IsMainImgBackgroundWihiteLast { get; set; }
|
||||
/// <summary>
|
||||
/// 是否盗链
|
||||
/// </summary>
|
||||
public bool IsSteal { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否保留前x张主图
|
||||
/// </summary>
|
||||
public SwitchParams<int> IsKeepMainImgNum { get; set; } = new SwitchParams<int>();
|
||||
|
||||
public ImageParameters()
|
||||
{
|
||||
IsLogoWaterMark = new SwitchParams<System.Drawing.Image>();
|
||||
//string brandPath = Path.Combine(GlobalConfig.AppDirectory + "Brand\\brand.png");
|
||||
//if(File.Exists(brandPath))
|
||||
//{
|
||||
// IsLogoWaterMark.Value = System.Drawing.Image.FromFile(brandPath);
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Models.PublishParameters.Price
|
||||
{
|
||||
/// <summary>
|
||||
/// 计算操作符
|
||||
/// </summary>
|
||||
public enum ComputationType
|
||||
{
|
||||
/// <summary>
|
||||
/// 加
|
||||
/// </summary>
|
||||
ADD,
|
||||
/// <summary>
|
||||
/// 减法
|
||||
/// </summary>
|
||||
SUB
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Store.Product.Models.Product.Sku;
|
||||
using System.Linq;
|
||||
|
||||
namespace Store.Product.Models.PublishParameters.Price
|
||||
{
|
||||
/// <summary>
|
||||
/// 高低价格配置
|
||||
/// </summary>
|
||||
public class HighLowPrice : PriceConfigBase
|
||||
{
|
||||
public override PriceStrategyType PriceType => PriceStrategyType.高低价格;
|
||||
|
||||
/// <summary>
|
||||
/// 低价倍数
|
||||
/// </summary>
|
||||
public decimal LowMultiples { get; set; } = 1;
|
||||
/// <summary>
|
||||
/// 其他倍数
|
||||
/// </summary>
|
||||
public decimal OtherMultiples { get; set; } = 1;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 计算价格
|
||||
/// </summary>
|
||||
/// <param name="oldPrice"></param>
|
||||
/// <returns></returns>
|
||||
public override decimal ComputedPrice(decimal oldPrice)
|
||||
{
|
||||
return oldPrice * OtherMultiples;
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算最低价
|
||||
/// </summary>
|
||||
/// <param name="oldPrice"></param>
|
||||
/// <returns></returns>
|
||||
public decimal ComputedLowPrice(decimal oldPrice)
|
||||
{
|
||||
return oldPrice * LowMultiples;
|
||||
}
|
||||
|
||||
|
||||
public override SkuMaps ComputedPrice(SkuMaps skuMaps)
|
||||
{
|
||||
decimal minPrice = skuMaps.Min(a => a.Price);
|
||||
foreach (var item in skuMaps)
|
||||
{
|
||||
if (item.Price == minPrice)
|
||||
{
|
||||
ComputedLowPrice(item.Price);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Price = ComputedPrice(item.Price);
|
||||
}
|
||||
}
|
||||
return skuMaps;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
|
||||
using Store.Product.Models.Product.Sku;
|
||||
|
||||
namespace Store.Product.Models.PublishParameters.Price
|
||||
{
|
||||
/// <summary>
|
||||
/// 翻倍价格配置
|
||||
/// </summary>
|
||||
public class MultiplesPrice : PriceConfigBase
|
||||
{
|
||||
public override PriceStrategyType PriceType => PriceStrategyType.常规价格;
|
||||
/// <summary>
|
||||
/// 翻 x 倍
|
||||
/// </summary>
|
||||
public int Multiples { get; set; } = 1;
|
||||
/// <summary>
|
||||
/// 计算
|
||||
/// </summary>
|
||||
public ComputationType Computation { get; set; } = ComputationType.ADD;
|
||||
/// <summary>
|
||||
/// 基础加价
|
||||
/// </summary>
|
||||
public decimal AddPrice { get; set; }
|
||||
public MultiplesPrice() { }
|
||||
/// <summary>
|
||||
/// 翻倍价格配置
|
||||
/// </summary>
|
||||
/// <param name="multiples">倍数</param>
|
||||
/// <param name="addprice">加价</param>
|
||||
public MultiplesPrice(int multiples, decimal addprice)
|
||||
{
|
||||
Multiples = multiples;
|
||||
AddPrice = addprice;
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算价格
|
||||
/// </summary>
|
||||
/// <param name="oldPrice"></param>
|
||||
/// <returns></returns>
|
||||
public override decimal ComputedPrice(decimal oldPrice)
|
||||
{
|
||||
var newPrice = oldPrice;
|
||||
newPrice = oldPrice * Multiples;
|
||||
switch (Computation)
|
||||
{
|
||||
case ComputationType.ADD:
|
||||
newPrice = newPrice + AddPrice;
|
||||
break;
|
||||
case ComputationType.SUB:
|
||||
newPrice = newPrice - AddPrice;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return newPrice;
|
||||
}
|
||||
|
||||
public override SkuMaps ComputedPrice(SkuMaps skuMaps)
|
||||
{
|
||||
foreach (var item in skuMaps)
|
||||
{
|
||||
item.Price = ComputedPrice(item.Price);
|
||||
}
|
||||
return skuMaps;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
using Store.Product.Models.Product.Sku;
|
||||
|
||||
namespace Store.Product.Models.PublishParameters.Price
|
||||
{
|
||||
/// <summary>
|
||||
/// 价格配置
|
||||
/// </summary>
|
||||
public abstract class PriceConfigBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 价格类型
|
||||
/// </summary>
|
||||
public abstract PriceStrategyType PriceType { get; }
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// 快递费是否增加到商品价格
|
||||
///// </summary>
|
||||
//public bool IsExpressAddPrice { get; set; } = false;
|
||||
///// <summary>
|
||||
///// 是否随机增加金额 0-1元
|
||||
///// </summary>
|
||||
//public bool IsRandomAddPrice { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 计算价格
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract decimal ComputedPrice(decimal oldPrice);
|
||||
|
||||
/// <summary>
|
||||
/// 计算价格
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract SkuMaps ComputedPrice(SkuMaps skuMaps);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Models.PublishParameters.Price
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class PriceStrategyFactory
|
||||
{
|
||||
public static PriceConfigBase GetPriceStrategy(PriceStrategyType strategyType)
|
||||
{
|
||||
PriceConfigBase priceConfig;
|
||||
switch (strategyType)
|
||||
{
|
||||
case PriceStrategyType.常规价格:
|
||||
priceConfig = new MultiplesPrice();
|
||||
break;
|
||||
case PriceStrategyType.高低价格:
|
||||
priceConfig = new HighLowPrice();
|
||||
break;
|
||||
case PriceStrategyType.分段价格:
|
||||
priceConfig = new SectionPrice();
|
||||
break;
|
||||
default:
|
||||
priceConfig = null;
|
||||
break;
|
||||
}
|
||||
return priceConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Store.Product.Models.PublishParameters.Price
|
||||
{
|
||||
/// <summary>
|
||||
/// 价格策略类型
|
||||
/// </summary>
|
||||
public enum PriceStrategyType
|
||||
{
|
||||
常规价格 = 0,
|
||||
高低价格 = 1,
|
||||
分段价格 = 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using Store.Product.Models.Product.Sku;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Store.Product.Models.PublishParameters.Price
|
||||
{
|
||||
/// <summary>
|
||||
/// 区间价格配置
|
||||
/// </summary>
|
||||
public class SectionPrice : PriceConfigBase
|
||||
{
|
||||
public override PriceStrategyType PriceType => PriceStrategyType.分段价格;
|
||||
|
||||
/// <summary>
|
||||
/// 区间列表
|
||||
/// </summary>
|
||||
public List<SectionItemPrice> SectionList { get; set; } = new List<SectionItemPrice>();
|
||||
|
||||
/// <summary>
|
||||
/// 计算价格
|
||||
/// </summary>
|
||||
/// <param name="oldPrice"></param>
|
||||
/// <returns></returns>
|
||||
public override decimal ComputedPrice(decimal oldPrice)
|
||||
{
|
||||
var newPrice = oldPrice;
|
||||
if (SectionList != null && SectionList.Count > 0)
|
||||
{
|
||||
foreach (var item in SectionList)
|
||||
{
|
||||
if (item.BeginPrice < newPrice && newPrice < item.EndPrice)
|
||||
{
|
||||
newPrice = item.ComputedPrice(newPrice);
|
||||
}
|
||||
}
|
||||
if (newPrice == oldPrice)
|
||||
{
|
||||
newPrice = SectionList.Last().ComputedPrice(newPrice);
|
||||
}
|
||||
}
|
||||
return newPrice;
|
||||
}
|
||||
|
||||
public override SkuMaps ComputedPrice(SkuMaps skuMaps)
|
||||
{
|
||||
foreach (var item in skuMaps)
|
||||
{
|
||||
item.Price = ComputedPrice(item.Price);
|
||||
}
|
||||
return skuMaps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 指定区间价格
|
||||
/// </summary>
|
||||
public class SectionItemPrice : MultiplesPrice
|
||||
{
|
||||
/// <summary>
|
||||
/// 开始价格
|
||||
/// </summary>
|
||||
public decimal BeginPrice { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// 结束价格
|
||||
/// </summary>
|
||||
public decimal EndPrice { get; set; } = 10000000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using Newtonsoft.Json;
|
||||
using Store.Product.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Models.PublishParameters
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 商品存储状态
|
||||
/// </summary>
|
||||
public class ProductStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// 立即上架
|
||||
/// </summary>
|
||||
public static ProductStorage OnSale
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ProductStorage() { Status = ProductStorageStatus.立刻上架 };
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 放入仓库
|
||||
/// </summary>
|
||||
public static ProductStorage InStock
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ProductStorage() { Status = ProductStorageStatus.放入仓库 };
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 定时上架
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static ProductStorage TimedOnSale(DateTime time)
|
||||
{
|
||||
return new ProductStorage { Status = ProductStorageStatus.定时上架, ShelfTime = time };
|
||||
}
|
||||
public ProductStorage()
|
||||
{
|
||||
|
||||
}
|
||||
public ProductStorage(ProductStorageStatus status, DateTime? time = null)
|
||||
{
|
||||
Status = status;
|
||||
if (Status == ProductStorageStatus.定时上架)
|
||||
{
|
||||
ShelfTime = time;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 发布商品状态
|
||||
/// </summary>
|
||||
public ProductStorageStatus Status { get; set; } = ProductStorageStatus.立刻上架;
|
||||
/// <summary>
|
||||
/// 定时上架时间
|
||||
/// </summary>
|
||||
public DateTime? ShelfTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
using Store.Framework.Models;
|
||||
using Store.Framework.Models.Product;
|
||||
using Store.Product.Enums;
|
||||
using Store.Product.Models.Product;
|
||||
using Store.Product.Models.PublishParameters.Image;
|
||||
using Store.Product.Models.PublishParameters.Price;
|
||||
using Store.Product.Models.PublishParameters.Sku;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Models.PublishParameters;
|
||||
|
||||
public class PublishParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 价格配置
|
||||
/// </summary>
|
||||
public PriceConfigBase PriceStrategy { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 图片上传参数
|
||||
/// </summary>
|
||||
public ImageParameters UpImageParams { get; set; } = new ImageParameters();
|
||||
|
||||
#region 重要参数
|
||||
/// <summary>
|
||||
/// Sku 上传参数
|
||||
/// </summary>
|
||||
public SkuParameters SkuParams { get; set; } = new SkuParameters();
|
||||
|
||||
/// <summary>1
|
||||
/// 存储类型 上架Or仓库 Stock
|
||||
/// </summary>
|
||||
public ProductStorage StorageType { get; set; } = new ProductStorage();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 店铺上传最大限制
|
||||
/// </summary>
|
||||
public int ShopUpMaxCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 过滤商品价格
|
||||
/// </summary>
|
||||
public SwitchParams<Tuple<int, int>> IsFilterPrice { get; set; } = new SwitchParams<Tuple<int, int>>(false, new Tuple<int, int>(0, int.MaxValue));
|
||||
|
||||
/// <summary>
|
||||
/// 运费模板类型
|
||||
/// </summary>
|
||||
public FreightTemplateType FreightTemplateType { get; set; } = FreightTemplateType.Fixed;
|
||||
|
||||
///// <summary>
|
||||
/// 运费模板
|
||||
/// </summary>
|
||||
//public FreightTemplateModel FreightTemplate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标题前缀
|
||||
/// </summary>
|
||||
public string TitlePrefix { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 其他参数
|
||||
/// <summary>
|
||||
/// 自定义删除标题关键字
|
||||
/// </summary>
|
||||
public bool IsRemoveCustomTitleKeywors { get; set; }
|
||||
/// <summary>
|
||||
/// 自定义过滤标题关键字
|
||||
/// </summary>
|
||||
public bool IsFilterCustomTitleKeywors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义类目
|
||||
/// </summary>
|
||||
public SwitchParams<CategoryModel> IsCustomCategory { get; set; } = new SwitchParams<CategoryModel>();
|
||||
/// <summary>
|
||||
/// 自定义描述
|
||||
/// </summary>
|
||||
public string CustomDescription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 过滤非法标题
|
||||
/// </summary>
|
||||
public bool IsFilterIllegalTitle { get; set; }
|
||||
/// <summary>
|
||||
/// 过滤不包邮
|
||||
/// </summary>
|
||||
public bool IsFilterPackage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否设置最低价库存
|
||||
/// </summary>
|
||||
public SwitchParams<int> IsSetLowPriceStock { get; set; } = new SwitchParams<int>();
|
||||
/// <summary>
|
||||
/// 是否使用代理
|
||||
/// </summary>
|
||||
public bool IsProxy { get; set; }
|
||||
/// <summary>
|
||||
/// 是否自动删除标题违规词语
|
||||
/// </summary>
|
||||
public bool IsRemoveIllegalTitle { get; set; }
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
using Store.Product.Models.PublishParameters.Price;
|
||||
|
||||
namespace Store.Product.Models.PublishParameters.Sku
|
||||
{
|
||||
/// <summary>
|
||||
/// 自定义Sku
|
||||
/// </summary>
|
||||
public class CustomSku
|
||||
{
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
/// <summary>
|
||||
/// 翻倍
|
||||
/// </summary>
|
||||
public MultiplesPrice Multiples { get; set; }
|
||||
/// <summary>
|
||||
/// 图片地址
|
||||
/// </summary>
|
||||
public string ImagePath { get; set; }
|
||||
/// <summary>
|
||||
/// 库存
|
||||
/// </summary>
|
||||
public int StockCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Store.Product.Models.PublishParameters;
|
||||
|
||||
namespace Store.Product.Models.PublishParameters.Sku
|
||||
{
|
||||
/// <summary>
|
||||
/// 上传Sku配置
|
||||
/// </summary>
|
||||
public class SkuParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Sku名称随机增加特殊字符
|
||||
/// </summary>
|
||||
public bool IsSkuPropertyRandomChar { get; set; }
|
||||
/// <summary>
|
||||
/// 随机删除Sku
|
||||
/// </summary>
|
||||
public bool IsRandomDelSku { get; set; }
|
||||
/// <summary>
|
||||
/// 自定义Sku
|
||||
/// </summary>
|
||||
public SwitchParams<CustomSku> IsCustomSku { get; set; } = new SwitchParams<CustomSku>();
|
||||
/// <summary>
|
||||
/// 是否固定截取
|
||||
/// </summary>
|
||||
public bool IsSkuFixedSplit { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Store.Product.Models.PublishParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 请求参数 是否开启 和值
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class SwitchParams<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否开启
|
||||
/// </summary>
|
||||
public bool IsOpened { get; set; } = false;
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
public T Value { get; set; } = default;
|
||||
public SwitchParams() { }
|
||||
public SwitchParams(bool isopen, T value)
|
||||
{
|
||||
IsOpened = isopen;
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
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 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; }
|
||||
public KJDDBProduct DbProduct { get; set; }
|
||||
public TemuDBProductSelect SelectProduct { get; set; }
|
||||
public DateTime StartTime { get; set; } = DateTime.Now;
|
||||
}
|
||||
|
||||
/// <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 dynamic UploadDraftProductList { get; set; }
|
||||
}
|
||||
|
||||
/// <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 ?? ""
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Contexts;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Publish;
|
||||
|
||||
public interface IPublishStep<TContext> where TContext : PublishContextBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
string Description { get; }
|
||||
/// <summary>
|
||||
/// 执行前检测 true 继续执行,false 跳过
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> CanExecuteAsync(TContext context, CancellationToken token);
|
||||
/// <summary>
|
||||
/// 执行
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
Task ExecuteAsync(TContext context, CancellationToken token);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Store.Framework.Models;
|
||||
using Store.Product.Models.Product;
|
||||
using Store.Product.Models.PublishParameters;
|
||||
using Store.Product.Models.PublishParameters.Wx;
|
||||
using Store.Product.Publish.Steps;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Publish;
|
||||
|
||||
/// <summary>
|
||||
/// 发布上下文
|
||||
/// </summary>
|
||||
public class PublishContextBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 商铺
|
||||
/// </summary>
|
||||
public ShopBase Shop { get; set; }
|
||||
/// <summary>
|
||||
/// 商铺名称
|
||||
/// </summary>
|
||||
public string ShopName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Shop == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return Shop.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public ProductBase Product { get; set; }
|
||||
|
||||
public WXPublishParameters Parameters { get; set; } = new WXPublishParameters();
|
||||
|
||||
/// <summary>微信小店商品上传的新上下文参数。</summary>
|
||||
public WxProductUploadParam WxUpload { get; set; } = new WxProductUploadParam();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Publish;
|
||||
|
||||
public class PublishPipeline<TContext> where TContext : PublishContextBase
|
||||
{
|
||||
private readonly IEnumerable<IPublishStep<TContext>> _steps;
|
||||
|
||||
public PublishPipeline(IEnumerable<IPublishStep<TContext>> steps)
|
||||
{
|
||||
_steps = steps;
|
||||
}
|
||||
|
||||
public async Task ExecuteAsync(
|
||||
TContext context,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var step in _steps)
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
if (await step.CanExecuteAsync(context, token))
|
||||
{
|
||||
await step.ExecuteAsync(context, token);
|
||||
}
|
||||
|
||||
// 步骤正常提前结束(提交成功/上传到草稿箱)时会写入 Result 并标记完成,此处跳出后续步骤。
|
||||
if (context.WxUpload?.IsCompleted == true)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Publish;
|
||||
|
||||
public class PublishResult
|
||||
{
|
||||
public bool IsSuccess { get; set; }
|
||||
public List<string> Logs { get; set; } = new();
|
||||
public string? ErrorMessage { get; set; }
|
||||
//public Product? PublishedProduct { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using MAX.Core.DependencyInjection;
|
||||
using MAX.Core.Logger;
|
||||
using MAX.Framework.Logger;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Store.Framework.Inerterfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Publish;
|
||||
|
||||
public abstract class PublishStep<TContext> : IPublishStep<TContext>, IDisposable where TContext : PublishContextBase
|
||||
{
|
||||
protected ILoggerFacade Looger => LazyServiceProvider.Instance.LazyGetService<ILoggerFacade>();
|
||||
protected ICurrentUser CurrentUser => LazyServiceProvider.Instance.LazyGetService<ICurrentUser>();
|
||||
public abstract string Description { get; }
|
||||
public async Task<bool> CanExecuteAsync(TContext context, CancellationToken token)
|
||||
{
|
||||
try
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
return await CanExecuteProvider(context, token);
|
||||
}
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Looger.Error(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
protected virtual Task<bool> CanExecuteProvider(TContext context, CancellationToken token) => Task.FromResult(true);
|
||||
|
||||
public async Task ExecuteAsync(TContext context, CancellationToken token)
|
||||
{
|
||||
try
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
await ExecuteProvider(context, token);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
Looger.Error(ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Task ExecuteProvider(TContext context, CancellationToken token);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Publish.Steps;
|
||||
|
||||
public class CheckProductPropertyStep : PublishStep
|
||||
{
|
||||
public override string Description => "检查商品属性";
|
||||
|
||||
protected override Task ExecuteProvider(PublishContextBase context, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using MAX.Core.Commons;
|
||||
using Store.Product.Publish;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LittleCow.ProductModule.ExecActions
|
||||
{
|
||||
/// <summary>
|
||||
/// 检测价格
|
||||
/// </summary>
|
||||
public class CheckPrice : PublishStep
|
||||
{
|
||||
public override string Description => "检测价格";
|
||||
|
||||
protected override Task ExecuteProvider(PublishContextBase context, CancellationToken token)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
////过滤上传商品价格
|
||||
//if (context.Parameters.IsFilterPrice.IsOpened)
|
||||
//{
|
||||
// decimal PriceStart = context.Parameters.IsFilterPrice.Value.Item1;
|
||||
// decimal PriceEnd = context.Parameters.IsFilterPrice.Value.Item2;
|
||||
// if (context.Product.Price <= PriceStart || context.Product.Price >= PriceEnd)
|
||||
// {
|
||||
// //result.Msg = "上传商品价格不符合条件,成功过滤";
|
||||
// //result.NextStep = Emums.UpResultStatus.Return;
|
||||
// }
|
||||
//}
|
||||
//return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Store.Product.Models.PublishParameters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Publish.Steps;
|
||||
|
||||
public class WXPublishParameters: PublishParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 跳过已存在的商品
|
||||
/// </summary>
|
||||
public bool SkipExisting { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
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 AddRandomImageBorderStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "为图片添加随机外框";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (selectProd.is_fission_title && chkRandomImgBorder.Checked)
|
||||
{
|
||||
// selectProd.isFission
|
||||
int mainCount = 9;
|
||||
int detailCount = 1;
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
mainCount = txtMainBorderImgCount.Text.Trim().ParseToInt();
|
||||
detailCount = txtDetailBorderImgCount.Text.Trim().ParseToInt();
|
||||
}));
|
||||
// api上传图片文件 边框主图
|
||||
if (1 == 1)
|
||||
{
|
||||
if (chkRandomMainImgOrder.Checked)
|
||||
upProdParam.product.info.headImg = upProdParam.product.info.headImg.OrderBy(x => Guid.NewGuid()).Take(100).ToList();
|
||||
for (int n = 0; n < upProdParam.product.info.headImg.Count && n < mainCount; n++)
|
||||
{
|
||||
var imgUrl = upProdParam.product.info.headImg[n];
|
||||
try
|
||||
{
|
||||
string errMsg = "";
|
||||
//var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, needAddRandomBlock, wantAddRandomBlock, 800, 800);
|
||||
var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, false, false, 800, 800, true);
|
||||
if (!string.IsNullOrEmpty(errMsg))
|
||||
{
|
||||
throw new Exception(errMsg);
|
||||
}
|
||||
|
||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
//upDate += "&is_file=true";
|
||||
//if (needAddRandomBlock || wantAddRandomBlock)
|
||||
// upDate += "&random_code=true";
|
||||
upDate += "&img_url=" + imgUrl;
|
||||
upDate += "&img_base64=" + imgBase64;
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在优化主图文件 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5 && apiUpImgFileRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref apiUpImgFileRst, "img_url");
|
||||
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||
{
|
||||
upProdParam.product.info.headImg[n] = upImgUrl;
|
||||
}
|
||||
else
|
||||
{
|
||||
string upImgErrMsg = BaseRegex.GetStringJsonByRegs(ref apiUpImgFileRst, apiUpImgFileRst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
|
||||
throw new Exception("优化主图失败 " + upImgErrMsg);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("优化主图失败 " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
// api上传图片文件 边框详情图
|
||||
if (1 == 1)
|
||||
{
|
||||
if (chkRandomDetailImgOrder.Checked)
|
||||
upProdParam.product.info.detail.detailImg = upProdParam.product.info.detail.detailImg.OrderBy(x => Guid.NewGuid()).Take(100).ToList();
|
||||
for (int n = 0; n < upProdParam.product.info.detail.detailImg.Count && n < detailCount; n++)
|
||||
{
|
||||
var imgUrl = upProdParam.product.info.detail.detailImg[n];
|
||||
try
|
||||
{
|
||||
string errMsg = "";
|
||||
//var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, needAddRandomBlock, wantAddRandomBlock, 800, 800);
|
||||
var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, false, false, 800, 800, true);
|
||||
if (!string.IsNullOrEmpty(errMsg))
|
||||
{
|
||||
throw new Exception(errMsg);
|
||||
}
|
||||
|
||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
//upDate += "&is_file=true";
|
||||
//if (needAddRandomBlock || wantAddRandomBlock)
|
||||
// upDate += "&random_code=true";
|
||||
upDate += "&img_url=" + imgUrl;
|
||||
upDate += "&img_base64=" + imgBase64;
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在优化详情图文件 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5 && apiUpImgFileRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref apiUpImgFileRst, "img_url");
|
||||
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||
{
|
||||
upProdParam.product.info.detail.detailImg[n] = upImgUrl;
|
||||
}
|
||||
else
|
||||
{
|
||||
string upImgErrMsg = BaseRegex.GetStringJsonByRegs(ref apiUpImgFileRst, apiUpImgFileRst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
|
||||
throw new Exception("优化详情图失败 " + upImgErrMsg);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("优化详情图失败 " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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 AddTitlePrefixStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "添加标题前缀";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(wxUploadRule.TitleHeadWords))
|
||||
upProdParam.product.info.title = wxUploadRule.TitleHeadWords + upProdParam.product.info.title;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
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;
|
||||
using Store.Framework.Extensions;
|
||||
|
||||
namespace Store.Product.Publish.Steps.Wx;
|
||||
/// <summary>
|
||||
/// 由 WXDBProdUploadForm.UploadProduct 的“构建SKU信息”区段迁移。
|
||||
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
||||
/// </summary>
|
||||
public sealed class BuildSkuInfoStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "构建SKU信息";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
upProdParam.product.productSkus = new List<productSkuParam>();
|
||||
skuIndex = 0;
|
||||
id = 3;
|
||||
catId = 200000000003;
|
||||
fCatId = 200000000003;
|
||||
valueCatId = (17 + Randomx.GetNumber(11)).ParseToLong();
|
||||
dicSpecParentNameId = new Dictionary<string, long>();
|
||||
dicSpecParentNameCatId = new Dictionary<string, long>();
|
||||
dicSpecNamefCatId = new Dictionary<string, long>();
|
||||
dicSpecNameCatId = new Dictionary<string, long>();
|
||||
foreach (var skuInfo in prodInfo.detail.sku)
|
||||
{
|
||||
foreach (var spec in skuInfo.spec)
|
||||
{
|
||||
if (!dicSpecParentNameId.Keys.Contains(spec.parent_name))
|
||||
{
|
||||
dicSpecParentNameId[spec.parent_name] = id++;
|
||||
dicSpecParentNameCatId[spec.parent_name] = catId++;
|
||||
}
|
||||
if (!dicSpecNamefCatId.Keys.Contains(spec.spec_name))
|
||||
{
|
||||
dicSpecNamefCatId[spec.spec_name] = fCatId++;
|
||||
dicSpecNameCatId[spec.spec_name] = valueCatId++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dbProd.product_get_type_text == "厂商直采" && !prodInfo.detail.sku.Any(s => s.quantity.ParseToInt() > 0))
|
||||
{
|
||||
throw new Exception("源商品库存为0");
|
||||
}
|
||||
foreach (var skuInfo in prodInfo.detail.sku)
|
||||
{
|
||||
productSkuParam skuParam = new productSkuParam();
|
||||
upProdParam.product.productSkus.Add(skuParam);
|
||||
for (int i = skuInfo.spec.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var specInfo = skuInfo.spec[i];
|
||||
skuParam.__skuKey = specInfo.parent_name + "." + specInfo.spec_name + "_";
|
||||
skuParam.__skuKey += specInfo.spec_name;
|
||||
}
|
||||
skuParam.__skuKey.TrimEnd('_');
|
||||
skuParam.index = skuIndex++;
|
||||
skuParam.productSkuInfo = new productSkuInfoParam();
|
||||
// 加价
|
||||
skuParam.productSkuInfo.salePrice = (skuInfo.multi_price * defaultAddPriceRule.AddPriceTimes + defaultAddPriceRule.AddMorePrice * 100).ParseToInt();
|
||||
if (defaultAddPriceRule.AddMorePriceFirst)
|
||||
skuParam.productSkuInfo.salePrice = ((skuInfo.multi_price + defaultAddPriceRule.AddMorePrice * 100) * defaultAddPriceRule.AddPriceTimes).ParseToInt();
|
||||
// 阶梯式加价,如果命中则按阶梯式加价进行
|
||||
if (defaultAddPriceRule.IsStepAddPrice)
|
||||
{
|
||||
foreach (var addPrice in lstAddPriceRule)
|
||||
{
|
||||
if (skuInfo.multi_price > addPrice.MoreThanPrice * 100 && skuInfo.multi_price <= addPrice.LessThanPrice * 100)
|
||||
{
|
||||
if (defaultAddPriceRule.AddMorePriceFirst) // 先加后乘
|
||||
skuParam.productSkuInfo.salePrice = ((skuInfo.multi_price + addPrice.AddMorePrice * 100) * addPrice.AddPriceTimes).ParseToInt();
|
||||
else
|
||||
skuParam.productSkuInfo.salePrice = (skuInfo.multi_price * addPrice.AddPriceTimes + addPrice.AddMorePrice * 100).ParseToInt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 聚水潭上微信小店,加运费(其他平台shipPrice默认为0)
|
||||
skuParam.productSkuInfo.salePrice += (shipPrice * defaultAddPriceRule.ShippingPriceTimes).ParseToInt();
|
||||
// 商品裂变随机增加价格
|
||||
if (selectProd.is_fission_title && chkFissionRandomPriceChange.Checked)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
var fissionRandomPrice = Randomx.GetId((txtFissionRandomPriceChange.Text.ParseToDecimal() * 100).ParseToInt() + 1);
|
||||
skuParam.productSkuInfo.salePrice += fissionRandomPrice;
|
||||
}));
|
||||
}
|
||||
// sku图
|
||||
skuParam.productSkuInfo.thumbImg = upProdParam.product.info.productSaleAttrs[0].items.FirstOrDefault(a => a.value == skuInfo.spec[0].spec_name)?.imgUrl;
|
||||
if (dbProd.special_prod_type == "爆款数据")
|
||||
{
|
||||
if (!skuInfo.out_sku_sn.StartsWith("BS")) // Best-seller 爆款
|
||||
skuInfo.out_sku_sn = "BS" + skuInfo.out_sku_sn;
|
||||
}
|
||||
skuParam.productSkuInfo.skuCode = skuInfo.out_sku_sn;
|
||||
skuParam.productSkuInfo.outSkuId = skuInfo.out_sku_sn;
|
||||
skuParam.productSkuInfo.out_sku_id = skuInfo.out_sku_sn;
|
||||
//skuParam.productSkuInfo.barCode = skuInfo.out_sku_sn; // 条形码
|
||||
skuParam.skuKey.outSkuId = skuInfo.out_sku_sn;
|
||||
skuParam.skuKey.productKey = new productKeyParam();
|
||||
skuParam.skuKey.productKey.outProductId = upProdParam.product.info.spuCode;
|
||||
// 库存
|
||||
skuParam.productSkuInfo.stockInfo = new stockInfoParam() { stockNum = defaultAddPriceRule.StockNum };
|
||||
// 厂商直采上家库存为0则按0上架
|
||||
if (dbProd.product_get_type_text == "厂商直采" && skuInfo.quantity.IsNullOrZero())
|
||||
skuParam.productSkuInfo.stockInfo.stockNum = 0;
|
||||
skuParam.productSkuInfo.saleParam = new List<saleParamParam>();
|
||||
foreach (var specInfo in skuInfo.spec)
|
||||
{
|
||||
saleParamParam saleParam = new saleParamParam();
|
||||
skuParam.productSkuInfo.saleParam.Add(saleParam);
|
||||
saleParam.categorys = new List<object>();
|
||||
|
||||
// specKey
|
||||
categoryKeyParam skuCateKeyParam = new categoryKeyParam();
|
||||
saleParam.categorys.Add(skuCateKeyParam);
|
||||
skuCateKeyParam.isCustomize = true;
|
||||
skuCateKeyParam.isMainSale = true;
|
||||
skuCateKeyParam.name = specInfo.parent_name;
|
||||
skuCateKeyParam.id = dicSpecParentNameId[specInfo.parent_name].ParseToInt(); // 3;
|
||||
skuCateKeyParam.catId = dicSpecParentNameCatId[specInfo.parent_name];
|
||||
skuCateKeyParam.label = "自定义规格";
|
||||
skuCateKeyParam.catInfo = new skuCatInfoParam() { isCustomize = 1 };
|
||||
skuCateKeyParam.catType = 8;
|
||||
|
||||
// specValue
|
||||
categoryValueParam skuCateValueParam = new categoryValueParam();
|
||||
saleParam.categorys.Add(skuCateValueParam);
|
||||
skuCateValueParam.fCatId = dicSpecNamefCatId[specInfo.spec_name];
|
||||
skuCateValueParam.catId = dicSpecNameCatId[specInfo.spec_name];
|
||||
skuCateValueParam.name = specInfo.spec_name;
|
||||
skuCateValueParam.skuNameValue = specInfo.spec_name;
|
||||
skuCateValueParam.desc = "";
|
||||
skuCateValueParam.catInfo = new categoryValueCatInfo() { editByUser = 1 };
|
||||
skuCateValueParam.thumbImg = "";
|
||||
var specIndex = skuInfo.spec.IndexOf(specInfo);
|
||||
skuCateValueParam.priority = prodInfo.detail.sku.Select(s => s.spec[specIndex].spec_name).Distinct().ToList().IndexOf(specInfo.spec_name);
|
||||
skuCateValueParam.selected = false;
|
||||
}
|
||||
skuParam.productSkuInfo.skuDeliverInfo = new skuDeliverInfoParam();
|
||||
skuParam.productSkuInfo.stockDiff = new stockDiffParam() { diffType = 1, num = defaultAddPriceRule.StockNum };
|
||||
// 厂商直采上家库存为0则按0上架
|
||||
if (dbProd.product_get_type_text == "厂商直采" && skuInfo.quantity.IsNullOrZero())
|
||||
skuParam.productSkuInfo.stockDiff.num = 0;
|
||||
skuParam.status = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
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.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Work;
|
||||
|
||||
namespace Store.Product.Publish.Steps.Wx;
|
||||
/// <summary>
|
||||
/// 由 WXDBProdUploadForm.UploadProduct 的“构建SKU规格属性”区段迁移。
|
||||
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
||||
/// </summary>
|
||||
public sealed class BuildSkuPropertiesStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "构建SKU规格属性";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成sku";
|
||||
}));
|
||||
}
|
||||
Thread.Sleep(Randomx.GetId(100, 300));
|
||||
|
||||
upProdParam.product.info.productSaleAttrs = new List<productSaleAttrParam>();
|
||||
if (prodInfo.detail.sku == null)
|
||||
prodInfo.detail.sku = new List<sku_item>();
|
||||
if (prodInfo.detail.sku.Count == 0)
|
||||
prodInfo.detail.sku.Add(new sku_item() { spec = new List<spec_item>() });
|
||||
if (prodInfo.detail.sku.FirstOrDefault().spec == null)
|
||||
prodInfo.detail.sku.FirstOrDefault().spec = new List<spec_item>();
|
||||
if (prodInfo.detail.sku.FirstOrDefault().spec.Count == 0)
|
||||
prodInfo.detail.sku.FirstOrDefault().spec.Add(new spec_item() { parent_name = "规格", spec_name = "默认" });
|
||||
if (prodInfo.detail.sku.FirstOrDefault().thumb_url.IsNullOrEmpty())
|
||||
prodInfo.detail.sku.FirstOrDefault().thumb_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url;
|
||||
|
||||
maxSkuSpecCnt = prodInfo.detail.sku.Max(x => x.spec?.Count).ParseToInt();
|
||||
foreach (var skuTmp in prodInfo.detail.sku.ToList())
|
||||
{
|
||||
if (skuTmp.spec?.Count != maxSkuSpecCnt)
|
||||
prodInfo.detail.sku.Remove(skuTmp);
|
||||
}
|
||||
|
||||
// 处理系统指定的规格名称
|
||||
//if ((upProdParam.product.info.category.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail.cats.FirstOrDefault() == "食品饮料") &&
|
||||
// (selectProd.cat_name == "坚果炒货" || selectProd.cat_name == "果干"))
|
||||
//{
|
||||
// if (!prodInfo.detail.sku.FirstOrDefault().spec.Any(s => s.parent_name == "规格/净含量"))
|
||||
// {
|
||||
// foreach (var sku in prodInfo.detail.sku)
|
||||
// {
|
||||
// sku.spec.FirstOrDefault().parent_name = "规格/净含量";
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
////else if ((upProdParam.product.info.category.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail.cats.FirstOrDefault() == "食品饮料"))
|
||||
////{
|
||||
//// if (!prodInfo.detail.sku.FirstOrDefault().spec.Any(s => s.parent_name == "规格"))
|
||||
//// {
|
||||
//// foreach (var sku in prodInfo.detail.sku)
|
||||
//// {
|
||||
//// sku.spec.FirstOrDefault().parent_name = "规格";
|
||||
//// }
|
||||
//// }
|
||||
////}
|
||||
// 坚果炒货类,系统返回的试规格/净含量但是要求填规格
|
||||
if ((upProdParam.product.info?.category?.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail?.cats?.FirstOrDefault() == "食品饮料") &&
|
||||
(upProdParam.product.info?.category?.LastOrDefault()?.name == "坚果炒货" || upProdParam.product.info?.category?.LastOrDefault()?.name == "果干"))
|
||||
{
|
||||
if (!prodInfo.detail.sku.FirstOrDefault().spec.Any(s => s.parent_name == "规格"))
|
||||
{
|
||||
foreach (var sku in prodInfo.detail.sku)
|
||||
{
|
||||
sku.spec.FirstOrDefault().parent_name = "规格";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var leafCat = upProdParam.product.info.category.LastOrDefault();
|
||||
if (leafCat?.catInfo?.saleAttr?.attr != null)
|
||||
{
|
||||
foreach (var att in leafCat.catInfo.saleAttr.attr)
|
||||
{
|
||||
//decimal4_unit //g;kg;斤
|
||||
if (att.isRequired == true)
|
||||
{
|
||||
// 规格属性名放在第二个规格上
|
||||
if (att.normalRelease.ruleType == 2 && prodInfo.detail.sku.FirstOrDefault()?.spec.Count == 2)
|
||||
{
|
||||
foreach (var sku in prodInfo.detail.sku)
|
||||
{
|
||||
// 如果有指定规格属性名称就不再设置
|
||||
if (!sku.spec.Any(sp => sp.parent_name == att.name))
|
||||
{
|
||||
sku.spec[1].parent_name = att.name;
|
||||
}
|
||||
// 如果不在指定位置上,交换位置
|
||||
else if (sku.spec[0].parent_name == att.name)
|
||||
{
|
||||
var specTmp = sku.spec[0];
|
||||
sku.spec[0] = sku.spec[1];
|
||||
sku.spec[1] = specTmp;
|
||||
}
|
||||
if (att.type == "decimal4_unit")
|
||||
{
|
||||
if (att.value == "g;kg;斤")
|
||||
{
|
||||
var specName = "";
|
||||
foreach (var unit in att.value.Split(';').Reverse().ToList())
|
||||
{
|
||||
Match specMatch = Regex.Match(sku.spec[1].spec_name.Replace(" ", "").Replace("-", "负号"), @"\d+(.\d+)?" + unit);
|
||||
//Match specMatch = Regex.Match(sku.spec[1].spec_name.Replace(" ", ""), @"((0{1}.\d{1,4})|([1-9]\d{1}.\d{1,4})|([1-9]+\d)|0)" + unit);
|
||||
if (specMatch.Success)
|
||||
{
|
||||
specName = specMatch.Value.Replace(unit, "")/*.ParseToDecimal().ParseToInt()*/ + " " + unit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(specName))
|
||||
specName = Randomx.GetId(10, 500) + " g";
|
||||
sku.spec[1].spec_name = specName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 规格属性名放在第一个规格上
|
||||
else
|
||||
{
|
||||
foreach (var sku in prodInfo.detail.sku)
|
||||
{
|
||||
// 如果有指定规格属性名称就不再设置
|
||||
if (!sku.spec.Any(sp => sp.parent_name == att.name))
|
||||
{
|
||||
sku.spec[0].parent_name = att.name;
|
||||
}
|
||||
// 如果不在指定位置上,交换位置
|
||||
else if (sku.spec.Count > 1 && sku.spec[1].parent_name == att.name)
|
||||
{
|
||||
var specTmp = sku.spec[0];
|
||||
sku.spec[0] = sku.spec[1];
|
||||
sku.spec[1] = specTmp;
|
||||
}
|
||||
if (att.type == "decimal4_unit")
|
||||
{
|
||||
if (att.value == "g;kg;斤")
|
||||
{
|
||||
var specName = "";
|
||||
foreach (var unit in att.value.Split(';').Reverse().ToList())
|
||||
{
|
||||
Match specMatch = Regex.Match(sku.spec[0].spec_name.Replace(" ", "").Replace("-", "负号"), @"\d+(.\d+)?" + unit);
|
||||
//Match specMatch = Regex.Match(sku.spec[0].spec_name.Replace(" ", ""), @"((0{1}.\d{1,4})|([1-9]\d{1}.\d{1,4})|([1-9]+\d)|0)" + unit);
|
||||
if (specMatch.Success)
|
||||
{
|
||||
specName = specMatch.Value.Replace(unit, "")/*.ParseToDecimal().ParseToInt()*/ + " " + unit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(specName))
|
||||
specName = Randomx.GetId(10, 500) + " g";
|
||||
sku.spec[0].spec_name = specName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prodInfo.detail.sku.FirstOrDefault()?.spec?.Count > 0)
|
||||
{
|
||||
productSaleAttrParam attrParam = new productSaleAttrParam()
|
||||
{
|
||||
key = prodInfo.detail.sku.FirstOrDefault()?.spec[0].parent_name,
|
||||
hasImg = true,
|
||||
items = new List<productSaleAttrItemParam>()
|
||||
};
|
||||
upProdParam.product.info.productSaleAttrs.Add(attrParam);
|
||||
foreach (var sku in prodInfo.detail.sku)
|
||||
{
|
||||
var spec = sku.spec[0];
|
||||
if (!attrParam.items.Any(it => it.value == spec.spec_name) && !string.IsNullOrEmpty(sku.thumb_url))
|
||||
{
|
||||
if (dbProd.product_get_type_text == "微信店采")
|
||||
{
|
||||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = sku.thumb_url, });
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取缓存盗链 sku图
|
||||
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(sku.thumb_url)))
|
||||
{
|
||||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)], });
|
||||
continue;
|
||||
}
|
||||
// 使用接口链接传sku图
|
||||
if (1 == 1 && !sku.thumb_url.Contains("wst.wxapp.tc.qq.com"))
|
||||
{
|
||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
upDate += "&post_data=" + GetHtml.UrlEncodeUtf8("{\"img_url\":\"" + sku.thumb_url.Replace("https://", "http://") + "\"}");
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成sku " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20 && upDateRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref upDateRst, "img_url");
|
||||
if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||
{
|
||||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = upImgUrl, });
|
||||
wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = upImgUrl;
|
||||
isChangeImgDic = true;
|
||||
continue; // 传图成功跳过模拟上传
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// api上传图片文件 sku图
|
||||
if (1 == 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
string errMsg = "";
|
||||
var imgBase64 = GetImgBase64ForApi(out errMsg, sku.thumb_url, false, false);
|
||||
if (!string.IsNullOrEmpty(errMsg))
|
||||
{
|
||||
throw new Exception(errMsg);
|
||||
}
|
||||
|
||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
//upDate += "&is_file=true";
|
||||
//if (needAddRandomBlock || wantAddRandomBlock)
|
||||
// upDate += "&random_code=true";
|
||||
upDate += "&img_url=" + sku.thumb_url;
|
||||
upDate += "&img_base64=" + imgBase64;
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在上传商品sku图文件 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5 && apiUpImgFileRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref apiUpImgFileRst, "img_url");
|
||||
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||
{
|
||||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = upImgUrl, });
|
||||
wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = upImgUrl;
|
||||
isChangeImgDic = true;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("修改详情图失败 " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
// 上传sku图
|
||||
var locationStr = UploadImg(shop, sku.thumb_url, cell);
|
||||
if (!locationStr.Contains("\"success\":true"))
|
||||
throw new Exception(locationStr);
|
||||
var location = BaseRegex.GetStringJson(ref locationStr, "Location");
|
||||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = location, });
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
|
||||
//wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = location;
|
||||
//isChangeImgDic = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prodInfo.detail.sku.FirstOrDefault()?.spec?.Count > 1)
|
||||
{
|
||||
productSaleAttrParam attrParam = new productSaleAttrParam()
|
||||
{
|
||||
key = prodInfo.detail.sku.FirstOrDefault()?.spec[1].parent_name,
|
||||
hasImg = false,
|
||||
items = new List<productSaleAttrItemParam>()
|
||||
};
|
||||
upProdParam.product.info.productSaleAttrs.Add(attrParam);
|
||||
foreach (var sku in prodInfo.detail.sku)
|
||||
{
|
||||
var spec = sku.spec[1];
|
||||
if (!attrParam.items.Any(it => it.value == spec.spec_name))
|
||||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
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.Framework.Extensions;
|
||||
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 CalculateShippingTemplateStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "获取推单运费模板并计算运费";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在选取运费模板";
|
||||
}));
|
||||
}
|
||||
|
||||
shippingTemplateJson = "";
|
||||
shipPrice = 0;
|
||||
|
||||
if (dbProd.product_get_type_text == "厂商直采")
|
||||
{
|
||||
var urlShipping = BaseClass.BuildObjString("product/wx_get_shipping_template");
|
||||
var dataShipping = Work.UserLogin.GetSignaturex() +
|
||||
"&coid=" + dbProd.skc_id;
|
||||
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
|
||||
{
|
||||
shippingTemplateJson = JsonHelper.SerializeObject(JsonHelper.JObjectParse(htmlShipping)["data"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(shippingTemplateJson))
|
||||
{
|
||||
// 获取运费模板
|
||||
var urlShip = BaseClass.BuildObjString("product/e57_get_freight_template");
|
||||
var dataShip = Work.UserLogin.GetSignaturex() + "&coid=" + dbProd.skc_id;
|
||||
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"}]
|
||||
shippingTemplateJson = JsonHelper.SerializeObject(JsonHelper.JObjectParse(shipRst)["data"]);
|
||||
if (shipRst.Contains("\"code\":0") && !string.IsNullOrEmpty(shippingTemplateJson))
|
||||
{
|
||||
urlShipping = BaseClass.BuildObjString("product/wx_add_mdy_shipping_template");
|
||||
dataShipping = Work.UserLogin.GetSignaturex() +
|
||||
"&coid=" + dbProd.skc_id +
|
||||
"&shipping_template_json=" + 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(shippingTemplateJson))
|
||||
{
|
||||
try
|
||||
{
|
||||
int count = 0;
|
||||
var shipObjs = JArray.Parse(shippingTemplateJson);
|
||||
foreach (var shipObj in shipObjs)
|
||||
{
|
||||
var provincesStr = shipObj["provinces"].ParseToString();
|
||||
if (provincesStr.Split(',').Length > count)
|
||||
{
|
||||
count = provincesStr.Split(',').Length;
|
||||
shipPrice = shipObj["freightPrice"].ParseToInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("运费模板获取失败 " + ex.Message);
|
||||
}
|
||||
}
|
||||
if (shipPrice <= 0)
|
||||
{
|
||||
throw new Exception("运费模板获取失败 未获取到");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
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.Framework.Extensions;
|
||||
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 CommissionPreparationStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "处理佣金上传";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (BaseClass.UserAuthority.Contains("佣金上货") && chkCommission.Checked)
|
||||
{
|
||||
if (dbProd.special_prod_type != "爆款数据" && dbProd.product_get_type_text != "微信小店")
|
||||
throw new Exception("拥金上货失败:仅爆款微信小店数据支持佣金上传!");
|
||||
|
||||
var rst = WXApi.GetAndUpdateWebStatus(context.Shop.Cookie);
|
||||
if (!rst.Html.Contains("\"isOpenLeague\":true"))
|
||||
{
|
||||
throw new Exception("拥金上货失败:需要开通优选联盟!");
|
||||
}
|
||||
|
||||
var url = BaseClass.BuildObjString("product/wx_get_commission_rate");
|
||||
var date = UserLogin.GetSignaturex();
|
||||
date += "&spu_ids=" + dbProd.spu_id;
|
||||
|
||||
var prodCommissionRst = GetHtml.PostUtf8(url, date);
|
||||
if (!prodCommissionRst.Contains("\"code\":200"))
|
||||
{
|
||||
var errMsg = BaseRegex.GetStringJsonByRegs(ref prodCommissionRst, prodCommissionRst, "msg");
|
||||
throw new Exception("拥金上货失败:" + errMsg);
|
||||
}
|
||||
fromCommissionRate = BaseRegex.GetStringJson(ref prodCommissionRst, "commission_rate").ParseToNullableInt();
|
||||
if (fromCommissionRate == null)
|
||||
fromCommissionRate = -1;
|
||||
if (prodCommissionRst.Contains("\"data\":[]") || BaseRegex.GetStringJson(ref prodCommissionRst, "mdy_time").ParseToString().ParseToDateTime() < DateTime.Now.AddDays(-30))
|
||||
{
|
||||
var assistantShop = new ShopLoginInfo();
|
||||
assistantShop.Cookies = JsonHelper.SerializeObject(lstWxSaleAssistantCookie);
|
||||
var result = WXApi.wxGetAssistant(context.Shop.Cookie, dbProd.spu_id);
|
||||
if (result.Html.Contains("mcn magic invalid"))
|
||||
{
|
||||
//throw new Exception("拥金上货失败:请先登录上货助手");
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
//BaseMsgForm.ShowError
|
||||
btnLoginAssistant_Click(null, null);
|
||||
}));
|
||||
assistantShop.Cookies = JsonHelper.SerializeObject(lstWxSaleAssistantCookie);
|
||||
result = WXApi.wxGetAssistant(assistantShop, dbProd.spu_id);
|
||||
if (result.Contains("mcn magic invalid"))
|
||||
throw new Exception("拥金上货失败:请先登录上货助手");
|
||||
}
|
||||
fromCommissionRate = BaseRegex.GetStringJson(ref result, "commissionRate").ParseToNullableInt();
|
||||
var prodName = BaseRegex.GetStringJson(ref result, "name");
|
||||
if (fromCommissionRate == null)
|
||||
fromCommissionRate = -1;
|
||||
if (prodName.IsNullOrEmpty())
|
||||
prodName = dbProd.product_name;
|
||||
//if (fromCommissionRate != null && !string.IsNullOrEmpty(prodName))
|
||||
{
|
||||
url = BaseClass.BuildObjString("product/wx_add_mdy_commission_rate");
|
||||
date = UserLogin.GetSignaturex();
|
||||
date += "&spu_id=" + dbProd.spu_id;
|
||||
date += "&commission_rate=" + fromCommissionRate;
|
||||
date += "&product_name=" + prodName;
|
||||
var addCommissionRateRst = GetHtml.PostUtf8(url, date);
|
||||
}
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
minCommissionRate = this.txtMinUpCommission.Text.Trim().ParseToInt() * 10000;
|
||||
maxCommissionRate = this.txtMaxUpCommission.Text.Trim().ParseToInt() * 10000;
|
||||
commissionRateChange = this.txtCommissionChangeValue.Text.Trim().ParseToInt() * 10000;
|
||||
if (cmbCommissionAddOrReduce.Text != "增加")
|
||||
commissionRateChange = -commissionRateChange;
|
||||
commissionRate = fromCommissionRate.ParseToInt() + commissionRateChange;
|
||||
}));
|
||||
if (fromCommissionRate < minCommissionRate || fromCommissionRate > maxCommissionRate)
|
||||
{
|
||||
throw new Exception("拥金上货失败:原商品佣金比例 " + fromCommissionRate * 0.0001 + "% 超过设置的佣金范围!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
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 的“1688商品格式转换”区段迁移。
|
||||
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
||||
/// </summary>
|
||||
public sealed class Convert1688ProductStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "1688商品格式转换";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (dbProd.product_get_type_text == "1688厂家")
|
||||
{
|
||||
string convertRst = "";
|
||||
var pInfo = new PDDProdFormConverter()._1688ClientToPddConvert(out convertRst, dbProd);
|
||||
if (!string.IsNullOrEmpty(convertRst))
|
||||
throw new Exception("商品查询错误 " + convertRst);
|
||||
}
|
||||
if (dbProd.product_get_type_text == "1688外部数据")
|
||||
{
|
||||
string convertRst = "";
|
||||
var pInfo = new PDDProdFormConverter()._1688OutToPddConvert(out convertRst, dbProd);
|
||||
if (!string.IsNullOrEmpty(convertRst))
|
||||
throw new Exception("商品查询错误 " + convertRst);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
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 ConvertCloudProductStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "云端商品格式转换";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (dbProd.db_type == "云端数据" && dbProd.product_get_type_text == "多多")
|
||||
{
|
||||
string convertRst = "";
|
||||
|
||||
var content = dbProd.product_json;
|
||||
if (content.Contains("\"spec_keys\"") && content.Contains("\"spec_values\"") && content.Contains("\"is_sku_pre_sale\""))
|
||||
{
|
||||
convertRst = new PDDProdFormConverter().PddFrontToPddBackConvert(content, true, null, true, false);
|
||||
}
|
||||
else if (content.Contains("\"goods_id\"") && content.Contains("\"goods_name\"") && content.Contains("\"gallery\"") &&
|
||||
content.Contains("\"priority\"") && content.Contains("\"enable_share\"") && content.Contains("\"goods_property\"") &&
|
||||
(content.Contains("\"ref_pid\"") || content.Contains("\"goods_property\":[]")) && content.Contains("\"sku_id\"") && content.Contains("\"quantity\"") &&
|
||||
content.Contains("\"specs\"") && content.Contains("\"spec_key\"") && content.Contains("\"spec_value\"") &&
|
||||
content.Contains("\"group_price\"") && content.Contains("img.pddpic.com"))
|
||||
{
|
||||
convertRst = new PDDProdFormConverter().PddFrontToPddBackConvert2(content, true, null, true, false);
|
||||
}
|
||||
else if (content.Contains("\"mallId\"") && content.Contains("\"mallName\"") && content.Contains("\"goodsId\"") && content.Contains("\"goodsName\"") &&
|
||||
content.Contains("\"catID\"") && content.Contains("\"catID4\"") && content.Contains("\"topGallery\"") && content.Contains("\"detailGallery\"") &&
|
||||
content.Contains("\"shareDesc\"") && content.Contains("\"maxOnSaleGroupPriceInCent\"") && content.Contains("\"shareDesc\"") &&
|
||||
content.Contains("\"specs\"") && content.Contains("\"spec_key\"") && content.Contains("\"spec_value\"") &&
|
||||
content.Contains("\"groupPrice\"") && content.Contains("img.pddpic.com"))
|
||||
{
|
||||
convertRst = new PDDProdFormConverter().PddFrontToPddBackConvert3(content, true, null, true, false);
|
||||
}
|
||||
else if (content.Contains("\"商品编号\"") && content.Contains("\"商品链接\"") && content.Contains("\"标题\""))
|
||||
{
|
||||
convertRst = new PDDProdFormConverter().PddFrontToPddBackConvertV4(content, true, null, true, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
convertRst = new PDDProdFormConverter().PddFrontToPddBackConvertFactory("", true, null, true, false, content);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(convertRst) && !convertRst.StartsWith("success"))
|
||||
throw new Exception("商品查询错误 " + convertRst);
|
||||
|
||||
if (convertRst.StartsWith("success"))
|
||||
convertRst = convertRst.Substring("success".Length);
|
||||
dbProd.product_json = convertRst;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
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 的“聚水潭商品转换为PDD统一格式”区段迁移。
|
||||
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
||||
/// </summary>
|
||||
public sealed class ConvertJstPddProductStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "聚水潭商品转换为PDD统一格式";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (dbProd.product_get_type_text == "厂商直采")
|
||||
{
|
||||
if (dbProd.sku_secret_json.IsNullOrEmpty() || !dbProd.sku_secret_json.Contains("goodsId"))
|
||||
{
|
||||
throw new Exception("商品查询格式错误");
|
||||
}
|
||||
if (dbProd.wx_cat_leaf.IsNullOrZero() || dbProd.send_to_out_server != 1 || dbProd.distribution_set != 1)
|
||||
{
|
||||
throw new Exception("商品查询校验错误");
|
||||
}
|
||||
|
||||
string convertRst = "";
|
||||
var pInfo = new PDDProdFormConverter().JstPddProdToPddConvert(out convertRst, dbProd);
|
||||
if (!string.IsNullOrEmpty(convertRst))
|
||||
throw new Exception("商品查询错误 " + convertRst);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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 的“微信小店App格式转换”区段迁移。
|
||||
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
||||
/// </summary>
|
||||
public sealed class ConvertWxAppProductStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "微信小店App格式转换";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (dbProd.product_get_type_text == "微信小店")
|
||||
{
|
||||
string convertRst = "";
|
||||
var pInfo = new PDDProdFormConverter().WXClientToPddConvert(out convertRst, dbProd);
|
||||
if (!string.IsNullOrEmpty(convertRst))
|
||||
throw new Exception("商品查询错误 " + convertRst);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
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 ConvertWxRecycleProductStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "微信回采格式转换";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采") && chkUseWXComplateProd.Checked && dbProd.has_wx_format == "1")
|
||||
{
|
||||
string errMsg = "";
|
||||
wxEditProdInfo = GetProductWXComplate(dbProd.secret_spu_id, out errMsg);
|
||||
|
||||
if (wxEditProdInfo == null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = errMsg;
|
||||
}));
|
||||
throw new Exception("" + errMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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 ConvertWxShopProductStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "微信店采格式转换";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (dbProd.product_get_type_text == "微信店采")
|
||||
{
|
||||
string convertRst = "";
|
||||
var pInfo = new PDDProdFormConverter().WXProdToPddConvert(out convertRst, dbProd);
|
||||
if (!string.IsNullOrEmpty(convertRst))
|
||||
throw new Exception("商品查询错误 " + convertRst);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
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 DetectCategoryStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "识别商品类目";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成类目属性";
|
||||
}));
|
||||
}
|
||||
aiCateIdLst = new List<long>();
|
||||
// 聚水潭商品已识别类目使用类目缓存
|
||||
if (dbProd.product_get_type_text == "厂商直采" && dbProd.wx_cat_leaf == null)
|
||||
{
|
||||
throw new Exception("该商品类目信息不完整");
|
||||
}
|
||||
// 微信商品使用类目缓存
|
||||
if (!dbProd.wx_cat_leaf.IsNullOrZero())
|
||||
{
|
||||
if (dbProd.wx_cat_3 == 7370)
|
||||
dbProd.wx_cat_3 = 547591;
|
||||
if (dbProd.wx_cat_leaf == 7370)
|
||||
dbProd.wx_cat_leaf = 547591;
|
||||
|
||||
if (!dbProd.wx_cat_1.IsNullOrZero())
|
||||
aiCateIdLst.Add(dbProd.wx_cat_1.ParseToLong());
|
||||
if (!dbProd.wx_cat_2.IsNullOrZero())
|
||||
aiCateIdLst.Add(dbProd.wx_cat_2.ParseToLong());
|
||||
if (!dbProd.wx_cat_3.IsNullOrZero())
|
||||
aiCateIdLst.Add(dbProd.wx_cat_3.ParseToLong());
|
||||
if (!dbProd.wx_cat_leaf.IsNullOrZero())
|
||||
aiCateIdLst.Add(dbProd.wx_cat_leaf.ParseToLong());
|
||||
aiCateIdLst = aiCateIdLst.Distinct().ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
// ai识别类目暂存主图位置
|
||||
int imgId = 0;
|
||||
string tempImgPath = Path.GetTempPath().Trim('\\') + "\\" + Randomx.GetWordWithNumber(8).ToLower();
|
||||
List<string> tempImgFullPathLst = new List<string>();
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
// 生成ai识别类目所需图片
|
||||
var aiGalleries = prodInfo.detail.galleries.Where(g => g.type == 1).Take(3).ToList();
|
||||
foreach (var gallery_item in aiGalleries) // 9张主图
|
||||
{
|
||||
imgId++;
|
||||
string getImgError;
|
||||
var imgUrl = gallery_item.url;
|
||||
{
|
||||
if (!imgUrl.Contains("wxapp") && imgUrl.Contains("mmecimage.cn"))
|
||||
imgUrl = imgUrl.Replace("https://", "http://");
|
||||
}
|
||||
var image = GetHtml.GetUrlImg(imgUrl, out getImgError);
|
||||
var imageBg = new Bitmap(800, 800);
|
||||
if (!string.IsNullOrEmpty(getImgError) || image == null)
|
||||
{
|
||||
throw new Exception("初始化主图上传失败");
|
||||
}
|
||||
using (Graphics g = Graphics.FromImage(imageBg))
|
||||
{
|
||||
g.DrawImage(image, new Rectangle(0, 0, imageBg.Width, imageBg.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
|
||||
}
|
||||
|
||||
// 取前三张图片保存到系统temp路径,配合商品标题获取商品类目
|
||||
if (imgId <= 3)
|
||||
{
|
||||
if (!Directory.Exists(tempImgPath))
|
||||
Directory.CreateDirectory(tempImgPath);
|
||||
string imgFullPath = tempImgPath + "\\图片" + imgId + ".jpg";
|
||||
tempImgFullPathLst.Add(imgFullPath);
|
||||
if (imgId == 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
image.Save(imgFullPath, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 真实图像失败传假图也能识别
|
||||
int fileSize = Randomx.GetId(1024, 10240);
|
||||
using (BinaryWriter writer = new BinaryWriter(File.Create(imgFullPath)))
|
||||
{
|
||||
for (int i = 0; i < fileSize; i++)
|
||||
{
|
||||
writer.Write((byte)Randomx.GetId(256)); // 生成0到255之间的随机字节
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 只需要传一张真实图像即可
|
||||
int fileSize = Randomx.GetId(1024, 10240);
|
||||
using (BinaryWriter writer = new BinaryWriter(File.Create(imgFullPath)))
|
||||
{
|
||||
for (int i = 0; i < fileSize; i++)
|
||||
{
|
||||
writer.Write((byte)Randomx.GetId(256)); // 生成0到255之间的随机字节
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Thread.Sleep(Randomx.GetId(100, 300));
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
// 根据Ai分类,获取类目信息
|
||||
//{"code":0,"predInfo":{"firstCatRes":[{"catId":10000111,"catName":"服饰内衣","level":1},{"catId":10000111,"catName":"服饰内衣","level":1},{"catId":10000111,"catName":"服饰内衣","level":1}],"secondCatRes":[{"catId":10000113,"catName":"女装","level":2},{"catId":10000113,"catName":"女装","level":2},{"catId":10000113,"catName":"女装","level":2}],"thirdCatRes":[{"catId":547705,"catName":"牛仔裤","level":3,"modelVersion":""},{"catId":547704,"catName":"加绒裤","level":3,"modelVersion":"商品标题含'加绒加厚、保暖'等关键词,这表示裤子具备加绒保暖功能。主图展示了加绒内衬,也符合【服饰内衣:女装:裤子:加绒裤】类目特征。"},{"catId":547701,"catName":"休闲裤","level":3,"modelVersion":""}],"singleSecondCatRes":[],"singleFirstCatRes":[],"isSupportedCate":1},"aiCategoryList":[{"id":547705,"paths":[{"id":"10000111","name":"服饰内衣","sonIdList":["10000397","10000115","10000112","10000113","10000114"],"fId":"0","level":1,"leaf":false},{"id":"10000113","name":"女装","sonIdList":["546810","546811","530041","547706","6090","6089","6088","6087","6083","6076","6073","6070","6065","6063","6058","10000672","10000671","10000670","10000669","10000668","10000667","10000666","10000665","10000664","10000663","10000662","10000661","10000660","10000659","10000658","10000657","10000656","10000655"],"fId":"10000111","level":2,"leaf":false},{"id":"10000672","name":"裤子","sonIdList":["547699","547700","547701","547702","547703","547704","547705"],"fId":"10000113","level":3,"leaf":false},{"id":"547705","name":"牛仔裤","fId":"10000672","level":4,"leaf":true,"state":0,"hasTrialCategory":false,"isTrialCategory":false,"isLocalLife":false}],"depositAmount":0,"catAuth":true,"limitSubjectTypes":[]},{"id":547704,"paths":[{"id":"10000111","name":"服饰内衣","sonIdList":["10000397","10000115","10000112","10000113","10000114"],"fId":"0","level":1,"leaf":false},{"id":"10000113","name":"女装","sonIdList":["546810","546811","530041","547706","6090","6089","6088","6087","6083","6076","6073","6070","6065","6063","6058","10000672","10000671","10000670","10000669","10000668","10000667","10000666","10000665","10000664","10000663","10000662","10000661","10000660","10000659","10000658","10000657","10000656","10000655"],"fId":"10000111","level":2,"leaf":false},{"id":"10000672","name":"裤子","sonIdList":["547699","547700","547701","547702","547703","547704","547705"],"fId":"10000113","level":3,"leaf":false},{"id":"547704","name":"加绒裤","fId":"10000672","level":4,"leaf":true,"state":0,"hasTrialCategory":false,"isTrialCategory":false,"isLocalLife":false}],"depositAmount":0,"catAuth":true,"limitSubjectTypes":[]},{"id":547701,"paths":[{"id":"10000111","name":"服饰内衣","sonIdList":["10000397","10000115","10000112","10000113","10000114"],"fId":"0","level":1,"leaf":false},{"id":"10000113","name":"女装","sonIdList":["546810","546811","530041","547706","6090","6089","6088","6087","6083","6076","6073","6070","6065","6063","6058","10000672","10000671","10000670","10000669","10000668","10000667","10000666","10000665","10000664","10000663","10000662","10000661","10000660","10000659","10000658","10000657","10000656","10000655"],"fId":"10000111","level":2,"leaf":false},{"id":"10000672","name":"裤子","sonIdList":["547699","547700","547701","547702","547703","547704","547705"],"fId":"10000113","level":3,"leaf":false},{"id":"547701","name":"休闲裤","fId":"10000672","level":4,"leaf":true,"state":0,"hasTrialCategory":false,"isTrialCategory":false,"isLocalLife":false}],"depositAmount":0,"catAuth":true,"limitSubjectTypes":[]}],"version":"ProductClsRAG","noQualificationCatIds":[547705,547704,547701],"depositCatInfos":[{"catId":547705,"amountToPay":0,"error":false},{"catId":547704,"amountToPay":0,"error":false},{"catId":547701,"amountToPay":0,"error":false}],"visionCallMethod":"ProductClsRAG"}
|
||||
var productClassifyRst = WXUpload.getProductClassify(shop, upProdInitParam.product.info.title, tempImgFullPathLst);
|
||||
if (!productClassifyRst.Contains("\"code\":0"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref productClassifyRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = productClassifyRst;
|
||||
throw new Exception("获取类目失败 " + error);
|
||||
}
|
||||
WXGetProdCateInfo cateInfo = new WXGetProdCateInfo();
|
||||
try
|
||||
{
|
||||
cateInfo = JsonHelper.DeserializeJsonToObject<WXGetProdCateInfo>(productClassifyRst);
|
||||
foreach (var catePath in cateInfo.aiCategoryList.FirstOrDefault().paths)
|
||||
{
|
||||
aiCateIdLst.Add(catePath.id.ParseToLong());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("" + "根据图片获取类目失败 " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
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 FillMainImagesStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "主图不足时使用详情图补充";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
mainImgCount = (prodInfo?.detail?.galleries?.Where(g => g.type == 1).Count()).ParseToInt();
|
||||
if (mainImgCount > 0 && mainImgCount < 3)
|
||||
{
|
||||
var gallery1 = prodInfo?.detail?.galleries?.Where(g => g.type == 2).FirstOrDefault();
|
||||
// 先补一张
|
||||
if (gallery1 != null)
|
||||
{
|
||||
prodInfo.detail.galleries.Add(new gallery_item()
|
||||
{
|
||||
type = 1,
|
||||
url = gallery1.url,
|
||||
width = gallery1.width,
|
||||
height = gallery1.height,
|
||||
});
|
||||
}
|
||||
// 如果补了只有两张再补一张
|
||||
if (mainImgCount == 1 && (prodInfo?.detail?.galleries?.Where(g => g.type == 1).Count()).ParseToInt() > 1)
|
||||
{
|
||||
var gallery2 = prodInfo?.detail?.galleries?[1];
|
||||
if (gallery2 != null)
|
||||
{
|
||||
prodInfo.detail.galleries.Add(new gallery_item()
|
||||
{
|
||||
type = 1,
|
||||
url = gallery2.url,
|
||||
width = gallery2.width,
|
||||
height = gallery2.height,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((prodInfo?.detail?.galleries?.Where(g => g.type == 1).Count()).ParseToInt() < 3)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "主图数量少于三张";
|
||||
}));
|
||||
throw new Exception("主图数量少于三张");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
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 FilterDuplicateImagesStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "过滤重复图片";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
needAddRandomBlock = false;
|
||||
wantAddRandomBlock = chkImgRandomBlock.Checked && (/*upProdParam.product.info.category.FirstOrDefault()?.name == "图书" ||*/
|
||||
prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸" || dbProd.main_cat_name == "图书" || dbProd.main_cat_name == "书籍/杂志/报纸");
|
||||
{
|
||||
List<gallery_item> galls = new List<gallery_item>();
|
||||
foreach (var gall in prodInfo.detail.galleries.Where(g => g.type == 1).ToList())
|
||||
{
|
||||
if (!galls.Any(g => g.url == gall.url)/* && !prodInfo.detail.sku.Any(s => s.thumb_url == gall.url)*/)
|
||||
galls.Add(gall);
|
||||
}
|
||||
foreach (var gall in prodInfo.detail.galleries.Where(g => g.type == 2).ToList())
|
||||
{
|
||||
if (!galls.Any(g => g.url == gall.url)/* && !prodInfo.detail.sku.Any(s => s.thumb_url == gall.url)*/)
|
||||
galls.Add(gall);
|
||||
}
|
||||
prodInfo.detail.galleries.Clear();
|
||||
prodInfo.detail.galleries.AddRange(galls);
|
||||
int repeatSn = 0;
|
||||
while (prodInfo.detail.galleries.Where(g => g.type == 1).Count() > 0 && prodInfo.detail.galleries.Where(g => g.type == 1).Count() < 3)
|
||||
{
|
||||
repeatSn++;
|
||||
var gallOld = prodInfo.detail.galleries.LastOrDefault(g => g.type == 1);
|
||||
var gallNew = JsonHelper.DeserializeJsonToObject<gallery_item>(JsonHelper.SerializeObject(gallOld));
|
||||
// 如果有 替换掉之前附加的后缀
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
gallNew.url = gallNew.url.Replace("?re_sn1=" + i, "");
|
||||
gallNew.url = gallNew.url.Replace("?re_sn1=" + i, "");
|
||||
}
|
||||
if (gallNew.url.Contains("?"))
|
||||
gallNew.url += "&re_sn1=" + repeatSn;
|
||||
else
|
||||
gallNew.url += "?re_sn1=" + repeatSn;
|
||||
prodInfo.detail.galleries.Add(gallNew);
|
||||
needAddRandomBlock = true;
|
||||
}
|
||||
if (prodInfo.detail.galleries.Where(g => g.type == 1).Count() > 0 && prodInfo.detail.galleries.Where(g => g.type == 2).Count() <= 0)
|
||||
{
|
||||
var gallOld = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1);
|
||||
var gallNew = JsonHelper.DeserializeJsonToObject<gallery_item>(JsonHelper.SerializeObject(gallOld));
|
||||
if (gallNew.url.Contains("?"))
|
||||
gallNew.url += "&re_sn2=" + 1;
|
||||
else
|
||||
gallNew.url += "?re_sn2=" + 1;
|
||||
gallNew.type = 2;
|
||||
prodInfo.detail.galleries.Add(gallNew);
|
||||
needAddRandomBlock = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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 FissionTitleStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "裂变标题";
|
||||
|
||||
protected override Task<bool> CanExecuteProvider(WXPublishContext context, CancellationToken token)
|
||||
{
|
||||
return CurrentUser.IsAuthorized("裂变调试") && chkFissionGoodsName.Checked;
|
||||
}
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
var titles = txtFissionTitle.Text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
if (titles.Count == 0)
|
||||
{
|
||||
cancellationTokenSource.Cancel();
|
||||
throw new Exception("裂变标题数量不足,将暂停上传");
|
||||
}
|
||||
selectProd.product_name = titles[0];
|
||||
selectProd.is_fission_title = true;
|
||||
titles.RemoveAt(0);
|
||||
txtFissionTitle.Text = string.Join("\r\n", titles);
|
||||
context.Progress.Report("标题裂变成功,更改为:" + selectProd.product_name);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
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 的“AI生成商品裂变图片”区段迁移。
|
||||
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
||||
/// </summary>
|
||||
public sealed class GenerateAiProductImageStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "AI生成商品裂变图片";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (chkAiImage.Checked)
|
||||
{
|
||||
int imgCount = 1;
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
if (cell != null)
|
||||
cell.Value = "正在Ai生图";
|
||||
imgCount = txtAiImgCount.Text.Trim().ParseToInt();
|
||||
if (imgCount == 0)
|
||||
imgCount = 1;
|
||||
}));
|
||||
|
||||
List<Task> tList = new List<Task>();
|
||||
List<string> errStrLst = new List<string>();
|
||||
for (int n = 0; n < upProdParam.product.info.headImg.Count && n < imgCount; n++)
|
||||
{
|
||||
while (tList.Count >= 10)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
tList.RemoveAll(t => t.IsCanceled || t.IsFaulted || t.IsCompleted);
|
||||
}
|
||||
var tt = Task.Run(() =>
|
||||
{
|
||||
var imgUrl = GetAiImg(upProdParam.product.info.headImg[n], upProdParam.product.info.shortTitle);
|
||||
if (imgUrl.StartsWith("生成Ai图片错误"))
|
||||
{
|
||||
errStrLst.Add(imgUrl);
|
||||
return;
|
||||
//throw new Exception("" + imgUrl);
|
||||
}
|
||||
|
||||
// api上传图片文件 Ai主图
|
||||
if (1 == 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
string errMsg = "";
|
||||
//var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, needAddRandomBlock, wantAddRandomBlock, 800, 800);
|
||||
var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, false, false, 800, 800);
|
||||
if (!string.IsNullOrEmpty(errMsg))
|
||||
{
|
||||
errStrLst.Add(errMsg);
|
||||
return;
|
||||
//return errMsg;
|
||||
}
|
||||
|
||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
//upDate += "&is_file=true";
|
||||
//if (needAddRandomBlock || wantAddRandomBlock)
|
||||
// upDate += "&random_code=true";
|
||||
upDate += "&img_url=" + imgUrl;
|
||||
upDate += "&img_base64=" + imgBase64;
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在上传Ai主图文件 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5 && apiUpImgFileRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref apiUpImgFileRst, "img_url");
|
||||
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||
{
|
||||
upProdParam.product.info.headImg[n] = upImgUrl;
|
||||
//if (n == 0)
|
||||
// upProdParam.product.info.detail.detailImg.Insert(0, upImgUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
string upImgErrMsg = BaseRegex.GetStringJsonByRegs(ref apiUpImgFileRst, apiUpImgFileRst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
|
||||
errStrLst.Add("上传Ai图失败 " + upImgErrMsg);
|
||||
return;
|
||||
//throw new Exception("上传Ai图失败 " + upImgErrMsg);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errStrLst.Add("上传Ai图失败 " + ex.Message);
|
||||
return;
|
||||
//throw new Exception("上传Ai图失败 " + ex.Message);
|
||||
}
|
||||
}
|
||||
});
|
||||
tList.Add(tt);
|
||||
}
|
||||
while (tList.Count > 0)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
tList.RemoveAll(t => t.IsCanceled || t.IsFaulted || t.IsCompleted);
|
||||
}
|
||||
// 错误超过一定数量直接报错返回
|
||||
if (errStrLst.Count > 0 && errStrLst.Count >= imgCount / 3)
|
||||
{
|
||||
throw new Exception(string.Join(",", errStrLst));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
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 的“生成AI短标题”区段迁移。
|
||||
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
||||
/// </summary>
|
||||
public sealed class GenerateAiShortTitleStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "生成AI短标题";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (wxUploadRule.IsAiShortTitle || chkAiImage.Checked)
|
||||
{
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成短标题";
|
||||
}));
|
||||
}
|
||||
|
||||
WXGetShortTitleParam titleParam = new WXGetShortTitleParam()
|
||||
{
|
||||
categories = new List<categorieParam>(),
|
||||
headImgUrls = upProdParam.product.info.headImg,
|
||||
productTitle = upProdParam.product.info.title,
|
||||
};
|
||||
foreach (var cate in upProdParam.product.info.category)
|
||||
{
|
||||
titleParam.categories.Add(new categorieParam() { catId = cate.catId, catName = cate.name });
|
||||
}
|
||||
var shortTitleRst = WXUpload.genProductShortTitle(shop, titleParam);
|
||||
if (!shortTitleRst.Contains("\"code\":0") && !shortTitleRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref shortTitleRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = shortTitleRst;
|
||||
throw new Exception("短标题获取失败 " + error);
|
||||
}
|
||||
upProdParam.product.info.shortTitle = BaseRegex.GetStringJson(ref shortTitleRst, "shortTitle");
|
||||
upProdParam.product.info.aiGenShortTitle = upProdParam.product.info.shortTitle;
|
||||
upProdParam.product.info.title = upProdParam.product.info.shortTitle + upProdParam.product.info.title;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
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 GenerateCategoryTemplateStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "生成类目模板";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成类目模板";
|
||||
}));
|
||||
}
|
||||
|
||||
if (aiCateIdLst.LastOrDefault() == 7370)
|
||||
{
|
||||
aiCateIdLst.RemoveAt(aiCateIdLst.Count - 1);
|
||||
aiCateIdLst.Add(547591);
|
||||
}
|
||||
|
||||
getCateRst = WXUpload.getCategoryOnShelf(shop, aiCateIdLst);
|
||||
if (!getCateRst.Contains("\"code\":0"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref getCateRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = getCateRst;
|
||||
throw new Exception("获取类目模板失败" + error);
|
||||
}
|
||||
|
||||
jCateRst = JObject.Parse(getCateRst);
|
||||
upProdParam.product.info.category = JsonHelper.DeserializeJsonToList<categoryParam>(JsonHelper.SerializeObject(jCateRst["category"]));
|
||||
// 这里用了ai获取类目,如下填写
|
||||
upProdParam.product.info.recommendCategory = new recommendCategoryParam()
|
||||
{
|
||||
isAccepted = true,
|
||||
categoryNames = new List<string>(),
|
||||
recommendSource = "ai",
|
||||
interfaceName = "ProductClsRAG",
|
||||
useNewInterface = 1,
|
||||
};
|
||||
foreach (var cateParam in upProdParam.product.info.category)
|
||||
{
|
||||
upProdParam.product.info.recommendCategory.categoryNames.Add(cateParam.name);
|
||||
}
|
||||
|
||||
// 获取叶子类目id
|
||||
|
||||
leafCatId = (upProdParam.product.info.category.LastOrDefault()?.catId).ParseToLong(); //哲学经典著作
|
||||
bound = GlobalConfig.WxCatBoundList.FirstOrDefault(b => b.leaf_id == leafCatId);
|
||||
if (leafCatId == 547591)
|
||||
bound = GlobalConfig.WxCatBoundList.FirstOrDefault(b => b.leaf_id == 7370);
|
||||
if (bound == null)
|
||||
throw new Exception("获取类目保证金失败");
|
||||
maxBount = txtFilterBoundMax.Text.Trim().ParseToInt();
|
||||
minBount = txtFilterBoundMin.Text.Trim().ParseToInt();
|
||||
if (bound.cat_bound < minBount || bound.cat_bound > maxBount)
|
||||
throw new Exception("类目保证金(" + bound.cat_bound + ")超过过滤限制(" + minBount + "-" + maxBount + ")");
|
||||
|
||||
// 定向类目需指定品牌Id
|
||||
spBrandId = "";
|
||||
spBrandName = "";
|
||||
if (leafCatId == 547591)
|
||||
{
|
||||
// 先写死
|
||||
//spBrandId = 10914219.ToString();
|
||||
|
||||
var rst = WXUpload.getMixBrand(shop, leafCatId.ToString());
|
||||
Invoke(new Action(() => { spBrandName = cmbSpBrandName.Text.Trim(); }));
|
||||
|
||||
if (!string.IsNullOrEmpty(spBrandName) && rst.Contains("\"code\":0"))
|
||||
{
|
||||
var jObj = JsonHelper.JObjectParse(rst);
|
||||
if (rst.Contains("mixBrandList"))
|
||||
{
|
||||
foreach (var jItem in jObj["mixBrandList"]) // bizuinBrandList mixBrandList
|
||||
{
|
||||
if (jItem["chName"].ParseToString() == spBrandName)
|
||||
spBrandId = jItem["brandId"].ParseToString();
|
||||
}
|
||||
}
|
||||
if (rst.Contains("bizuinBrandList"))
|
||||
{
|
||||
foreach (var jItem in jObj["bizuinBrandList"]) // bizuinBrandList mixBrandList
|
||||
{
|
||||
if (jItem["chName"].ParseToString() == spBrandName)
|
||||
spBrandId = jItem["brandId"].ParseToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (spBrandId.IsNullOrEmpty())
|
||||
{
|
||||
throw new Exception("定向类目绑定品牌失败");
|
||||
}
|
||||
|
||||
// 国表定向类目
|
||||
upProdParam.product.info.brandId = spBrandId.ParseToLong();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// 检测是否有类目上传权限
|
||||
var cateUpCheckRst = WXUpload.batchCheckCategoryRelation(shop, leafCatId);
|
||||
//"{\"code\":0,\"list\":[{\"category_id\":\"1427\",\"result\":0,\"no_auth_reason_type\":0}]}"
|
||||
//"{\"code\":0,\"list\":[{\"category_id\":\"7486\",\"result\":0,\"no_auth_reason_type\":0}]}"
|
||||
if (!cateUpCheckRst.Contains("\"code\":0") && !cateUpCheckRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref cateUpCheckRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = cateUpCheckRst;
|
||||
throw new Exception("类目校验错误 " + error);
|
||||
}
|
||||
if (!cateUpCheckRst.Contains("\"result\":1"))
|
||||
{
|
||||
if (aiCateIdLst.FirstOrDefault() == 10000215)
|
||||
{
|
||||
//@"{""categoryInfo"":{""categories"":[{""id"":10000215},{""id"":10000222},{""id"":7483}],""categoryDeposit"":""1000.00"",""isNewApplyCat"":true,""licenseGroupList"":[{""licenseGroupId"":""1"",""license"":{""licenseId"":""4"",""cosIdList"":[""1771897594802-oM5657FQAaKYlf2uP300NBgx9HYY-0581""],""licenseFieldList"":[{""key"":""audit_license_registration_no"",""value"":""YB23509020049441""},{""key"":""search_url"",""value"":""""}],""isReuse"":true}}],""ruleVersion"":5234,""certificate"":[]},""brandIdList"":[],""leafCategoryId"":7483,""reuse"":0,""applyType"":""normalApply""}";
|
||||
var getCatDataRst = WXUpload.getSingleCategoryData(shop, leafCatId, aiCateIdLst);
|
||||
if (!getCatDataRst.Contains("\"code\":0") && !getCatDataRst.Contains("\"success\":true"))
|
||||
{
|
||||
throw new Exception("类目申请失败 查询类目资质文件失败");
|
||||
}
|
||||
|
||||
WXCateAuthParam wxCateAuthParam = new WXCateAuthParam();
|
||||
wxCateAuthParam.leafCategoryId = leafCatId;
|
||||
wxCateAuthParam.categoryInfo.categoryDeposit = bound.cat_bound.ToString("0.00");
|
||||
wxCateAuthParam.categoryInfo.ruleVersion = BaseRegex.GetIntJson(ref getCatDataRst, "ruleVersion");
|
||||
foreach (var cateId in aiCateIdLst)
|
||||
{
|
||||
wxCateAuthParam.categoryInfo.categories.Add(new WXCateId() { id = cateId });
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!JsonHelper.JObjectParse(getCatDataRst)["reuseApplyData"].IsJTokenNullOrEmpty())
|
||||
{
|
||||
var jlicenseGroupList = JsonHelper.JObjectParse(getCatDataRst)["reuseApplyData"]["catInfo"]["licenseGroupList"];
|
||||
var licenseGroupListStr = JsonHelper.SerializeObject(jlicenseGroupList);
|
||||
wxCateAuthParam.categoryInfo.licenseGroupList = JsonHelper.DeserializeJsonToList<licenseGroup>(licenseGroupListStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
var licenseGroup = new licenseGroup();
|
||||
wxCateAuthParam.categoryInfo.licenseGroupList.Add(licenseGroup);
|
||||
licenseGroup.license.licenseId = "4";
|
||||
var cosIdList = "[" + BaseRegex.GetMatchRegexString(ref getCatDataRst, "\"cosIdList\":\\[([\\s\\S]*?)\\]") + "]";
|
||||
licenseGroup.license.cosIdList = JsonHelper.DeserializeJsonToList<string>(cosIdList);
|
||||
var licenseFieldList = "[" + BaseRegex.GetMatchRegexString(ref getCatDataRst, "\"licenseFieldList\":\\[([\\s\\S]*?)\\]") + "]";
|
||||
licenseGroup.license.licenseFieldList = JsonHelper.DeserializeJsonToList<KeyValueParam>(licenseFieldList);
|
||||
}
|
||||
var authCateRst = WXUpload.wxCateAuth(shop, aiCateIdLst, wxCateAuthParam);
|
||||
if (!authCateRst.Contains("\"code\":0") && !authCateRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref authCateRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = BaseRegex.GetStringJson(ref authCateRst, "errmsg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = authCateRst;
|
||||
throw new Exception("类目申请失败 " + error);
|
||||
}
|
||||
Thread.Sleep(Randomx.GetId(5000, 7000));
|
||||
cateUpCheckRst = WXUpload.batchCheckCategoryRelation(shop, leafCatId);
|
||||
if (!cateUpCheckRst.Contains("\"code\":0") && !cateUpCheckRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref cateUpCheckRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = cateUpCheckRst;
|
||||
throw new Exception("类目申请校验错误 " + error);
|
||||
}
|
||||
if (!cateUpCheckRst.Contains("\"result\":1"))
|
||||
throw new Exception("类目申请审核中 请稍后再试");
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new Exception("类目申请失败 复用资质文件失败,请重新提交资质文件");
|
||||
}
|
||||
//throw new Exception("类目申请失败 请手动申请资质类目");
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(Randomx.GetId(1000, 2000));
|
||||
var cateAuthorRst = WXUpload.addFinderCategoryV2(shop, leafCatId);
|
||||
if (!cateAuthorRst.Contains("\"code\":0") && !cateAuthorRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref cateAuthorRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = BaseRegex.GetStringJson(ref cateAuthorRst, "errmsg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = cateAuthorRst;
|
||||
throw new Exception("类目申请错误 " + error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
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 的“获取店铺Api Token”区段迁移。
|
||||
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
||||
/// </summary>
|
||||
public sealed class GetShopApiTokenStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "获取店铺Api Token";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
// 获取店铺的accessToken
|
||||
token = lstWXShopTokenInfo.FirstOrDefault(t => t.shopId == shop.ShopId);
|
||||
if (token == null)
|
||||
token = new WXShopTokenInfo();
|
||||
if (token.isExpire || string.IsNullOrEmpty(token.accessToken))
|
||||
{
|
||||
AuthInfo auth = GlobalConfig.lstWxShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
|
||||
//if (auth != null && auth.ExpiresTime > DateTime.Now.AddMinutes(5))
|
||||
{
|
||||
token = new WxApiBLL().GetShopWxToken(shop);
|
||||
|
||||
if (!string.IsNullOrEmpty(token.accessToken))
|
||||
{
|
||||
lstWXShopTokenInfo.RemoveAll(t => t.shopId == shop.ShopId);
|
||||
lstWXShopTokenInfo.Add(token);
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_token_list", lstWXShopTokenInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果店铺token不可用,随机获取一个上传图片的accessToken
|
||||
if (token == null || token.isExpire || string.IsNullOrEmpty(token.accessToken))
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
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;
|
||||
using Store.Framework.Extensions;
|
||||
|
||||
namespace Store.Product.Publish.Steps.Wx;
|
||||
/// <summary>
|
||||
/// 由 WXDBProdUploadForm.UploadProduct 的“获取店铺运费模板”区段迁移。
|
||||
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
||||
/// </summary>
|
||||
public sealed class GetShopShippingTemplateStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "获取店铺运费模板";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
expressRst = WXUpload.getFreightTemplate(shop);
|
||||
if (!expressRst.Contains("\"code\":0") && !expressRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref expressRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = expressRst;
|
||||
throw new Exception("运费模板获取失败 " + error);
|
||||
}
|
||||
try
|
||||
{
|
||||
var addressArr = JsonHelper.JObjectParse(expressRst)["freightTemplateList"];
|
||||
foreach (var addressObj in addressArr)
|
||||
{
|
||||
var addressStr = JsonHelper.SerializeObject(addressObj);
|
||||
if (addressObj["isDefault"].ParseToInt() == 1)
|
||||
{
|
||||
string templateId = addressObj["templateId"].ParseToString();
|
||||
upProdParam.product.info.expressInfo = new expressInfoParam();
|
||||
upProdParam.product.info.expressInfo.templateId = templateId; // BaseRegex.GetStringJson(ref expressRst, "templateId");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (upProdParam.product.info.expressInfo == null)
|
||||
{
|
||||
upProdParam.product.info.expressInfo = new expressInfoParam();
|
||||
upProdParam.product.info.expressInfo.templateId = BaseRegex.GetStringJson(ref expressRst, "templateId");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("运费模板获取失败 " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,363 @@
|
||||
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 MAX.Core.Helpers;
|
||||
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;
|
||||
using Store.Framework.Extensions;
|
||||
|
||||
namespace Store.Product.Publish.Steps.Wx;
|
||||
/// <summary>
|
||||
/// 由 WXDBProdUploadForm.UploadProduct 的“初始化微信小店商品参数”区段迁移。
|
||||
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
||||
/// </summary>
|
||||
public sealed class InitializeProductDataStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "初始化微信小店商品参数";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
prodJObj = new JObject();
|
||||
try
|
||||
{
|
||||
prodJObj = JObject.Parse(dbProd.product_json);
|
||||
|
||||
var lstTitleReplaceText = new List<string>();
|
||||
if (!txtReplaceText.Text.Trim().IsNullOrEmpty())
|
||||
lstTitleReplaceText.AddRange(txtReplaceText.Text.Trim().Split(new string[] { ",", ",", " ", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries));
|
||||
// 过滤标题敏感词
|
||||
if (lstTitleReplaceText.Count > 0)
|
||||
{
|
||||
if (chkSkipReplaceText.Checked)
|
||||
{
|
||||
if (lstTitleReplaceText.Any(t => selectProd.product_name.Contains(t)))
|
||||
throw new Exception("命中敏感词");
|
||||
if (lstTitleReplaceText.Any(t => dbProd.product_name.Contains(t)))
|
||||
throw new Exception("命中敏感词");
|
||||
var goods_name = prodJObj["detail"]["goods_name"].ParseToString();
|
||||
if (lstTitleReplaceText.Any(t => goods_name.Contains(t)))
|
||||
throw new Exception("命中敏感词");
|
||||
var tiny_name = prodJObj["detail"]["tiny_name"].ParseToString();
|
||||
if (lstTitleReplaceText.Any(t => tiny_name.Contains(t)))
|
||||
throw new Exception("命中敏感词");
|
||||
var goods_desc = prodJObj["detail"]["goods_desc"].ParseToString();
|
||||
if (lstTitleReplaceText.Any(t => goods_desc.Contains(t)))
|
||||
throw new Exception("命中敏感词");
|
||||
var share_desc = prodJObj["detail"]["share_desc"].ParseToString();
|
||||
if (lstTitleReplaceText.Any(t => share_desc.Contains(t)))
|
||||
throw new Exception("命中敏感词");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var txt in lstTitleReplaceText)
|
||||
{
|
||||
dbProd.product_name = dbProd.product_name.Replace(txt, "");
|
||||
selectProd.product_name = selectProd.product_name.Replace(txt, "");
|
||||
}
|
||||
|
||||
var goods_name = prodJObj["detail"]["goods_name"].ParseToString();
|
||||
foreach (var txt in lstTitleReplaceText)
|
||||
{
|
||||
goods_name = goods_name.Replace(txt, "");
|
||||
}
|
||||
prodJObj["detail"]["goods_name"] = goods_name;
|
||||
|
||||
var tiny_name = prodJObj["detail"]["tiny_name"].ParseToString();
|
||||
foreach (var txt in lstTitleReplaceText)
|
||||
{
|
||||
tiny_name = tiny_name.Replace(txt, "");
|
||||
}
|
||||
prodJObj["detail"]["tiny_name"] = tiny_name;
|
||||
|
||||
var goods_desc = prodJObj["detail"]["goods_desc"].ParseToString();
|
||||
foreach (var txt in lstTitleReplaceText)
|
||||
{
|
||||
goods_desc = goods_desc.Replace(txt, "");
|
||||
}
|
||||
prodJObj["detail"]["goods_desc"] = goods_desc;
|
||||
|
||||
var share_desc = prodJObj["detail"]["share_desc"].ParseToString();
|
||||
foreach (var txt in lstTitleReplaceText)
|
||||
{
|
||||
share_desc = share_desc.Replace(txt, "");
|
||||
}
|
||||
prodJObj["detail"]["share_desc"] = share_desc;
|
||||
}
|
||||
}
|
||||
// 过滤标题特殊字符
|
||||
if (chkRemoveSpecialChar.Checked)
|
||||
{
|
||||
var chLst = new List<char> { ']', '】', ')', ')', '}', };
|
||||
foreach (var ch in chLst)
|
||||
{
|
||||
if (dbProd.product_name.Contains(ch) && dbProd.product_name.IndexOf(ch) < dbProd.product_name.Length / 2 && dbProd.product_name.Length > 10)
|
||||
dbProd.product_name = dbProd.product_name.Substring(dbProd.product_name.IndexOf(ch)).Trim(ch);
|
||||
|
||||
if (selectProd.product_name.Contains(ch) && selectProd.product_name.IndexOf(ch) < selectProd.product_name.Length / 2 && selectProd.product_name.Length > 10)
|
||||
selectProd.product_name = selectProd.product_name.Substring(selectProd.product_name.IndexOf(ch)).Trim(ch);
|
||||
|
||||
var goods_name = prodJObj["detail"]["goods_name"].ParseToString();
|
||||
if (goods_name.Contains(ch) && goods_name.IndexOf(ch) < goods_name.Length / 2 && goods_name.Length > 10)
|
||||
prodJObj["detail"]["goods_name"] = goods_name.Substring(goods_name.IndexOf(ch)).Trim(ch);
|
||||
}
|
||||
|
||||
}
|
||||
// 替换货号
|
||||
if (!string.IsNullOrEmpty(dbProd.ext_code))
|
||||
prodJObj["detail"]["out_goods_sn"] = dbProd.ext_code;
|
||||
// 替换编辑过的sku
|
||||
if (!string.IsNullOrEmpty(dbProd.sku_edit_json))
|
||||
prodJObj["detail"]["sku"] = JArray.Parse(JsonHelper.SerializeObject(JsonHelper.DeserializeJsonToList<sku_item>(dbProd.sku_edit_json)));
|
||||
// 过滤sku敏感词
|
||||
if (lstTitleReplaceText.Count > 0)
|
||||
{
|
||||
var skuJArr = prodJObj["detail"]["sku"] as JArray;
|
||||
try
|
||||
{
|
||||
foreach (var skuJObj in skuJArr)
|
||||
{
|
||||
var specJArr = skuJObj["spec"] as JArray;
|
||||
for (int i = 0; i < specJArr.Count; i++)
|
||||
{
|
||||
foreach (var txt in lstTitleReplaceText)
|
||||
{
|
||||
specJArr[i]["spec_name"] = specJArr[i]["spec_name"].ParseToString().Replace(txt, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("商品数据初始化失败" + ex.Message);
|
||||
}
|
||||
}
|
||||
// 同颜色规格向上浮动同价格
|
||||
if (chkSameSpecPriceUp.Checked)
|
||||
{
|
||||
var priceTextLst = dbProd.price_text.Split('-');
|
||||
if (priceTextLst.Length != 2 || priceTextLst[0] != priceTextLst[1])
|
||||
{
|
||||
Dictionary<string, int> specPriceDic = new Dictionary<string, int>();
|
||||
Dictionary<string, int> specMultiPriceDic = new Dictionary<string, int>();
|
||||
var skuJArr = prodJObj["detail"]["sku"] as JArray;
|
||||
try
|
||||
{
|
||||
// 计算主spec的最高价
|
||||
foreach (var skuJObj in skuJArr)
|
||||
{
|
||||
var specJArr = skuJObj["spec"] as JArray;
|
||||
if (!specPriceDic.ContainsKey(specJArr[0]["spec_name"].ParseToString()) || skuJObj["price"].ParseToInt() > specPriceDic[specJArr[0]["spec_name"].ParseToString()])
|
||||
{
|
||||
specPriceDic[specJArr[0]["spec_name"].ParseToString()] = skuJObj["price"].ParseToInt();
|
||||
}
|
||||
if (!specMultiPriceDic.ContainsKey(specJArr[0]["spec_name"].ParseToString()) || skuJObj["multi_price"].ParseToInt() > specMultiPriceDic[specJArr[0]["spec_name"].ParseToString()])
|
||||
{
|
||||
specMultiPriceDic[specJArr[0]["spec_name"].ParseToString()] = skuJObj["multi_price"].ParseToInt();
|
||||
}
|
||||
}
|
||||
// 统一按最高价设置
|
||||
foreach (var skuJObj in skuJArr)
|
||||
{
|
||||
var specJArr = skuJObj["spec"] as JArray;
|
||||
skuJObj["price"] = specPriceDic[specJArr[0]["spec_name"].ParseToString()];
|
||||
skuJObj["multi_price"] = specMultiPriceDic[specJArr[0]["spec_name"].ParseToString()];
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("商品数据初始化失败" + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 同颜色规格向下浮动同价格
|
||||
if (chkSameSpecPriceDown.Checked)
|
||||
{
|
||||
var priceTextLst = dbProd.price_text.Split('-');
|
||||
if (priceTextLst.Length != 2 || priceTextLst[0] != priceTextLst[1])
|
||||
{
|
||||
Dictionary<string, int> specPriceDic = new Dictionary<string, int>();
|
||||
Dictionary<string, int> specMultiPriceDic = new Dictionary<string, int>();
|
||||
var skuJArr = prodJObj["detail"]["sku"] as JArray;
|
||||
try
|
||||
{
|
||||
// 计算主spec的最低价
|
||||
foreach (var skuJObj in skuJArr)
|
||||
{
|
||||
var specJArr = skuJObj["spec"] as JArray;
|
||||
if (!specPriceDic.ContainsKey(specJArr[0]["spec_name"].ParseToString()) || skuJObj["price"].ParseToInt() < specPriceDic[specJArr[0]["spec_name"].ParseToString()])
|
||||
{
|
||||
specPriceDic[specJArr[0]["spec_name"].ParseToString()] = skuJObj["price"].ParseToInt();
|
||||
}
|
||||
if (!specMultiPriceDic.ContainsKey(specJArr[0]["spec_name"].ParseToString()) || skuJObj["multi_price"].ParseToInt() < specMultiPriceDic[specJArr[0]["spec_name"].ParseToString()])
|
||||
{
|
||||
specMultiPriceDic[specJArr[0]["spec_name"].ParseToString()] = skuJObj["multi_price"].ParseToInt();
|
||||
}
|
||||
}
|
||||
// 统一按最低价设置
|
||||
foreach (var skuJObj in skuJArr)
|
||||
{
|
||||
var specJArr = skuJObj["spec"] as JArray;
|
||||
skuJObj["price"] = specPriceDic[specJArr[0]["spec_name"].ParseToString()];
|
||||
skuJObj["multi_price"] = specMultiPriceDic[specJArr[0]["spec_name"].ParseToString()];
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("商品数据初始化失败" + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 只保留最高价
|
||||
if (chkHighestPriceSku.Checked)
|
||||
{
|
||||
int price = 0;
|
||||
var skuJArr = prodJObj["detail"]["sku"] as JArray;
|
||||
try
|
||||
{
|
||||
// 计算主spec的最高价
|
||||
foreach (var skuJObj in skuJArr)
|
||||
{
|
||||
if (price < skuJObj["multi_price"].ParseToInt())
|
||||
price = skuJObj["multi_price"].ParseToInt();
|
||||
}
|
||||
|
||||
var product_json_tmp = JsonHelper.SerializeObject(prodJObj);
|
||||
|
||||
// 移除第一组所有sku
|
||||
skuJArr.RemoveAll();
|
||||
|
||||
// 序列化第二组,从组中挑选符合价格条件的sku往第一组内填写
|
||||
var prodJObj2 = JObject.Parse(product_json_tmp);
|
||||
var skuJArr2 = prodJObj2["detail"]["sku"] as JArray;
|
||||
foreach (var skuJObj2 in skuJArr2)
|
||||
{
|
||||
if (skuJObj2["multi_price"].ParseToInt() >= price)
|
||||
skuJArr.Add(skuJObj2);
|
||||
}
|
||||
if (skuJArr.Count == 0)
|
||||
{
|
||||
throw new Exception("商品sku差价不满足上货条件,跳过");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("商品数据初始化失败" + ex.Message);
|
||||
}
|
||||
}
|
||||
// 只保留最低价
|
||||
if (chkLowestPriceSku.Checked)
|
||||
{
|
||||
int price = 99999999;
|
||||
var skuJArr = prodJObj["detail"]["sku"] as JArray;
|
||||
try
|
||||
{
|
||||
// 计算主spec的最低价
|
||||
foreach (var skuJObj in skuJArr)
|
||||
{
|
||||
if (price > skuJObj["multi_price"].ParseToInt())
|
||||
price = skuJObj["multi_price"].ParseToInt();
|
||||
}
|
||||
|
||||
var product_json_tmp = JsonHelper.SerializeObject(prodJObj);
|
||||
|
||||
// 移除第一组所有sku
|
||||
skuJArr.RemoveAll();
|
||||
|
||||
// 序列化第二组,从组中挑选符合价格条件的sku往第一组内填写
|
||||
var prodJObj2 = JObject.Parse(product_json_tmp);
|
||||
var skuJArr2 = prodJObj2["detail"]["sku"] as JArray;
|
||||
foreach (var skuJObj2 in skuJArr2)
|
||||
{
|
||||
if (skuJObj2["multi_price"].ParseToInt() <= price)
|
||||
skuJArr.Add(skuJObj2);
|
||||
}
|
||||
if (skuJArr.Count == 0)
|
||||
{
|
||||
throw new Exception("商品sku差价不满足上货条件,跳过");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("商品数据初始化失败" + ex.Message);
|
||||
}
|
||||
}
|
||||
// 过滤低价sku,如果所有sku都不达标,跳过商品
|
||||
if (!string.IsNullOrEmpty(txtMinPrice.Text))
|
||||
{
|
||||
var product_json_tmp = JsonHelper.SerializeObject(prodJObj);
|
||||
|
||||
// 移除第一组所有sku
|
||||
var skuJArr = prodJObj["detail"]["sku"] as JArray;
|
||||
skuJArr.RemoveAll();
|
||||
|
||||
// 序列化第二组,从组中挑选符合价格条件的sku往第一组内填写
|
||||
var prodJObj2 = JObject.Parse(product_json_tmp);
|
||||
var skuJArr2 = prodJObj2["detail"]["sku"] as JArray;
|
||||
foreach (var skuJObj2 in skuJArr2)
|
||||
{
|
||||
var limitMinPrice = this.txtMinPrice.Text.Trim().ParseToDecimal() * 100;
|
||||
// 供应商价加价10%(最低1元)赚取差价 先加价后过滤,过滤条件也要相应增加10%
|
||||
//if (dbProd.product_get_type_text == "厂商直采")
|
||||
// limitPrice += Math.Max(100m, limitPrice * 0.1m);
|
||||
if (skuJObj2["multi_price"].ParseToInt() >= limitMinPrice)
|
||||
skuJArr.Add(skuJObj2);
|
||||
}
|
||||
if (skuJArr.Count == 0)
|
||||
{
|
||||
throw new Exception("商品sku价格不满足上货条件,跳过");
|
||||
}
|
||||
}
|
||||
// 过滤高价sku,如果所有sku都不达标,跳过商品
|
||||
if (!string.IsNullOrEmpty(txtMaxPrice.Text))
|
||||
{
|
||||
var product_json_tmp = JsonHelper.SerializeObject(prodJObj);
|
||||
|
||||
// 移除第一组所有sku
|
||||
var skuJArr = prodJObj["detail"]["sku"] as JArray;
|
||||
skuJArr.RemoveAll();
|
||||
|
||||
// 序列化第二组,从组中挑选符合价格条件的sku往第一组内填写
|
||||
var prodJObj2 = JObject.Parse(product_json_tmp);
|
||||
var skuJArr2 = prodJObj2["detail"]["sku"] as JArray;
|
||||
foreach (var skuJObj2 in skuJArr2)
|
||||
{
|
||||
var limitMaxPrice = this.txtMaxPrice.Text.Trim().ParseToDecimal() * 100;
|
||||
// 供应商价加价10%(最低1元)赚取差价 先加价后过滤,过滤条件也要相应增加10%
|
||||
//if (dbProd.product_get_type_text == "厂商直采")
|
||||
// limitPrice += Math.Max(100m, limitPrice * 0.1m);
|
||||
if (skuJObj2["multi_price"].ParseToInt() <= limitMaxPrice)
|
||||
skuJArr.Add(skuJObj2);
|
||||
}
|
||||
if (skuJArr.Count == 0)
|
||||
{
|
||||
throw new Exception("商品sku价格不满足上货条件,跳过");
|
||||
}
|
||||
}
|
||||
|
||||
dbProd.product_json = JsonHelper.SerializeObject(prodJObj);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("商品数据初始化失败" + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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 InitializeUploadProductStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "初始化上传参数与店铺登录校验";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (shop == null || string.IsNullOrEmpty(shop.ShopId) || shop.LoginStatus != "登录成功")
|
||||
{
|
||||
throw new Exception("店铺为空或未登录!");
|
||||
}
|
||||
if (cell != null)
|
||||
{
|
||||
context.Progress.Report("正在初始化上传");
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# 微信 UploadProduct 步骤迁移说明
|
||||
|
||||
本次把 `TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs` 中 `UploadProduct` 的原有 `#region` 按顺序迁入 `Store.Product/Publish/Steps/Wx`。
|
||||
|
||||
## 新入口参数
|
||||
|
||||
- `WxProductUploadParam` 是新的承载实体,入口位于 `WXDBProdUploadForm.UploadProduct`。
|
||||
- 原上传参数实体 `WXUploadProductParam` / `WXUploadProductInitParam` 未修改。
|
||||
- 上传时由 `CaptureWxProductUploadFormState()` 和 `WxProductPublishState` 把旧对象、窗体控件值和运行时回调赋给新实体。
|
||||
- 后续可逐步把 `ProductParameter` / `InitParameter` 替换为 `Store.Product` 自有 DTO。
|
||||
|
||||
## 需要手工核对的重点
|
||||
|
||||
1. `WxProductPublishState` 中标记为 `dynamic` 的跨步骤字段,应替换为最终 DTO 的明确类型。
|
||||
2. `WxProductUploadFormState` / `WxControlState` 是窗体控件快照代理。若控件类型、名称或属性不一致,请对照 `CaptureWxProductUploadFormState()` 修改。
|
||||
3. 原代码依赖但仍在 `TEMUKJD` 中的服务包括:`WXUpload`、`PDDProdFormConverter`、`WxApiBLL`、`WXVideoUploader`、`WxGetAssistant`、`WXProdNoCheckEditHelper`、`AdminForms.WXAdminQualificationImageForm`、`BaseMsgForm`。
|
||||
- 为避免让 `Store.Product` 反向引用 WinForms 主程序,本次没有加 `TEMUKJD` 项目引用。
|
||||
- 后续应把这些能力迁到 `Store.Product` 服务或通过运行时适配接口注入。
|
||||
4. `WxProductUploadRuntime.Cell` / `CancellationTokenSource` 已用状态代理替代 WinForms 对象。
|
||||
5. `GetProductWXComplate`、`btnLoginAssistant_Click` 目前在 `WxProductPublishStepBase` 中是迁移占位实现。
|
||||
6. `WxShopTokenInfoList` 当前在入口处做了列表快照;若步骤内需要直接回写窗体静态列表,需要改为共享集合或增加回调。
|
||||
7. `SubmitProductStep` 中的 `DataGridViewRow` 统计逻辑仍直接依赖表格控件,后续建议迁到运行时回调。
|
||||
|
||||
## 步骤顺序
|
||||
|
||||
步骤顺序由 `WxProductPublishPipelineFactory.CreateDefault()` 统一维护,和原 `UploadProduct` 从上到下的执行顺序一致。
|
||||
@@ -0,0 +1,759 @@
|
||||
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 MatchProductPropertiesStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "匹配产品属性";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
//真丝、蚕丝、香云纱、羊绒、羊毛、羊羔毛、羽绒、皮草
|
||||
upProdParam.product.info.param = new List<wxPropParam>(); // 商品属性值
|
||||
productAttr = upProdParam.product.info.category.LastOrDefault().catInfo.productAttr;
|
||||
|
||||
// 直接转换微信回采
|
||||
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采") && chkUseWXComplateProd.Checked && dbProd.has_wx_format == "1" && wxEditProdInfo != null)
|
||||
{
|
||||
foreach (var wxEditPropParam in wxEditProdInfo.product.info.param)
|
||||
{
|
||||
var wxPropParam = new wxPropParam();
|
||||
upProdParam.product.info.param.Add(wxPropParam);
|
||||
foreach (var wxEditCategoryParam in wxEditPropParam.categorys)
|
||||
{
|
||||
var wxCategoryParam = new categoryPropParam()
|
||||
{
|
||||
catType = wxEditCategoryParam.catType,
|
||||
name = wxEditCategoryParam.name,
|
||||
catInfo = new catInfoParam()
|
||||
{
|
||||
inputType = wxEditCategoryParam.catInfo.inputType,
|
||||
isRequired = wxEditCategoryParam.catInfo.isRequired,
|
||||
isCustomize = wxEditCategoryParam.catInfo.isCustomize,
|
||||
}
|
||||
};
|
||||
wxPropParam.categorys.Add(wxCategoryParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 直接转换微信店采
|
||||
else if (dbProd.product_get_type_text == "微信店采")
|
||||
{
|
||||
foreach (var wxEditPropParam in wxEditProdInfo.product.info.param)
|
||||
{
|
||||
var wxPropParam = new wxPropParam();
|
||||
upProdParam.product.info.param.Add(wxPropParam);
|
||||
foreach (var wxEditCategoryParam in wxEditPropParam.categorys)
|
||||
{
|
||||
// 修改书名
|
||||
if (wxEditPropParam.categorys.FirstOrDefault().name == "书名" && wxEditCategoryParam == wxEditPropParam.categorys.LastOrDefault())
|
||||
{
|
||||
wxEditCategoryParam.name = prodTitle;
|
||||
}
|
||||
var wxCategoryParam = new categoryPropParam()
|
||||
{
|
||||
catType = wxEditCategoryParam.catType,
|
||||
name = wxEditCategoryParam.name,
|
||||
catInfo = new catInfoParam()
|
||||
{
|
||||
inputType = wxEditCategoryParam?.catInfo?.inputType,
|
||||
isRequired = wxEditCategoryParam?.catInfo?.isRequired,
|
||||
isCustomize = wxEditCategoryParam?.catInfo?.isCustomize,
|
||||
}
|
||||
};
|
||||
wxPropParam.categorys.Add(wxCategoryParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var propInfo in prodInfo.property.goods_properties)
|
||||
{
|
||||
if (propInfo.name == "容量")
|
||||
{
|
||||
|
||||
}
|
||||
if (propInfo.name == "格数")
|
||||
{
|
||||
|
||||
}
|
||||
if (propInfo.values.Count == 0)
|
||||
continue;
|
||||
|
||||
|
||||
var attr = productAttr.attr.FirstOrDefault(r => r.name == propInfo.name);
|
||||
if (attr == null)
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name.Replace("填充材料", "填充材质") == propInfo.name ||
|
||||
r.name.Replace("材质", "材质种类") == propInfo.name);
|
||||
// 材质 产品名称 适用年龄 面料 生产企业名称 CCC证书编号 尺寸(长) 尺寸(宽) 尺寸(高) 物品(含配件)清单 型号 产品名称
|
||||
if (propInfo.name == "生产日期" && propInfo.values.Count > 0)
|
||||
{
|
||||
propInfo.values.FirstOrDefault().value = DateTime.Now.Date.AddDays(-15).ToString("yyyy-MM-dd");
|
||||
propInfo.values.FirstOrDefault().raw_value = propInfo.values.FirstOrDefault().value;
|
||||
}
|
||||
if (attr == null)
|
||||
{
|
||||
if (propInfo.name.Contains("面料俗称"))
|
||||
{
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "面料材质");
|
||||
}
|
||||
if (propInfo.name.Contains("适用年龄"))
|
||||
{
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "适用年龄" || r.name == "适用年龄段");
|
||||
}
|
||||
if (propInfo.name.Contains("填充物"))
|
||||
{
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "填充物种类" || r.name == "填充物");
|
||||
}
|
||||
|
||||
// 书籍类目属性匹配
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "图书" || prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸")
|
||||
{
|
||||
if (propInfo.name == "出版社名称")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "出版社名称");
|
||||
else if ((propInfo.name == "ISBN编号" || propInfo.name == "书号") && !prodInfo.property.goods_properties.Any(p => p.name == "ISBN版号/CN刊号"))
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "ISBN版号/CN刊号");
|
||||
else if (propInfo.name == "书名")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "书名");
|
||||
else if (propInfo.name == "定价")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "定价");
|
||||
else if (propInfo.name == "作者")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "作者");
|
||||
else if (propInfo.name == "出版时间")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "出版时间");
|
||||
else if (propInfo.name == "版次")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "版次");
|
||||
else if (propInfo.name == "装帧类型")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "包装");
|
||||
else if (propInfo.name == "包册数")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "图书册数");
|
||||
}
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail.cats.FirstOrDefault() == "食品饮料")
|
||||
{
|
||||
if (propInfo.name == "厂名")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "生产企业名称");
|
||||
else if (propInfo.name == "食品生产许可证编号")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "食品生产许可证编号");
|
||||
else if (propInfo.name == "产品标准号")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "产品标准号");
|
||||
else if (propInfo.name == "保质期")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "保质期");
|
||||
else if (propInfo.name == "生产日期")
|
||||
{
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "生产日期");
|
||||
}
|
||||
else if (propInfo.name == "产品重量")
|
||||
{
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "单件净含量");
|
||||
if (attr == null)
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "净含量");
|
||||
}
|
||||
else if (propInfo.name == "包装方式")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "包装方式");
|
||||
//else if (propInfo.name == "配料表")
|
||||
// attr = productAttr.attr.FirstOrDefault(r => r.name == "配料表");
|
||||
//else if (propInfo.name == "联系方式")
|
||||
// attr = productAttr.attr.FirstOrDefault(r => r.name == "联系方式");
|
||||
else if (propInfo.name == "厂址")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "地址");
|
||||
else if (propInfo.name == "储藏方法")
|
||||
attr = productAttr.attr.FirstOrDefault(r => r.name == "贮存条件");
|
||||
}
|
||||
}
|
||||
if (attr == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var attrValueLst = attr.value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
var attrValue = attrValueLst.FirstOrDefault(v => v == propInfo.values.FirstOrDefault()?.value);
|
||||
if (attrValue.IsNullOrEmpty())
|
||||
attrValue = attrValueLst.FirstOrDefault(v => v.Replace("高硼硅玻璃", "耐热玻璃(高硼硅)") == propInfo.values.FirstOrDefault()?.value);
|
||||
if (propInfo.name == "保质期")
|
||||
{
|
||||
attrValue = "30 天";
|
||||
if (propInfo.values.Count > 0)
|
||||
{
|
||||
if (propInfo.values.FirstOrDefault().value.Contains("年") || propInfo.values.FirstOrDefault().value.Contains("月")
|
||||
|| propInfo.values.FirstOrDefault().value.Contains("日") || propInfo.values.FirstOrDefault().value.Contains("天")
|
||||
|| propInfo.values.FirstOrDefault().value.Contains("见包装"))
|
||||
{
|
||||
attrValue = propInfo.values.FirstOrDefault().value;
|
||||
}
|
||||
if (attrValue.Contains("天") && attrValue.Replace("天", "").ParseToInt() < 30)
|
||||
{
|
||||
throw new Exception("食品保质期小于30天,跳过上传");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (propInfo.name == "产品重量")
|
||||
{
|
||||
attrValue = "10g";
|
||||
if (propInfo.values.FirstOrDefault().value.Contains("g") || propInfo.values.FirstOrDefault().value.Contains("kg"))
|
||||
attrValue = propInfo.values.FirstOrDefault().value;
|
||||
}
|
||||
if (propInfo.name == "风格" && attrValue == null)
|
||||
{
|
||||
attrValue = attrValueLst.FirstOrDefault(v => v == propInfo.values.FirstOrDefault().value + "风");
|
||||
}
|
||||
if (attr.type == "string")
|
||||
{
|
||||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||||
}
|
||||
//书籍属性处理
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "图书" || prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸")
|
||||
{
|
||||
// 修改书名 作者
|
||||
if (attr.name == "书名" /*&& dbProd.product_get_type_text == "微信小店"*/)
|
||||
{
|
||||
attrValue = prodTitle;
|
||||
}
|
||||
if (attr.name == "作者" && attrValue == "无")
|
||||
{
|
||||
attrValue = new List<string>() { "赵老师", "钱老师", "孙老师", "李老师", "周老师", "吴老师", "郑老师", "王老师", "张老师", "孙老师", "刘老师" }.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
||||
attrValue = "无";
|
||||
}
|
||||
|
||||
if (attrValue.IsNullOrEmpty() && attr.type == "integer_unit" && (propInfo.values.FirstOrDefault()?.value).IsNumber())
|
||||
{
|
||||
attrValue = propInfo.values.FirstOrDefault()?.value + " " + attr.value.Split(';').FirstOrDefault();
|
||||
}
|
||||
if (attrValue.IsNullOrEmpty() && attr.name == "包装")
|
||||
{
|
||||
if (propInfo.values.FirstOrDefault()?.value == "平装-胶订")
|
||||
attrValue = "平装";
|
||||
}
|
||||
}
|
||||
// 强制改为国产
|
||||
{
|
||||
if (attrValueLst.Contains("国产"))
|
||||
attrValue = "国产";
|
||||
else if (attr.name == "是否进口")
|
||||
{
|
||||
attrValue = "非进口";
|
||||
if (attr.value == "是;否")
|
||||
attrValue = "否";
|
||||
}
|
||||
else if (attr.name == "商品产地")
|
||||
{
|
||||
attrValue = "中国大陆";
|
||||
}
|
||||
else if (attr.name == "产地")
|
||||
{
|
||||
if (attr.type == "select_one")
|
||||
{
|
||||
//北京;天津;上海;重庆;河北石家庄;河北唐山;河北秦皇岛;河北邯郸;河北邢台;河北保定;河北张家口;河北承德;河北沧州;河北廊坊;河北衡水;山西太原;山西大同;山西阳泉;山西长治;山西晋城;山西朔州;山西晋中;山西运城;山西忻州;山西临汾;山西吕梁;内蒙古呼和浩特;内蒙古包头;内蒙古乌海;内蒙古赤峰;内蒙古通辽;内蒙古鄂尔多斯;内蒙古呼伦贝尔;内蒙古巴彦淖尔;内蒙古乌兰察布;内蒙古兴安;内蒙古锡林郭勒;内蒙古阿拉善;辽宁沈阳;辽宁大连;辽宁鞍山;辽宁抚顺;辽宁本溪;辽宁丹东;辽宁锦州;辽宁营口;辽宁阜新;辽宁辽阳;辽宁盘锦;辽宁铁岭;辽宁朝阳;辽宁葫芦岛;吉林长春;吉林吉林;吉林四平;吉林辽源;吉林通化;吉林白山;吉林松原;吉林白城;吉林延边;黑龙江哈尔滨;黑龙江齐齐哈尔;黑龙江鸡西;黑龙江鹤岗;黑龙江双鸭山;黑龙江大庆;黑龙江伊春;黑龙江佳木斯;黑龙江七台河;黑龙江牡丹江;黑龙江黑河;黑龙江绥化;黑龙江大兴安岭;江苏南京;江苏无锡;江苏徐州;江苏常州;江苏苏州;江苏南通;江苏连云港;江苏淮安;江苏盐城;江苏扬州;江苏镇江;江苏泰州;江苏宿迁;浙江杭州;浙江宁波;浙江温州;浙江嘉兴;浙江湖州;浙江绍兴;浙江金华;浙江衢州;浙江舟山;浙江台州;浙江丽水;安徽合肥;安徽芜湖;安徽蚌埠;安徽淮南;安徽马鞍山;安徽淮北;安徽铜陵;安徽安庆;安徽黄山;安徽滁州;安徽阜阳;安徽宿州;安徽六安;安徽亳州;安徽池州;安徽宣城;福建福州;福建厦门;福建莆田;福建三明;福建泉州;福建漳州;福建南平;福建龙岩;福建宁德;江西南昌;江西景德镇;江西萍乡;江西九江;江西新余;江西鹰潭;江西赣州;江西吉安;江西宜春;江西抚州;江西上饶;山东济南;山东青岛;山东淄博;山东枣庄;山东东营;山东烟台;山东潍坊;山东济宁;山东泰安;山东威海;山东日照;山东临沂;山东德州;山东聊城;山东滨州;山东菏泽;河南郑州;河南开封;河南洛阳;河南平顶山;河南安阳;河南鹤壁;河南新乡;河南焦作;河南濮阳;河南许昌;河南漯河;河南三门峡;河南南阳;河南商丘;河南信阳;河南周口;河南驻马店;河南济源;湖北武汉;湖北黄石;湖北十堰;湖北宜昌;湖北襄阳;湖北鄂州;湖北荆门;湖北孝感;湖北荆州;湖北黄冈;湖北咸宁;湖北随州;湖北恩施;湖北仙桃;湖北潜江;湖北天门;湖北神农架;湖南长沙;湖南株洲;湖南湘潭;湖南衡阳;湖南邵阳;湖南岳阳;湖南常德;湖南张家界;湖南益阳;湖南郴州;湖南永州;湖南怀化;湖南娄底;湖南湘西;广东广州;广东韶关;广东深圳;广东珠海;广东汕头;广东佛山;广东江门;广东湛江;广东茂名;广东肇庆;广东惠州;广东梅州;广东汕尾;广东河源;广东阳江;广东清远;广东东莞;广东中山;广东潮州;广东揭阳;广东云浮;广西南宁;广西柳州;广西桂林;广西梧州;广西北海;广西防城港;广西钦州;广西贵港;广西玉林;广西百色;广西贺州;广西河池;广西来宾;广西崇左;海南海口;海南三亚;海南三沙;海南儋州;海南五指山;海南琼海;海南文昌;海南万宁;海南东方;海南定安;海南屯昌;海南澄迈;海南临高;海南白沙;海南昌江;海南乐东;海南陵水;海南保亭;海南琼中;四川成都;四川自贡;四川攀枝花;四川泸州;四川德阳;四川绵阳;四川广元;四川遂宁;四川内江;四川乐山;四川南充;四川眉山;四川宜宾;四川广安;四川达州;四川雅安;四川巴中;四川资阳;四川阿坝;四川甘孜;四川凉山;贵州贵阳;贵州六盘水;贵州遵义;贵州安顺;贵州毕节;贵州铜仁;贵州黔西南;贵州黔东南;贵州黔南;云南昆明;云南曲靖;云南玉溪;云南保山;云南昭通;云南丽江;云南普洱;云南临沧;云南楚雄;云南红河;云南文山;云南西双版纳;云南大理;云南德宏;云南怒江;云南迪庆;西藏拉萨;西藏日喀则;西藏昌都;西藏林芝;西藏山南;西藏那曲;西藏阿里;陕西西安;陕西铜川;陕西宝鸡;陕西咸阳;陕西渭南;陕西延安;陕西汉中;陕西榆林;陕西安康;陕西商洛;甘肃兰州;甘肃嘉峪关;甘肃金昌;甘肃白银;甘肃天水;甘肃武威;甘肃张掖;甘肃平凉;甘肃酒泉;甘肃庆阳;甘肃定西;甘肃陇南;甘肃临夏;甘肃甘南;青海西宁;青海海东;青海海北;青海黄南;青海海南;青海果洛;青海玉树;青海海西;宁夏银川;宁夏石嘴山;宁夏吴忠;宁夏固原;宁夏中卫;新疆乌鲁木齐;新疆克拉玛依;新疆吐鲁番;新疆哈密;新疆昌吉;新疆博尔塔拉;新疆巴音郭楞;新疆阿克苏;新疆克孜勒苏;新疆喀什;新疆和田;新疆伊犁;新疆塔城;新疆阿勒泰;新疆石河子;新疆阿拉尔;新疆图木舒克;新疆五家渠;新疆北屯;新疆铁门关;新疆双河;新疆可克Line truncated
|
||||
//北京;天津;上海;重庆;河北;山西;内蒙古;辽宁;吉林;黑龙江;江苏;浙江;安徽;福建;江西;山东;河南;湖北;湖南;广东;广西;海南;四川;贵州;云南;西藏;陕西;甘肃;青海;宁夏;新疆
|
||||
var values = attr.value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).OrderBy(x => Guid.NewGuid()).ToList();
|
||||
if (values.Contains("中国大陆"))
|
||||
attrValue = "中国大陆";
|
||||
else
|
||||
{
|
||||
var value = values.FirstOrDefault(v => prodTitle.ParseToString().Contains(v));
|
||||
if (value == null)
|
||||
value = values.FirstOrDefault(v => prodTitle.ParseToString().Contains(string.Join("", v.Take(2))));
|
||||
if (value == null)
|
||||
value = values.FirstOrDefault(v => "北京;天津;上海;重庆;河北;山西;内蒙古;辽宁;吉林;黑龙江;江苏;浙江;安徽;福建;江西;山东;河南;湖北;湖南;广东;广西;海南;四川;贵州;云南;西藏;陕西;甘肃;青海;宁夏;新疆".Contains(string.Join("", v.Take(2))));
|
||||
attrValue = value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
attrValue = "中国大陆";
|
||||
}
|
||||
}
|
||||
}
|
||||
// 强制非收藏品
|
||||
{
|
||||
if (attrValueLst.Contains("是否具有拍卖/收藏价值"))
|
||||
{
|
||||
attrValue = "不具有";
|
||||
}
|
||||
if (attrValueLst.Contains("是否批量生产(孤品)"))
|
||||
{
|
||||
attrValue = "批量生产";
|
||||
}
|
||||
}
|
||||
if (attrValue.IsNullOrEmpty() && attr.isRequired == true)
|
||||
{
|
||||
if (attrValueLst.Contains("其他"))
|
||||
attrValue = "其他";
|
||||
else if (attrValueLst.Contains("常规"))
|
||||
attrValue = "常规";
|
||||
else if (attrValueLst.Contains("通用"))
|
||||
attrValue = "通用";
|
||||
else if (attr.value.Contains("绒丝;羽毛;白鸭绒;白鹅绒;灰鸭绒;灰鹅绒;鸭毛片;鹅毛片"))
|
||||
{
|
||||
attrValue = "绒丝";
|
||||
}
|
||||
//else if (attrValueLst.Any(v => v.Contains("%")))
|
||||
//{
|
||||
// attrValue = attrValueLst.FirstOrDefault();
|
||||
//}
|
||||
else
|
||||
attrValue = attrValueLst.Where(v => !"真丝、蚕丝、香云纱、羊绒、羊毛、羊羔绒、羊羔毛、羽绒、皮草".Contains(v)).OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
||||
}
|
||||
if (attrValue.IsNullOrEmpty())
|
||||
{
|
||||
if (attrValueLst.Contains("其他"))
|
||||
attrValue = "其他";
|
||||
else if (attrValueLst.Contains("通用"))
|
||||
attrValue = "通用";
|
||||
}
|
||||
if (attrValue.IsNullOrEmpty() && attr.type == "string")
|
||||
{
|
||||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||||
}
|
||||
if (attr.type == "decimal4_unit" || attr.type == "integer_unit")
|
||||
{
|
||||
if (attr.value == "%")
|
||||
attrValue = "1 %";
|
||||
else if (attr.value == "g;kg")
|
||||
attrValue = "50 g";
|
||||
else if (attr.value == "g")
|
||||
attrValue = "10 g";
|
||||
else if (attr.value == "kg")
|
||||
attrValue = "1 kg";
|
||||
//else if (attr.value == "g;kg;ml;L")
|
||||
// attrValue = "100 g";
|
||||
else if (attr.value == "cm")
|
||||
{
|
||||
var propValue = propInfo.values.FirstOrDefault()?.value;
|
||||
var match = BaseRegex.GetMatchRegexString(ref propValue, @"([\d]{1,4})cm");
|
||||
if (!string.IsNullOrEmpty(match))
|
||||
{
|
||||
attrValue = match + " cm";
|
||||
}
|
||||
}
|
||||
else if (attr.value == "mm")
|
||||
{
|
||||
var propValue = propInfo.values.FirstOrDefault()?.value;
|
||||
var match = BaseRegex.GetMatchRegexString(ref propValue, @"([\d]{1,4})mm");
|
||||
if (!string.IsNullOrEmpty(match))
|
||||
{
|
||||
attrValue = match + " mm";
|
||||
}
|
||||
}
|
||||
else if (attr.value.Contains("岁以上") && attr.value.Contains("个月以上"))
|
||||
{
|
||||
attrValue = "7 岁以上";
|
||||
if (propInfo.values.FirstOrDefault().value.Contains("岁以上") || propInfo.values.FirstOrDefault().value.Contains("个月以上"))
|
||||
attrValue = propInfo.values.FirstOrDefault().value;
|
||||
if (propInfo.values.FirstOrDefault().value.Contains("岁"))
|
||||
{
|
||||
var propValue = propInfo.values.FirstOrDefault().value;
|
||||
var match = BaseRegex.GetMatchRegexString(ref propValue, @"([\d]{1,3})");
|
||||
if (!string.IsNullOrEmpty(match))
|
||||
{
|
||||
attrValue = match + " 岁以上";
|
||||
}
|
||||
}
|
||||
else if (propInfo.values.FirstOrDefault().value.Contains("月"))
|
||||
{
|
||||
var propValue = propInfo.values.FirstOrDefault().value;
|
||||
var match = BaseRegex.GetMatchRegexString(ref propValue, @"([\d]{1,3})");
|
||||
if (!string.IsNullOrEmpty(match))
|
||||
{
|
||||
attrValue = match + " 个月以上";
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (attr.value == "个")
|
||||
{
|
||||
if ((propInfo.values.FirstOrDefault()?.value).ParseToString().EndsWith("个"))
|
||||
{
|
||||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||||
if (attrValue.TrimEnd('个').ParseToInt() == 0)
|
||||
attrValue = BaseRegex.GetMatchMaxRegexString(ref attrValue, "(\\d{1,6})") + (attrValue.Contains("只") ? " 只" : " 个");
|
||||
if (attrValue.TrimEnd('个').ParseToInt() == 0)
|
||||
attrValue = "1 个";
|
||||
}
|
||||
else
|
||||
attrValue = "1 个";
|
||||
}
|
||||
else if (attr.value == "只;个")
|
||||
{
|
||||
if ((propInfo.values.FirstOrDefault()?.value).ParseToString().EndsWith("只") || (propInfo.values.FirstOrDefault()?.value).ParseToString().EndsWith("个"))
|
||||
{
|
||||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||||
if (attrValue.TrimEnd('只', '个').ParseToInt() == 0)
|
||||
attrValue = BaseRegex.GetMatchMaxRegexString(ref attrValue, "(\\d{1,6})") + (attrValue.Contains("只") ? " 只" : " 个");
|
||||
if (attrValue.TrimEnd('只', '个').ParseToInt() == 0)
|
||||
attrValue = "1 个";
|
||||
}
|
||||
else
|
||||
attrValue = "1 个";
|
||||
}
|
||||
else if (attr.value == "ml")
|
||||
{
|
||||
if ((propInfo.values.FirstOrDefault()?.value).ParseToString().EndsWith(attr.value))
|
||||
attrValue = propInfo.values.FirstOrDefault()?.value.TrimStart('-', ' ');
|
||||
else
|
||||
attrValue = "100 ml";
|
||||
}
|
||||
else if (attr.value == "L")
|
||||
{
|
||||
if ((propInfo.values.FirstOrDefault()?.value).ParseToString().EndsWith(attr.value))
|
||||
{
|
||||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||||
if (attrValue.TrimEnd('L').ParseToInt() == 0)
|
||||
attrValue = BaseRegex.GetMatchMaxRegexString(ref attrValue, "(\\d{1,6})") + " L";
|
||||
if (attrValue.TrimEnd('L').ParseToInt() == 0)
|
||||
attrValue = "1 L";
|
||||
}
|
||||
else
|
||||
attrValue = "1 L";
|
||||
}
|
||||
else if (attr.value == "g;kg;ml;L")
|
||||
{
|
||||
var propInfoValue = (propInfo.values.FirstOrDefault()?.value).ParseToString();
|
||||
if (propInfoValue.EndsWith("g") || propInfoValue.EndsWith("kg") || propInfoValue.EndsWith("ml") || propInfoValue.EndsWith("L"))
|
||||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||||
else
|
||||
attrValue = "100 g";
|
||||
}
|
||||
else if (attr.value == "日;月;年")
|
||||
{
|
||||
var propInfoValue = (propInfo.values.FirstOrDefault()?.value).ParseToString();
|
||||
if (propInfoValue.EndsWith("日") || propInfoValue.EndsWith("月") || propInfoValue.EndsWith("年"))
|
||||
attrValue = propInfo.values.FirstOrDefault()?.value + propInfoValue.LastOrDefault();
|
||||
else
|
||||
attrValue = "30 日";
|
||||
}
|
||||
else if (attr.value.ParseToString().Length > 0 && !attr.value.ParseToString().Contains(";"))
|
||||
{
|
||||
if ((propInfo.values.FirstOrDefault()?.value).ParseToString().EndsWith(attr.value))
|
||||
{
|
||||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||||
if (attrValue.Substring(0, attrValue.Length - attr.value.Length - 1).ParseToInt() == 0)
|
||||
attrValue = BaseRegex.GetMatchMaxRegexString(ref attrValue, "(\\d{1,6})") + " " + attr.value;
|
||||
if (attrValue.Substring(0, attrValue.Length - attr.value.Length - 1).ParseToInt() == 0)
|
||||
attrValue = "1 " + attr.value;
|
||||
}
|
||||
else
|
||||
attrValue = "1 " + attr.value;
|
||||
}
|
||||
else
|
||||
{
|
||||
var param = recommendParamRst.productInfo.param.FirstOrDefault(p => p.categorys?.FirstOrDefault()?.name == attr.name);
|
||||
if (param != null && param.categorys.Count == 2)
|
||||
{
|
||||
attrValue = param.categorys[1].name;
|
||||
if (attrValue.Contains("磅") && attrValue.Replace("磅", "").ParseToDecimal() > 0)
|
||||
{
|
||||
if ((";" + attr.value + ";").Contains(";g;"))
|
||||
attrValue = (attrValue.Replace("磅", "").ParseToDecimal() * 454).ParseToInt() + "g";
|
||||
else if ((";" + attr.value + ";").Contains(";kg;"))
|
||||
attrValue = (attrValue.Replace("磅", "").ParseToDecimal() * 0.454m).ParseToDecimal() + "kg";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
attrValue = propInfo.values.FirstOrDefault()?.value.ParseToString();
|
||||
var units = attr.value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var unit in units)
|
||||
{
|
||||
var val = attrValue.Replace(unit, "").Trim();
|
||||
if (attr.type == "decimal4_unit" && val.ParseToDecimal() != 0m)
|
||||
{
|
||||
attrValue = val + " " + unit;
|
||||
break;
|
||||
}
|
||||
if (attr.type == "integer_unit" && val.ParseToInt() != 0)
|
||||
{
|
||||
attrValue = val + " " + unit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(attrValue))
|
||||
continue;
|
||||
|
||||
var wxPropParam = new wxPropParam();
|
||||
upProdParam.product.info.param.Add(wxPropParam);
|
||||
var wxCategoryParam1 = new categoryPropParam()
|
||||
{
|
||||
catType = 7,
|
||||
name = attr.name,
|
||||
catInfo = new catInfoParam() { inputType = attr.normalRelease.ruleType, isRequired = attr.isRequired == true ? 1 : 0, isCustomize = 0 }
|
||||
};
|
||||
var wxCategoryParam2 = new categoryPropParam()
|
||||
{
|
||||
catType = 7,
|
||||
name = attrValue,
|
||||
catInfo = new catInfoParam() { inputType = attr.normalRelease.ruleType, isRequired = attr.isRequired == true ? 1 : 0, isCustomize = 0 }
|
||||
};
|
||||
wxPropParam.categorys.Add(wxCategoryParam1);
|
||||
wxPropParam.categorys.Add(wxCategoryParam2);
|
||||
}
|
||||
}
|
||||
foreach (var wxPropParam in upProdParam.product.info.param)
|
||||
{
|
||||
if (wxPropParam.categorys.Count > 0 &&
|
||||
wxPropParam.categorys.FirstOrDefault().name == "作者" && (wxPropParam.categorys.LastOrDefault().name == "无" ||
|
||||
wxPropParam.categorys.LastOrDefault().name == "-" || wxPropParam.categorys.LastOrDefault().name == "/"))
|
||||
{
|
||||
wxPropParam.categorys.LastOrDefault().name = upProdParam.product.info.param.FirstOrDefault(p => p.categorys.FirstOrDefault()?.name == "出版社名称").categorys.LastOrDefault()?.name;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var attr in productAttr.attr)
|
||||
{
|
||||
if (attr.isRequired != true)
|
||||
continue;
|
||||
// 已填写内没有但是必填属性
|
||||
if (upProdParam.product.info.param.Any(p => p.categorys.FirstOrDefault()?.name == attr.name))
|
||||
continue;
|
||||
|
||||
var attrValueLst = attr.value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
string attrValue = "";
|
||||
if (attrValue.IsNullOrEmpty() && attr.isRequired == true)
|
||||
{
|
||||
if (attrValueLst.Contains("其他"))
|
||||
attrValue = "其他";
|
||||
else if (attrValueLst.Contains("常规"))
|
||||
attrValue = "常规";
|
||||
else if (attrValueLst.Contains("通用"))
|
||||
attrValue = "通用";
|
||||
else if (attrValueLst.Contains("国产"))
|
||||
attrValue = "国产";
|
||||
else if (attr.value.Contains("绒丝;羽毛;白鸭绒;白鹅绒;灰鸭绒;灰鹅绒;鸭毛片;鹅毛片"))
|
||||
{
|
||||
attrValue = "绒丝";
|
||||
}
|
||||
else if (attr.name == "是否进口")
|
||||
{
|
||||
attrValue = "非进口";
|
||||
if (attr.value == "是;否")
|
||||
attrValue = "否";
|
||||
}
|
||||
else if (attr.name == "商品产地")
|
||||
{
|
||||
attrValue = "中国大陆";
|
||||
}
|
||||
else if (attr.name == "产地")
|
||||
{
|
||||
if (attr.type == "select_one")
|
||||
{
|
||||
//北京;天津;上海;重庆;河北石家庄;河北唐山;河北秦皇岛;河北邯郸;河北邢台;河北保定;河北张家口;河北承德;河北沧州;河北廊坊;河北衡水;山西太原;山西大同;山西阳泉;山西长治;山西晋城;山西朔州;山西晋中;山西运城;山西忻州;山西临汾;山西吕梁;内蒙古呼和浩特;内蒙古包头;内蒙古乌海;内蒙古赤峰;内蒙古通辽;内蒙古鄂尔多斯;内蒙古呼伦贝尔;内蒙古巴彦淖尔;内蒙古乌兰察布;内蒙古兴安;内蒙古锡林郭勒;内蒙古阿拉善;辽宁沈阳;辽宁大连;辽宁鞍山;辽宁抚顺;辽宁本溪;辽宁丹东;辽宁锦州;辽宁营口;辽宁阜新;辽宁辽阳;辽宁盘锦;辽宁铁岭;辽宁朝阳;辽宁葫芦岛;吉林长春;吉林吉林;吉林四平;吉林辽源;吉林通化;吉林白山;吉林松原;吉林白城;吉林延边;黑龙江哈尔滨;黑龙江齐齐哈尔;黑龙江鸡西;黑龙江鹤岗;黑龙江双鸭山;黑龙江大庆;黑龙江伊春;黑龙江佳木斯;黑龙江七台河;黑龙江牡丹江;黑龙江黑河;黑龙江绥化;黑龙江大兴安岭;江苏南京;江苏无锡;江苏徐州;江苏常州;江苏苏州;江苏南通;江苏连云港;江苏淮安;江苏盐城;江苏扬州;江苏镇江;江苏泰州;江苏宿迁;浙江杭州;浙江宁波;浙江温州;浙江嘉兴;浙江湖州;浙江绍兴;浙江金华;浙江衢州;浙江舟山;浙江台州;浙江丽水;安徽合肥;安徽芜湖;安徽蚌埠;安徽淮南;安徽马鞍山;安徽淮北;安徽铜陵;安徽安庆;安徽黄山;安徽滁州;安徽阜阳;安徽宿州;安徽六安;安徽亳州;安徽池州;安徽宣城;福建福州;福建厦门;福建莆田;福建三明;福建泉州;福建漳州;福建南平;福建龙岩;福建宁德;江西南昌;江西景德镇;江西萍乡;江西九江;江西新余;江西鹰潭;江西赣州;江西吉安;江西宜春;江西抚州;江西上饶;山东济南;山东青岛;山东淄博;山东枣庄;山东东营;山东烟台;山东潍坊;山东济宁;山东泰安;山东威海;山东日照;山东临沂;山东德州;山东聊城;山东滨州;山东菏泽;河南郑州;河南开封;河南洛阳;河南平顶山;河南安阳;河南鹤壁;河南新乡;河南焦作;河南濮阳;河南许昌;河南漯河;河南三门峡;河南南阳;河南商丘;河南信阳;河南周口;河南驻马店;河南济源;湖北武汉;湖北黄石;湖北十堰;湖北宜昌;湖北襄阳;湖北鄂州;湖北荆门;湖北孝感;湖北荆州;湖北黄冈;湖北咸宁;湖北随州;湖北恩施;湖北仙桃;湖北潜江;湖北天门;湖北神农架;湖南长沙;湖南株洲;湖南湘潭;湖南衡阳;湖南邵阳;湖南岳阳;湖南常德;湖南张家界;湖南益阳;湖南郴州;湖南永州;湖南怀化;湖南娄底;湖南湘西;广东广州;广东韶关;广东深圳;广东珠海;广东汕头;广东佛山;广东江门;广东湛江;广东茂名;广东肇庆;广东惠州;广东梅州;广东汕尾;广东河源;广东阳江;广东清远;广东东莞;广东中山;广东潮州;广东揭阳;广东云浮;广西南宁;广西柳州;广西桂林;广西梧州;广西北海;广西防城港;广西钦州;广西贵港;广西玉林;广西百色;广西贺州;广西河池;广西来宾;广西崇左;海南海口;海南三亚;海南三沙;海南儋州;海南五指山;海南琼海;海南文昌;海南万宁;海南东方;海南定安;海南屯昌;海南澄迈;海南临高;海南白沙;海南昌江;海南乐东;海南陵水;海南保亭;海南琼中;四川成都;四川自贡;四川攀枝花;四川泸州;四川德阳;四川绵阳;四川广元;四川遂宁;四川内江;四川乐山;四川南充;四川眉山;四川宜宾;四川广安;四川达州;四川雅安;四川巴中;四川资阳;四川阿坝;四川甘孜;四川凉山;贵州贵阳;贵州六盘水;贵州遵义;贵州安顺;贵州毕节;贵州铜仁;贵州黔西南;贵州黔东南;贵州黔南;云南昆明;云南曲靖;云南玉溪;云南保山;云南昭通;云南丽江;云南普洱;云南临沧;云南楚雄;云南红河;云南文山;云南西双版纳;云南大理;云南德宏;云南怒江;云南迪庆;西藏拉萨;西藏日喀则;西藏昌都;西藏林芝;西藏山南;西藏那曲;西藏阿里;陕西西安;陕西铜川;陕西宝鸡;陕西咸阳;陕西渭南;陕西延安;陕西汉中;陕西榆林;陕西安康;陕西商洛;甘肃兰州;甘肃嘉峪关;甘肃金昌;甘肃白银;甘肃天水;甘肃武威;甘肃张掖;甘肃平凉;甘肃酒泉;甘肃庆阳;甘肃定西;甘肃陇南;甘肃临夏;甘肃甘南;青海西宁;青海海东;青海海北;青海黄南;青海海南;青海果洛;青海玉树;青海海西;宁夏银川;宁夏石嘴山;宁夏吴忠;宁夏固原;宁夏中卫;新疆乌鲁木齐;新疆克拉玛依;新疆吐鲁番;新疆哈密;新疆昌吉;新疆博尔塔拉;新疆巴音郭楞;新疆阿克苏;新疆克孜勒苏;新疆喀什;新疆和田;新疆伊犁;新疆塔城;新疆阿勒泰;新疆石河子;新疆阿拉尔;新疆图木舒克;新疆五家渠;新疆北屯;新疆铁门关;新疆双河;新疆可克达Line truncated
|
||||
//北京;天津;上海;重庆;河北;山西;内蒙古;辽宁;吉林;黑龙江;江苏;浙江;安徽;福建;江西;山东;河南;湖北;湖南;广东;广西;海南;四川;贵州;云南;西藏;陕西;甘肃;青海;宁夏;新疆
|
||||
var values = attr.value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).OrderBy(x => Guid.NewGuid()).ToList();
|
||||
if (values.Contains("中国大陆"))
|
||||
attrValue = "中国大陆";
|
||||
else
|
||||
{
|
||||
var value = values.FirstOrDefault(v => prodTitle.ParseToString().Contains(v));
|
||||
if (value == null)
|
||||
value = values.FirstOrDefault(v => prodTitle.ParseToString().Contains(string.Join("", v.Take(2))));
|
||||
if (value == null)
|
||||
value = values.FirstOrDefault(v => "北京;天津;上海;重庆;河北;山西;内蒙古;辽宁;吉林;黑龙江;江苏;浙江;安徽;福建;江西;山东;河南;湖北;湖南;广东;广西;海南;四川;贵州;云南;西藏;陕西;甘肃;青海;宁夏;新疆".Contains(string.Join("", v.Take(2))));
|
||||
attrValue = value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
attrValue = "中国大陆";
|
||||
}
|
||||
}
|
||||
else if (attr.name == "是否具有拍卖/收藏价值")
|
||||
{
|
||||
attrValue = "不具有";
|
||||
}
|
||||
else if (attr.name == "是否批量生产(孤品)")
|
||||
{
|
||||
attrValue = "批量生产";
|
||||
}
|
||||
//else if (attrValueLst.Any(v => v.Contains("%")))
|
||||
//{
|
||||
// attrValue = attrValueLst.FirstOrDefault();
|
||||
//}
|
||||
else if (!(attr.type == "decimal4_unit" || attr.type == "integer_unit"))
|
||||
attrValue = attrValueLst.Where(v => !"真丝、蚕丝、香云纱、羊绒、羊毛、羊羔绒、羊羔毛、羽绒、皮草".Contains(v)).OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
||||
|
||||
//书籍属性处理
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "图书" || prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸")
|
||||
{
|
||||
//if (attr.name == "ISBN版号/CN刊号")
|
||||
// attrValue = "9787922575016";
|
||||
if (attr.name == "书名")
|
||||
attrValue = prodTitle;
|
||||
if (attr.name == "是否为单一书号丛书")
|
||||
attrValue = "是";
|
||||
if (attr.name == "图书册数")
|
||||
attrValue = "1 册";
|
||||
if (attr.name == "出版社名称")
|
||||
attrValue = new List<string>() { "技术出版社", "文化出版社", "美术出版社" }[Randomx.GetId(3)];
|
||||
if (attr.name == "作者")
|
||||
{
|
||||
attrValue = new List<string>() { "赵老师", "钱老师", "孙老师", "李老师", "周老师", "吴老师", "郑老师", "王老师", "张老师", "孙老师", "刘老师" }.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
||||
attrValue = "无";
|
||||
}
|
||||
if (attr.name == "包装")
|
||||
attrValue = "平装";
|
||||
if (attr.name == "出版时间")
|
||||
attrValue = DateTime.Now.AddMonths(0 - Randomx.GetId(3, 7)).ToString("yyyy-MM");
|
||||
}
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail.cats.FirstOrDefault() == "食品饮料")
|
||||
{
|
||||
if (attr.name == "食品名称")
|
||||
attrValue = prodTitle;
|
||||
if (attr.name == "生产企业名称")
|
||||
attrValue = "见包装";
|
||||
if (attr.name == "食品生产许可证编号")
|
||||
{
|
||||
attrValue = "SC10241162100670";
|
||||
attrValue = "见包装";
|
||||
}
|
||||
if (attr.name == "产品标准号")
|
||||
{
|
||||
attrValue = "GB 2726";
|
||||
attrValue = "见包装";
|
||||
}
|
||||
if (attr.name == "生产日期")
|
||||
attrValue = DateTime.Now.Date.AddDays(-15).ToString("yyyy-MM-dd");
|
||||
if (attr.name == "净含量")
|
||||
attrValue = "见包装";
|
||||
if (attr.name == "单件净含量")
|
||||
{
|
||||
attrValue = "见包装";
|
||||
}
|
||||
if (attr.name == "包装方式")
|
||||
attrValue = "袋装";
|
||||
if (attr.name == "配料表")
|
||||
attrValue = "水";
|
||||
if (attr.name == "联系方式")
|
||||
attrValue = "无";
|
||||
if (attr.name == "地址")
|
||||
attrValue = "见包装";
|
||||
if (attr.name == "贮存条件")
|
||||
attrValue = "常温";
|
||||
|
||||
//if (attr.name == "保质期")
|
||||
//{
|
||||
// if (chkDefaultBestBefore.Checked == false)
|
||||
//throw new Exception("食品属性不含保质期,跳过上传");
|
||||
// if (txtDefaultBestBefore.Text.ParseToInt() < 15)
|
||||
//throw new Exception("食品默认保质期设置小于15天,跳过上传");
|
||||
// attrValue = txtDefaultBestBefore.Text.ParseToInt() + " 天";
|
||||
//}
|
||||
}
|
||||
|
||||
if (attr.name == "保质期")
|
||||
{
|
||||
if (chkDefaultBestBefore.Checked == false)
|
||||
throw new Exception("属性不含保质期,跳过上传");
|
||||
if (txtDefaultBestBefore.Text.ParseToInt() < 3)
|
||||
throw new Exception("默认保质期设置小于3天,跳过上传");
|
||||
attrValue = txtDefaultBestBefore.Text.ParseToInt() + " 天";
|
||||
}
|
||||
}
|
||||
if (attrValue.IsNullOrEmpty() && attr.type == "string")
|
||||
{
|
||||
attrValue = "其他";
|
||||
}
|
||||
if ((attrValue.IsNullOrEmpty() || attrValue == "见包装" || attrValue == "%") && (attr.type == "decimal4_unit" || attr.type == "integer_unit"))
|
||||
{
|
||||
// 走系统推荐
|
||||
var param = recommendParamRst.productInfo.param.FirstOrDefault(p => p.categorys?.FirstOrDefault()?.name == attr.name);
|
||||
if (param != null && param.categorys.Count == 2)
|
||||
{
|
||||
attrValue = param.categorys[1].name;
|
||||
if (attrValue.Contains("磅") && attrValue.Replace("磅", "").ParseToDecimal() > 0)
|
||||
{
|
||||
if ((";" + attr.value + ";").Contains(";g;"))
|
||||
attrValue = (attrValue.Replace("磅", "").ParseToDecimal() * 454).ParseToInt() + "g";
|
||||
else if ((";" + attr.value + ";").Contains(";kg;"))
|
||||
attrValue = (attrValue.Replace("磅", "").ParseToDecimal() * 0.454m).ParseToDecimal() + "kg";
|
||||
}
|
||||
}
|
||||
else if (attr.value == "%")
|
||||
attrValue = "1 %";
|
||||
else if (attr.value == "g;kg")
|
||||
attrValue = "50 g";
|
||||
else if (attr.value == "g")
|
||||
attrValue = "10 g";
|
||||
else if (attr.value == "kg")
|
||||
attrValue = "1 kg";
|
||||
else if (attr.value == "g;kg;ml;L")
|
||||
attrValue = "100 g";
|
||||
else if (attr.value == "cm")
|
||||
attrValue = "20 cm";
|
||||
else if (attr.value == "mm")
|
||||
attrValue = "20 mm";
|
||||
else if (attr.value == "毫米(mm);厘米(cm);米(m)")
|
||||
attrValue = "20 毫米(mm)";
|
||||
else if (attr.value.Contains("岁以上") && attr.value.Contains("个月以上"))
|
||||
attrValue = "7 岁以上";
|
||||
else if (attr.value == "只;个")
|
||||
attrValue = "1 个";
|
||||
else if (attr.value == "个")
|
||||
attrValue = "1 个";
|
||||
else if (attr.value == "ml")
|
||||
attrValue = "100 ml";
|
||||
else if (attr.value == "L")
|
||||
attrValue = "1 L";
|
||||
else if (attr.value == "日;月;年")
|
||||
attrValue = "30 日";
|
||||
}
|
||||
|
||||
var wxPropParam = new wxPropParam();
|
||||
upProdParam.product.info.param.Add(wxPropParam);
|
||||
var wxCategoryParam1 = new categoryPropParam()
|
||||
{
|
||||
catType = 7,
|
||||
name = attr.name,
|
||||
catInfo = new catInfoParam() { inputType = attr.normalRelease.ruleType, isRequired = attr.isRequired == true ? 1 : 0, isCustomize = 0 }
|
||||
};
|
||||
var wxCategoryParam2 = new categoryPropParam()
|
||||
{
|
||||
catType = 7,
|
||||
name = attrValue,
|
||||
catInfo = new catInfoParam() { inputType = attr.normalRelease.ruleType, isRequired = attr.isRequired == true ? 1 : 0, isCustomize = 0 }
|
||||
};
|
||||
wxPropParam.categorys.Add(wxCategoryParam1);
|
||||
wxPropParam.categorys.Add(wxCategoryParam2);
|
||||
}
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "图书" || prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸")
|
||||
{
|
||||
foreach (var param in upProdParam.product.info.param.ToList())
|
||||
{
|
||||
if (param.categorys.FirstOrDefault()?.name == "作者" && param.categorys.LastOrDefault()?.name == "无")
|
||||
{
|
||||
param.categorys.LastOrDefault().name = upProdParam.product.info.param.FirstOrDefault(p => p.categorys.FirstOrDefault()?.name == "出版社名称")?.categorys?.LastOrDefault()?.name;
|
||||
if (param.categorys.LastOrDefault().name.IsNullOrEmpty())
|
||||
param.categorys.LastOrDefault().name = "无";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
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 PrepareHotlinkImageMapStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "生成图片盗链映射";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
isChangeImgDic = false;
|
||||
wxImgMapDic = new Dictionary<string, string>();
|
||||
if (!string.IsNullOrEmpty(dbProd.wx_img_map_json))
|
||||
{
|
||||
try
|
||||
{
|
||||
wxImgMapDic = JsonHelper.DeserializeJsonToObject<Dictionary<string, string>>(dbProd.wx_img_map_json);
|
||||
}
|
||||
catch
|
||||
{
|
||||
isChangeImgDic = true;
|
||||
wxImgMapDic = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
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 的“提取源商品详情并生成SKU货号”区段迁移。
|
||||
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
||||
/// </summary>
|
||||
public sealed class PrepareSourceProductStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "提取源商品详情并生成SKU货号";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
prodInfo = JsonHelper.DeserializeJsonToObject<PDDProductInfo>(dbProd.product_json);
|
||||
|
||||
// 如果没有货号或有相同货号无法区分sku,自定义货号
|
||||
if (dbProd.db_type == "云端数据")
|
||||
{
|
||||
foreach (var sku in prodInfo.detail.sku)
|
||||
{
|
||||
var skuId = sku.sku_id;
|
||||
if (skuId.IsNullOrZero())
|
||||
skuId = BaseClass.GetLong(string.Join(";", sku.spec.Select(s => s.spec_name)));
|
||||
sku.out_sku_sn = GetNewExtCode(skuId.ParseToString());
|
||||
}
|
||||
}
|
||||
else if (dbProd.product_get_type_text != "厂商直采")
|
||||
{
|
||||
if (prodInfo.detail.sku.Any(s => s.out_sku_sn.IsNullOrEmpty()) ||
|
||||
prodInfo.detail.sku.Select(s => s.out_sku_sn).ToList().Count > prodInfo.detail.sku.Select(s => s.out_sku_sn).Distinct().ToList().Count)
|
||||
{
|
||||
foreach (var sku in prodInfo.detail.sku)
|
||||
{
|
||||
sku.out_sku_sn = string.Join(";", sku.spec.Select(s => s.spec_name));
|
||||
sku.out_sku_sn = "EC1" + Math.Abs(BaseClass.GetLong(sku.out_sku_sn)) + "A";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
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 RestoreWxShopSourceProductStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "微信店采原始格式还原";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
wxEditProdInfo = null;
|
||||
if (dbProd.product_get_type_text == "微信店采")
|
||||
{
|
||||
try
|
||||
{
|
||||
wxEditProdInfo = JsonHelper.DeserializeJsonToObject<WXGetEditProductInfoLite>(dbProd.product_json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("微信商品格式获取失败" + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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 SaveDetailImageHotlinkMapStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "保存详情图盗链映射";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (isChangeImgDic && dbProd.db_type != "云端数据")
|
||||
{
|
||||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
||||
var data = "";
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
data = UserLogin.GetSignaturex();
|
||||
data += "&spu_id=" + dbProd.spu_id;
|
||||
data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic);
|
||||
}));
|
||||
var html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
isChangeImgDic = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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 SaveDraftHotlinkMapStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "保存草稿商品盗链映射";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (isChangeImgDic && dbProd.db_type != "云端数据")
|
||||
{
|
||||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
||||
var data = "";
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
data = UserLogin.GetSignaturex();
|
||||
data += "&spu_id=" + dbProd.spu_id;
|
||||
data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic);
|
||||
}));
|
||||
var html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
isChangeImgDic = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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 SaveMainImageHotlinkMapStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "保存主图盗链映射";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (isChangeImgDic && dbProd.db_type != "云端数据")
|
||||
{
|
||||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
||||
var data = "";
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
data = UserLogin.GetSignaturex();
|
||||
data += "&spu_id=" + dbProd.spu_id;
|
||||
data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic);
|
||||
}));
|
||||
var html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
isChangeImgDic = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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 的“保存SKU图片盗链映射”区段迁移。
|
||||
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
||||
/// </summary>
|
||||
public sealed class SaveSkuHotlinkMapStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "保存SKU图片盗链映射";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (isChangeImgDic && dbProd.db_type != "云端数据")
|
||||
{
|
||||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
||||
var data = "";
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
data = UserLogin.GetSignaturex();
|
||||
data += "&spu_id=" + dbProd.spu_id;
|
||||
data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic);
|
||||
}));
|
||||
var html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
isChangeImgDic = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
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 SetAfterSaleInfoStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "设置售后信息";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在选取售后属性";
|
||||
}));
|
||||
}
|
||||
|
||||
// 非上海仓退货
|
||||
if (!chkUseShanghaiReturnOrderAddress.Checked)
|
||||
{
|
||||
var afterSaleAddress = "";
|
||||
var afterSaleDetail = "";
|
||||
// 厂商直采获取售后地址用于处理售后单
|
||||
if (dbProd.product_get_type_text == "厂商直采")
|
||||
{
|
||||
|
||||
var urlAfterSale = BaseClass.BuildObjString("product/wx_get_after_sale");
|
||||
var dataAfterSale = Work.UserLogin.GetSignaturex();
|
||||
if (!string.IsNullOrEmpty(dbProd.real_coid))
|
||||
dataAfterSale += "&coid=" + dbProd.skc_id + "->" + dbProd.real_coid;
|
||||
else
|
||||
dataAfterSale += "&coid=" + dbProd.skc_id;
|
||||
var htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
||||
if (string.IsNullOrEmpty(htmlAfterSale) || !htmlAfterSale.Contains("\"code\":200"))
|
||||
htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
||||
if (string.IsNullOrEmpty(htmlAfterSale) || !htmlAfterSale.Contains("\"code\":200"))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (htmlAfterSale.Contains("\"data\":\"\""))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
afterSaleAddress = JsonHelper.SerializeObject(JsonHelper.JObjectParse(htmlAfterSale)["data"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//{"address_id":null,"user_name":"退货","postal_code":null,"province_name":"广东省","city_name":"揭阳市","county_name":"榕城区","street_name":"东兴街道","detail_info":"建阳路万泰华庭二期对面眼镜","tel_number":"13024622251","number":"10431013","name":"麦多多供应链"}
|
||||
//{"address_id":null,"user_name":"退货","postal_code":null,"province_name":"广东省","city_name":"揭阳市","county_name":"榕城区","street_name":"东兴街道","detail_info":"建阳路万泰华庭二期对面眼镜","tel_number":"13024622251","number":"10431013","name":"麦多多供应链"}
|
||||
if (string.IsNullOrEmpty(afterSaleAddress))
|
||||
{
|
||||
// 获取推单售后地址
|
||||
var urlAfter = BaseClass.BuildObjString("product/e57_after_sale");
|
||||
var dataAfter = Work.UserLogin.GetSignaturex() + "&coid=" + dbProd.skc_id;
|
||||
var afterRst = GetHtml.PostUtf8(urlAfter, dataAfter);
|
||||
try
|
||||
{
|
||||
afterSaleAddress = JsonHelper.SerializeObject(JsonHelper.JObjectParse(afterRst)["data"]);
|
||||
if (afterRst.Contains("\"code\":0") && !string.IsNullOrEmpty(afterSaleAddress))
|
||||
{
|
||||
urlAfterSale = BaseClass.BuildObjString("product/wx_add_mdy_after_sale");
|
||||
dataAfterSale = Work.UserLogin.GetSignaturex() +
|
||||
"&coid=" + dbProd.skc_id +
|
||||
"&after_sale_json=" + afterSaleAddress;
|
||||
htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
||||
if (string.IsNullOrEmpty(htmlAfterSale) || !htmlAfterSale.Contains("\"code\":200"))
|
||||
htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(afterSaleAddress))
|
||||
{
|
||||
throw new Exception("售后地址信息获取失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 官方库1688厂家数据必须有退货地址才能上传,用户自采数据使用店铺或默认退货地址 26.5.29
|
||||
// 官方库暂时也放开限制可以随意传 26.5.31
|
||||
else if (dbProd.product_get_type_text == "1688厂家" && dbProd.add_user_name == "admin" && 1 == 2)
|
||||
{
|
||||
var urlAfterSale = BaseClass.BuildObjString("product/wx_get_after_sale");
|
||||
var dataAfterSale = Work.UserLogin.GetSignaturex();
|
||||
dataAfterSale += "&coid=" + dbProd.from_shop_id;
|
||||
var htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
||||
if (string.IsNullOrEmpty(htmlAfterSale) || !htmlAfterSale.Contains("\"code\":200"))
|
||||
htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
||||
if (string.IsNullOrEmpty(htmlAfterSale) || !htmlAfterSale.Contains("\"code\":200"))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (htmlAfterSale.Contains("\"data\":\"\""))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
afterSaleAddress = JsonHelper.SerializeObject(JsonHelper.JObjectParse(htmlAfterSale)["data"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(afterSaleAddress))
|
||||
{
|
||||
throw new Exception("售后地址信息获取失败");
|
||||
}
|
||||
}
|
||||
|
||||
else if (GlobalConfig.GlobalSettings.IsWxUseSoftwareDefaultAddress == true && !IsWxNotUseSoftwareDefaultAddressOnce)
|
||||
{
|
||||
if (GlobalConfig.WXShopDefaultAddressList.Any(a => a.shop_id == shop.ShopId))
|
||||
WXShopDefaultAddressListForm.GetShopDefaultAddress(new List<ShopLoginInfo>() { shop });
|
||||
var address = GlobalConfig.WXShopDefaultAddressList.First(a => a.shop_id == shop.ShopId);
|
||||
if (!address.isFullAddress)
|
||||
throw new Exception("店铺地址信息获取失败");
|
||||
afterSaleAddress = JsonHelper.SerializeObject(address);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(afterSaleAddress))
|
||||
{
|
||||
afterSaleDetail = BaseRegex.GetStringJson(ref afterSaleAddress, "detail_info");
|
||||
if (string.IsNullOrEmpty(afterSaleDetail))
|
||||
{
|
||||
throw new Exception("售后地址详细信息获取失败");
|
||||
}
|
||||
}
|
||||
|
||||
var addressRst = WXUpload.getAddress(shop, afterSaleDetail);
|
||||
if (!addressRst.Contains("\"code\":0") && !addressRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref addressRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = addressRst;
|
||||
throw new Exception("售后地址获取失败 " + error);
|
||||
}
|
||||
if (addressRst.Contains("\"totalNum\":0") && !string.IsNullOrEmpty(afterSaleDetail))
|
||||
{
|
||||
string provinceName = BaseRegex.GetStringJson(ref afterSaleAddress, "province_name");
|
||||
string cityName = BaseRegex.GetStringJson(ref afterSaleAddress, "city_name");
|
||||
string countyName = BaseRegex.GetStringJson(ref afterSaleAddress, "county_name");
|
||||
string detailInfo = afterSaleDetail;
|
||||
string userName = BaseRegex.GetStringJson(ref afterSaleAddress, "user_name");
|
||||
string telNumber = BaseRegex.GetStringJson(ref afterSaleAddress, "tel_number");
|
||||
var addAddRst = WXUpload.addAddress(shop, provinceName, cityName, countyName, detailInfo, userName, telNumber);
|
||||
|
||||
Thread.Sleep(Randomx.GetId(500, 1000));
|
||||
|
||||
addressRst = WXUpload.getAddress(shop, afterSaleDetail);
|
||||
if (!addressRst.Contains("\"code\":0") && !addressRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref addressRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = addressRst;
|
||||
throw new Exception("售后地址获取失败 " + error);
|
||||
}
|
||||
}
|
||||
|
||||
if (addressRst.Contains("\"totalNum\":0"))
|
||||
{
|
||||
throw new Exception("售后地址获取失败");
|
||||
}
|
||||
|
||||
upProdParam.product.info.afterSaleInfo = new afterSaleInfoParam();
|
||||
upProdParam.product.info.afterSaleInfo.afterSaleAddressId = BaseRegex.GetStringJson(ref addressRst, "addressId");
|
||||
}
|
||||
// 上海仓退货
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
string addressId = "";
|
||||
string setAddressRst = WXProdNoCheckEditHelper.SetShanghaiReturnOrderAddress(shop);
|
||||
if (setAddressRst.Contains("\"success\":true"))
|
||||
{
|
||||
addressId = WXProdNoCheckEditHelper.dicShopAddressId[shop.ShopId];
|
||||
}
|
||||
else
|
||||
{
|
||||
var errmsg = BaseRegex.GetStringJson(ref setAddressRst, "msg");
|
||||
if (string.IsNullOrWhiteSpace(errmsg))
|
||||
errmsg = setAddressRst;
|
||||
WXProdNoCheckEditHelper.dicShopAddressId.Remove(shop.ShopId);
|
||||
throw new Exception("退货地址指定失败:" + errmsg);
|
||||
}
|
||||
|
||||
upProdParam.product.info.afterSaleInfo = new afterSaleInfoParam();
|
||||
upProdParam.product.info.afterSaleInfo.afterSaleAddressId = addressId;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WXProdNoCheckEditHelper.dicShopAddressId.Remove(shop.ShopId);
|
||||
throw new Exception("退货地址指定失败:" + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
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 SetCommissionInfoStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "设置佣金信息";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (BaseClass.UserAuthority.Contains("佣金上货") && chkCommission.Checked)
|
||||
{
|
||||
upProdParam.product.info.leagueItemInfo = new leagueItemInfoParam();
|
||||
upProdParam.product.info.leagueItemInfo.itemSwitch = 1;
|
||||
upProdParam.product.info.leagueItemInfo.itemRatio = commissionRate;
|
||||
upProdParam.product.info.leagueItemInfo.headSupplierPublicItemSwitch = 1;
|
||||
upProdParam.product.info.leagueItemInfo.headSupplierPublicItemServiceRatio = commissionRate;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
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 SetPreSaleInfoStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "设置预售信息";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (chkPreSale.Checked)
|
||||
{
|
||||
upProdParam.product.deliverInfo = new productDeliverInfoParam();
|
||||
upProdParam.product.deliverInfo.deliverType = 1;
|
||||
int preSaleDays = Math.Max(3, wxUploadRule.PreSaleDays);
|
||||
preSaleDays = Math.Min(45, preSaleDays);
|
||||
upProdParam.product.deliverInfo.skuDeliverInfo = new skuDeliverInfoParam()
|
||||
{
|
||||
stockType = 1,
|
||||
fullPaymentPresaleDeliveryTime = preSaleDays.ParseToString()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
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 SetProductExtCodeStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "设置商品货号";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
extCode = dbProd.ext_code.IsNullOrEmpty() ? prodInfo.detail.out_goods_sn : dbProd.ext_code;
|
||||
if (extCode.IsNullOrEmpty() || extCode.Length <= 10)
|
||||
{
|
||||
//extCode = "EC" + Randomx.GetId(1000).ToString().PadLeft(3, '0') + dbProd.spu_id + "C";
|
||||
extCode = GetEC1ExtCode(dbProd.spu_id);
|
||||
}
|
||||
upProdParam.product.info.spuCode = extCode;
|
||||
upProdParam.product.info.outProductId = extCode;
|
||||
upProdParam.product.info.out_product_id = extCode;
|
||||
upProdParam.product.productKey.outProductId = extCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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 SetProductTitleStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "设置商品标题";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
prodTitle = selectProd.product_name;
|
||||
if (prodTitle.IsNullOrEmpty())
|
||||
prodTitle = dbProd.product_name.IsNullOrEmpty() ? prodInfo.detail.goods_name : dbProd.product_name;
|
||||
|
||||
upProdInitParam.product.info.title = prodTitle;
|
||||
upProdParam.product.info.title = prodTitle;
|
||||
upProdParam.sessionInfo.sessionId = upProdInitParam.product.sessionId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,673 @@
|
||||
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 SetQualificationsAndTagImagesStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "设置资质信息并生成标签图";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
// 微信回采直接复制
|
||||
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采") && chkUseWXComplateProd.Checked && dbProd.has_wx_format == "1" && wxEditProdInfo != null)
|
||||
{
|
||||
upProdParam.product.info.qualificationList.Clear();
|
||||
if (wxEditProdInfo.product?.info?.qualificationList?.Count > 0)
|
||||
{
|
||||
foreach (var editQualification in wxEditProdInfo.product.info.qualificationList)
|
||||
{
|
||||
upProdParam.product.info.qualificationList.Add(new qualificationParam()
|
||||
{
|
||||
qualificationId = editQualification.qualificationId,
|
||||
qualificationUrl = editQualification.qualificationUrl,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
|
||||
{
|
||||
if (wxEditProdInfo.product.info.brandId.ParseToLong() > 0)
|
||||
DefaultAdultBrandId = wxEditProdInfo.product.info.brandId;
|
||||
if (wxEditProdInfo.product.info.brandId.ParseToLong() > 0)
|
||||
upProdParam.product.info.brandId = wxEditProdInfo.product.info.brandId.ParseToLong();
|
||||
}
|
||||
}
|
||||
// 微信店采直接复制
|
||||
//else if (dbProd.product_get_type_text == "微信店采" && upProdParam.product.info.category.FirstOrDefault()?.name != "图书" &&
|
||||
// upProdParam.product.info.category.FirstOrDefault()?.name != "食品饮料")
|
||||
else if (dbProd.product_get_type_text == "微信店采" &&
|
||||
upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
|
||||
{
|
||||
upProdParam.product.info.qualificationList.Clear();
|
||||
if (wxEditProdInfo.product?.info?.qualificationList?.Count > 0)
|
||||
{
|
||||
foreach (var editQualification in wxEditProdInfo.product.info.qualificationList)
|
||||
{
|
||||
upProdParam.product.info.qualificationList.Add(new qualificationParam()
|
||||
{
|
||||
qualificationId = editQualification.qualificationId,
|
||||
qualificationUrl = editQualification.qualificationUrl,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
|
||||
{
|
||||
if (wxEditProdInfo.product.info.brandId.ParseToLong() > 0)
|
||||
DefaultAdultBrandId = wxEditProdInfo.product.info.brandId;
|
||||
if (wxEditProdInfo.product.info.brandId.ParseToLong() > 0)
|
||||
upProdParam.product.info.brandId = wxEditProdInfo.product.info.brandId.ParseToLong();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//qualificationList
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "图书" || prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸")
|
||||
{
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成图书专有信息";
|
||||
}));
|
||||
}
|
||||
|
||||
if (lstQulificationImage.Count == 0)
|
||||
{
|
||||
var pageCount = 1;
|
||||
var seconds = 0m;
|
||||
lstQulificationImage = AdminForms.WXAdminQualificationImageForm.AdminGetServerQualificationImageLst(out pageCount, out seconds, "图书");
|
||||
}
|
||||
var qulificationImage = lstQulificationImage.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
||||
if (qulificationImage != null)
|
||||
{
|
||||
if (qulificationImage.img_base64.IsNullOrEmpty())
|
||||
{
|
||||
var pageCount = 1;
|
||||
var seconds = 0m;
|
||||
qulificationImage.img_base64 = AdminForms.WXAdminQualificationImageForm.AdminGetServerQualificationImageLst(out pageCount, out seconds, "图书", qulificationImage.img_md5)
|
||||
.FirstOrDefault()?.img_base64;
|
||||
}
|
||||
}
|
||||
|
||||
//string publisher = "出版社名称:" + new List<string>() { "技术出版社", "文化出版社", "美术出版社" }[Randomx.GetId(3)];
|
||||
////string isbn = "ISBN:";
|
||||
//string isbn = "ISBN/CN刊号:";
|
||||
////string bookName = "书名:";
|
||||
//string bookName = "图书名称:";
|
||||
//string bookPrice = "定价:" + upProdParam.product.productSkus.Max(s => s.productSkuInfo.salePrice) * 0.01;
|
||||
//string author = "作者:王老师";
|
||||
//string publishTime = "出版时间:" + DateTime.Now.AddMonths(-3).ToString("yyyy年MM月dd日");
|
||||
//string edition = "版次:1";
|
||||
//string binding = "装帧:平装";
|
||||
|
||||
//foreach (var propParam in upProdParam.product.info.param)
|
||||
//{
|
||||
// if (propParam.categorys[0].name.Contains("出版社名称"))
|
||||
// publisher = "出版社名称:" + propParam.categorys[1].name;
|
||||
// else if (propParam.categorys[0].name.Contains("ISBN版号/CN刊号"))
|
||||
// {
|
||||
// //isbn = "ISBN:" + propParam.categorys[1].name;
|
||||
// isbn = "ISBN/CN刊号:" + propParam.categorys[1].name;
|
||||
// if (propParam.categorys[1].name.Length == 13)
|
||||
// {
|
||||
// var isbnStr = propParam.categorys[1].name;
|
||||
// isbn = "ISBN/CN刊号:" + isbnStr[0] + isbnStr[1] + isbnStr[2] + "-" + isbnStr[3] + "-" + isbnStr[4] + isbnStr[5] + isbnStr[6] + isbnStr[7] + "-" + isbnStr[8] + isbnStr[9] + isbnStr[10] + isbnStr[11] + "-" + isbnStr[12];
|
||||
// }
|
||||
// }
|
||||
// else if (propParam.categorys[0].name.Contains("书名"))
|
||||
// {
|
||||
// //bookName = "书名:" + propParam.categorys[1].name;
|
||||
// bookName = "图书名称:" + propParam.categorys[1].name;
|
||||
// }
|
||||
// else if (propParam.categorys[0].name.Contains("定价"))
|
||||
// {
|
||||
// //bookPrice = "定价:" + propParam.categorys[1].name;
|
||||
// propParam.categorys[1].name = bookPrice;
|
||||
// }
|
||||
// else if (propParam.categorys[0].name.Contains("作者"))
|
||||
// author = "作者:" + propParam.categorys[1].name;
|
||||
// else if (propParam.categorys[0].name.Contains("出版时间"))
|
||||
// publishTime = "出版时间:" + propParam.categorys[1].name;
|
||||
// else if (propParam.categorys[0].name.Contains("版次"))
|
||||
// edition = "版次:" + propParam.categorys[1].name;
|
||||
// else if (propParam.categorys[0].name.Contains("包装"))
|
||||
// binding = "装帧:" + propParam.categorys[1].name;
|
||||
//}
|
||||
|
||||
//var bookStr = publisher + "\r\n" + "\r\n" +
|
||||
// isbn + "\r\n" + "\r\n" +
|
||||
// bookName + "\r\n" + "\r\n" +
|
||||
// bookPrice + "\r\n" + "\r\n" +
|
||||
// author + "\r\n" + "\r\n" +
|
||||
// publishTime + "\r\n" + "\r\n" +
|
||||
// edition + "\r\n" + "\r\n" +
|
||||
// binding;
|
||||
|
||||
//int imgW = 800; int imgH = 800; int textImgH = 0;
|
||||
//string getImgError;
|
||||
//var img_url = upProdParam.product.info.headImg[0];
|
||||
//if (!img_url.Contains("wst.wxapp.tc.qq.com") && !img_url.Contains("mmecimage.cn"))
|
||||
// img_url = img_url.Replace("https://", "http://");
|
||||
//var imageMain = GetHtml.GetUrlImg(img_url, out getImgError);
|
||||
//if (imageMain == null)
|
||||
// imageMain = new Bitmap(800, 800);
|
||||
//using (Bitmap bitmap = new Bitmap(1, 1)) // 尺寸不重要,只是为了使用Graphics对象
|
||||
//using (Graphics g = Graphics.FromImage(bitmap)) // 获取Graphics对象
|
||||
//{
|
||||
// // 定义字体
|
||||
// Font font = new Font("微软雅黑", 16, FontStyle.Regular);
|
||||
// g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
// // 定义要测量的字符串
|
||||
// string text = bookStr;
|
||||
// // 测量字符串大小
|
||||
// SizeF size = g.MeasureString(text, font, imgW - 120);
|
||||
// // 输出高度信息
|
||||
// //Console.WriteLine("Text Height: " + size.Height);
|
||||
// textImgH = size.Height.ParseToInt() + 180;
|
||||
//}
|
||||
|
||||
////var bookImg = new Bitmap(imgW, imgH);
|
||||
////using (Graphics g = Graphics.FromImage(bookImg))
|
||||
////{
|
||||
//// g.Clear(Color.White);
|
||||
//// //Font font = new Font("宋体", 15, FontStyle.Bold);
|
||||
//// //Font font = new Font("微软雅黑", 15, FontStyle.Regular);
|
||||
//// Font font = new Font("微软雅黑", 16, FontStyle.Regular);
|
||||
//// //Font font = new Font("宋体", 17, FontStyle.Bold);
|
||||
//// Brush textBrush = Brushes.Black;
|
||||
//// g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
//// RectangleF rectF = new RectangleF(60, 80, imgW - 120, imgH - 180);
|
||||
//// g.DrawString(bookStr, font, textBrush, rectF);
|
||||
////}
|
||||
|
||||
//// 绘制一张带主图的商品详情页
|
||||
//var bookImg = new Bitmap(imgW, imgH + textImgH);
|
||||
//using (Graphics g = Graphics.FromImage(bookImg))
|
||||
//{
|
||||
// g.Clear(Color.FromArgb(248, 239, 244));
|
||||
|
||||
// g.DrawImage(imageMain, new Rectangle(0, 0, imgW, imgH), 0, 0, imageMain.Width, imageMain.Height, GraphicsUnit.Pixel);
|
||||
|
||||
// //Font font = new Font("宋体", 15, FontStyle.Bold);
|
||||
// //Font font = new Font("微软雅黑", 15, FontStyle.Regular);
|
||||
// Font font = new Font("微软雅黑", 18, FontStyle.Regular);
|
||||
// //Font font = new Font("宋体", 17, FontStyle.Bold);
|
||||
// Brush textBrush = Brushes.Black;
|
||||
// g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
// RectangleF rectF = new RectangleF(60, imgH + 80, imgW - 120, textImgH - 180);
|
||||
// g.DrawString(bookStr, font, textBrush, rectF);
|
||||
//}
|
||||
|
||||
|
||||
string publisher = "出版发行:" + new List<string>() { "技术出版社", "文化出版社", "美术出版社" }[Randomx.GetId(3)];
|
||||
//string isbn = "ISBN:";
|
||||
string isbn = "ISBN/CN刊号:";
|
||||
//string bookName = "书名:";
|
||||
string bookName = "图书名称:";
|
||||
string bookPrice = "定 价:" + upProdParam.product.productSkus.Max(s => s.productSkuInfo.salePrice) * 0.01;
|
||||
string author = "作 者:王老师";
|
||||
string publishTime = "出版时间:" + DateTime.Now.AddMonths(-3).ToString("yyyy年MM月dd日");
|
||||
string edition = "版 次:1";
|
||||
string binding = "装 帧:平装";
|
||||
|
||||
foreach (var propParam in upProdParam.product.info.param)
|
||||
{
|
||||
if (propParam.categorys[0].name.Contains("出版社名称"))
|
||||
publisher = "出版发行:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("ISBN版号/CN刊号"))
|
||||
{
|
||||
//isbn = "ISBN:" + propParam.categorys[1].name;
|
||||
isbn = "ISBN/CN刊号:" + propParam.categorys[1].name;
|
||||
if (propParam.categorys[1].name.Length == 13)
|
||||
{
|
||||
var isbnStr = propParam.categorys[1].name;
|
||||
isbn = "ISBN/CN刊号:" + isbnStr[0] + isbnStr[1] + isbnStr[2] + "-" + isbnStr[3] + "-" + isbnStr[4] + isbnStr[5] + isbnStr[6] + isbnStr[7] + "-" + isbnStr[8] + isbnStr[9] + isbnStr[10] + isbnStr[11] + "-" + isbnStr[12];
|
||||
}
|
||||
}
|
||||
else if (propParam.categorys[0].name.Contains("书名"))
|
||||
{
|
||||
//bookName = "书名:" + propParam.categorys[1].name;
|
||||
bookName = "图书名称:" + propParam.categorys[1].name;
|
||||
}
|
||||
else if (propParam.categorys[0].name.Contains("定价"))
|
||||
{
|
||||
//bookPrice = "定价:" + propParam.categorys[1].name;
|
||||
propParam.categorys[1].name = bookPrice;
|
||||
}
|
||||
else if (propParam.categorys[0].name.Contains("作者"))
|
||||
{
|
||||
if (propParam.categorys[1].name != "/")
|
||||
author = "作 者:" + propParam.categorys[1].name;
|
||||
else
|
||||
author = "";
|
||||
}
|
||||
else if (propParam.categorys[0].name.Contains("出版时间"))
|
||||
publishTime = "出版时间:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("版次"))
|
||||
edition = "版 次:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("包装"))
|
||||
binding = "装 帧:" + propParam.categorys[1].name;
|
||||
}
|
||||
if (author.IsNullOrEmpty())
|
||||
author = "作 者:" + publisher.Replace("出版发行:", "");
|
||||
|
||||
var bookStr = publisher + "\r\n" + "\r\n" +
|
||||
isbn + "\r\n" + "\r\n" +
|
||||
bookName + "\r\n" + "\r\n" +
|
||||
bookPrice + "\r\n" + "\r\n" +
|
||||
author + "\r\n" + "\r\n" +
|
||||
publishTime + "\r\n" + "\r\n" +
|
||||
edition + "\r\n" + "\r\n" +
|
||||
binding;
|
||||
|
||||
int imgW = 800; int imgH = 800; int textImgH = 0;
|
||||
string getImgError;
|
||||
var img_url = upProdParam.product.info.headImg[0];
|
||||
if (!img_url.Contains("wst.wxapp.tc.qq.com") && !img_url.Contains("mmecimage.cn"))
|
||||
img_url = img_url.Replace("https://", "http://");
|
||||
var imageMain = GetHtml.GetUrlImg(img_url, out getImgError);
|
||||
if (imageMain == null)
|
||||
imageMain = new Bitmap(800, 800);
|
||||
using (Bitmap bitmap = new Bitmap(1, 1)) // 尺寸不重要,只是为了使用Graphics对象
|
||||
using (Graphics g = Graphics.FromImage(bitmap)) // 获取Graphics对象
|
||||
{
|
||||
// 定义字体
|
||||
Font font = new Font("微软雅黑", 16, FontStyle.Regular);
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
// 定义要测量的字符串
|
||||
string text = bookStr;
|
||||
// 测量字符串大小
|
||||
SizeF size = g.MeasureString(text, font, imgW - 120);
|
||||
// 输出高度信息
|
||||
//Console.WriteLine("Text Height: " + size.Height);
|
||||
textImgH = size.Height.ParseToInt() + 180;
|
||||
}
|
||||
|
||||
|
||||
var bookImg = TemuKJD.Properties.Resources.empty_book_900_1200;
|
||||
if (!string.IsNullOrEmpty(qulificationImage?.img_base64))
|
||||
{
|
||||
// 使用服务端随即图
|
||||
try
|
||||
{
|
||||
bookImg = Base64ChangeImgUrl.Base64ToImage(qulificationImage.img_base64);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
imgH = bookImg.Height;
|
||||
imgW = bookImg.Width;
|
||||
using (Graphics g = Graphics.FromImage(bookImg))
|
||||
{
|
||||
Brush textBrush = Brushes.Black;
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
|
||||
float txtTop = 240, txtBottom = 240, txtLeft = 280, txtRight = 270;
|
||||
if (qulificationImage.txt_margin.ParseToString().Split(',').Select(m => m.ParseToInt()).ToList() is List<int> marginValueList && marginValueList.Count == 4)
|
||||
{
|
||||
txtLeft = marginValueList[0] + 10 - Randomx.GetId(21);
|
||||
txtTop = marginValueList[1] + 10 - Randomx.GetId(21);
|
||||
txtRight = marginValueList[2] + 10 - Randomx.GetId(21);
|
||||
txtBottom = marginValueList[3] + 10 - Randomx.GetId(21);
|
||||
}
|
||||
int txtWidth = (int)imgW - (int)txtLeft - (int)txtRight; // 370;
|
||||
|
||||
// 书名
|
||||
Font font = new Font("宋体", 22, FontStyle.Bold);
|
||||
RectangleF rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop - 80);
|
||||
g.DrawString(bookName.Replace("图书名称:", ""), font, textBrush, rectF);
|
||||
// 测量文本的高度 决定接下来文字绘制位置
|
||||
var textSize = g.MeasureString(bookName.Replace("图书名称:", ""), font, txtWidth);
|
||||
txtTop += 20 + textSize.Height;
|
||||
|
||||
font = new Font("宋体", 15, FontStyle.Bold);
|
||||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop - 80);
|
||||
g.DrawString(author.Replace("作 者:", "").TrimEnd('著', ' ') + " 著", font, textBrush, rectF);
|
||||
// 测量文本的高度
|
||||
textSize = g.MeasureString(author.Replace("作 者:", "").TrimEnd('著', ' ') + " 著", font, txtWidth);
|
||||
txtTop += 20 + textSize.Height;
|
||||
|
||||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop - 80);
|
||||
g.DrawString(publisher.Replace("出版发行:", ""), font, textBrush, rectF);
|
||||
// 测量文本的高度
|
||||
textSize = g.MeasureString(publisher.Replace("出版发行:", ""), font, txtWidth);
|
||||
txtTop += 20 + textSize.Height;
|
||||
|
||||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop - 80);
|
||||
g.DrawString(isbn.Replace("ISBN/CN刊号:", "ISBN "), font, textBrush, rectF);
|
||||
// 测量文本的高度
|
||||
textSize = g.MeasureString(isbn.Replace("ISBN/CN刊号:", "ISBN "), font, txtWidth);
|
||||
txtTop += 20 + textSize.Height;
|
||||
|
||||
// 以下从下往上写
|
||||
txtTop = imgH - txtBottom;
|
||||
// 测量文本的高度
|
||||
textSize = g.MeasureString(binding, font, txtWidth);
|
||||
txtTop -= (10 + textSize.Height);
|
||||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||||
g.DrawString(binding, font, textBrush, rectF);
|
||||
|
||||
// 测量文本的高度
|
||||
textSize = g.MeasureString(edition, font, txtWidth);
|
||||
txtTop -= (10 + textSize.Height);
|
||||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||||
g.DrawString(edition, font, textBrush, rectF);
|
||||
|
||||
// 测量文本的高度
|
||||
textSize = g.MeasureString(publishTime, font, txtWidth);
|
||||
txtTop -= (10 + textSize.Height);
|
||||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||||
g.DrawString(publishTime, font, textBrush, rectF);
|
||||
|
||||
// 测量文本的高度
|
||||
textSize = g.MeasureString(author, font, txtWidth);
|
||||
txtTop -= (10 + textSize.Height);
|
||||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||||
g.DrawString(author, font, textBrush, rectF);
|
||||
|
||||
// 测量文本的高度
|
||||
textSize = g.MeasureString(bookPrice + "元", font, txtWidth);
|
||||
txtTop -= (10 + textSize.Height);
|
||||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||||
g.DrawString(bookPrice + "元", font, textBrush, rectF);
|
||||
|
||||
// 测量文本的高度
|
||||
textSize = g.MeasureString(bookName, font, txtWidth);
|
||||
txtTop -= (10 + textSize.Height);
|
||||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||||
g.DrawString(bookName, font, textBrush, rectF);
|
||||
|
||||
// 测量文本的高度
|
||||
textSize = g.MeasureString(isbn.Replace("ISBN/CN刊号:", "书 号:ISBN "), font, txtWidth);
|
||||
textSize = g.MeasureString(isbn.Replace("ISBN/CN刊号:", "书 号:"), font, txtWidth);
|
||||
txtTop -= (10 + textSize.Height);
|
||||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||||
g.DrawString(isbn.Replace("ISBN/CN刊号:", "书 号: "), font, textBrush, rectF);
|
||||
|
||||
// 测量文本的高度
|
||||
textSize = g.MeasureString(publisher, font, txtWidth);
|
||||
txtTop -= (10 + textSize.Height);
|
||||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||||
g.DrawString(publisher, font, textBrush, rectF);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Thread.Sleep(Randomx.GetId(500, 800));
|
||||
var locationStr = UploadImg(shop, bookImg, cell);
|
||||
if (!locationStr.Contains("\"success\":true"))
|
||||
throw new Exception(locationStr);
|
||||
var location = BaseRegex.GetStringJson(ref locationStr, "Location");
|
||||
upProdParam.product.info.qualificationList.Add(new qualificationParam() { qualificationId = "1111485", qualificationUrl = new List<string>() { location }, });
|
||||
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
bookImg.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
byte[] imageBytes = memoryStream.ToArray();
|
||||
var imgBase64 = Convert.ToBase64String(imageBytes);
|
||||
|
||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
//upDate += "&is_file=true";
|
||||
//if (needAddRandomBlock || wantAddRandomBlock)
|
||||
// upDate += "&random_code=true";
|
||||
upDate += "&img_url=" + location;
|
||||
upDate += "&img_base64=" + imgBase64;
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在上传资质图文件 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5 && apiUpImgFileRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref apiUpImgFileRst, "img_url");
|
||||
upProdParam.product.info.headImg = upProdParam.product.info.headImg.Take(8).ToList();
|
||||
upProdParam.product.info.headImg.Add(upImgUrl);
|
||||
}
|
||||
}
|
||||
|
||||
//qualificationList
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail.cats.FirstOrDefault() == "食品饮料")
|
||||
{
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成食品饮料专有信息";
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
string foodName = "食品名称:" + prodTitle;
|
||||
string companyName = "生产商名称:中国地区食品厂";
|
||||
string SCID = "食品生产许可证编号:SC10241162100670";
|
||||
string GBID = "产品标准号:GB 2726";
|
||||
string ExpDate = "保质期:30天";
|
||||
string MakeDate = "生产日期:" + DateTime.Now.AddDays(-15).ToString("yyyy-MM-dd");
|
||||
string NetContent = "净含量:见包装";
|
||||
string Pack = "包装方式:袋装";
|
||||
string inList = "配料表:水";
|
||||
string contact = "联系方式:无";
|
||||
string address = "地址:见包装";
|
||||
string Storage = "贮存条件:常温";
|
||||
|
||||
foreach (var propParam in upProdParam.product.info.param)
|
||||
{
|
||||
if (propParam.categorys[0].name.Contains("食品名称") && !propParam.categorys[1].name.Contains("见包装") && !propParam.categorys[1].name.Contains("见外包装") &&
|
||||
!propParam.categorys[1].name.Contains("1") && propParam.categorys[1].name.Length > 5)
|
||||
foodName = "食品名称:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("生产企业名称") && !propParam.categorys[1].name.Contains("见包装") && !propParam.categorys[1].name.Contains("见外包装"))
|
||||
companyName = "生产商名称:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("食品生产许可证编号") && !propParam.categorys[1].name.Contains("见包装") && !propParam.categorys[1].name.Contains("见外包装"))
|
||||
SCID = "食品生产许可证编号:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("产品标准号") && !propParam.categorys[1].name.Contains("见包装") && !propParam.categorys[1].name.Contains("见外包装"))
|
||||
GBID = "产品标准号:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("保质期"))
|
||||
ExpDate = "保质期:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("生产日期"))
|
||||
MakeDate = "生产日期:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("净含量"))
|
||||
NetContent = "净含量:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("包装方式"))
|
||||
Pack = "包装方式:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("配料表"))
|
||||
inList = "配料表:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("联系方式"))
|
||||
contact = "联系方式:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("地址"))
|
||||
address = "地址:" + propParam.categorys[1].name;
|
||||
else if (propParam.categorys[0].name.Contains("贮存条件"))
|
||||
Storage = "贮存条件:" + propParam.categorys[1].name;
|
||||
}
|
||||
|
||||
var bookStr = foodName + "\r\n" + "\r\n";
|
||||
bookStr += companyName + "\r\n" + "\r\n";
|
||||
bookStr += SCID + "\r\n" + "\r\n";
|
||||
bookStr += GBID + "\r\n" + "\r\n";
|
||||
bookStr += ExpDate + "\r\n" + "\r\n";
|
||||
bookStr += MakeDate + "\r\n" + "\r\n";
|
||||
bookStr += NetContent + "\r\n" + "\r\n";
|
||||
bookStr += Pack + "\r\n" + "\r\n";
|
||||
bookStr += inList + "\r\n" + "\r\n";
|
||||
bookStr += contact + "\r\n" + "\r\n";
|
||||
bookStr += address + "\r\n" + "\r\n";
|
||||
bookStr += Storage + "\r\n" + "\r\n";
|
||||
|
||||
int width = 800;
|
||||
int height = 1000;
|
||||
var bookImg = new Bitmap(width, height);
|
||||
using (Graphics g = Graphics.FromImage(bookImg))
|
||||
{
|
||||
g.Clear(Color.Gray);
|
||||
|
||||
Brush borderBrush = Brushes.Gray;
|
||||
Brush contentBrush = Brushes.White;
|
||||
g.FillRectangle(contentBrush, new RectangleF(8, 8, width - 16, height - 16));
|
||||
g.FillRectangle(borderBrush, new RectangleF(18, 18, width - 36, height - 36));
|
||||
g.FillRectangle(contentBrush, new RectangleF(22, 22, width - 44, height - 44));
|
||||
g.FillRectangle(borderBrush, new RectangleF(40, 140, width - 80, 4));
|
||||
|
||||
SizeF textSize;
|
||||
{
|
||||
Font font = new Font("微软雅黑", 30, FontStyle.Regular);
|
||||
Brush textBrush = Brushes.DarkRed;
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
// 测量文本的宽度
|
||||
textSize = g.MeasureString("商 品 标 签", font);
|
||||
float x = (width - textSize.Width) / 2;
|
||||
|
||||
RectangleF rectF = new RectangleF(x, 50, width - x, height - 200);
|
||||
g.DrawString("商 品 标 签", font, textBrush, rectF);
|
||||
}
|
||||
|
||||
{
|
||||
//Font font = new Font("宋体", 15, FontStyle.Bold);
|
||||
Font font = new Font("微软雅黑", 15, FontStyle.Regular);
|
||||
Brush textBrush = Brushes.Black;
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
RectangleF rectF = new RectangleF(80, 120 + textSize.Height, width - 160, height - 80 - 120 - textSize.Height);
|
||||
g.DrawString(bookStr, font, textBrush, rectF);
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(Randomx.GetId(500, 800));
|
||||
var locationStr = UploadImg(shop, bookImg, cell);
|
||||
if (!locationStr.Contains("\"success\":true"))
|
||||
throw new Exception(locationStr);
|
||||
var location = BaseRegex.GetStringJson(ref locationStr, "Location");
|
||||
upProdParam.product.info.qualificationList.Add(new qualificationParam() { qualificationId = "50000057", qualificationUrl = new List<string>() { location }, });
|
||||
}
|
||||
|
||||
//qualificationList
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
|
||||
{
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成成人用品专有信息";
|
||||
}));
|
||||
}
|
||||
|
||||
string prodName = "产品名称:" +
|
||||
(upProdParam.product.info.category.Count > 2 ? upProdParam.product.info.category[2].name : upProdParam.product.info.category.LastOrDefault()?.name);
|
||||
string company = "生产企业:浙江邦臣医药有限公司";
|
||||
string address = "制造商地址:浙江省金华市婺城区神丽路1399号6号厂房";
|
||||
string model = "产品型号:见包装";
|
||||
string material = "材质:其他";
|
||||
string user = "适用人群:18岁以上成年人";
|
||||
|
||||
foreach (var propParam in upProdParam.product.info.param)
|
||||
{
|
||||
//if (propParam.categorys[0].name.Contains("产品名称"))
|
||||
// prodName = "产品名称:" + propParam.categorys[1].name;
|
||||
}
|
||||
|
||||
var bookStr = prodName + "\r\n" + "\r\n" +
|
||||
company + "\r\n" + "\r\n" +
|
||||
address + "\r\n" + "\r\n" +
|
||||
model + "\r\n" + "\r\n" +
|
||||
material + "\r\n" + "\r\n" +
|
||||
user;
|
||||
|
||||
var bookImg = new Bitmap(800, 800);
|
||||
using (Graphics g = Graphics.FromImage(bookImg))
|
||||
{
|
||||
g.Clear(Color.White);
|
||||
//Font font = new Font("宋体", 15, FontStyle.Bold);
|
||||
Font font = new Font("微软雅黑", 15, FontStyle.Regular);
|
||||
Brush textBrush = Brushes.Black;
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
RectangleF rectF = new RectangleF(80, 80, 800 - 80, 800 - 80);
|
||||
g.DrawString(bookStr, font, textBrush, rectF);
|
||||
}
|
||||
|
||||
Thread.Sleep(Randomx.GetId(500, 800));
|
||||
var locationStr = UploadImg(shop, bookImg, cell);
|
||||
if (!locationStr.Contains("\"success\":true"))
|
||||
throw new Exception(locationStr);
|
||||
var location = BaseRegex.GetStringJson(ref locationStr, "Location");
|
||||
upProdParam.product.info.qualificationList.Add(new qualificationParam() { qualificationId = "50000089", qualificationUrl = new List<string>() { location }, });
|
||||
}
|
||||
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
|
||||
{
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成成人用品专有信息";
|
||||
}));
|
||||
}
|
||||
|
||||
string prodName = (upProdParam.product.info.category.Count > 2 ? upProdParam.product.info.category[2].name : upProdParam.product.info.category.LastOrDefault()?.name);
|
||||
|
||||
var baseImg = TemuKJD.Properties.Resources.qingqu;
|
||||
var newImg = new Bitmap(baseImg.Width, baseImg.Height);
|
||||
using (Graphics g = Graphics.FromImage(newImg))
|
||||
{
|
||||
//g.Clear(Color.White);
|
||||
g.DrawImage(baseImg, new Rectangle(0, 0, newImg.Width, newImg.Height), 0, 0, baseImg.Width, baseImg.Height, GraphicsUnit.Pixel);
|
||||
|
||||
g.FillRectangle(Brushes.White, 860.ParseToInt(), (1024 - 4).ParseToInt(), 500, 120);
|
||||
|
||||
//Font font = new Font("宋体", txtSize.Text.Trim().ParseToInt(), FontStyle.Bold);
|
||||
Font font = new Font("宋体", 44.ParseToInt(), FontStyle.Regular);
|
||||
//Font font = new Font("微软雅黑", 15, FontStyle.Regular);
|
||||
Brush textBrush = Brushes.Black;
|
||||
textBrush = new SolidBrush(Color.FromArgb(0, 0, 0));
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
|
||||
RectangleF rectF = new RectangleF(860, 1024, baseImg.Width - 80, baseImg.Height - 80);
|
||||
if (!string.IsNullOrWhiteSpace(prodName.Trim()))
|
||||
g.DrawString(prodName.Trim(), font, textBrush, rectF);
|
||||
}
|
||||
|
||||
Thread.Sleep(Randomx.GetId(500, 800));
|
||||
var locationStr = UploadImg(shop, newImg, cell);
|
||||
if (!locationStr.Contains("\"success\":true"))
|
||||
throw new Exception(locationStr);
|
||||
var location = BaseRegex.GetStringJson(ref locationStr, "Location");
|
||||
upProdParam.product.info.qualificationList.Add(new qualificationParam() { qualificationId = "50000115", qualificationUrl = new List<string>() { location }, });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
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 MAX.Core.DependencyInjection;
|
||||
using MAX.Core.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Store.Framework.Extensions;
|
||||
using Store.Management.Framework.Apis;
|
||||
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 SkipUploadedProductStep : WxProductPublishStepBase
|
||||
{
|
||||
|
||||
public SkipUploadedProductStep()
|
||||
{
|
||||
}
|
||||
public override string Description => "跳过已上传商品";
|
||||
|
||||
protected override Task<bool> CanExecuteProvider(WXPublishContext context, CancellationToken token)
|
||||
{
|
||||
return Task.FromResult(context.Parameters.SkipExisting);
|
||||
}
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
// 裂变按标题名称
|
||||
if (selectProd.is_fission_title)
|
||||
{
|
||||
HttpResult result = WXApi.searchProductWithTitle(context.Shop.Cookie, GetHtml.UrlEncodeUtf8(context.Product.Title));
|
||||
string searchRst = result.Html;
|
||||
if (!searchRst.Contains("\"code\":0") && !searchRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref searchRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = searchRst;
|
||||
throw new Exception("已存在商品查询错误 " + error);
|
||||
}
|
||||
try
|
||||
{
|
||||
var num = JObject.Parse(searchRst)["totalNum"].ParseToInt();
|
||||
if (num > 0)
|
||||
{
|
||||
throw new Exception("商品已存在,选择跳过");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("已存在商品查询错误 " + ex.Message);
|
||||
}
|
||||
}
|
||||
// 非裂变商品按商品Id
|
||||
else
|
||||
{
|
||||
var searchExtCode = dbProd.ext_code;
|
||||
if (dbProd.db_type == "云端数据")
|
||||
{
|
||||
dbProd.ext_code = searchExtCode = GetNewExtCode(dbProd.spu_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (searchExtCode.ParseToString().Length < 10)
|
||||
searchExtCode = GetEC1ExtCode(dbProd.spu_id);
|
||||
}
|
||||
if (dbProd.sku_secret_json != null && dbProd.sku_secret_json.Contains("goodsId"))
|
||||
{
|
||||
var sku_secret_json = dbProd.sku_secret_json;
|
||||
searchExtCode = BaseRegex.GetStringJson(ref sku_secret_json, "goodsId");
|
||||
}
|
||||
var result = WXApi.searchProduct(context.Shop.Cookie, searchExtCode);
|
||||
string searchRst = result.Html;
|
||||
if (!searchRst.Contains("\"code\":0") && !searchRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref searchRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = searchRst;
|
||||
throw new Exception("已存在商品查询错误 " + error);
|
||||
}
|
||||
try
|
||||
{
|
||||
var num = JObject.Parse(searchRst)["totalNum"].ParseToInt();
|
||||
if (num > 0)
|
||||
{
|
||||
throw new Exception("商品已存在,选择跳过");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("已存在商品查询错误 " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
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() + "秒";
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
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 SubmitProductStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "提交商品上架";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
upProdParam.product.productKey.productId = BaseRegex.GetLongJson(ref uploadDraftRst, "productId").ParseToString();
|
||||
|
||||
commissionRstStr = "";
|
||||
if (chkUpDraft.Checked && BaseClass.UserAuthority.Contains("佣金上货") && chkCommission.Checked)
|
||||
{
|
||||
var rst = WXUpload.addLeagueItemForUpdatingProduct(shop, 1, commissionRate, 1, commissionRate, upProdParam.product.productKey.productId.ParseToLong());
|
||||
if (!rst.Contains("\"code\":0"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJsonByRegs(ref rst, rst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
|
||||
commissionRstStr = "设置佣金比例失败 " + rst;
|
||||
}
|
||||
}
|
||||
|
||||
if (chkUpDraft.Checked)
|
||||
{
|
||||
selectProd.wxDraftProduct = upProdParam;
|
||||
selectProd.draft_id = upProdParam.product.productKey.productId;
|
||||
selectProd.status = "草稿箱";
|
||||
selectProd.add_time = DateTime.Now;
|
||||
upload_draft_product_lst.Add(selectProd);
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_select_upload_draft_products", upload_draft_product_lst);
|
||||
|
||||
StopWithResult("{\"success\":true,\"draftId\":" + upProdParam.product.productKey.productId + ",\"status\":\"草稿箱\",\"errMsg\":\"指定上传到草稿箱" + commissionRstStr + "\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 提交商品上架
|
||||
if (!chkTestNoAuditUpload.Checked)
|
||||
{
|
||||
var uploadProdRst = WXUpload.upProductV2(shop, upProdParam);
|
||||
//{"success":true,"retcode":209006,"errcode":209006,"productId":10001226244322,"productKey":{"productId":"10001226244322"}} // 提审成功
|
||||
//{"success":true,"retcode":0,"errcode":0,"productId":10001226095876,"productKey":{"productId":"10001226095876"}} // 未能提审
|
||||
if (!uploadProdRst.Contains("\"code\":0") && !uploadProdRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref uploadProdRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = BaseRegex.GetStringJson(ref uploadProdRst, "errmsg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = BaseRegex.GetStringJson(ref uploadProdRst, "errcode");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = uploadProdRst;
|
||||
throw new Exception("上架失败 " + error);
|
||||
}
|
||||
if (upProdParam.product.productKey.productId.IsNullOrEmpty())
|
||||
upProdParam.product.productKey.productId = BaseRegex.GetLongJson(ref uploadProdRst, "productId").ParseToString();
|
||||
|
||||
if (BaseClass.UserAuthority.Contains("佣金上货") && chkCommission.Checked)
|
||||
{
|
||||
var rst = WXUpload.addLeagueItemForUpdatingProduct(shop, 1, commissionRate, 1, commissionRate, upProdParam.product.productKey.productId.ParseToLong(), 1);
|
||||
if (!rst.Contains("\"code\":0"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJsonByRegs(ref rst, rst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
|
||||
commissionRstStr = "设置佣金比例失败 " + rst;
|
||||
}
|
||||
}
|
||||
if (chkIsSubmitSuccess.Checked)
|
||||
{
|
||||
Thread.Sleep(Randomx.GetId(2000, 3001));
|
||||
var uploadCheckRst = WXUpload.SearchProductUpload(shop, upProdParam.product.productKey.productId);
|
||||
if (uploadCheckRst.Contains("\"productList\":[]") || uploadCheckRst.Contains("\"totalNum\":0"))
|
||||
{
|
||||
throw new Exception("上架提审失败 请检查是否在架商品数已达到上限或店铺受到其他限制");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var getEditProd = WXUpload.getEditProductV2(shop, upProdParam.product.productKey.productId);
|
||||
//getEditProd = getEditProd.Replace("8388275713", "33333333");
|
||||
//getEditProd = getEditProd.Replace("33333333", "8387633147");
|
||||
|
||||
string productJson = "";
|
||||
try
|
||||
{
|
||||
// 获取免审编辑回传数据
|
||||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||||
var prodStr = JsonConvert.SerializeObject(upProdParam, jsonSetting);
|
||||
JObject jObj = JsonHelper.JObjectParse(prodStr);
|
||||
|
||||
JObject jObjTmp = JsonHelper.JObjectParse(getEditProd);
|
||||
jObj["product"] = jObjTmp["product"];
|
||||
|
||||
//productJson = productJson.Replace("999", "1005");
|
||||
jObj["product"]["status"] = 1; //默认为5
|
||||
foreach (var sku in jObj["product"]["productSkus"])
|
||||
{
|
||||
sku["productSkuInfo"]["stockInfo"]["stockNum"] = "1000";
|
||||
sku["productSkuInfo"]["stockInfo"]["totalNum"] = "1000";
|
||||
//sku["productSkuInfo"]["realStockInfo"]["stockNum"] = "1000";
|
||||
//sku["productSkuInfo"]["realStockInfo"]["totalNum"] = "1000";
|
||||
|
||||
var realStockInfo = new realStockInfoParam() { stockNum = 999, totalNum = 999 };
|
||||
sku["productSkuInfo"]["realStockInfo"] = JsonHelper.JObjectParse(JsonHelper.SerializeObject(realStockInfo));
|
||||
}
|
||||
productJson = JsonHelper.SerializeObject(jObj);
|
||||
|
||||
// 提交上架
|
||||
//var uploadProdRst = WXUpload.upProductJObjectV2(shop, productJson);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
string submitJson = "{\"name\":\"goods/" + upProdParam.product.productKey.productId + "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" +
|
||||
BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now) + "/submit.json\"}";
|
||||
var initFileName = BaseRegex.GetStringJson(ref submitJson, "name");
|
||||
DateTime tickTime = DateTime.Now.AddSeconds(0 - Randomx.GetId(10, 30));
|
||||
int time1 = BaseClass.DateTimeToTimestampSeconds(tickTime) - Randomx.GetId(80, 150);
|
||||
int time2 = BaseClass.DateTimeToTimestampSeconds(tickTime);
|
||||
|
||||
var uploadPartRst = WXUpload.initUploadPart(shop, submitJson, upProdParam.product.productKey.productId, time1, time2);
|
||||
string uploadPartId = BaseRegex.GetStringJson(ref uploadPartRst, "uploadId");
|
||||
|
||||
//upProdParam.product.status = 5;
|
||||
//upProdParam.product.editStatus = 0;
|
||||
//upProdParam.product.auditReason = "";
|
||||
//upProdParam.product.info.skuIdList = new skuIdListParam();
|
||||
//upProdParam.product.info.skuList = new skuListParam();
|
||||
//upProdParam.product.info.skuList.skuInfo = new List<skuInfoParam>();
|
||||
//var listingAuditFreeRst = WXUpload.listingAuditFree(shop, upProdParam, upProdParam.product.productKey.productId, time1, time2);
|
||||
// 提交免审修改(实际生效接口)
|
||||
var listingAuditFreeRst = WXUpload.listingAuditFree(shop, productJson, upProdParam.product.productKey.productId, time1, time2);
|
||||
|
||||
string tempBlobPath = Path.GetTempPath().Trim('\\') + "\\" + Randomx.GetWordWithNumber(8).ToLower();
|
||||
if (!Directory.Exists(tempBlobPath))
|
||||
Directory.CreateDirectory(tempBlobPath);
|
||||
string blobFullPath = tempBlobPath + "\\blob"; // C:\Users\Administrator\AppData\Local\Temp\3mer3k21\blob
|
||||
using (StreamWriter sw = new StreamWriter(blobFullPath))
|
||||
{
|
||||
//skuParam.productSkuInfo.realStockInfo = new realStockInfoParam() { stockNum = 1005, totalNum = 1005 };
|
||||
|
||||
|
||||
var jObj = JsonHelper.JObjectParse(productJson);
|
||||
foreach (JObject skuObj in jObj["product"]["productSkus"])
|
||||
{
|
||||
skuObj["productSkuInfo"]["stockInfo"]["stockNum"] = 1005;
|
||||
|
||||
var realStockInfo = new realStockInfoParam() { stockNum = 999, totalNum = 999 };
|
||||
skuObj["productSkuInfo"]["realStockInfo"] = JsonHelper.JObjectParse(JsonHelper.SerializeObject(realStockInfo));
|
||||
}
|
||||
|
||||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||||
foreach (var sku in upProdParam.product.productSkus)
|
||||
{
|
||||
sku.productSkuInfo.stockInfo.stockNum = 1005;
|
||||
}
|
||||
var prodStr = JsonConvert.SerializeObject(upProdParam, jsonSetting);
|
||||
prodStr = JsonHelper.SerializeObject(jObj["product"]);
|
||||
sw.Write(prodStr);
|
||||
}
|
||||
uploadPartRst = WXUpload.uploadPartBinary(shop, initFileName, blobFullPath, uploadPartId, upProdParam.product.productKey.productId, time1, time2);
|
||||
//{"code":0,"etag":"18e3f73046378472219641ef181d3232"}
|
||||
//C:\Users\Administrator\AppData\Local\Temp\9uaeiplr\blob
|
||||
|
||||
var eTag = BaseRegex.GetStringJson(ref uploadPartRst, "etag");
|
||||
string rstParmStr = @"{""name"":""" + initFileName + @""",""uploadId"":""" + uploadPartId + @""",""etagList"":[""" + eTag + @"""],""partSeqList"":[1]}";
|
||||
var complateRst = WXUpload.completeUploadPart(shop, rstParmStr, upProdParam.product.productKey.productId, time1, time2);
|
||||
|
||||
}
|
||||
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
var timeSpan = DateTime.Now - startTime;
|
||||
var duration = timeSpan.TotalSeconds;
|
||||
cell.Value = "商品已上传" + " " + duration.ParseToInt() + "秒";
|
||||
}));
|
||||
}
|
||||
|
||||
// 已传的商品保存为安全商品
|
||||
if (dbProd.wx_safe_status == "未校验")
|
||||
{
|
||||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
||||
var data = "";
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
data = UserLogin.GetSignaturex();
|
||||
data += "&spu_id=" + dbProd.spu_id;
|
||||
data += "&wx_safe_status=安全商品";
|
||||
}));
|
||||
var html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(dbProd.secret_spu_id))
|
||||
{
|
||||
//add_secret_spu_id_shop_id_map //测试id "2017522348787531778" FC4C8B7F3C6E4B029AD2A12D4D323B41 // 老函数已作废
|
||||
var url = BaseClass.BuildObjString("product/wx_add_secret_id_up_map");
|
||||
var data = "";
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
data = UserLogin.GetSignaturex();
|
||||
data += "&up_secret_spu_id=" + dbProd.secret_spu_id;
|
||||
data += "&up_spu_id=" + dbProd.spu_id;
|
||||
data += "&shop_id=" + shop.ShopId;
|
||||
data += "&index=" + Math.Abs(dbProd.secret_spu_id.GetHashCode()) % 1024;
|
||||
data += "&price_max=" + upProdParam.product.productSkus.Max(s => s.productSkuInfo.salePrice);
|
||||
data += "&price_min=" + upProdParam.product.productSkus.Min(s => s.productSkuInfo.salePrice);
|
||||
}));
|
||||
var html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
}
|
||||
|
||||
//colUploadCount
|
||||
var dgvShopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(row => row.Cells["colShopId"]?.Value.ParseToString() == shop.ShopId);
|
||||
if (dgvShopRow != null)
|
||||
{
|
||||
var day = DateTime.Now.ToString("yyyyMMdd").ParseToInt();
|
||||
if (!GlobalConfig.dicWxShopUploadInfo.ContainsKey(shop.ShopId))
|
||||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId] = new WxShopUploadInfo();
|
||||
if (!GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.ContainsKey(day))
|
||||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day] = 0;
|
||||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day] += 1;
|
||||
// 删除45天前的记录
|
||||
var removeKeys = GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.Keys.Where(s => s < DateTime.Now.AddDays(-45).ToString("yyyyMMdd").ParseToInt()).ToList();
|
||||
foreach (var key in removeKeys)
|
||||
{
|
||||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.Remove(key);
|
||||
}
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_upload_info", GlobalConfig.dicWxShopUploadInfo);
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
dgvShopRow.Cells["colUploadCount"].Value = GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day];
|
||||
}));
|
||||
}
|
||||
|
||||
StopWithResult("{\"success\":true,\"draftId\":" + upProdParam.product.productKey.productId + ",\"status\":\"已上传\",\"msg\":\"上传成功" + commissionRstStr + "\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
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 UploadDetailImagesStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "上传详情图";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成商品详情";
|
||||
}));
|
||||
}
|
||||
Thread.Sleep(Randomx.GetId(100, 300));
|
||||
upProdParam.product.info.detail = new productDetailParam(); // 详情图
|
||||
detailGalleries = prodInfo.detail.galleries.Where(g => g.type == 2).ToList();
|
||||
if (detailGalleries.Count == 0)
|
||||
detailGalleries.Add(new gallery_item() { type = 2, url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url });
|
||||
|
||||
foreach (var gallery_item in detailGalleries)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dbProd.product_get_type_text == "微信店采")
|
||||
{
|
||||
upProdParam.product.info.detail.detailImg.Add(gallery_item.url);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取缓存盗链 详情图
|
||||
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(gallery_item.url)))
|
||||
{
|
||||
upProdParam.product.info.detail.detailImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (needAddRandomBlock || wantAddRandomBlock || gallery_item.url.Contains("wst.wxapp.tc.qq.com"))
|
||||
{
|
||||
// 如果想打码或者需要打码,就走差异化详情图,不走api直传
|
||||
}
|
||||
else
|
||||
{
|
||||
// 使用接口链接传详情图
|
||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
upDate += "&post_data=" + GetHtml.UrlEncodeUtf8("{\"img_url\":\"" + gallery_item.url.Replace("https://", "http://") + "\"}");
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成商品详情图 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20 && upDateRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref upDateRst, "img_url");
|
||||
if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||
{
|
||||
upProdParam.product.info.detail.detailImg.Add(upImgUrl);
|
||||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
||||
isChangeImgDic = true;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
// api上传图片文件 详情图
|
||||
if (1 == 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
string errMsg = "";
|
||||
var imgBase64 = GetImgBase64ForApi(out errMsg, gallery_item.url, needAddRandomBlock, wantAddRandomBlock);
|
||||
if (!string.IsNullOrEmpty(errMsg))
|
||||
{
|
||||
throw new Exception(errMsg);
|
||||
}
|
||||
|
||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
//upDate += "&is_file=true";
|
||||
//if (needAddRandomBlock || wantAddRandomBlock)
|
||||
// upDate += "&random_code=true";
|
||||
upDate += "&img_url=" + gallery_item.url;
|
||||
upDate += "&img_base64=" + imgBase64;
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在上传商品详情图文件 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5 && apiUpImgFileRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref apiUpImgFileRst, "img_url");
|
||||
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||
{
|
||||
upProdParam.product.info.detail.detailImg.Add(upImgUrl);
|
||||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
||||
isChangeImgDic = true;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("修改详情图失败 " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
// 模拟上传图片
|
||||
bool randomDrawBlock = false;
|
||||
if (needAddRandomBlock || wantAddRandomBlock)
|
||||
randomDrawBlock = true;
|
||||
var locationStr = UploadImg(shop, gallery_item.url, cell, randomDrawBlock);
|
||||
if (!locationStr.Contains("\"success\":true"))
|
||||
throw new Exception(locationStr);
|
||||
var location = BaseRegex.GetStringJson(ref locationStr, "Location");
|
||||
upProdParam.product.info.detail.detailImg.Add(location);
|
||||
//wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = location;
|
||||
//isChangeImgDic = true;
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
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 UploadMainImagesStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "上传主图";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成主图并识别商品";
|
||||
}));
|
||||
}
|
||||
Thread.Sleep(Randomx.GetId(100, 300));
|
||||
mainGalleries = prodInfo.detail.galleries.Where(g => g.type == 1).Take(9).ToList();
|
||||
foreach (var gallery_item in mainGalleries) // 9张主图
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dbProd.product_get_type_text == "微信店采")
|
||||
{
|
||||
upProdInitParam.product.info.headImg.Add(gallery_item.url);
|
||||
upProdParam.product.info.headImg.Add(gallery_item.url);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取缓存盗链 主图
|
||||
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(gallery_item.url)))
|
||||
{
|
||||
upProdInitParam.product.info.headImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]);
|
||||
upProdParam.product.info.headImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (needAddRandomBlock || wantAddRandomBlock || gallery_item.url.Contains("wst.wxapp.tc.qq.com"))
|
||||
{
|
||||
// 如果想打码或者需要打码,就走差异化详情图,不走api直传
|
||||
}
|
||||
else
|
||||
{
|
||||
// 使用接口链接传主图
|
||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
upDate += "&post_data=" + GetHtml.UrlEncodeUtf8("{\"img_url\":\"" + gallery_item.url.Replace("https://", "http://") + "\"}");
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成主图并识别商品 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20 && upDateRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref upDateRst, "img_url");
|
||||
if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||
{
|
||||
upProdInitParam.product.info.headImg.Add(upImgUrl);
|
||||
upProdParam.product.info.headImg.Add(upImgUrl);
|
||||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
||||
isChangeImgDic = true;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
// api上传图片文件 主图
|
||||
if (1 == 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
string errMsg = "";
|
||||
var imgBase64 = GetImgBase64ForApi(out errMsg, gallery_item.url, needAddRandomBlock, wantAddRandomBlock, 800, 800);
|
||||
if (!string.IsNullOrEmpty(errMsg))
|
||||
{
|
||||
throw new Exception(errMsg);
|
||||
}
|
||||
|
||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
//upDate += "&is_file=true";
|
||||
//if (needAddRandomBlock || wantAddRandomBlock)
|
||||
// upDate += "&random_code=true";
|
||||
upDate += "&img_url=" + gallery_item.url;
|
||||
upDate += "&img_base64=" + imgBase64;
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在上传主图文件并识别商品 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5 && apiUpImgFileRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref apiUpImgFileRst, "img_url");
|
||||
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||
{
|
||||
upProdInitParam.product.info.headImg.Add(upImgUrl);
|
||||
upProdParam.product.info.headImg.Add(upImgUrl);
|
||||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
||||
isChangeImgDic = true;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("修改主图失败 " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
// 模拟上传图片
|
||||
if (1 == 1)
|
||||
{
|
||||
var upImgAuthRst = WXUpload.getUploadTempImgAuth(shop);
|
||||
for (int i = 0; i < 10 && upImgAuthRst.Contains("LogicError"); i++)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "图片提报失败,正在重试。" + (i + 1);
|
||||
}));
|
||||
Thread.Sleep(Randomx.GetId(3000, 6000));
|
||||
upImgAuthRst = WXUpload.getUploadTempImgAuth(shop);
|
||||
}
|
||||
if (!upImgAuthRst.Contains("\"code\":0"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref upImgAuthRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = upImgAuthRst;
|
||||
throw new Exception("申请上传主图失败 " + GetHtml.UrlEncodeUtf8(error));
|
||||
}
|
||||
string disK = BaseRegex.GetStringJson(ref upImgAuthRst, "disK");
|
||||
long disT = BaseRegex.GetLongJson(ref upImgAuthRst, "disT");
|
||||
string ext = BaseRegex.GetStringJson(ref upImgAuthRst, "ext");
|
||||
string imgBase64 = "";
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
//生成主图base64字符串
|
||||
string getImgError;
|
||||
var image = GetHtml.GetUrlImg(gallery_item.url.Replace("https://", "http://"), out getImgError);
|
||||
var imageBg = new Bitmap(800, 800);
|
||||
if (!string.IsNullOrEmpty(getImgError) || image == null)
|
||||
{
|
||||
throw new Exception("初始化主图上传失败");
|
||||
}
|
||||
try
|
||||
{
|
||||
using (Graphics g = Graphics.FromImage(imageBg))
|
||||
{
|
||||
g.DrawImage(image, new Rectangle(0, 0, imageBg.Width, imageBg.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
|
||||
if (needAddRandomBlock || wantAddRandomBlock)
|
||||
{
|
||||
g.FillRectangle(new SolidBrush(Color.FromArgb(Randomx.GetId(256), Randomx.GetId(256), Randomx.GetId(256))),
|
||||
new Rectangle(Randomx.GetId(imageBg.Width - 30), Randomx.GetId(imageBg.Height - 30), 30, 30));
|
||||
}
|
||||
}
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
imageBg.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
byte[] imageBytes = memoryStream.ToArray();
|
||||
imgBase64 = Convert.ToBase64String(imageBytes);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("修改主图失败 " + ex.Message);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
//上传主图获取路径
|
||||
var upImgRst = WXUpload.adtimageupload(shop, imgBase64, disK, disT, ext).ParseToString();
|
||||
var location = BaseRegex.GetStringJson(ref upImgRst, "Location");
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref upImgAuthRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = upImgAuthRst;
|
||||
throw new Exception("主图上传失败 " + error);
|
||||
}
|
||||
upProdInitParam.product.info.headImg.Add(location);
|
||||
upProdParam.product.info.headImg.Add(location);
|
||||
//wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = location;
|
||||
//isChangeImgDic = true;
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
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 UploadVideoStep : WxProductPublishStepBase
|
||||
{
|
||||
public override string Description => "上传商品视频";
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (prodInfo.detail.galleries.Any(a => a.type == 6))
|
||||
{
|
||||
List<gallery_item> videos = prodInfo.detail.galleries.Where(a => a.type == 6).ToList();
|
||||
//下载视频保存
|
||||
foreach (var item in videos)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "开始下载视频";
|
||||
}));
|
||||
byte[] files;
|
||||
bool d_ret = GetHtml.DownloadFile(item.url, out files);
|
||||
if (d_ret == false)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "视频下载失败";
|
||||
}));
|
||||
throw new Exception("视频下载失败");
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "开始上传视频";
|
||||
}));
|
||||
var uploader = new WXVideoUploader();
|
||||
var video = uploader.Upload(shop, selectProd.id.ToString(), files);
|
||||
upProdParam.product.info.headVideoInfo.Add(new
|
||||
{
|
||||
videoUrl = video.DownloadUrl,
|
||||
videoHeadImg = video.VideoImgUrl,
|
||||
videoLen = video.VideoDuration,
|
||||
videoSize = 0,
|
||||
videoSource = 0,
|
||||
videoFormat = 0,
|
||||
playableVideoUrl = video.DownloadUrl
|
||||
});
|
||||
}
|
||||
}
|
||||
//prodInfo.detail.galleries.RemoveAll(g => g.type == 6); // 视频暂时移除,以后再视情况加上
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Product.Publish.Steps.Wx;
|
||||
|
||||
public class WXPublishContext : PublishContextBase
|
||||
{
|
||||
public IProgress<string> Progress { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Store.Product.Publish.Steps.Wx;
|
||||
|
||||
public class WXPublishPipeline : PublishPipeline<WXPublishContext>
|
||||
{
|
||||
public WXPublishPipeline(IEnumerable<IPublishStep<WXPublishContext>> steps) : base(steps)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 微信商品上传步骤顺序,来源于 WXDBProdUploadForm.UploadProduct 的原有执行顺序。
|
||||
/// </summary>
|
||||
public static class WxProductPublishPipelineFactory
|
||||
{
|
||||
public static WXPublishPipeline CreateDefault()
|
||||
{
|
||||
return new WXPublishPipeline(
|
||||
[
|
||||
new InitializeUploadProductStep(),//初始化上传参数与店铺登录校验
|
||||
new FissionTitleStep(),//裂变标题
|
||||
new SkipUploadedProductStep(),//跳过已上传商品
|
||||
new CommissionPreparationStep(),//佣金上传准备
|
||||
new ConvertJstPddProductStep(),//聚水潭商品转换为PDD统一格式
|
||||
new RestoreWxShopSourceProductStep(),//微信店采原始格式还原
|
||||
new ConvertWxShopProductStep(),//微信店采格式转换
|
||||
new ConvertWxRecycleProductStep(),//微信回采格式转换
|
||||
new ConvertWxAppProductStep(),//微信小店App格式转换
|
||||
new Convert1688ProductStep(),//1688商品格式转换
|
||||
new ConvertCloudProductStep(),//云端商品格式转换
|
||||
new InitializeProductDataStep(),//初始化微信小店商品参数
|
||||
new PrepareHotlinkImageMapStep(),//生成图片盗链映射
|
||||
new PrepareSourceProductStep(),//提取源商品详情并生成SKU货号
|
||||
new UploadVideoStep(),//上传商品视频
|
||||
new FillMainImagesStep(),//主图不足时使用详情图补充
|
||||
new FilterDuplicateImagesStep(),//过滤重复图片
|
||||
new GetShopApiTokenStep(),//获取店铺ApiToken
|
||||
new SetProductTitleStep(),//设置商品标题
|
||||
new SetProductExtCodeStep(),//设置商品货号
|
||||
new UploadMainImagesStep(),//上传主图
|
||||
new SaveMainImageHotlinkMapStep(),//保存主图盗链映射
|
||||
new DetectCategoryStep(),//识别商品类目
|
||||
new GenerateCategoryTemplateStep(),//生成类目模板
|
||||
new GenerateAiShortTitleStep(),//生成AI短标题
|
||||
new AddTitlePrefixStep(),//添加标题前缀
|
||||
new SetAfterSaleInfoStep(),//设置售后信息
|
||||
new CalculateShippingTemplateStep(),//获取推单运费模板并计算运费
|
||||
new GetShopShippingTemplateStep(),//获取店铺运费模板
|
||||
new UploadDetailImagesStep(),//上传详情图
|
||||
new SaveDetailImageHotlinkMapStep(),//保存详情图盗链映射
|
||||
new MatchProductPropertiesStep(),//匹配产品属性
|
||||
new BuildSkuPropertiesStep(),//构建SKU规格属性
|
||||
new SaveSkuHotlinkMapStep(),//保存SKU图片盗链映射
|
||||
new BuildSkuInfoStep(),//构建SKU信息
|
||||
new SetPreSaleInfoStep(),//设置预售信息
|
||||
new SetCommissionInfoStep(),//设置佣金信息
|
||||
new SetQualificationsAndTagImagesStep(),//资质信息(含书籍、食品、成人用品标签图)
|
||||
new GenerateAiProductImageStep(),//AI生成商品裂变图片
|
||||
new AddRandomImageBorderStep(),//为图片添加随机外框
|
||||
new SubmitProductDraftStep(),//保存商品草稿
|
||||
new SaveDraftHotlinkMapStep(),//保存草稿商品盗链映射
|
||||
new SubmitProductStep(),//提交商品上架
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
using AllBase;
|
||||
using AllBase.Extension;
|
||||
using AllBase.Helper;
|
||||
using AllBase.Model.DBModel;
|
||||
using AllBase.Model.Param.WXParam;
|
||||
using AllBase.Model.Result;
|
||||
using AllBase.Model.Result.PDDResult;
|
||||
using AllBase.Model.Result.WXResult;
|
||||
using MAX.Core.DependencyInjection;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Store.Management.Framework.Apis;
|
||||
using Store.Product.Models.PublishParameters.Wx;
|
||||
using Store.Product.Publish;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Store.Product.Publish.Steps.Wx;
|
||||
|
||||
/// <summary>
|
||||
/// 微信商品发布步骤基类。
|
||||
/// 该基类把原窗体方法的可变状态、控件快照和窗体能力适配集中到一个入口,
|
||||
/// 让各 Step 尽量保持与原 UploadProduct 区段一致的代码,便于逐段核对。
|
||||
/// </summary>
|
||||
public abstract class WxProductPublishStepBase : PublishStep<WXPublishContext>
|
||||
{
|
||||
protected WXApi WXApi => LazyServiceProvider.Instance.LazyGetService<WXApi>();
|
||||
|
||||
|
||||
private PublishContextBase _context;
|
||||
|
||||
protected WxProductUploadParam Upload => _context.WxUpload;
|
||||
protected WxProductPublishState State => Upload.State;
|
||||
protected WxProductUploadOptions Options => Upload.Options;
|
||||
protected WxProductUploadFormState Form => Options.Form;
|
||||
protected dynamic RuntimeHost => Upload.Runtime.Host;
|
||||
|
||||
protected ShopLoginInfo shop => Upload.Source.Shop;
|
||||
protected KJDDBProduct dbProd => Upload.Source.DbProduct;
|
||||
protected TemuDBProductSelect selectProd => Upload.Source.SelectProduct;
|
||||
protected DateTime startTime => Upload.Source.StartTime;
|
||||
protected WXUploadProductInitParam upProdInitParam => Upload.InitParameter;
|
||||
protected WXUploadProductParam upProdParam => Upload.ProductParameter;
|
||||
|
||||
// TODO(迁移): cell/cancellationTokenSource 原为 WinForms 对象,这里通过代理回调保持步骤代码形状。
|
||||
protected dynamic cell => Upload.Runtime.Cell;
|
||||
protected dynamic cancellationTokenSource => Upload.Runtime.CancellationTokenSource;
|
||||
|
||||
protected dynamic chkFissionGoodsName => Form.chkFissionGoodsName;
|
||||
protected dynamic txtFissionTitle => Form.txtFissionTitle;
|
||||
protected dynamic chkSkipUploaded => Form.chkSkipUploaded;
|
||||
protected dynamic chkCommission => Form.chkCommission;
|
||||
protected dynamic cmbCommissionAddOrReduce => Form.cmbCommissionAddOrReduce;
|
||||
protected dynamic txtCommissionChangeValue => Form.txtCommissionChangeValue;
|
||||
protected dynamic txtMinUpCommission => Form.txtMinUpCommission;
|
||||
protected dynamic txtMaxUpCommission => Form.txtMaxUpCommission;
|
||||
protected dynamic chkImgRandomBlock => Form.chkImgRandomBlock;
|
||||
protected dynamic chkRandomMainImgOrder => Form.chkRandomMainImgOrder;
|
||||
protected dynamic chkRandomDetailImgOrder => Form.chkRandomDetailImgOrder;
|
||||
protected dynamic chkFissionRandomPriceChange => Form.chkFissionRandomPriceChange;
|
||||
protected dynamic txtFissionRandomPriceChange => Form.txtFissionRandomPriceChange;
|
||||
protected dynamic chkHighestPriceSku => Form.chkHighestPriceSku;
|
||||
protected dynamic chkLowestPriceSku => Form.chkLowestPriceSku;
|
||||
protected dynamic chkSameSpecPriceUp => Form.chkSameSpecPriceUp;
|
||||
protected dynamic chkSameSpecPriceDown => Form.chkSameSpecPriceDown;
|
||||
protected dynamic txtMinPrice => Form.txtMinPrice;
|
||||
protected dynamic txtMaxPrice => Form.txtMaxPrice;
|
||||
protected dynamic txtReplaceText => Form.txtReplaceText;
|
||||
protected dynamic chkSkipReplaceText => Form.chkSkipReplaceText;
|
||||
protected dynamic chkRemoveSpecialChar => Form.chkRemoveSpecialChar;
|
||||
protected dynamic chkUseWXComplateProd => Form.chkUseWXComplateProd;
|
||||
protected dynamic chkUseRecommand => Form.chkUseRecommand;
|
||||
protected dynamic cmbSpBrandName => Form.cmbSpBrandName;
|
||||
protected dynamic txtFilterBoundMax => Form.txtFilterBoundMax;
|
||||
protected dynamic txtFilterBoundMin => Form.txtFilterBoundMin;
|
||||
protected dynamic txtMainBorderImgCount => Form.txtMainBorderImgCount;
|
||||
protected dynamic txtDetailBorderImgCount => Form.txtDetailBorderImgCount;
|
||||
protected dynamic chkRandomImgBorder => Form.chkRandomImgBorder;
|
||||
protected dynamic chkAiImage => Form.chkAiImage;
|
||||
protected dynamic txtAiImgCount => Form.txtAiImgCount;
|
||||
protected dynamic chkFreightInsurance => Form.chkFreightInsurance;
|
||||
protected dynamic chkUseShanghaiReturnOrderAddress => Form.chkUseShanghaiReturnOrderAddress;
|
||||
protected dynamic chkPreSale => Form.chkPreSale;
|
||||
protected dynamic chkDefaultBestBefore => Form.chkDefaultBestBefore;
|
||||
protected dynamic txtDefaultBestBefore => Form.txtDefaultBestBefore;
|
||||
protected dynamic chkTestNoAuditUpload => Form.chkTestNoAuditUpload;
|
||||
protected dynamic chkUpDraft => Form.chkUpDraft;
|
||||
protected dynamic chkIsSubmitSuccess => Form.chkIsSubmitSuccess;
|
||||
protected dynamic dgvShop => Form.dgvShop;
|
||||
|
||||
protected int commissionRate { get => State.CommissionRate; set => State.CommissionRate = value; }
|
||||
protected int minCommissionRate { get => State.MinCommissionRate; set => State.MinCommissionRate = value; }
|
||||
protected int maxCommissionRate { get => State.MaxCommissionRate; set => State.MaxCommissionRate = value; }
|
||||
protected int commissionRateChange { get => State.CommissionRateChange; set => State.CommissionRateChange = value; }
|
||||
protected int? fromCommissionRate { get => State.FromCommissionRate; set => State.FromCommissionRate = value; }
|
||||
protected WXGetEditProductInfoLite wxEditProdInfo { get => State.WxEditProdInfo; set => State.WxEditProdInfo = value; }
|
||||
protected JObject prodJObj { get => State.ProdJObject; set => State.ProdJObject = value; }
|
||||
protected bool isChangeImgDic { get => State.IsChangeImgDic; set => State.IsChangeImgDic = value; }
|
||||
protected Dictionary<string, string> wxImgMapDic { get => State.WxImgMapDic; set => State.WxImgMapDic = value; }
|
||||
protected PDDProductInfo prodInfo { get => State.ProdInfo; set => State.ProdInfo = value; }
|
||||
protected int mainImgCount { get => State.MainImgCount; set => State.MainImgCount = value; }
|
||||
protected bool needAddRandomBlock { get => State.NeedAddRandomBlock; set => State.NeedAddRandomBlock = value; }
|
||||
protected bool wantAddRandomBlock { get => State.WantAddRandomBlock; set => State.WantAddRandomBlock = value; }
|
||||
protected WXShopTokenInfo token { get => State.Token; set => State.Token = value; }
|
||||
protected string prodTitle { get => State.ProdTitle; set => State.ProdTitle = value; }
|
||||
protected string extCode { get => State.ExtCode; set => State.ExtCode = value; }
|
||||
protected List<gallery_item> mainGalleries { get => State.MainGalleries; set => State.MainGalleries = value; }
|
||||
protected List<long> aiCateIdLst { get => State.AiCateIdLst; set => State.AiCateIdLst = value; }
|
||||
protected string getCateRst { get => State.GetCateRst; set => State.GetCateRst = value; }
|
||||
protected JObject jCateRst { get => State.JCateRst; set => State.JCateRst = value; }
|
||||
protected long leafCatId { get => State.LeafCatId; set => State.LeafCatId = value; }
|
||||
protected WxCatBoundInfo bound { get => State.Bound; set => State.Bound = value; }
|
||||
protected int maxBount { get => State.MaxBound; set => State.MaxBound = value; }
|
||||
protected int minBount { get => State.MinBound; set => State.MinBound = value; }
|
||||
protected string spBrandId { get => State.SpBrandId; set => State.SpBrandId = value; }
|
||||
protected string spBrandName { get => State.SpBrandName; set => State.SpBrandName = value; }
|
||||
protected string shippingTemplateJson { get => State.ShippingTemplateJson; set => State.ShippingTemplateJson = value; }
|
||||
protected int shipPrice { get => State.ShipPrice; set => State.ShipPrice = value; }
|
||||
protected string expressRst { get => State.ExpressRst; set => State.ExpressRst = value; }
|
||||
protected List<gallery_item> detailGalleries { get => State.DetailGalleries; set => State.DetailGalleries = value; }
|
||||
protected WXUploadProductInfoRecommendParam recommendParamRst { get => State.RecommendParamRst; set => State.RecommendParamRst = value; }
|
||||
protected allAttrParam productAttr { get => State.ProductAttr; set => State.ProductAttr = value; }
|
||||
protected int maxSkuSpecCnt { get => State.MaxSkuSpecCnt; set => State.MaxSkuSpecCnt = value; }
|
||||
protected int skuIndex { get => State.SkuIndex; set => State.SkuIndex = value; }
|
||||
protected int id { get => State.Id; set => State.Id = value; }
|
||||
protected long catId { get => State.CatId; set => State.CatId = value; }
|
||||
protected long fCatId { get => State.FCatId; set => State.FCatId = value; }
|
||||
protected long valueCatId { get => State.ValueCatId; set => State.ValueCatId = value; }
|
||||
protected Dictionary<string, long> dicSpecParentNameId { get => State.DicSpecParentNameId; set => State.DicSpecParentNameId = value; }
|
||||
protected Dictionary<string, long> dicSpecParentNameCatId { get => State.DicSpecParentNameCatId; set => State.DicSpecParentNameCatId = value; }
|
||||
protected Dictionary<string, long> dicSpecNamefCatId { get => State.DicSpecNameFCatId; set => State.DicSpecNameFCatId = value; }
|
||||
protected Dictionary<string, long> dicSpecNameCatId { get => State.DicSpecNameCatId; set => State.DicSpecNameCatId = value; }
|
||||
protected string uploadDraftRst { get => State.UploadDraftRst; set => State.UploadDraftRst = value; }
|
||||
protected string commissionRstStr { get => State.CommissionRstStr; set => State.CommissionRstStr = value; }
|
||||
protected string DefaultAdultBrandId { get => State.DefaultAdultBrandId; set => State.DefaultAdultBrandId = value; }
|
||||
protected bool IsWxNotUseSoftwareDefaultAddressOnce { get => State.IsWxNotUseSoftwareDefaultAddressOnce; set => State.IsWxNotUseSoftwareDefaultAddressOnce = value; }
|
||||
protected List<WXShopTokenInfo> lstWXShopTokenInfo { get => State.WxShopTokenInfoList; set => State.WxShopTokenInfoList = value; }
|
||||
protected List<wx_qualification_image_info> lstQulificationImage { get => State.QualificationImages; set => State.QualificationImages = value; }
|
||||
protected List<string> forceFilteKeyWords { get => State.ForceFilterKeywords; set => State.ForceFilterKeywords = value; }
|
||||
protected dynamic lstAddPriceRule => State.AddPriceRules;
|
||||
protected dynamic wxUploadRule => State.WxUploadRule;
|
||||
protected string pdd_product_cates { get => State.PddProductCates; set => State.PddProductCates = value; }
|
||||
protected dynamic upload_draft_product_lst => State.UploadDraftProductList;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 正常结束发布流程(例如提交成功、指定上传到草稿箱)时写入最终结果并停止后续步骤。
|
||||
/// 失败场景请直接抛出异常。
|
||||
/// </summary>
|
||||
protected void StopWithResult(string result)
|
||||
{
|
||||
Upload.Result = result;
|
||||
Upload.IsCompleted = true;
|
||||
}
|
||||
|
||||
protected void Invoke(Action action)
|
||||
{
|
||||
action?.Invoke();
|
||||
}
|
||||
|
||||
protected string UploadImg(ShopLoginInfo shopInfo, string imgUrl, object cellState = null, bool randomBlock = false)
|
||||
{
|
||||
return Upload.Runtime.UploadImgByUrl?.Invoke(shopInfo, imgUrl, cellState ?? cell, randomBlock) ?? "";
|
||||
}
|
||||
|
||||
protected string UploadImg(ShopLoginInfo shopInfo, Bitmap image, object cellState = null)
|
||||
{
|
||||
return Upload.Runtime.UploadImgByBitmap?.Invoke(shopInfo, image, cellState ?? cell) ?? "";
|
||||
}
|
||||
|
||||
protected string GetImgBase64ForApi(out string errorMsg, string imgUrl, bool needAddRandomBlock, bool wantAddRandomBlock,
|
||||
int imgWidth = 0, int imgHeight = 0, bool wantAddRandomBorder = false)
|
||||
{
|
||||
if (Upload.Runtime.GetImgBase64ForApi == null)
|
||||
{
|
||||
errorMsg = "GetImgBase64ForApi 尚未从窗体映射到新上下文";
|
||||
return "";
|
||||
}
|
||||
|
||||
return Upload.Runtime.GetImgBase64ForApi(out errorMsg, imgUrl, needAddRandomBlock, wantAddRandomBlock, imgWidth, imgHeight, wantAddRandomBorder);
|
||||
}
|
||||
|
||||
protected string GetAiImg(string imgUrl, string imgWord)
|
||||
{
|
||||
return Upload.Runtime.GetAiImg?.Invoke(imgUrl, imgWord) ?? "";
|
||||
}
|
||||
|
||||
protected static string GetNewExtCode(string spuId)
|
||||
{
|
||||
if (spuId.IsNullOrEmpty())
|
||||
throw new Exception("货号指定失败,值不能为空!");
|
||||
if (!spuId.StartsWith("P1-"))
|
||||
return "P1-" + spuId;
|
||||
return spuId;
|
||||
}
|
||||
|
||||
protected static string GetEC1ExtCode(string spuId)
|
||||
{
|
||||
if (spuId.IsNullOrEmpty())
|
||||
throw new Exception("货号指定失败,值不能为空!");
|
||||
if (!spuId.StartsWith("EC1") && !spuId.EndsWith("A"))
|
||||
return "EC1" + spuId + "A";
|
||||
return spuId;
|
||||
}
|
||||
|
||||
// TODO(迁移): 以下两个窗体私有方法的真实实现仍留在 WXDBProdUploadForm,后续应迁到对应服务。
|
||||
protected virtual void btnLoginAssistant_Click(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException("请把 WXDBProdUploadForm.btnLoginAssistant_Click 的实现迁入微信发布运行时适配。");
|
||||
}
|
||||
|
||||
protected virtual WXGetEditProductInfoLite GetProductWXComplate(string secretSpuId, out string errMsg)
|
||||
{
|
||||
errMsg = "GetProductWXComplate 尚未迁移";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
|
||||
<ProjectReference Include="..\AllBase\AllBase.csproj" />
|
||||
<ProjectReference Include="..\Store.Management.Framework\Store.Management.Framework.csproj" />
|
||||
<ProjectReference Include="..\Work\Work.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in new issue
Block a user