增加 导入外部微信数据
This commit is contained in:
1 parent
5ed558e343
commit
a9f7b1f831
13 files changed
+2088
-1589
No files matched your search
@@ -235,6 +235,7 @@
|
||||
<Compile Include="Model\Result\PDDResult\PDDFrontProductInfo3.cs" />
|
||||
<Compile Include="Model\Result\PDDResult\PDDFrontProductInfo5.cs" />
|
||||
<Compile Include="Model\Result\PDDResult\PDDFrontProductInfo4.cs" />
|
||||
<Compile Include="Model\Result\PlatformType.cs" />
|
||||
<Compile Include="Model\Result\VDianShopLoginInfo.cs" />
|
||||
<Compile Include="Model\Result\WXResult\DSRShopScoreInfo.cs" />
|
||||
<Compile Include="Model\Result\WXResult\WxActivityData.cs" />
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace AllBase.Model.Result.PDDResult
|
||||
{
|
||||
public class PDDFrontProductInfo5
|
||||
{
|
||||
public PlatformType Platform { get; set; }
|
||||
[Description("商品编号")]
|
||||
public long GoodsId { get; set; }
|
||||
|
||||
|
||||
@@ -4,10 +4,11 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TemuKJD.BLL
|
||||
namespace AllBase.Model.Result
|
||||
{
|
||||
public enum PlatformType
|
||||
{
|
||||
None,
|
||||
PDD,
|
||||
WX,
|
||||
}
|
||||
@@ -13,15 +13,17 @@ namespace TemuKJD.BLL.ImportConverts
|
||||
private static List<IGoodsConverter> _converters = new List<IGoodsConverter>
|
||||
{
|
||||
new ConverterToPddV5(),
|
||||
new ConverterWXToPddV1(),
|
||||
};
|
||||
public static PDDFrontProductInfo5 Convert(string data)
|
||||
public static PDDFrontProductInfo5 Convert(string filePath)
|
||||
{
|
||||
|
||||
foreach (var item in _converters)
|
||||
foreach (IGoodsConverter item in _converters)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (item.IsMatch(data))
|
||||
item.ReadContent(filePath);
|
||||
if (item.IsMatch())
|
||||
{
|
||||
return item.Convert();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AllBase.Model.Result.PDDResult;
|
||||
using AllBase.Model.Result;
|
||||
using AllBase.Model.Result.PDDResult;
|
||||
using CefSharp.DevTools.CSS;
|
||||
using NaiBa.Util.Extension;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@@ -0,0 +1,314 @@
|
||||
using AllBase.Model.Result;
|
||||
using AllBase.Model.Result.PDDResult;
|
||||
using NaiBa.Util.Extension;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TemuKJD.BLL.ImportConverters
|
||||
{
|
||||
internal class ConverterWXToPddV1 : GoodsConverterBase
|
||||
{
|
||||
private JObject jsonRoot;
|
||||
|
||||
public override string ConverterName => "微信转拼多多数据源";
|
||||
|
||||
public override PlatformType Platform => PlatformType.WX;
|
||||
|
||||
|
||||
protected override bool IsMatchProvider()
|
||||
{
|
||||
try
|
||||
{
|
||||
jsonRoot = JsonConvert.DeserializeObject<JObject>(RawData);
|
||||
if (jsonRoot == null) return false;
|
||||
|
||||
// 1. 检查 extra_service 是否存在且为对象类型
|
||||
var extraService = jsonRoot.SelectToken("$.extra_service");
|
||||
if (extraService == null || extraService.Type != JTokenType.Object) return false;
|
||||
|
||||
// 2. 检查 out_product_id 是否存在且为字符串类型(非空)
|
||||
var outProductId = jsonRoot.SelectToken("$.out_product_id")?.ToString();
|
||||
if (string.IsNullOrEmpty(outProductId)) return false;
|
||||
|
||||
// 3. 检查 skus 是否存在且为数组,且第一个元素包含 out_sku_id
|
||||
var skus = jsonRoot.SelectToken("$.skus");
|
||||
if (skus == null) return true;
|
||||
if (skus.Type != JTokenType.Array) return false;
|
||||
var skusArray = skus as JArray;
|
||||
if (skusArray.Count == 0) return true;
|
||||
|
||||
var outSkuId = skusArray[0]?.SelectToken("$.out_sku_id")?.ToString();
|
||||
if (string.IsNullOrEmpty(outSkuId)) return false;
|
||||
|
||||
// 三个条件全部通过
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
protected override PDDFrontProductInfo5 ConverterProvider()
|
||||
{
|
||||
var product = new PDDFrontProductInfo5();
|
||||
|
||||
product.Platform = Platform;
|
||||
// 解析JSON数据
|
||||
var jsonData = JsonConvert.DeserializeObject<JObject>(RawData);
|
||||
product.GoodsId = Path.GetFileNameWithoutExtension(FilePath).ParseToLong();
|
||||
// 商品基本信息
|
||||
product.Title = jsonData["title"]?.Value<string>() ?? "";
|
||||
product.Description = jsonData["short_title"]?.Value<string>() ?? "";
|
||||
|
||||
// 品牌ID - 转换为long
|
||||
product.BrandId = jsonData["brand_id"]?.Value<long>() ?? 0;
|
||||
|
||||
// 类目信息
|
||||
product.CategoryId = GetCategoryIdFromCats(jsonData);
|
||||
product.CategoryPath = GetCategoryPathFromCats(jsonData);
|
||||
|
||||
// 主图
|
||||
product.MainImages = GetMainImagesFromNewFormat(jsonData);
|
||||
|
||||
// 详情图
|
||||
product.DetailImages = GetDetailImagesFromNewFormat(jsonData);
|
||||
|
||||
// 商品属性
|
||||
product.Propertys = GetPropertiesFromNewFormat(jsonData);
|
||||
|
||||
// SKU和规格信息
|
||||
product.Skus = GetSkusFromNewFormat(jsonData);
|
||||
product.Specs = GetSpecsFromNewFormat(jsonData);
|
||||
|
||||
// 其他默认值
|
||||
product.ThumbUrl = jsonData["head_imgs"]?[0]?.Value<string>() ?? "";
|
||||
product.MallId = 0; // 新格式中没有mallID
|
||||
product.Price = GetMinPrice(jsonData); // 从SKU中获取最低价
|
||||
product.Videos = new List<string>(); // 新格式中没有视频信息
|
||||
|
||||
return product;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 从cats_v2中获取类目ID
|
||||
/// </summary>
|
||||
private int GetCategoryIdFromCats(JObject jsonData)
|
||||
{
|
||||
var cats = jsonData["cats_v2"] as JArray;
|
||||
if (cats == null || cats.Count == 0)
|
||||
return 0;
|
||||
|
||||
// 获取最后一个类目(最细分类目)
|
||||
var lastCat = cats.Last;
|
||||
return lastCat?["cat_id"]?.Value<int>() ?? 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从cats_v2中获取类目路径
|
||||
/// </summary>
|
||||
private List<int> GetCategoryPathFromCats(JObject jsonData)
|
||||
{
|
||||
var result = new List<int>();
|
||||
var cats = jsonData["cats_v2"] as JArray;
|
||||
|
||||
if (cats == null)
|
||||
return result;
|
||||
|
||||
foreach (var cat in cats)
|
||||
{
|
||||
var catId = cat["cat_id"]?.Value<int>();
|
||||
if (catId.HasValue && catId.Value > 0)
|
||||
result.Add(catId.Value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取主图(新格式)
|
||||
/// </summary>
|
||||
private List<string> GetMainImagesFromNewFormat(JObject jsonData)
|
||||
{
|
||||
var result = new List<string>();
|
||||
var headImgs = jsonData["head_imgs"] as JArray;
|
||||
|
||||
if (headImgs == null)
|
||||
return result;
|
||||
|
||||
foreach (var img in headImgs)
|
||||
{
|
||||
var url = img?.Value<string>();
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
result.Add(url);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取详情图(新格式)
|
||||
/// </summary>
|
||||
private List<string> GetDetailImagesFromNewFormat(JObject jsonData)
|
||||
{
|
||||
var result = new List<string>();
|
||||
var descInfo = jsonData["desc_info"];
|
||||
|
||||
if (descInfo == null)
|
||||
return result;
|
||||
|
||||
var imgs = descInfo["imgs"] as JArray;
|
||||
if (imgs == null)
|
||||
return result;
|
||||
|
||||
foreach (var img in imgs)
|
||||
{
|
||||
var url = img?.Value<string>();
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
result.Add(url);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品属性(新格式)
|
||||
/// </summary>
|
||||
private List<Property> GetPropertiesFromNewFormat(JObject jsonData)
|
||||
{
|
||||
var result = new List<Property>();
|
||||
var attrs = jsonData["attrs"] as JArray;
|
||||
|
||||
if (attrs == null)
|
||||
return result;
|
||||
|
||||
foreach (var attr in attrs)
|
||||
{
|
||||
var key = attr["attr_key"]?.Value<string>();
|
||||
var value = attr["attr_value"]?.Value<string>();
|
||||
|
||||
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
|
||||
{
|
||||
result.Add(new Property
|
||||
{
|
||||
Key = key,
|
||||
Value = value
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取SKU(新格式)
|
||||
/// </summary>
|
||||
private List<SkuItem> GetSkusFromNewFormat(JObject jsonData)
|
||||
{
|
||||
var result = new List<SkuItem>();
|
||||
var skus = jsonData["skus"] as JArray;
|
||||
|
||||
if (skus == null)
|
||||
return result;
|
||||
|
||||
foreach (var sku in skus)
|
||||
{
|
||||
var skuAttrs = sku["sku_attrs"] as JArray;
|
||||
var specValues = new List<string>();
|
||||
|
||||
if (skuAttrs != null)
|
||||
{
|
||||
foreach (var attr in skuAttrs)
|
||||
{
|
||||
var key = attr["attr_key"]?.Value<string>();
|
||||
var value = attr["attr_value"]?.Value<string>();
|
||||
|
||||
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
|
||||
specValues.Add($"{key}:{value}");
|
||||
}
|
||||
}
|
||||
|
||||
// sale_price 是分,需要转换为元
|
||||
var salePriceInCents = sku["sale_price"]?.Value<decimal>() ?? 0;
|
||||
var salePriceInYuan = salePriceInCents / 100;
|
||||
|
||||
result.Add(new SkuItem
|
||||
{
|
||||
SkuId = sku["out_sku_id"]?.Value<string>() ?? "",
|
||||
Spec = string.Join(";", specValues),
|
||||
Price = salePriceInYuan,
|
||||
OriginalPrice = salePriceInCents.ToString(), // 保留原始价格(分)
|
||||
Stock = 999, // 新格式中没有库存,设置默认值
|
||||
SpecImage = sku["thumb_img"]?.Value<string>() ?? ""
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取规格(新格式)
|
||||
/// </summary>
|
||||
private List<SpecItem> GetSpecsFromNewFormat(JObject jsonData)
|
||||
{
|
||||
var result = new List<SpecItem>();
|
||||
var skus = jsonData["skus"] as JArray;
|
||||
|
||||
if (skus == null)
|
||||
return result;
|
||||
|
||||
foreach (var sku in skus)
|
||||
{
|
||||
var skuAttrs = sku["sku_attrs"] as JArray;
|
||||
if (skuAttrs == null)
|
||||
continue;
|
||||
|
||||
foreach (var attr in skuAttrs)
|
||||
{
|
||||
var specKey = attr["attr_key"]?.Value<string>() ?? "";
|
||||
var specValue = attr["attr_value"]?.Value<string>() ?? "";
|
||||
|
||||
// 去重
|
||||
if (result.Any(x => x.SpecKey == specKey && x.SpecValue == specValue))
|
||||
continue;
|
||||
|
||||
result.Add(new SpecItem
|
||||
{
|
||||
SpecKey = specKey,
|
||||
SpecValue = specValue,
|
||||
SpecKeyId = 0, // 新格式中没有ID
|
||||
SpecValueId = 0
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取最低价格
|
||||
/// </summary>
|
||||
private decimal GetMinPrice(JObject jsonData)
|
||||
{
|
||||
var skus = jsonData["skus"] as JArray;
|
||||
if (skus == null || skus.Count == 0)
|
||||
return 0;
|
||||
|
||||
var minPrice = decimal.MaxValue;
|
||||
foreach (var sku in skus)
|
||||
{
|
||||
var price = sku["sale_price"]?.Value<decimal>() ?? 0;
|
||||
if (price > 0 && price < minPrice)
|
||||
minPrice = price;
|
||||
}
|
||||
|
||||
return minPrice > 0 ? minPrice / 100 : 0; // 转换为元
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
using AllBase.Model.Result.PDDResult;
|
||||
using AllBase.Model.Result;
|
||||
using AllBase.Model.Result.PDDResult;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace TemuKJD.BLL.ImportConverters
|
||||
{
|
||||
@@ -29,10 +32,15 @@ namespace TemuKJD.BLL.ImportConverters
|
||||
/// </summary>
|
||||
PlatformType Platform { get; }
|
||||
/// <summary>
|
||||
/// 读取内容
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
void ReadContent(string filePath);
|
||||
/// <summary>
|
||||
/// 判断是否匹配当前转换器
|
||||
/// </summary>
|
||||
/// <returns>是否匹配</returns>
|
||||
bool IsMatch(string data);
|
||||
bool IsMatch();
|
||||
|
||||
/// <summary>
|
||||
/// 转换为标准商品模型
|
||||
@@ -43,15 +51,29 @@ namespace TemuKJD.BLL.ImportConverters
|
||||
public abstract class GoodsConverterBase : IGoodsConverter
|
||||
{
|
||||
private bool _isMatch = false;
|
||||
public string FilePath { get; private set; }
|
||||
public string RawData { get; private set; }
|
||||
public abstract string ConverterName { get; }
|
||||
public abstract PlatformType Platform { get; }
|
||||
|
||||
void IGoodsConverter.ReadContent(string filePath)
|
||||
{
|
||||
ReadContent(filePath);
|
||||
}
|
||||
protected virtual void ReadContent(string filePath)
|
||||
{
|
||||
if (File.Exists(filePath) == false) throw new Exception("文件不存在");
|
||||
FilePath = filePath;
|
||||
using (StreamReader sr = new StreamReader(filePath, Work.Api.UploadPinduoduoMain.GetFileEncoding(filePath)))
|
||||
{
|
||||
RawData = sr.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsMatch(string data)
|
||||
|
||||
public virtual bool IsMatch()
|
||||
{
|
||||
_isMatch = true;
|
||||
RawData = data;
|
||||
return IsMatchProvider();
|
||||
}
|
||||
protected abstract bool IsMatchProvider();
|
||||
@@ -83,8 +105,5 @@ namespace TemuKJD.BLL.ImportConverters
|
||||
}
|
||||
|
||||
protected abstract PDDFrontProductInfo5 ConverterProvider();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -549,21 +549,21 @@ namespace TemuKJD.BLL
|
||||
width = 0,
|
||||
height = 0,
|
||||
});
|
||||
}
|
||||
else if (frontGallery.type==9 && !string.IsNullOrEmpty(frontGallery.video_url))
|
||||
{
|
||||
}
|
||||
else if (frontGallery.type == 9 && !string.IsNullOrEmpty(frontGallery.video_url))
|
||||
{
|
||||
//"url": "http://video3.yangkeduo.com/i1/2020-06-06/bec95fd51b79e5c572153f7cb923a1c3.mp4.0_0.p0.jpg",
|
||||
//"video_url": "https://video3.pddpic.com/i1/2020-06-06/bec95fd51b79e5c572153f7cb923a1c3.mp4.f30.mp4",
|
||||
|
||||
prodInfo.detail.galleries.Add(new gallery_item()
|
||||
{
|
||||
url = frontGallery.video_url,
|
||||
type = 6,
|
||||
width = 0,
|
||||
height = 0,
|
||||
});
|
||||
}
|
||||
else
|
||||
|
||||
prodInfo.detail.galleries.Add(new gallery_item()
|
||||
{
|
||||
url = frontGallery.video_url,
|
||||
type = 6,
|
||||
width = 0,
|
||||
height = 0,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
//string getImgError;
|
||||
//var image = GetHtml.GetUrlImg(frontGallery.url.Replace("https://", "http://"), out getImgError);
|
||||
@@ -1672,18 +1672,18 @@ namespace TemuKJD.BLL
|
||||
/// <param name="specialProdType"></param>
|
||||
/// <param name="IsCollectAuthorityUser"></param>
|
||||
/// <returns></returns>
|
||||
public string PddFrontToPddBackConvertFactory(string outProdJson, bool UpdateOldData = true, string specialProdType = null, bool IsCollectAuthorityUser = false)
|
||||
public string PddFrontToPddBackConvertFactory(string filePath, bool UpdateOldData = true, string specialProdType = null, bool IsCollectAuthorityUser = false)
|
||||
{
|
||||
PDDFrontProductInfo5 frontProdInfo = null;
|
||||
try
|
||||
{
|
||||
frontProdInfo = ConverterToPddFactory.Convert(outProdJson);
|
||||
frontProdInfo = ConverterToPddFactory.Convert(filePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "转换错误" + ex.Message;
|
||||
}
|
||||
|
||||
|
||||
if (frontProdInfo == null || frontProdInfo.GoodsId == null)
|
||||
{
|
||||
return "商品数据信息为空";
|
||||
@@ -2016,7 +2016,14 @@ namespace TemuKJD.BLL
|
||||
return "已存在相同id商品,跳过";
|
||||
}
|
||||
}
|
||||
string product_get_type = "多多外部数据";
|
||||
|
||||
switch (frontProdInfo.Platform)
|
||||
{
|
||||
case PlatformType.WX:
|
||||
product_get_type = "微信外部数据";
|
||||
break;
|
||||
}
|
||||
var data = Work.UserLogin.GetSignaturex() +
|
||||
"&from_shop_id=" + frontProdInfo.MallId +
|
||||
"&spu_id=" + prodInfo.detail.goods_id.ParseToString() + collectAuthorityTag +
|
||||
@@ -2033,7 +2040,8 @@ namespace TemuKJD.BLL
|
||||
"&main_img=" + HttpUtility.UrlEncode(dbProd.main_img, Encoding.UTF8) +
|
||||
"&sale_count=" + HttpUtility.UrlEncode(prodInfo.sale_count, Encoding.UTF8) +
|
||||
"&sale_count_text=" + HttpUtility.UrlEncode(prodInfo.sale_count_text, Encoding.UTF8) +
|
||||
"&product_get_type=" + HttpUtility.UrlEncode("多多外部数据", Encoding.UTF8);
|
||||
"&product_get_type=" + HttpUtility.UrlEncode(product_get_type, Encoding.UTF8);
|
||||
|
||||
if (!string.IsNullOrEmpty(specialProdType))
|
||||
data += "&special_prod_type=" + HttpUtility.UrlEncode(specialProdType, Encoding.UTF8);
|
||||
if (IsCollectAuthorityUser)
|
||||
|
||||
+1
-1
@@ -144,6 +144,7 @@
|
||||
</Compile>
|
||||
<Compile Include="BLL\AuthorBLL.cs" />
|
||||
<Compile Include="BLL\HttpResponseWxAiTalkBLL.cs" />
|
||||
<Compile Include="BLL\ImportConverters\ConverterWXToPddV1.cs" />
|
||||
<Compile Include="BLL\ImportConverters\ConvertToPddFactory.cs" />
|
||||
<Compile Include="BLL\ImportConverters\ConverterToPddV5.cs" />
|
||||
<Compile Include="BLL\ImportConverters\IGoodsConverter.cs" />
|
||||
@@ -152,7 +153,6 @@
|
||||
<Compile Include="BLL\Pdd\PddApiHelper.cs" />
|
||||
<Compile Include="BLL\Pdd\PddApi.cs" />
|
||||
<Compile Include="BLL\PDDProdFormConverter.cs" />
|
||||
<Compile Include="BLL\PlatformType.cs" />
|
||||
<Compile Include="BLL\ProductSelectBLL.cs" />
|
||||
<Compile Include="BLL\Tools\DownloadBLL.cs" />
|
||||
<Compile Include="BLL\VDian\VDianUpProdMappingApiBLL.cs" />
|
||||
|
||||
+1568
-1540
File diff suppressed because it is too large.
Load diff
@@ -16,6 +16,7 @@ using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
@@ -1122,7 +1123,7 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
|
||||
using (StreamReader sr = new StreamReader(path, Work.Api.UploadPinduoduoMain.GetFileEncoding(path)))
|
||||
{
|
||||
content = sourceContent = sr.ReadToEnd();
|
||||
content = sourceContent = sr.ReadToEnd();
|
||||
}
|
||||
|
||||
content = JsonHelper.SerializeObject(JsonHelper.JObjectParse(content));
|
||||
@@ -1152,7 +1153,7 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
}
|
||||
else
|
||||
{
|
||||
rst = new PDDProdFormConverter().PddFrontToPddBackConvertFactory(sourceContent, true, null, true);
|
||||
rst = new PDDProdFormConverter().PddFrontToPddBackConvertFactory(path, true, null, true);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -1185,6 +1186,53 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
bool isCollectAuthorityUser = true;
|
||||
Get1688ProductForm.Out1688ProductImport(isCollectAuthorityUser, this.statusBar, this.pbLoading, OutProdSaveDbCallBack);
|
||||
}
|
||||
private void bt_import_wx_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||
openFileDialog.Multiselect = true;
|
||||
// 设置过滤条件,只显示文本文件
|
||||
openFileDialog.Filter = "文本文件 (*.txt)|*.txt|All files (*.*)|*.*";
|
||||
// 显示对话框并获取结果
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
var filePathLst = openFileDialog.FileNames.ToList();
|
||||
int successNum = 0;
|
||||
int failedNum = 0;
|
||||
foreach (var filePath in filePathLst)
|
||||
{
|
||||
string sourceContent = "";
|
||||
string content = "";
|
||||
string rst = "商品未识别";
|
||||
try
|
||||
{
|
||||
rst = new PDDProdFormConverter().PddFrontToPddBackConvertFactory(filePath, true, null, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
rst = ex.Message;
|
||||
}
|
||||
if (string.IsNullOrEmpty(rst))
|
||||
successNum++;
|
||||
else
|
||||
failedNum++;
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1);
|
||||
this.statusBar.lblTaskStatus.Text = "正在导入,尝试导入" + (successNum + failedNum) + ",成功" + successNum + ",失败" + failedNum;
|
||||
}));
|
||||
}
|
||||
|
||||
SearchDbProd(1, " 导入完成,尝试导入" + (successNum + failedNum) + ",成功" + successNum + ",失败" + failedNum);
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
pbLoading.Visible = false;
|
||||
this.statusBar.lblTaskStatus.Text = "导入完成,尝试导入" + (successNum + failedNum) + ",成功" + successNum + ",失败" + failedNum;
|
||||
BaseMsgForm.ShowInfo("导入完成!");
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OutProdSaveDbCallBack(object msg)
|
||||
{
|
||||
@@ -1274,21 +1322,23 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
PDDDBProdListForm.GetPDDProductNotes(new List<ComboBox> { cmbBatchEditNotes }, addUserName);
|
||||
}
|
||||
|
||||
private void btnBatchEditCate_Click(object sender, EventArgs e)
|
||||
{
|
||||
var rows = dgvDbProduct.Rows.Cast<DataGridViewRow>().Where(row
|
||||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true);
|
||||
var prodIdList = rows.Select(r => r.Cells["col_spu_id"]?.Value.ToString()).ToList();
|
||||
var prodList = lstTemuDbProduct.Where(p => prodIdList.Contains(p.spu_id)).ToList();
|
||||
if (prodList.Count == 0)
|
||||
{
|
||||
BaseMsgForm.ShowError("请选择要修改类目的商品");
|
||||
return;
|
||||
}
|
||||
private void btnBatchEditCate_Click(object sender, EventArgs e)
|
||||
{
|
||||
var rows = dgvDbProduct.Rows.Cast<DataGridViewRow>().Where(row
|
||||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true);
|
||||
var prodIdList = rows.Select(r => r.Cells["col_spu_id"]?.Value.ToString()).ToList();
|
||||
var prodList = lstTemuDbProduct.Where(p => prodIdList.Contains(p.spu_id)).ToList();
|
||||
if (prodList.Count == 0)
|
||||
{
|
||||
BaseMsgForm.ShowError("请选择要修改类目的商品");
|
||||
return;
|
||||
}
|
||||
|
||||
WXUserCollectAuthProdEditCatesForm form = new WXUserCollectAuthProdEditCatesForm(prodList);
|
||||
WXUserCollectAuthProdEditCatesForm form = new WXUserCollectAuthProdEditCatesForm(prodList);
|
||||
form.ShowDialog();
|
||||
SearchDbProd(this.ucSplitPage1.CurrentPage);
|
||||
}
|
||||
}
|
||||
SearchDbProd(this.ucSplitPage1.CurrentPage);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using TemuKJD.BLL;
|
||||
using TemuKJD.BLL.ImportConverts;
|
||||
|
||||
namespace KJD.Test
|
||||
{
|
||||
@@ -13,7 +14,80 @@ namespace KJD.Test
|
||||
public void Test1()
|
||||
{
|
||||
string json = File.ReadAllText(@"C:\Users\chaih\Documents\xwechat_files\hongfei357_a567\msg\file\2026-08\850\531430339344.txt");
|
||||
new PDDProdFormConverter().PddFrontToPddBackConvertFactory(json);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWXToPDD()
|
||||
{
|
||||
string folderPath = @"C:\Users\chaih\Documents\xwechat_files\hongfei357_a567\msg\file\2026-08\破局(1)";
|
||||
if (!Directory.Exists(folderPath))
|
||||
{
|
||||
Console.WriteLine($"文件夹不存在: {folderPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取所有 txt 文件
|
||||
var txtFiles = Directory.GetFiles(folderPath, "*.txt", SearchOption.AllDirectories);
|
||||
|
||||
if (txtFiles.Length == 0)
|
||||
{
|
||||
Console.WriteLine("未找到任何 .txt 文件");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine($"共找到 {txtFiles.Length} 个 txt 文件,开始扫描...\n");
|
||||
Console.WriteLine(new string('-', 60));
|
||||
|
||||
var matchedFiles = new List<string>();
|
||||
var unmatchedFiles = new List<string>();
|
||||
var errorFiles = new List<string>();
|
||||
|
||||
foreach (var filePath in txtFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 读取文件内容
|
||||
var frontProdInfo = ConverterToPddFactory.Convert(filePath);
|
||||
var isMatch = frontProdInfo != null;
|
||||
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
string result = isMatch ? "✅ 匹配" : "❌ 不匹配";
|
||||
|
||||
Console.WriteLine($"[{result}] {fileName}");
|
||||
|
||||
if (isMatch)
|
||||
{
|
||||
matchedFiles.Add(fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
unmatchedFiles.Add(fileName);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
Console.WriteLine($"[⚠️ 读取失败] {fileName} - {ex.Message}");
|
||||
errorFiles.Add(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
// 输出统计结果
|
||||
Console.WriteLine(new string('-', 60));
|
||||
Console.WriteLine($"\n📊 扫描完成统计:");
|
||||
Console.WriteLine($" ✅ 匹配: {matchedFiles.Count} 个");
|
||||
Console.WriteLine($" ❌ 不匹配: {unmatchedFiles.Count} 个");
|
||||
Console.WriteLine($" ⚠️ 读取失败: {errorFiles.Count} 个");
|
||||
|
||||
if (matchedFiles.Count > 0)
|
||||
{
|
||||
Console.WriteLine($"\n📋 匹配文件列表:");
|
||||
foreach (var file in matchedFiles)
|
||||
{
|
||||
Console.WriteLine($" - {file}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user