From 7a07e172cd9a7ba06ca79174c5256f56717c393d Mon Sep 17 00:00:00 2001 From: chfei Date: Thu, 13 Aug 2026 16:26:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=96=E9=83=A8=E5=AF=BC=E5=85=A5pdd?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E3=80=82=E5=A2=9E=E5=8A=A0=20=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=B7=A5=E5=8E=82=E5=92=8C=20IgoodsConverter=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AllBase/AllBase.csproj | 1 + .../Result/PDDResult/PDDFrontProductInfo5.cs | 134 ++++++ .../ImportConverters/ConvertToPddFactory.cs | 38 ++ .../BLL/ImportConverters/ConverterToPddV5.cs | 315 ++++++++++++++ .../BLL/ImportConverters/IGoodsConverter.cs | 90 ++++ TEMUKJD/BLL/PDDProdFormConverter.cs | 390 +++++++++++++++++- TEMUKJD/BLL/PlatformType.cs | 14 + TEMUKJD/KJD.csproj | 4 + .../WXUserCollectAuthProdListForm.cs | 4 + 9 files changed, 989 insertions(+), 1 deletion(-) create mode 100644 AllBase/Model/Result/PDDResult/PDDFrontProductInfo5.cs create mode 100644 TEMUKJD/BLL/ImportConverters/ConvertToPddFactory.cs create mode 100644 TEMUKJD/BLL/ImportConverters/ConverterToPddV5.cs create mode 100644 TEMUKJD/BLL/ImportConverters/IGoodsConverter.cs create mode 100644 TEMUKJD/BLL/PlatformType.cs diff --git a/AllBase/AllBase.csproj b/AllBase/AllBase.csproj index a2fb324..b56fb3c 100644 --- a/AllBase/AllBase.csproj +++ b/AllBase/AllBase.csproj @@ -233,6 +233,7 @@ + diff --git a/AllBase/Model/Result/PDDResult/PDDFrontProductInfo5.cs b/AllBase/Model/Result/PDDResult/PDDFrontProductInfo5.cs new file mode 100644 index 0000000..56d527c --- /dev/null +++ b/AllBase/Model/Result/PDDResult/PDDFrontProductInfo5.cs @@ -0,0 +1,134 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data.SqlTypes; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace AllBase.Model.Result.PDDResult +{ + public class PDDFrontProductInfo5 + { + [Description("商品编号")] + public long GoodsId { get; set; } + + [Description("商品链接")] + public string GoodsUrl { get; set; } + [Description("品牌Id")] + public long BrandId { get; set; } + + [Description("标题")] + public string Title { get; set; } + + [Description("描述")] + public string Description { get; set; } + + [Description("视频链接")] + public string VideoUrl { get; set; } + + [Description("类目")] + public int CategoryId { get; set; } + [Description("所有类目")] + public List CategoryPath { get; set; } + + [Description("商铺Id")] + public int MallId { get; set; } + [Description("商铺Name")] + public string MallName { get; set; } + + [Description("属性")] + public List Propertys { get; set; } + [Description("缩略图")] + public string ThumbUrl { get; set; } + [Description("主图")] + public List MainImages { get; set; } + + [Description("详情图")] + public List DetailImages { get; set; } + [Description("视频")] + public List Videos { get; set; } + + [Description("规格")] + public List Specs { get; set; } + + [Description("价格与库存")] + public List Skus { get; set; } + [Description("价格")] + public decimal Price { get; set; } + [Description("最低价")] + public decimal MinPrice + { + get + { + return Skus?.Min(a => a.Price) ?? 0; + } + } + [Description("最高价")] + public decimal MaxPrice + { + get + { + return Skus?.Max(a => a.Price) ?? 0; + } + } + } + /// + /// 属性 + /// + public class Property + { + [Description("属性ID")] + public string Id { get; set; } + + [Description("属性Key")] + public string Key { get; set; } + + [Description("属性值")] + public string Value { get; set; } + } + + /// + /// 规格 + /// + public class SpecItem + { + [Description("规格KeyID")] + public long SpecKeyId { get; set; } + + [Description("规格键名")] + public string SpecKey { get; set; } + + [Description("规格值")] + public string SpecValue { get; set; } + [Description("规格值Id")] + public long SpecValueId { get; set; } + } + /// + /// SKU + /// + public class SkuItem + { + [Description("SKU编码")] + public string SkuId { get; set; } + [Description("规格值组合")] + public string Spec { get; set; } + + [Description("价格")] + public decimal Price { get; set; } + + [Description("原价")] + public string OriginalPrice { get; set; } + + [Description("库存")] + public int Stock { get; set; } + + [Description("规格图")] + public string SpecImage { get; set; } + } + + + +} diff --git a/TEMUKJD/BLL/ImportConverters/ConvertToPddFactory.cs b/TEMUKJD/BLL/ImportConverters/ConvertToPddFactory.cs new file mode 100644 index 0000000..ddff516 --- /dev/null +++ b/TEMUKJD/BLL/ImportConverters/ConvertToPddFactory.cs @@ -0,0 +1,38 @@ +using AllBase.Model.Result.PDDResult; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TemuKJD.BLL.ImportConverters; + +namespace TemuKJD.BLL.ImportConverts +{ + public class ConverterToPddFactory + { + private static List _converters = new List + { + new ConverterToPddV5(), + }; + public static PDDFrontProductInfo5 Convert(string data) + { + + foreach (var item in _converters) + { + try + { + if (item.IsMatch(data)) + { + return item.Convert(); + } + } + catch (Exception ex) + { + throw ex; + } + } + return null; + + } + } +} diff --git a/TEMUKJD/BLL/ImportConverters/ConverterToPddV5.cs b/TEMUKJD/BLL/ImportConverters/ConverterToPddV5.cs new file mode 100644 index 0000000..3bac6b4 --- /dev/null +++ b/TEMUKJD/BLL/ImportConverters/ConverterToPddV5.cs @@ -0,0 +1,315 @@ +using AllBase.Model.Result.PDDResult; +using CefSharp.DevTools.CSS; +using NaiBa.Util.Extension; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TemuKJD.BLL.ImportConverters; +using Work.GoodDetail; + +namespace TemuKJD.BLL.ImportConverts +{ + internal class ConverterToPddV5 : GoodsConverterBase + { + private JObject jsonRoot; + + + public override string ConverterName => "To PDD V5"; + + public override PlatformType Platform => PlatformType.PDD; + + protected override bool IsMatchProvider() + { + try + { + jsonRoot = JsonConvert.DeserializeObject(RawData); + return jsonRoot.SelectToken("$.store.initDataObj.goods") != null; + } + catch { return false; } + } + + protected override PDDFrontProductInfo5 ConverterProvider() + { + var goodsToken = jsonRoot.SelectToken("$.store.initDataObj.goods"); + var product = new PDDFrontProductInfo5(); + + // 逐个属性赋值,方便打断点调试 + product.GoodsId = goodsToken["goodsID"].Value(); + + product.GoodsUrl = ""; + + product.BrandId = goodsToken["brandId"].ParseToLong(); + + product.Title = goodsToken["goodsName"]?.Value(); + + product.Description = goodsToken["short_name"]?.Value() ?? ""; + + product.ThumbUrl = goodsToken["thumbUrl"]?.Value() ?? ""; + + product.CategoryId = goodsToken["catID"]?.Value() ?? 0; + + product.CategoryPath = GetCategoryPath(goodsToken); + + product.MallId = goodsToken["mallID"]?.Value() ?? 0; + + product.Price = goodsToken["linePrice"]?.Value() ?? 0; + + product.Propertys = GetProperties(goodsToken); + + product.MainImages = GetMainImages(goodsToken); + + product.DetailImages = GetDetailImages(goodsToken); + + product.Videos = GetVideos(goodsToken); + + product.Specs = GetSpecs(goodsToken); + + product.Skus = GetSkus(goodsToken); + + return product; + } + + /// + /// 获取类目路径 + /// + private List GetCategoryPath(JToken goods) + { + var result = new List(); + + // JSON 中有 catID1 ~ catID4 + for (int i = 1; i <= 4; i++) + { + var token = goods[$"catID{i}"]; + + if (token != null && token.Type != JTokenType.Null) + { + var value = token.Value(); + + if (value > 0) + result.Add(value); + } + } + + // 如果没有,则至少加入当前类目 + if (result.Count == 0) + { + var categoryId = goods["catID"]?.Value() ?? 0; + + if (categoryId > 0) + result.Add(categoryId); + } + + return result; + } + /// + /// 商品属性 + /// + private List GetProperties(JToken goods) + { + var result = new List(); + + var propertyArray = goods["goodsProperty"] as JArray; + + if (propertyArray == null) + return result; + + foreach (var item in propertyArray) + { + var key = item["key"]?.Value(); + + var values = item["values"] as JArray; + + result.Add(new Property + { + Key = key ?? "", + Value = string.Join(",", values?.Select(a => a)) + }); + } + + return result; + } + /// + /// 主图 + /// + private List GetMainImages(JToken goods) + { + var result = new List(); + + var images = goods["topGallery"] as JArray; + + if (images != null) + { + foreach (var item in images) + { + var url = item["url"]?.Value(); + + if (!string.IsNullOrEmpty(url)) + result.Add(url); + } + return result; + } + + images = goods["viewImageData"] as JArray; + if (images != null) + { + foreach (var item in images) + { + var url = item.ToString(); + + if (!string.IsNullOrEmpty(url)) + result.Add(url); + } + return result; + } + return result; + } + /// + /// 详情图 + /// + private List GetDetailImages(JToken goods) + { + var result = new List(); + + var images = goods["detailGallery"] as JArray; + + if (images == null) + return result; + + foreach (var item in images) + { + var url = item["url"]?.Value(); + + if (!string.IsNullOrEmpty(url)) + result.Add(url); + } + + return result; + } + /// + /// 商品视频 + /// + private List GetVideos(JToken goods) + { + var result = new List(); + + var videos = goods["videoGallery"] as JArray; + + if (videos == null) + return result; + + foreach (var item in videos) + { + var url = + item["videoUrl"]?.Value() ?? + item["url"]?.Value(); + + if (!string.IsNullOrEmpty(url)) + result.Add(url); + } + + return result; + } + + /// + /// 获取规格 + /// + private List GetSpecs(JToken goods) + { + var result = new List(); + + var skus = goods["skus"] as JArray; + + if (skus == null) + return result; + + foreach (var sku in skus) + { + var specs = sku["specs"] as JArray; + + if (specs == null) + continue; + + foreach (var spec in specs) + { + var specKey = spec["spec_key"]?.Value() ?? ""; + var specValue = spec["spec_value"]?.Value() ?? ""; + var specKeyId = spec["spec_key_id"]?.Value() ?? 0; + var specValueId = spec["spec_value_id"]?.Value() ?? 0; + + // 去重 + if (result.Any(x => x.SpecKey == specKey && x.SpecValue == specValue)) + continue; + + result.Add(new SpecItem + { + SpecKey = specKey, + SpecValue = specValue, + SpecKeyId = specKeyId, + SpecValueId = specValueId, + }); + } + } + + return result; + } + /// + /// SKU + /// + private List GetSkus(JToken goods) + { + var result = new List(); + + var skus = goods["skus"] as JArray; + + if (skus == null) + return result; + + foreach (var sku in skus) + { + var specs = sku["specs"] as JArray; + + var specValues = new List(); + + if (specs != null) + { + foreach (var spec in specs) + { + var key = spec["spec_key"]?.Value(); + var value = spec["spec_value"]?.Value(); + + if (!string.IsNullOrEmpty(value)) + specValues.Add($"{key}:{value}"); + } + } + + // 优先使用 normalPrice + var price = sku["normalPrice"].Value(); + + result.Add(new SkuItem + { + SkuId = sku["skuId"]?.Value() ?? "", + + Spec = string.Join(";", specValues), + + Price = price, + + // oldGroupPrice 在这个 JSON 中是整数分价格, + // 这里暂时转成字符串 + OriginalPrice = sku["oldGroupPrice"]?.Value() ?? "", + + Stock = sku["quantity"]?.Value() ?? 0, + + SpecImage = sku["thumbUrl"]?.Value() ?? "", + }); + } + + return result; + } + + + } +} diff --git a/TEMUKJD/BLL/ImportConverters/IGoodsConverter.cs b/TEMUKJD/BLL/ImportConverters/IGoodsConverter.cs new file mode 100644 index 0000000..30fc6ce --- /dev/null +++ b/TEMUKJD/BLL/ImportConverters/IGoodsConverter.cs @@ -0,0 +1,90 @@ +using AllBase.Model.Result.PDDResult; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TemuKJD.BLL.ImportConverters +{ + /// + /// 导入商品数据转换器 + /// + public interface IGoodsConverter + { + /// + /// 原始数据 + /// + string RawData { get; } + + /// + /// 获取转换器名称 + /// + string ConverterName { get; } + + /// + /// 支持的平台类型 + /// + PlatformType Platform { get; } + /// + /// 判断是否匹配当前转换器 + /// + /// 是否匹配 + bool IsMatch(string data); + + /// + /// 转换为标准商品模型 + /// + PDDFrontProductInfo5 Convert(); + } + + public abstract class GoodsConverterBase : IGoodsConverter + { + private bool _isMatch = false; + public string RawData { get; private set; } + public abstract string ConverterName { get; } + public abstract PlatformType Platform { get; } + + + public virtual bool IsMatch(string data) + { + _isMatch = true; + RawData = data; + return IsMatchProvider(); + } + protected abstract bool IsMatchProvider(); + + /// + /// 带校验的转换(基类统一实现) + /// + public virtual PDDFrontProductInfo5 Convert() + { + if (_isMatch == false) throw new Exception("未校验数据"); + try + { + JObject.Parse(RawData); + } + catch { throw new Exception("数据解析失败,不是有效的JSON格式"); } + + + var product = ConverterProvider(); + if (product == null) + throw new Exception("转换失败"); + // 基础校验 + if (product.GoodsId == 0) + throw new Exception("商品ID不能为空"); + + if (product.Skus == null || !product.Skus.Any()) + throw new Exception("至少需要一个SKU"); + + return product; + } + + protected abstract PDDFrontProductInfo5 ConverterProvider(); + + + + } +} diff --git a/TEMUKJD/BLL/PDDProdFormConverter.cs b/TEMUKJD/BLL/PDDProdFormConverter.cs index 0f5bfd9..0df3a65 100644 --- a/TEMUKJD/BLL/PDDProdFormConverter.cs +++ b/TEMUKJD/BLL/PDDProdFormConverter.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using TemuKJD.BLL.ImportConverts; using Work; namespace TemuKJD.BLL @@ -721,7 +722,7 @@ namespace TemuKJD.BLL shipment_limit_second_list = null, sku69_code = "", }; - if ((int)frontSku.sku_price.ParseToDecimal() > 0) + if ((int)frontSku.sku_price?.ParseToDecimal() > 0) skuInfo.multi_price = Math.Min(skuInfo.multi_price.ParseToInt(), (int)frontSku.sku_price.ParseToDecimal()); //List specIds = frontSku.spec.Split(',').ToList(); @@ -1650,8 +1651,395 @@ namespace TemuKJD.BLL } + /// + /// 外来格式V5 + /// + /// + /// + /// + /// + /// + public string PddFrontToPddBackConvertFactory(string outProdJson, bool UpdateOldData = true, string specialProdType = null, bool IsCollectAuthorityUser = false) + { + PDDFrontProductInfo5 frontProdInfo = null; + try + { + frontProdInfo = ConverterToPddFactory.Convert(outProdJson); + } + catch (Exception ex) + { + return "转换错误" + ex.Message; + } + + if (frontProdInfo == null || frontProdInfo.GoodsId == null) + { + return "商品数据信息为空"; + } + KJDDBProduct dbProd = new KJDDBProduct() { size_json = "{}" }; + PDDProductInfo prodInfo = new PDDProductInfo() + { + //source_json = JsonHelper.JObjectParse(outProdJson), + source_json = null, + //sale_count = frontProdInfo.goods.sold_quantity.ParseToString(), + //sale_count_text = frontProdInfo.goods.side_sales_tip, + }; + prodInfo.chance_id = null; + prodInfo.chance_refere = null; + prodInfo.chance_tab = null; + prodInfo.decoration = new PDDProductDecorationInfo() { floor_list = new List() }; + + // 商品详情 + prodInfo.detail = new PDDProductDetailInfo(); + prodInfo.detail.allergy_refund = 0; + prodInfo.detail.allowed_region = new List(); + //prodInfo.detail.appeal_status = null; + //prodInfo.detail.app_id = null; + //prodInfo.detail.app_name = null; + //prodInfo.detail.bad_claim_text = null; + prodInfo.detail.bad_fruit_claim = 0; + //prodInfo.detail.business_source_type = null; + prodInfo.detail.can_appeal = null; + prodInfo.detail.card_verification_list = null; + prodInfo.detail.cats = new List(); + prodInfo.detail.cat_id = frontProdInfo.CategoryId; + prodInfo.detail.cat_ids = frontProdInfo.CategoryPath.Select(a => (int?)a).ToList(); + prodInfo.detail.check_status = 9; + //prodInfo.detail.check_type = null; + //prodInfo.detail.client_id = null; + prodInfo.detail.commit_deleted = 0; + //prodInfo.detail.commit_extension = null; + //prodInfo.detail.community_group_buying = null; + prodInfo.detail.cost_template_id = 0; + //prodInfo.detail.country = null; + prodInfo.detail.country_id = 0; + //prodInfo.detail.created_at = null; + //prodInfo.detail.creator_name = null; + prodInfo.detail.customizable = 0; + prodInfo.detail.customs = ""; + prodInfo.detail.damage_claim = 0; + prodInfo.detail.delivery_one_day = 0; + //prodInfo.detail.delivery_type = null; + //prodInfo.detail.elec_goods_attributes = null; + prodInfo.detail.estimate_quantity = 0; + prodInfo.detail.event_type = 0; + prodInfo.detail.extend_warranty_dto = new extend_warranty_dto_item() { extend_warranty = 0 }; + //prodInfo.detail.fabric = null; + //prodInfo.detail.fabric_content = null; + prodInfo.detail.galleries = new List(); + int galleryIndex = 0; + foreach (var frontGallery in frontProdInfo.MainImages) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = frontGallery, + type = 1, + width = 0, + height = 0, + }); + galleryIndex++; + } + foreach (var frontGallery in frontProdInfo.DetailImages) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = frontGallery, + type = 2, + width = 0, + height = 0, + }); + galleryIndex++; + } + prodInfo.detail.gold_price_template_id = null; + prodInfo.detail.gold_price_type = null; + prodInfo.detail.goods_certificate = null; + prodInfo.detail.goods_commit_check = new List(); + prodInfo.detail.goods_desc = frontProdInfo.Description; + prodInfo.detail.goods_id = frontProdInfo.GoodsId; + prodInfo.detail.goods_name = frontProdInfo.Title; + prodInfo.detail.goods_name_prefix = ""; + prodInfo.detail.goods_pattern = 8; + prodInfo.detail.goods_property_list = null; + prodInfo.detail.goods_sn = null; + prodInfo.detail.goods_srv_templates = new List(); + prodInfo.detail.goods_trade_attr = null; + prodInfo.detail.goods_travel_attr = null; + prodInfo.detail.goods_type = 1; + prodInfo.detail.groups = new group_item() { single_price = 0, group_price = 0, customer_num = 2, buy_limit = 999999, order_limit = 999999 }; + prodInfo.detail.hd_thumb_url = ""; + prodInfo.detail.id = 0; // 编辑id,随意填写 + prodInfo.detail.image_url = frontProdInfo.MainImages?.FirstOrDefault() ?? ""; + prodInfo.detail.instruction_vo = new instruction_vo_item() { template_status = -1 }; + prodInfo.detail.invoice_mode = null; + prodInfo.detail.invoice_mode_sub_type = null; + prodInfo.detail.invoice_status = 0; + prodInfo.detail.is_all_weight_same = true; + prodInfo.detail.is_app = 0; + prodInfo.detail.is_bangdan = 0; + prodInfo.detail.is_card_secret = false; + prodInfo.detail.is_certificate_provide = 0; + prodInfo.detail.is_customized = 0; + prodInfo.detail.is_customs = 0; + prodInfo.detail.is_deposit = false; + prodInfo.detail.is_draft = false; + prodInfo.detail.is_folt = 0; + prodInfo.detail.is_general_trade = 0; + prodInfo.detail.is_gold_price_matched = null; + prodInfo.detail.is_goods_copy = null; + prodInfo.detail.is_goods_decoration = 1; + prodInfo.detail.is_group_pre_sale = 0; + prodInfo.detail.is_only_for_remote_area = false; + prodInfo.detail.is_pre_sale = 0; + prodInfo.detail.is_refundable = 1; + prodInfo.detail.is_refundable_fifteen_day = 0; + prodInfo.detail.is_shop = 1; + prodInfo.detail.is_size_change_casually = 0; + prodInfo.detail.is_sku_pre_sale = 0; + prodInfo.detail.is_sku_shipment = 0; + prodInfo.detail.is_small_group = null; + prodInfo.detail.is_spring_festival_open_tag = false; + prodInfo.detail.is_two_num_group = false; + prodInfo.detail.is_warranty_one_year = 0; + prodInfo.detail.is_wms = 0; + prodInfo.detail.is_wp_service = 0; + prodInfo.detail.lack_of_weight_claim = 0; + prodInfo.detail.last_commit_check_status = 2; + prodInfo.detail.list_desc = new List(); + prodInfo.detail.local_service_id_list = null; + prodInfo.detail.mai_jia_zi_ti = null; + prodInfo.detail.mall_id = frontProdInfo.MallId; + prodInfo.detail.mall_info = new mall_info_item() { mall_name = frontProdInfo.MallName }; + + prodInfo.detail.must_check_type = 0; + prodInfo.detail.name_prefix = ""; + prodInfo.detail.origin_country_id = 0; + prodInfo.detail.origin_country_name = ""; + prodInfo.detail.out_goods_sn = ""; + prodInfo.detail.out_source_goods_id = null; + prodInfo.detail.out_source_type = null; + prodInfo.detail.oversea_goods = null; + prodInfo.detail.oversea_type = 0; + prodInfo.detail.owner = "主账号"; + prodInfo.detail.owner_name = ""; + prodInfo.detail.paper_length = null; + prodInfo.detail.paper_net_weight = null; + prodInfo.detail.paper_plies_num = null; + prodInfo.detail.paper_width = null; + prodInfo.detail.pre_sale_time = 0; + prodInfo.detail.privacy_delivery = 0; + prodInfo.detail.processing_charges = null; + prodInfo.detail.processing_charges_type = null; + prodInfo.detail.promised_delivery_seconds = null; + prodInfo.detail.purchase_info_supply = 0; + prodInfo.detail.qualification_id_list = new List(); + prodInfo.detail.quan_guo_lian_bao = 0; + prodInfo.detail.quick_refund = 0; + prodInfo.detail.reason = null; + prodInfo.detail.region_limit = 1; + prodInfo.detail.reject_reason = null; + prodInfo.detail.reject_status = null; + prodInfo.detail.same_city_template_id = 0; + prodInfo.detail.schedule_sale = new schedule_sale_item() { sale_type = 0 }; + prodInfo.detail.second_hand = 0; + prodInfo.detail.sf_markup_template_sn = null; + prodInfo.detail.shang_men_an_zhuang = null; + prodInfo.detail.share_desc = frontProdInfo.Description; + prodInfo.detail.shipment_limit_second = 172800; + prodInfo.detail.shoes_template_id = null; + prodInfo.detail.shop_group_id = null; + prodInfo.detail.shop_group_name = null; + prodInfo.detail.show_activity_price = false; + prodInfo.detail.size_parent_spec_id = null; + prodInfo.detail.size_spec_id = null; + prodInfo.detail.sku = new List(); + int maxPrice = int.MinValue; + int minPrice = int.MaxValue; + foreach (var skuItem in frontProdInfo.Skus) + { + sku_item skuInfo = new sku_item() + { + id = 0, + sku_id = null, + sku_sn = null, + carnival_price = 0, + init_quantity = 0, + is_onsale = 1, + limit_quantity = 999999, + multi_price = (int)(skuItem.Price.ParseToDecimal() * 100), + multi_price_in_yuan = null, + price = (int)(skuItem.Price.ParseToDecimal() * 100 + 100), + price_in_yuan = null, + quantity = 0, + reserve_quantity = 0, + weight = 0, + thumb_url = skuItem.SpecImage, + thumb_url_file_id = null, + thumb_url_status = null, + thumb_url_is_deleted = null, + quantity_delta = skuItem.Stock, + spec = new List(), + out_sku_sn = "", + batch_id = null, + priority = 1, + ware_id = 0, + ware_biz_type = null, + advice_price = null, + length = null, + oversea_sku = null, + cspu_id = null, + child_skus = null, + ref_sku_commit_id = 0, + start_time = null, + end_time = null, + sku_srv_templates = null, + calendar_rule_id = null, + hot_live_group = null, + pre_sale_time = 0, + out_source_sku_id = null, + dd_grocery_sku_params = null, + sku_extended_attribute_dtos = null, + sku_basic_property_dtos = null, + spec_note_map = null, + delivery_schedule_dtos = null, + shipment_limit_second_list = null, + sku69_code = "", + }; + + maxPrice = Math.Max(maxPrice, skuInfo.price.Value); + minPrice = Math.Min(minPrice, skuInfo.price.Value); + + var specList = skuItem.Spec.Split(';').ToList(); + foreach (var spec in specList) + { + string specKey = spec.Split(':')[0]; + string specValue = spec.Split(':')[1]; + var specItem = frontProdInfo.Specs.FirstOrDefault(a => a.SpecKey == specKey && a.SpecValue == specValue); + if (specItem == null) continue; + skuInfo.spec.Add(new spec_item() + { + parent_name = specItem.SpecKey, + spec_name = specItem.SpecValue, + }); + } + prodInfo.detail.sku.Add(skuInfo); + } + + prodInfo.detail.market_price = maxPrice * 2; + prodInfo.detail.max_group_price = maxPrice; + prodInfo.detail.min_group_price = minPrice; + + prodInfo.detail.sku_type = null; + prodInfo.detail.song_huo_an_zhuang = null; + prodInfo.detail.song_huo_ru_hu = null; + prodInfo.detail.source = 0; + prodInfo.detail.spu_id = null; + prodInfo.detail.spu_version = null; + prodInfo.detail.submit_time = 0; + prodInfo.detail.thawed_refund = 0; + prodInfo.detail.third_type = 0; + prodInfo.detail.thumb_url = frontProdInfo.ThumbUrl; + prodInfo.detail.tiny_name = ""; + prodInfo.detail.transport_type_list = null; + prodInfo.detail.two_pieces_discount = 99; + prodInfo.detail.user_source = 1; + prodInfo.detail.warehouse = ""; + prodInfo.detail.warm_tips = ""; + prodInfo.detail.zhi_huan_bu_xiu = 0; + + prodInfo.size = null; + prodInfo.material1 = null; + prodInfo.material3 = null; + prodInfo.property = new PDDProductPropertyInfo(); + prodInfo.property.sku_properties = new object(); + prodInfo.property.goods_properties = new List(); + foreach (var frontProp in frontProdInfo.Propertys) + { + goods_propertie_item propInfo = new goods_propertie_item(); + propInfo.name = frontProp.Key; + propInfo.values = new List(); + string[] p_values = frontProp.Value.Split(','); + foreach (var frontPropValue in p_values) + { + propInfo.values.Add(new value_item() { value = frontPropValue, raw_value = frontPropValue, unit = "" }); + } + prodInfo.property.goods_properties.Add(propInfo); + } + dbProd.main_img = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1).url; + dbProd.product_json = JsonHelper.SerializeObject(prodInfo); + + // 商品采集权限用户采集的数据加上用户前缀(商品前缀显示给用户的时候隐藏) + string collectAuthorityTag = ""; + if (IsCollectAuthorityUser) + collectAuthorityTag = "-" + BaseClass.UserName; + + bool isExist = false; + var existUrl = BaseClass.BuildPDDObjString("product/get_product_spu_id_list"); + string existData = UserLogin.GetSignaturex() + "&search_spu_ids=" + prodInfo.detail.goods_id + collectAuthorityTag; + string html = GetHtml.PostUtf8(existUrl, existData); + if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) + html = GetHtml.PostUtf8(existUrl, existData); + if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) + html = GetHtml.PostUtf8(existUrl, existData); + if (!string.IsNullOrEmpty(html) && html.Contains("\"code\":200")) + { + if (html.Contains("\"data\":[") && !html.Contains("\"data\":[]")) + isExist = true; + } + else + { + return "入库失败,产品数据库已存在商品查询失败"; + } + + var url = BaseClass.BuildPDDObjString("product/add_product"); + if (isExist) + { + if (UpdateOldData) + { + url = BaseClass.BuildPDDObjString("product/mdy_product"); + } + else + { + return "已存在相同id商品,跳过"; + } + } + + var data = Work.UserLogin.GetSignaturex() + + "&from_shop_id=" + frontProdInfo.MallId + + "&spu_id=" + prodInfo.detail.goods_id.ParseToString() + collectAuthorityTag + + "&skc_id=" + prodInfo.detail.goods_id.ParseToString() + + "&price_text=" + prodInfo.detail.sku.Min(s => s.multi_price).ParseToInt() * 0.01m + "-" + prodInfo.detail.sku.Max(s => s.multi_price).ParseToInt() * 0.01m + + "&main_cat_id=" + (prodInfo.detail.cat_ids?.FirstOrDefault(c => c != null)).ParseToString() + + "&main_cat_name=" + HttpUtility.UrlEncode((prodInfo.detail.cat_ids?.FirstOrDefault(c => c != null)).ParseToString(), Encoding.UTF8) + // 取不到catname直接用catid,上货时候再取 + "&cat_id=" + prodInfo.detail.cat_id.ParseToString() + + "&cat_name=" + HttpUtility.UrlEncode(prodInfo.detail.cat_id.ParseToString(), Encoding.UTF8) + // 取不到catname直接用catid,上货时候再取 + "&ext_code=" + HttpUtility.UrlEncode(prodInfo.detail.out_goods_sn, Encoding.UTF8) + + "&product_name=" + HttpUtility.UrlEncode(prodInfo.detail.goods_name, Encoding.UTF8) + + "&product_json=" + HttpUtility.UrlEncode(dbProd.product_json, Encoding.UTF8) + + "&size_json=" + HttpUtility.UrlEncode(dbProd.size_json, Encoding.UTF8) + + "&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); + if (!string.IsNullOrEmpty(specialProdType)) + data += "&special_prod_type=" + HttpUtility.UrlEncode(specialProdType, Encoding.UTF8); + if (IsCollectAuthorityUser) + { + data += "&add_user_name=" + BaseClass.UserName; + data += "&group=用户" + BaseClass.UserName; + } + + 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")) + { + return "商品采集保存失败!请检查网络连接:" + BaseRegex.GetStringJson(ref html, "msg"); + } + return ""; + + } + /// /// 聚水潭转pdd格式 /// diff --git a/TEMUKJD/BLL/PlatformType.cs b/TEMUKJD/BLL/PlatformType.cs new file mode 100644 index 0000000..e3213bf --- /dev/null +++ b/TEMUKJD/BLL/PlatformType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TemuKJD.BLL +{ + public enum PlatformType + { + PDD, + WX, + } +} diff --git a/TEMUKJD/KJD.csproj b/TEMUKJD/KJD.csproj index 309b1ce..084eb92 100644 --- a/TEMUKJD/KJD.csproj +++ b/TEMUKJD/KJD.csproj @@ -144,11 +144,15 @@ + + + + diff --git a/TEMUKJD/WXForms/ProductForms/WXUserCollectAuthProdListForm.cs b/TEMUKJD/WXForms/ProductForms/WXUserCollectAuthProdListForm.cs index 2184968..52abea7 100644 --- a/TEMUKJD/WXForms/ProductForms/WXUserCollectAuthProdListForm.cs +++ b/TEMUKJD/WXForms/ProductForms/WXUserCollectAuthProdListForm.cs @@ -1150,6 +1150,10 @@ namespace TemuKJD.WXForms.ProductForms { rst = new PDDProdFormConverter().PddFrontToPddBackConvertV4(sourceContent, true, null, true); } + else + { + rst = new PDDProdFormConverter().PddFrontToPddBackConvertFactory(sourceContent, true, null, true); + } } catch (Exception ex) {