diff --git a/AllBase/AllBase.csproj b/AllBase/AllBase.csproj index 5f4f98c..a2fb324 100644 --- a/AllBase/AllBase.csproj +++ b/AllBase/AllBase.csproj @@ -233,6 +233,7 @@ + diff --git a/AllBase/Model/Result/PDDResult/PDDFrontProductInfo4.cs b/AllBase/Model/Result/PDDResult/PDDFrontProductInfo4.cs new file mode 100644 index 0000000..6086915 --- /dev/null +++ b/AllBase/Model/Result/PDDResult/PDDFrontProductInfo4.cs @@ -0,0 +1,73 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +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 PDDFrontProductInfo4 + { + [JsonProperty("商品编号")] + public string ProductId { get; set; } + + [JsonProperty("商品链接")] + public string ProductUrl { get; set; } + + [JsonProperty("标题")] + public string Title { get; set; } + + [JsonProperty("描述")] + public string Description { get; set; } + + [JsonProperty("视频链接")] + public string VideoUrl { get; set; } + + [JsonProperty("类目")] + public string Category { get; set; } + + [JsonProperty("链接")] + public string Link { get; set; } + + [JsonProperty("评论")] + public string Comments { get; set; } + + [JsonProperty("属性")] + public Dictionary Attributes { get; set; } + + [JsonProperty("主图")] + public List MainImages { get; set; } + + [JsonProperty("详情图")] + public List DetailImages { get; set; } + + [JsonProperty("规格")] + public Dictionary> Specifications { get; set; } + + [JsonProperty("价格与库存")] + public Dictionary SKU { get; set; } + } + + + + public class PriceStock + { + [JsonProperty("规格值组合")] + public string SpecValue { get; set; } + + [JsonProperty("价格")] + public string Price { get; set; } + + [JsonProperty("原价")] + public string OriginalPrice { get; set; } + + [JsonProperty("库存")] + public int Stock { get; set; } + + [JsonProperty("规格图")] + public string SpecImage { get; set; } + } +} diff --git a/TEMUKJD/BLL/PDDProdFormConverter.cs b/TEMUKJD/BLL/PDDProdFormConverter.cs index bca0b8c..c700871 100644 --- a/TEMUKJD/BLL/PDDProdFormConverter.cs +++ b/TEMUKJD/BLL/PDDProdFormConverter.cs @@ -14,3214 +14,3618 @@ using Work; namespace TemuKJD.BLL { - public class PDDProdFormConverter - { - /// - /// 拼多多前端采集转拼多多后台采集数据 - /// - /// - /// - /// - /// - public string PddFrontToPddBackConvert(string outProdJson, bool UpdateOldData = true, string specialProdType = null, bool IsCollectAuthorityUser = false) - { - PDDFrontProductInfo frontProdInfo = null; - try - { - frontProdInfo = JsonHelper.DeserializeJsonToObject(outProdJson); - } - catch(Exception ex) - { - return "转换错误" + ex.Message; - } - if (frontProdInfo == null || frontProdInfo.goods_id == 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.goods.cat_id.ParseToInt(); - prodInfo.detail.cat_ids = new List() { frontProdInfo.goods.cat_id_1.ParseToInt(), frontProdInfo.goods.cat_id_2.ParseToInt(), frontProdInfo.goods.cat_id_3.ParseToInt(), frontProdInfo.goods.cat_id_4.ParseToInt() }; - 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.goods.gallery) - { - if (frontGallery.type == 6) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = frontGallery.url, - type = frontGallery.type, - width = 0, - height = 0, - }); - } - else - { - //string getImgError; - //var image = GetHtml.GetUrlImg(frontGallery.url.Replace("https://", "http://"), out getImgError); - //if (!string.IsNullOrEmpty(getImgError)) - //{ - // return getImgError; - //} - prodInfo.detail.galleries.Add(new gallery_item() - { - url = frontGallery.url, - type = frontGallery.type, - //width = image.Width, - //height = image.Height, - }); - } - 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.goods.share_desc; - prodInfo.detail.goods_id = frontProdInfo.goods.goods_id ?? frontProdInfo.goods_id; - prodInfo.detail.goods_name = frontProdInfo.goods.goods_name; - 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 = frontProdInfo.goods.hd_thumb_url; - prodInfo.detail.id = 0; // 编辑id,随意填写 - prodInfo.detail.image_url = frontProdInfo.goods.image_url; - 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.goods.mall_id; - prodInfo.detail.mall_info = new mall_info_item() { mall_name = frontProdInfo.mall?.mall_name }; - prodInfo.detail.market_price = frontProdInfo.price.line_price; - prodInfo.detail.max_group_price = frontProdInfo.price.max_group_price; - prodInfo.detail.min_group_price = frontProdInfo.price.min_group_price; - 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.goods.share_desc; - 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(); - foreach (var frontSku in frontProdInfo.sku) - { - sku_item skuInfo = new sku_item() - { - id = 0, - sku_id = frontSku.sku_id, - sku_sn = null, - carnival_price = 0, - init_quantity = 0, - is_onsale = 1, - limit_quantity = 999999, - multi_price = (int)(frontSku.group_price.ParseToDecimal() * 100), - multi_price_in_yuan = null, - price = (int)(frontSku.normal_price.ParseToDecimal() * 100), - price_in_yuan = null, - quantity = 0, - reserve_quantity = 0, - weight = 0, - thumb_url = frontSku.thumb_url, - thumb_url_file_id = null, - thumb_url_status = null, - thumb_url_is_deleted = null, - quantity_delta = frontSku.quantity, - 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 = "", - }; - List specIds = frontSku.spec.Split(',').ToList(); - List specKeys = frontSku.spec_keys.Split(';').ToList(); - List specValues = frontSku.spec_values.Split(';').ToList(); - for (int i = 0; i < specIds.Count; i++) - { - skuInfo.spec.Add(new spec_item() - { - parent_name = specKeys[i], - spec_id = specIds[i].ParseToLong(), - spec_name = specValues[i], - }); - } - prodInfo.detail.sku.Add(skuInfo); - } - 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.goods.thumb_url; - 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.goods.property) - { - goods_propertie_item propInfo = new goods_propertie_item(); - propInfo.name = frontProp.key; - propInfo.values = new List(); - foreach (var frontPropValue in frontProp.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.mall?.mall_id + - "&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 ""; - } - - /// - /// 拼多多前端采集转拼多多后台采集数据 - /// - /// - /// - /// - /// - public string PddFrontToPddBackConvert2(string outProdJson, bool UpdateOldData = true, string specialProdType = null, bool IsCollectAuthorityUser = false) - { - PDDFrontProductInfo2 frontProdInfo = null; - try - { - frontProdInfo = JsonHelper.DeserializeJsonToObject(outProdJson); - } - catch (Exception ex) - { - return "转换错误" + ex.Message; - } - if (frontProdInfo == null || frontProdInfo.goods.goods_id == 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.ParseToLong().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.goods.cat_id.ParseToInt(); - prodInfo.detail.cat_ids = new List() { frontProdInfo.goods.cat_id_1.ParseToInt(), frontProdInfo.goods.cat_id_2.ParseToInt(), frontProdInfo.goods.cat_id_3.ParseToInt(), frontProdInfo.goods.cat_id_4.ParseToInt() }; - 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; - if (!frontProdInfo.goods.gallery.Any(g => g.type == 1)) - { - var jsonStr = BaseRegex.GetJsonObjStrJson(ref outProdJson, "carousel_section").OrderByDescending(s => s.Length).FirstOrDefault(); - if (jsonStr != null) - { - var jArrStr = BaseRegex.GetJsonArrStrJson(ref jsonStr, "picture_list").OrderByDescending(s => s.Length).FirstOrDefault(); - if (jArrStr != null) - { - foreach (var jObj in JArray.Parse(jArrStr)) - { - var jStr = JsonHelper.SerializeObject(jObj); - var type = BaseRegex.GetIntJson(ref jStr, "type"); - var img_url = BaseRegex.GetStringJson(ref jStr, "url"); - var id = BaseRegex.GetLongJson(ref jStr, "id"); - var goods_id = BaseRegex.GetLongJson(ref jStr, "goods_id"); - var width = BaseRegex.GetIntJson(ref jStr, "width"); - var height = BaseRegex.GetIntJson(ref jStr, "height"); - var enable_share = BaseRegex.GetIntJson(ref jStr, "enable_share"); - var gallery_pic = BaseRegex.GetIntJson(ref jStr, "gallery_pic"); - if (!img_url.IsNullOrEmpty() && !type.IsNullOrZero()) - { - frontProdInfo.goods.gallery.Add(new PDDFrontProductInfo2_gallery() - { - enable_share = enable_share, - goods_id = goods_id, - width = width, - height = height, - id = id, - type = type, - url = img_url, - priority = frontProdInfo.goods.gallery.Count, - }); - } - } - } - } - } - - if (!frontProdInfo.goods.gallery.Any(g => g.type == 1) && frontProdInfo.goods.gallery.Any(g => g.type == 13)) - { - foreach (var g in frontProdInfo.goods.gallery) - { - if (g.type == 13) - g.type = 1; - } - } - if (!frontProdInfo.goods.gallery.Any(g => g.type == 1) && frontProdInfo.goods.gallery.Any(g => g.type == 2)) - { - foreach (var g in frontProdInfo.goods.gallery.Where(g => g.type == 2) - .OrderBy(g => Math.Abs(100m - 100m * g.width.ParseToDecimal() / g.height.ParseToDecimal(1))).Take(3).ToList()) - { - frontProdInfo.goods.gallery.Add(new PDDFrontProductInfo2_gallery() - { - enable_share = g.enable_share, - goods_id = g.goods_id, - height = g.height, - id = g.id, - priority = g.priority, - type = 1, - url = g.url, - width = g.width, - }); - } - } - prodInfo.detail.galleries = new List(); - int galleryIndex = 0; - foreach (var frontGallery in frontProdInfo.goods.gallery) - { - if (frontGallery.type == 6) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = frontGallery.url, - type = frontGallery.type, - width = 0, - height = 0, - }); - } - else - { - //string getImgError; - //var image = GetHtml.GetUrlImg(frontGallery.url.Replace("https://", "http://"), out getImgError); - //if (!string.IsNullOrEmpty(getImgError)) - //{ - // return getImgError; - //} - prodInfo.detail.galleries.Add(new gallery_item() - { - url = frontGallery.url, - type = frontGallery.type, - //width = image.Width, - //height = image.Height, - }); - } - 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.goods.share_desc; - prodInfo.detail.goods_id = frontProdInfo.goods.goods_id; - prodInfo.detail.goods_name = frontProdInfo.goods.goods_name; - 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 = frontProdInfo.goods.hd_thumb_url; - prodInfo.detail.id = 0; // 编辑id,随意填写 - prodInfo.detail.image_url = frontProdInfo.goods.image_url; - 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.goods.mall_id; - prodInfo.detail.mall_info = new mall_info_item() { mall_name = frontProdInfo.mall_entrance?.mall_data?.mall_name }; - prodInfo.detail.market_price = frontProdInfo.price.line_price; - prodInfo.detail.max_group_price = frontProdInfo.price.max_group_price; - prodInfo.detail.min_group_price = frontProdInfo.price.min_group_price; - 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.goods.share_desc; - 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(); - foreach (var frontSku in frontProdInfo.sku) - { - sku_item skuInfo = new sku_item() - { - id = 0, - sku_id = frontSku.sku_id, - sku_sn = null, - carnival_price = 0, - init_quantity = 0, - is_onsale = 1, - limit_quantity = 999999, - multi_price = (int)frontSku.group_price.ParseToDecimal(), - multi_price_in_yuan = null, - price = (int)frontSku.normal_price.ParseToDecimal(), - price_in_yuan = null, - quantity = 0, - reserve_quantity = 0, - weight = 0, - thumb_url = frontSku.thumb_url, - thumb_url_file_id = null, - thumb_url_status = null, - thumb_url_is_deleted = null, - quantity_delta = frontSku.quantity, - 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 = "", - }; - 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(); - //List specKeys = frontSku.spec_keys.Split(';').ToList(); - //List specValues = frontSku.spec_values.Split(';').ToList(); - //for (int i = 0; i < specIds.Count; i++) - //{ - // skuInfo.spec.Add(new spec_item() - // { - // parent_name = specKeys[i], - // spec_id = specIds[i].ParseToLong(), - // spec_name = specValues[i], - // }); - //} - foreach (var frontSpec in frontSku.specs) - { - skuInfo.spec.Add(new spec_item() - { - parent_id = frontSpec.spec_key_id, - parent_name = frontSpec.spec_key, - spec_id = frontSpec.spec_value_id, - spec_name = frontSpec.spec_value, - }); - } - prodInfo.detail.sku.Add(skuInfo); - } - 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.goods.thumb_url; - 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.goods.goods_property) - { - goods_propertie_item propInfo = new goods_propertie_item(); - propInfo.name = frontProp.key; - propInfo.values = new List(); - foreach (var frontPropValue in frontProp.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.goods?.mall_id + - "&from_shop_name=" + prodInfo.detail.mall_info.mall_name + - "&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 ""; - } - - /// - /// 驼峰命名的一种新的拼多多格式 - /// - /// - /// - /// - /// - /// - public string PddFrontToPddBackConvert3(string outProdJson3, bool UpdateOldData = true, string specialProdType = null, bool IsCollectAuthorityUser = false) - { - initDataObjInfo frontProdInfo = null; - try - { - frontProdInfo = JsonHelper.DeserializeJsonToObject(outProdJson3)?.store?.initDataObj; - } - catch (Exception ex) - { - return "转换错误" + ex.Message; - } - if (frontProdInfo == null || frontProdInfo.goods?.goodsID == null || frontProdInfo.mall?.mallId == null || frontProdInfo.mall?.mallName == null) - { - return "商品数据信息为空"; - } - - KJDDBProduct dbProd = new KJDDBProduct() { size_json = "{}" }; - PDDProductInfo prodInfo = new PDDProductInfo() - { - //source_json = JsonHelper.JObjectParse(outProdJson), - source_json = null, - sale_count = BaseRegex.GetStringJson(ref outProdJson3, "sold_quantity").ParseToLong().ParseToString(), - sale_count_text = BaseRegex.GetStringJson(ref outProdJson3, "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.goods.catID.ParseToInt(); - prodInfo.detail.cat_ids = new List() { frontProdInfo.goods.catID1.ParseToInt(), frontProdInfo.goods.catID2.ParseToInt(), frontProdInfo.goods.catID3.ParseToInt(), frontProdInfo.goods.catID4.ParseToInt() }; - 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 topGallery in frontProdInfo.goods.topGallery) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = topGallery.url, - type = 1, - //width = image.Width, - //height = image.Height, - }); - galleryIndex++; - } - foreach (var detailGallery in frontProdInfo.goods.detailGallery) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = detailGallery.url, - type = 2, - //width = image.Width, - //height = image.Height, - }); - 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.goods.shareDesc; - prodInfo.detail.goods_id = frontProdInfo.goods.goodsID; - prodInfo.detail.goods_name = frontProdInfo.goods.goodsName; - 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 = frontProdInfo.goods.hdThumbUrl; - prodInfo.detail.id = 0; // 编辑id,随意填写 - prodInfo.detail.image_url = frontProdInfo.goods.topGallery.FirstOrDefault()?.url; // frontProdInfo.goods.image_url; - 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.mall.mallId.ParseToLong(); - prodInfo.detail.mall_info = new mall_info_item() { mall_name = frontProdInfo.mall.mallName }; - prodInfo.detail.market_price = (frontProdInfo.goods.linePrice.ParseToDecimal() * 100).ParseToInt(); - prodInfo.detail.max_group_price = frontProdInfo.goods.maxOnSaleGroupPriceInCent; - prodInfo.detail.min_group_price = frontProdInfo.goods.minOnSaleGroupPriceInCent; - 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.goods.shareDesc; - 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(); - foreach (var frontSku in frontProdInfo.goods.skus) - { - sku_item skuInfo = new sku_item() - { - id = 0, - sku_id = frontSku.skuId, - sku_sn = null, - carnival_price = 0, - init_quantity = 0, - is_onsale = 1, - limit_quantity = 999999, - multi_price = (int)(frontSku.groupPrice.ParseToDecimal() * 100), - multi_price_in_yuan = null, - price = (int)(frontSku.normalPrice.ParseToDecimal() * 100), - price_in_yuan = null, - quantity = 0, - reserve_quantity = 0, - weight = 0, - thumb_url = frontSku.thumbUrl, - thumb_url_file_id = null, - thumb_url_status = null, - thumb_url_is_deleted = null, - quantity_delta = frontSku.quantity, - 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 = "", - }; - if ((int)(frontSku.groupPrice.ParseToDecimal() * 100) > 0) - skuInfo.multi_price = Math.Min(skuInfo.multi_price.ParseToInt(), (int)(frontSku.groupPrice.ParseToDecimal() * 100)); - - //List specIds = frontSku.spec.Split(',').ToList(); - //List specKeys = frontSku.spec_keys.Split(';').ToList(); - //List specValues = frontSku.spec_values.Split(';').ToList(); - //for (int i = 0; i < specIds.Count; i++) - //{ - // skuInfo.spec.Add(new spec_item() - // { - // parent_name = specKeys[i], - // spec_id = specIds[i].ParseToLong(), - // spec_name = specValues[i], - // }); - //} - foreach (var frontSpec in frontSku.specs) - { - skuInfo.spec.Add(new spec_item() - { - parent_id = frontSpec.spec_key_id, - parent_name = frontSpec.spec_key, - spec_id = frontSpec.spec_value_id, - spec_name = frontSpec.spec_value, - }); - } - prodInfo.detail.sku.Add(skuInfo); - } - 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.goods.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.goods.goodsProperty) - { - goods_propertie_item propInfo = new goods_propertie_item(); - propInfo.name = frontProp.key; - propInfo.values = new List(); - foreach (var frontPropValue in frontProp.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.mall?.mallId + - "&from_shop_name=" + frontProdInfo.mall?.mallName + - "&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格式 - /// - /// - /// - /// - public PDDProductInfo JstPddProdToPddConvert(out string convertRst, KJDDBProduct dbProd) - { - convertRst = ""; - try - { - var prodObj = JsonHelper.JObjectParse(dbProd.product_json); - if (prodObj["pddData"].IsJTokenNullOrEmpty()) - { - convertRst = "缺少指定的数据格式"; - return null; - } - var jstGoodsObj = prodObj["pddData"]; - var jstPddPropMapLst = JsonHelper.DeserializeJsonToList(JsonHelper.SerializeObject(prodObj["pddPropMap"])); - //{"goodsId":"2016474712785620994","warehouseGoodsId":"C7108311198A4217B022DCA87B6A5863","spuCode":"3783056947394249077","skus":[{"skuId":"2016692758292738050","warehouseSkuId":"C742B3FCB0364448AF92332F8F6005A6","skuCode":"ZH-XP-YWQYW-010"},{"skuId":"2016692758317903874","warehouseSkuId":"703E87F1B7774C14923821A57EEE6EFA","skuCode":"ZH-XP-YWQYW-010-111"},{"skuId":"2016692758338875394","warehouseSkuId":"895EDCDF6ECC4FAE8AD4DB9503719002","skuCode":"ZH-XP-YWQYW-010-222"}]} - var jstSecretCodeLst = JsonHelper.JObjectParse(dbProd.sku_secret_json.TrimStart('[').TrimEnd(']')); - - PDDProductInfo prodInfo = new PDDProductInfo() - { - sale_count = dbProd.sale_count.ParseToString(), - sale_count_text = dbProd.sale_count_text, - }; - 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 = jstGoodsObj["catId"].ParseToInt(); - prodInfo.detail.cat_ids = new List(); - var catLst = (jstGoodsObj["categoryData"] as JArray).Select(a => a.ParseToInt()).ToList(); - foreach (var cId in catLst) - { - prodInfo.detail.cat_ids.Add(cId); - } - 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(); - foreach (var imgObj in jstGoodsObj["carouselGallery"]) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = imgObj.ParseToString(), - type = 1, - }); - } - foreach (var imgObj in jstGoodsObj["detailGallery"]) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = imgObj.ParseToString(), - type = 2, - }); - } - 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 = jstGoodsObj["goodsDesc"].ParseToString(); - // 聚水潭为string,散列取数值 - prodInfo.detail.goods_id = jstGoodsObj["itemSpuId"].ParseToString().GetHashCode(); - prodInfo.detail.goods_name = jstGoodsObj["itemName"].ParseToString(); - 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.galleries.FirstOrDefault(g => g.type == 1)?.url; - // 编辑id,随意填写 - prodInfo.detail.id = 0; - // 复用前面已经填写过的 - prodInfo.detail.image_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; - 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 = 0; - // 聚水潭没有 - prodInfo.detail.mall_info = new mall_info_item(); - // 聚水潭没有此处随意填 - prodInfo.detail.market_price = 0; - // 聚水潭没有此处随意填 - prodInfo.detail.max_group_price = 0; - // 聚水潭没有此处随意填 - prodInfo.detail.min_group_price = 0; - 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 = jstSecretCodeLst["goodsId"].ParseToString(); - // 货号直接替换成加密的,注意千万不要再把这个ext_code入库 - dbProd.ext_code = prodInfo.detail.out_goods_sn; - if (prodInfo.detail.out_goods_sn.IsNullOrEmpty()) - { - convertRst = "货号不存在"; - return null; - } - 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 = ""; - 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; - - if (jstGoodsObj["skuInfo"].IsJTokenNullOrEmpty() || jstGoodsObj["skuInfo"]["goodsSkuDetail"].IsJTokenNullOrEmpty()) - { - convertRst = "缺少sku信息"; - return null; - } - prodInfo.detail.sku = new List(); - foreach (JObject jSku in jstGoodsObj["skuInfo"]["goodsSkuDetail"]) - { - sku_item skuInfo = new sku_item() - { - id = 0, - // 聚水潭为string,散列取数值 - sku_id = jSku["baseSkuId"].ParseToString().GetHashCode(), - sku_sn = null, - carnival_price = 0, - init_quantity = 0, - is_onsale = 1, - limit_quantity = 999999, - multi_price = (int)(jSku["supplyPrice"].ParseToDecimal() * 100), - multi_price_in_yuan = null, - price = (int)(jSku["supplyPrice"].ParseToDecimal() * 100 + 100), - price_in_yuan = null, - quantity = jSku["quantity"].ParseToInt(), - reserve_quantity = 0, - weight = (int)(jSku["weight"].ParseToDecimal() * 1000), - thumb_url = jSku["pic"].ParseToString(), - thumb_url_file_id = null, - thumb_url_status = null, - thumb_url_is_deleted = null, - quantity_delta = 0, - spec = new List(), - // sku货号下面单独设置 - 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 = "", - }; - // 聚水潭广告sku价格为0库存不为零的给库存也改为0 - if (skuInfo.multi_price == 0) - { - skuInfo.quantity = 0; - skuInfo.quantity_delta = 0; - } - - // 聚水潭供应商价加价10%(最低1元)赚取差价 - int addPrice = (skuInfo.multi_price * 0.1).ParseToInt(); - if (addPrice < 100) - addPrice = 100; - skuInfo.multi_price += addPrice; - skuInfo.price += addPrice; - foreach (JObject jSpec in jSku["skus"]) - { - skuInfo.spec.Add(new spec_item() - { - parent_id = jSpec["kid"].ParseToLong(), - parent_name = jSpec["k"].ParseToString(), - spec_id = jSpec["vid"].ParseToLong(), - spec_name = jSpec["v"].ParseToString(), - }); - } - var itemNo = jSku["itemNo"].ParseToString(); - var baseSkuId = jSku["baseSkuId"].ParseToString(); - // skuCode可能不唯一,使用skuId取加密后的货号 - //var skuId = jstSecretCodeLst["skus"].FirstOrDefault(s => s["skuCode"].ParseToString() == itemNo)?["skuId"].ParseToString(); - var skuStr = jSku.ParseToString(); - var jstSecretCodeLstSkuStr = jstSecretCodeLst["skus"].ParseToString(); - var skuId = jstSecretCodeLst["skus"].FirstOrDefault(s => s["warehouseSkuId"].ParseToString() == baseSkuId)?["skuId"].ParseToString(); - if (skuId.IsNullOrEmpty() || string.IsNullOrEmpty(itemNo)) - { - convertRst = "SKU货号不存在"; - return null; - } - // 外部编码(货号) - skuInfo.out_sku_sn = skuId; - prodInfo.detail.sku.Add(skuInfo); - } - // 测试发现skuCoke重复可能对推单有影响,先吧skuCode重复的排除掉 - var skuCount = jstGoodsObj["skuInfo"]["goodsSkuDetail"].Select(s => s["baseSkuId"].ParseToString()).Distinct().Count(); - var itemNoCount = jstGoodsObj["skuInfo"]["goodsSkuDetail"].Select(s => s["itemNo"].ParseToString()).Distinct().Count(); - var skusStr = jstGoodsObj["skuInfo"]["goodsSkuDetail"].ParseToString(); - var skuSkuIdStr = string.Join("\r\n", jstGoodsObj["skuInfo"]["goodsSkuDetail"].Select(s => s["baseSkuId"].ParseToString())); - var skuItemNoStr = string.Join("\r\n", jstGoodsObj["skuInfo"]["goodsSkuDetail"].Select(s => s["itemNo"].ParseToString())); - if (skuCount != itemNoCount) - { - //convertRst = "SKU货号重复"; - //return null; - } - 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 = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; - 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(); - - if (!jstGoodsObj["goodsProperties"].IsJTokenNullOrEmpty()) - { - foreach (JObject jProp in jstGoodsObj["goodsProperties"]) - { - string name = ""; - if (!jProp["propName"].IsJTokenNullOrEmpty()) - name = jProp["propName"].ParseToString(); - else - { - try - { - if (jstPddPropMapLst != null) - name = jstPddPropMapLst.FirstOrDefault(p => p.ref_pid.ParseToString() == jProp["refPid"].ParseToString())?.name; - if (string.IsNullOrEmpty(name)) - name = jProp["refPid"].ParseToString(); - } - catch - { - } - } - goods_propertie_item propInfo = new goods_propertie_item(); - prodInfo.property.goods_properties.Add(propInfo); - propInfo.name = name; - propInfo.ref_pid = jProp["refPid"].ParseToInt(); - string propStr = JsonHelper.SerializeObject(jProp); - propInfo.values = new List(); - if (propStr.Contains("multipleValue") && !propStr.Contains("\"multipleValue\":[]")) - { - foreach (var propValueObj in jProp["multipleValue"]) - { - propInfo.values.Add(new value_item() - { - value = propValueObj["label"].ParseToString(), - raw_value = propValueObj["label"].ParseToString(), - vid = propValueObj["value"].ParseToLong(), - unit = "" - }); - } - } - else - { - var label = BaseRegex.GetStringJson(ref propStr, "label"); - var valueId = BaseRegex.GetStringJson(ref propStr, "value").ParseToLong(); - if (string.IsNullOrEmpty(label)) - label = BaseRegex.GetStringJson(ref propStr, "inputValue") + " " + BaseRegex.GetStringJson(ref propStr, "valueUnit"); - label = label.Trim(); - propInfo.values.Add(new value_item() - { - value = label, - raw_value = label, - vid = valueId, - unit = "" - }); - } - } - } - else - { - //outGoodsParam.productAttrs.Add(new osProductAttrParam { attrKey = "品牌", attrValue = "无品牌" }); - } - // 主图 - dbProd.main_img = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1).url; - dbProd.product_json = JsonHelper.SerializeObject(prodInfo); - - return prodInfo; - - //bool isExist = false; - //var existUrl = BaseClass.BuildPDDObjString("product/get_product_list"); - //string existData = UserLogin.GetSignaturex() + "&search_spu=" + prodInfo.detail.goods_id; - //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.mall?.mall_id + - // "&spu_id=" + prodInfo.detail.goods_id.ParseToString() + - // "&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); - - //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 ""; - } - catch (Exception ex) - { - convertRst = "转换错误 " + ex.Message; - return null; - } - } - - /// - /// 微信店铺采集转拼多多 - /// - /// - /// - /// - public PDDProductInfo WXProdToPddConvert(out string convertRst, KJDDBProduct dbProd) - { - convertRst = ""; - try - { - //var prodObj = JsonHelper.JObjectParse(dbProd.product_json); - //if (prodObj["pddData"].IsJTokenNullOrEmpty()) - //{ - // convertRst = "缺少指定的数据格式"; - // return null; - //} - //var jstGoodsObj = prodObj["pddData"]; - //var jstPddPropMapLst = JsonHelper.DeserializeJsonToList(JsonHelper.SerializeObject(prodObj["pddPropMap"])); - ////{"goodsId":"2016474712785620994","warehouseGoodsId":"C7108311198A4217B022DCA87B6A5863","spuCode":"3783056947394249077","skus":[{"skuId":"2016692758292738050","warehouseSkuId":"C742B3FCB0364448AF92332F8F6005A6","skuCode":"ZH-XP-YWQYW-010"},{"skuId":"2016692758317903874","warehouseSkuId":"703E87F1B7774C14923821A57EEE6EFA","skuCode":"ZH-XP-YWQYW-010-111"},{"skuId":"2016692758338875394","warehouseSkuId":"895EDCDF6ECC4FAE8AD4DB9503719002","skuCode":"ZH-XP-YWQYW-010-222"}]} - //var jstSecretCodeLst = JsonHelper.JObjectParse(dbProd.sku_secret_json.TrimStart('[').TrimEnd(']')); - - WXGetEditProductInfoLite wxEditProdInfo = JsonHelper.DeserializeJsonToObject(dbProd.product_json); - - PDDProductInfo prodInfo = new PDDProductInfo() - { - sale_count = dbProd.sale_count.ParseToString(), - sale_count_text = dbProd.sale_count_text, - }; - 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 = dbProd.cat_id.ParseToInt(); - prodInfo.detail.cat_ids = new List(); - //微信商品的类目直接输入,上传的时候不用。 - foreach (var category in wxEditProdInfo.product.info.category) - { - prodInfo.detail.cat_ids.Add(category.catId.ParseToInt()); - } - 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(); - foreach (var imgItem in wxEditProdInfo.product.info.headImg) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = imgItem, - type = 1, - }); - } - foreach (var imgItem in wxEditProdInfo.product.info.detail.detailImg) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = imgItem, - type = 2, - }); - } - 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 = wxEditProdInfo.product.info.title; - prodInfo.detail.goods_id = wxEditProdInfo.product.productKey.productId.ParseToLong(); - prodInfo.detail.goods_name = wxEditProdInfo.product.info.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.galleries.FirstOrDefault(g => g.type == 1)?.url; - // 编辑id,随意填写 - prodInfo.detail.id = 0; - // 复用前面已经填写过的 - prodInfo.detail.image_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; - 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 = 0; - // 微信没有 - prodInfo.detail.mall_info = new mall_info_item(); - // 微信没有此处随意填 - prodInfo.detail.market_price = 0; - // 微信没有此处随意填 - prodInfo.detail.max_group_price = 0; - // 微信没有此处随意填 - prodInfo.detail.min_group_price = 0; - 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 = wxEditProdInfo.product.info.spuCode; - //if (prodInfo.detail.out_goods_sn.IsNullOrEmpty()) - //{ - // convertRst = "货号不存在"; - // return null; - //} - 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 = ""; - 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; - - //if (jstGoodsObj["skuInfo"].IsJTokenNullOrEmpty() || jstGoodsObj["skuInfo"]["goodsSkuDetail"].IsJTokenNullOrEmpty()) - //{ - // convertRst = "缺少sku信息"; - // return null; - //} - prodInfo.detail.sku = new List(); - //foreach (JObject jSku in jstGoodsObj["skuInfo"]["goodsSkuDetail"]) - foreach (var wxEditSkuInfo in wxEditProdInfo.product.productSkus) - { - sku_item skuInfo = new sku_item() - { - id = 0, - sku_id = wxEditSkuInfo.skuKey.skuId.ParseToLong(), - sku_sn = null, - carnival_price = 0, - init_quantity = 0, - is_onsale = 1, - limit_quantity = 999999, - multi_price = wxEditSkuInfo.productSkuInfo.salePrice.ParseToInt(), - multi_price_in_yuan = null, - price = wxEditSkuInfo.productSkuInfo.salePrice.ParseToInt() + 100, - price_in_yuan = null, - quantity = wxEditSkuInfo.productSkuInfo.realStockInfo?.stockNum ?? wxEditSkuInfo.productSkuInfo.stockInfo?.stockNum.ParseToInt(), - reserve_quantity = 0, - weight = 0, - thumb_url = wxEditSkuInfo.productSkuInfo.thumbImg, - thumb_url_file_id = null, - thumb_url_status = null, - thumb_url_is_deleted = null, - quantity_delta = 0, - spec = new List(), - // sku货号下面单独设置 - 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 = "", - }; - //// 聚水潭供应商价加价10%(最低1元)赚取差价 - //int addPrice = (skuInfo.multi_price * 0.1).ParseToInt(); - //if (addPrice < 100) - // addPrice = 100; - //skuInfo.multi_price += addPrice; - //skuInfo.price += addPrice; - foreach (var wxSpec in wxEditSkuInfo.productSkuInfo.saleParam) - { - skuInfo.spec.Add(new spec_item() - { - parent_id = wxSpec.categorys[0].catId.ParseToLong(), - parent_name = wxSpec.categorys[0].name, - spec_id = wxSpec.categorys[1].catId.ParseToLong(), - spec_name = wxSpec.categorys[1].name, - }); - } - skuInfo.out_sku_sn = wxEditSkuInfo.productSkuInfo.skuCode; - prodInfo.detail.sku.Add(skuInfo); - } - 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 = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; - 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(); - - if (1 == 1) - { - foreach (var wxProp in wxEditProdInfo.product.info.param) - { - string name = wxProp.categorys.FirstOrDefault()?.name; - goods_propertie_item propInfo = new goods_propertie_item(); - prodInfo.property.goods_properties.Add(propInfo); - propInfo.name = name; - propInfo.ref_pid = null; - //propInfo.wx_input_type = wxProp.categorys.FirstOrDefault()?.catInfo.inputType; - propInfo.values = new List(); - foreach (var wxPropVal in wxProp.categorys) - { - // 第一个是属性名,装载属性值的时候跳过 - if (wxProp.categorys.IndexOf(wxPropVal) == 0) - continue; - - propInfo.values.Add(new value_item() - { - value = wxPropVal.name.ParseToString(), - raw_value = wxPropVal.name.ParseToString(), - vid = null, - unit = "" - }); - } - } - } - else - { - //outGoodsParam.productAttrs.Add(new osProductAttrParam { attrKey = "品牌", attrValue = "无品牌" }); - } - // 主图 复用前面的 - dbProd.main_img = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1).url; - dbProd.product_json = JsonHelper.SerializeObject(prodInfo); - - return prodInfo; - } - catch (Exception ex) - { - convertRst = "转换错误 " + ex.Message; - return null; - } - } - - /// - /// 1688网页端采集转拼多多 - /// - /// - /// - /// - public PDDProductInfo _1688ClientToPddConvert(out string convertRst, KJDDBProduct dbProd) - { - convertRst = ""; - try - { - var prod_json = dbProd.product_json; - var _1688Json = BaseRegex.GetOneJsonObjStrJson(ref prod_json, "_1688DetailData"); - _1688ClientProductInfo _1688ClentProdInfo = JsonHelper.DeserializeJsonToObject<_1688ClientProductInfo>(_1688Json); - - PDDProductInfo prodInfo = new PDDProductInfo() - { - sale_count = dbProd.sale_count.ParseToString(), - sale_count_text = dbProd.sale_count_text, - }; - 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 = dbProd.cat_id.ParseToInt(); - prodInfo.detail.cat_ids = new List(); - //foreach (var category in _1688EditProdInfo.product.info.category) - //{ - // prodInfo.detail.cat_ids.Add(category.catId.ParseToInt()); - //} - 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(); - foreach (var imgItem in _1688ClentProdInfo.mainImage) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = imgItem, - type = 1, - }); - } - foreach (var imgItem in _1688ClentProdInfo.offerImgList) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = imgItem, - type = 2, - }); - } - 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 = _1688ClentProdInfo.tempModel.offerTitle; - prodInfo.detail.goods_id = _1688ClentProdInfo.tempModel.offerId; - prodInfo.detail.goods_name = _1688ClentProdInfo.tempModel.offerTitle; - 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.galleries.FirstOrDefault(g => g.type == 1)?.url; - // 编辑id,随意填写 - prodInfo.detail.id = 0; - // 复用前面已经填写过的 - prodInfo.detail.image_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; - 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; - // 1688没有 - prodInfo.detail.mall_id = 0; - // 1688没有 - prodInfo.detail.mall_info = new mall_info_item(); - // 1688没有此处随意填 - prodInfo.detail.market_price = 0; - // 1688没有此处随意填 - prodInfo.detail.max_group_price = 0; - // 1688没有此处随意填 - prodInfo.detail.min_group_price = 0; - prodInfo.detail.must_check_type = 0; - prodInfo.detail.name_prefix = ""; - prodInfo.detail.origin_country_id = 0; - prodInfo.detail.origin_country_name = ""; - // 货号 1688没有字段直接标明,可能存在属性里面 - prodInfo.detail.out_goods_sn = (_1688ClentProdInfo.offerDetail?.featureAttributes?.FirstOrDefault(s=>s.name == "货号")?.value).ParseToString(); - //if (prodInfo.detail.out_goods_sn.IsNullOrEmpty()) - //{ - // convertRst = "货号不存在"; - // return null; - //} - 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; - // 1688没有 - prodInfo.detail.share_desc = ""; - 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(); - foreach (string skuKey in _1688ClentProdInfo.skuModel.skuInfoMap.Keys) - { - _1688skuInfo _1688skuInfo = _1688ClentProdInfo.skuModel.skuInfoMap[skuKey]; - - sku_item skuInfo = new sku_item() - { - id = 0, - sku_id = _1688skuInfo.skuId.ParseToLong(), - sku_sn = null, - carnival_price = 0, - init_quantity = 0, - is_onsale = 1, - limit_quantity = 999999, - multi_price = (_1688skuInfo.price.ParseToDecimal() * 100 + _1688ClentProdInfo.postFeeValue.ParseToDecimal() * 100).ParseToInt(), - multi_price_in_yuan = null, - price = (_1688skuInfo.price.ParseToDecimal() * 100 + _1688ClentProdInfo.postFeeValue.ParseToDecimal() * 100).ParseToInt() + 100, - price_in_yuan = null, - quantity = _1688skuInfo.canBookCount, - reserve_quantity = 0, - weight = 0, - //thumb_url = _1688skuInfo.productSkuInfo.thumbImg, - thumb_url_file_id = null, - thumb_url_status = null, - thumb_url_is_deleted = null, - quantity_delta = 0, - spec = new List(), - // sku货号 - out_sku_sn = _1688skuInfo.specId, - 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 = "", - }; - //// 聚水潭供应商价加价10%(最低1元)赚取差价 - //int addPrice = (skuInfo.multi_price * 0.1).ParseToInt(); - //if (addPrice < 100) - // addPrice = 100; - //skuInfo.multi_price += addPrice; - //skuInfo.price += addPrice; - foreach (_1688skuProp _1688skuProp in _1688ClentProdInfo.skuModel.skuProps) - { - foreach (_1688skuValue _1688SpecValue in _1688skuProp.value) - { - if ((">" + skuKey + ">").Contains(">" + _1688SpecValue.name + ">")) - { - skuInfo.spec.Add(new spec_item() - { - parent_id = _1688skuProp.fid.ParseToLong(), - parent_name = _1688skuProp.prop, - spec_id = 0, - spec_name = _1688SpecValue.name, - }); - if (!string.IsNullOrEmpty(_1688SpecValue.imageUrl)) - skuInfo.thumb_url = _1688SpecValue.imageUrl; - } - } - } - prodInfo.detail.sku.Add(skuInfo); - } - 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 = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; - 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(); - - if (1 == 1) - { - foreach (_1688featureAttributes _1688Attr in _1688ClentProdInfo.offerDetail.featureAttributes) - { - string name = _1688Attr.name; - goods_propertie_item propInfo = new goods_propertie_item(); - prodInfo.property.goods_properties.Add(propInfo); - propInfo.name = name; - propInfo.ref_pid = null; - //propInfo.wx_input_type = wxProp.categorys.FirstOrDefault()?.catInfo.inputType; - propInfo.values = new List(); - List values = (_1688Attr.values == null || _1688Attr.values.Count() == 0) ? _1688Attr.decisionValues : _1688Attr.values; - foreach (var wxPropVal in values) - { - propInfo.values.Add(new value_item() - { - value = wxPropVal, - raw_value = wxPropVal, - vid = null, - unit = "" - }); - } - } - } - else - { - //outGoodsParam.productAttrs.Add(new osProductAttrParam { attrKey = "品牌", attrValue = "无品牌" }); - } - // 主图 复用前面的 - dbProd.main_img = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1).url; - dbProd.product_json = JsonHelper.SerializeObject(prodInfo); - - return prodInfo; - } - catch (Exception ex) - { - convertRst = "转换错误 " + ex.Message; - return null; - } - } - - /// - /// 1688外部数据转拼多多(万象工具) - /// - /// - /// - /// - public PDDProductInfo _1688OutToPddConvert(out string convertRst, KJDDBProduct dbProd) - { - convertRst = ""; - try - { - var prod_json = dbProd.product_json; - _1688OutProductInfo _1688OutProdInfo = JsonHelper.DeserializeJsonToObject<_1688OutProductInfo>(prod_json); - - PDDProductInfo prodInfo = new PDDProductInfo() - { - sale_count = dbProd.sale_count.ParseToString(), - sale_count_text = dbProd.sale_count_text, - }; - 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 = dbProd.cat_id.ParseToInt(); - prodInfo.detail.cat_ids = new List(); - //foreach (var category in _1688EditProdInfo.product.info.category) - //{ - // prodInfo.detail.cat_ids.Add(category.catId.ParseToInt()); - //} - 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(); - foreach (var imgItem in _1688OutProdInfo.itemImgs) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = imgItem, - type = 1, - }); - } - var desc = _1688OutProdInfo.desc.ParseToString(); - var descLst = desc.Split(new string[] { "src=\"", "\" usemap", "\"/>", "\"" }, StringSplitOptions.RemoveEmptyEntries).ToList(); - foreach (var imgItem in descLst) - { - if (!imgItem.StartsWith("http") || (!imgItem.ToLower().Contains(".jpg") && !imgItem.ToLower().Contains(".jpeg") && !imgItem.ToLower().Contains(".png"))) - continue; - prodInfo.detail.galleries.Add(new gallery_item() - { - url = imgItem, - type = 2, - }); - } - 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 = _1688OutProdInfo.productName; - prodInfo.detail.goods_id = _1688OutProdInfo.productId.ParseToLong(); - prodInfo.detail.goods_name = _1688OutProdInfo.productName; - 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.galleries.FirstOrDefault(g => g.type == 1)?.url; - // 编辑id,随意填写 - prodInfo.detail.id = 0; - // 复用前面已经填写过的 - prodInfo.detail.image_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; - 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; - // 1688没有 - prodInfo.detail.mall_id = 0; - // 1688没有 - prodInfo.detail.mall_info = new mall_info_item(); - // 1688没有此处随意填 - prodInfo.detail.market_price = 0; - // 1688没有此处随意填 - prodInfo.detail.max_group_price = 0; - // 1688没有此处随意填 - prodInfo.detail.min_group_price = 0; - 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 = (_1688OutProdInfo.attribute.FirstOrDefault(a => a.key == "货号")?.value).ParseToString(); - //if (prodInfo.detail.out_goods_sn.IsNullOrEmpty()) - //{ - // convertRst = "货号不存在"; - // return null; - //} - 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; - // 1688没有 - prodInfo.detail.share_desc = ""; - 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(); - if (_1688OutProdInfo.skus == null) - _1688OutProdInfo.skus = new List<_1688Sku>(); - if (_1688OutProdInfo.skus.Count == 0) - { - _1688OutProdInfo.skus.Add(new _1688Sku() - { - skuId = -1, - quantity = 999, - price = (_1688OutProdInfo.priceHigh.ParseToDecimal() * 100).ParseToInt(), - }); - } - foreach (var sku in _1688OutProdInfo.skus) - { - var postFeeValue = (_1688OutProdInfo.deliveryInfo?.carriageList?.Max(c => c.price)).ParseToDecimal(); - - //_1688skuInfo _1688skuInfo = _1688OutProdInfo.skuModel.skuInfoMap[sku]; - - sku_item skuInfo = new sku_item() - { - id = 0, - sku_id = sku.skuId, - sku_sn = null, - carnival_price = 0, - init_quantity = 0, - is_onsale = 1, - limit_quantity = 999999, - multi_price = (sku.price + postFeeValue * 100).ParseToInt(), - multi_price_in_yuan = null, - price = (sku.price + postFeeValue * 100).ParseToInt() + 100, - price_in_yuan = null, - quantity = sku.quantity, - reserve_quantity = 0, - weight = 0, - //thumb_url = _1688skuInfo.productSkuInfo.thumbImg, - thumb_url_file_id = null, - thumb_url_status = null, - thumb_url_is_deleted = null, - quantity_delta = 0, - spec = new List(), - // sku货号 - 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 = "", - }; - //// 聚水潭供应商价加价10%(最低1元)赚取差价 - //int addPrice = (skuInfo.multi_price * 0.1).ParseToInt(); - //if (addPrice < 100) - // addPrice = 100; - //skuInfo.multi_price += addPrice; - //skuInfo.price += addPrice; - foreach (_1688PropsName _1688skuProp in _1688OutProdInfo.propsName) - { - foreach (_1688PropsNameValue _1688skuPropValue in _1688skuProp.values) - { - if ((";" + sku.id + ";").Contains(";" + _1688skuProp.pid + ":" + _1688skuPropValue.vid + ";")) - { - skuInfo.spec.Add(new spec_item() - { - parent_id = _1688skuProp.pid.ParseToLong(), - parent_name = _1688skuProp.pname, - spec_id = _1688skuPropValue.vid.ParseToLong(), - spec_name = _1688skuPropValue.vname, - }); - if (!string.IsNullOrEmpty(_1688skuPropValue.sku_url)) - skuInfo.thumb_url = _1688skuPropValue.sku_url; - } - } - } - if (skuInfo.spec.Count == 0) - skuInfo.spec.Add(new spec_item() - { - parent_id = 0, - parent_name = "款式", - spec_id = 0, - spec_name = "默认", - }); - if(string.IsNullOrEmpty(skuInfo.thumb_url)) - { - skuInfo.thumb_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; - } - prodInfo.detail.sku.Add(skuInfo); - } - 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 = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; - 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(); - - if (1 == 1) - { - foreach (_1688AttributeInfo _1688Attr in _1688OutProdInfo.attribute) - { - // 1688会把商品sku属性放到商品属性里面,需要剔除这个属性 - if (_1688OutProdInfo.propsName.Any(p => p.pname == _1688Attr.key && string.Join(",", p.values.Select(pp => pp.vname)) == _1688Attr.value)) - continue; - - goods_propertie_item propInfo = new goods_propertie_item(); - prodInfo.property.goods_properties.Add(propInfo); - propInfo.name = _1688Attr.key; - propInfo.ref_pid = null; - propInfo.values = new List(); - List values = new List { _1688Attr.value }; - foreach (var wxPropVal in values) - { - propInfo.values.Add(new value_item() - { - value = wxPropVal, - raw_value = wxPropVal, - vid = null, - unit = "" - }); - } - } - } - else - { - //outGoodsParam.productAttrs.Add(new osProductAttrParam { attrKey = "品牌", attrValue = "无品牌" }); - } - // 主图 复用前面的 - dbProd.main_img = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1).url; - dbProd.product_json = JsonHelper.SerializeObject(prodInfo); - - return prodInfo; - } - catch (Exception ex) - { - convertRst = "转换错误 " + ex.Message; - return null; - } - } - - /// - /// 微信商城手机版转拼多多 - /// - /// - /// - /// - public PDDProductInfo WXClientToPddConvert(out string convertRst, KJDDBProduct dbProd) - { - convertRst = ""; - try - { - var wxxdData = JsonHelper.SerializeObject(JsonHelper.JObjectParse(dbProd.product_json)["wxxdData"]); - var baseData = JsonHelper.JObjectParse(dbProd.product_json)["baseData"].ParseToString(); - - var str_lst = BaseRegex.GetJsonArrStrJson(ref baseData, "productSkus"); - try - { - var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault(); - var productSkus = JsonHelper.DeserializeJsonToList(regex_str); - } - catch - { - } - - WXClientProductInfoLite wxClientProdInfo = JsonHelper.DeserializeJsonToObject(wxxdData); - if (wxClientProdInfo.info.sku_list == null) - { - wxClientProdInfo.info.sku_list = new wx_sku(); - } - if (wxClientProdInfo.info.sku_list.sku_info == null) - { - wxClientProdInfo.info.sku_list.sku_info = new List(); - - try - { - if (baseData.Contains("{\"sku_info\"")) - { - var skuInfoStr = baseData.Substring(baseData.IndexOf("{\"sku_info\"")); - if (skuInfoStr.Contains(" KB)")) - skuInfoStr = skuInfoStr.Substring(0, skuInfoStr.IndexOf(" KB)")); - while (skuInfoStr.IndexOf("{\"sku_id\"") >= 0) - { - skuInfoStr = skuInfoStr.Substring(skuInfoStr.IndexOf("{\"sku_id\"")); - var wxClientSkuInfo = new wx_client_sku_info(); - wxClientSkuInfo.sku_id = BaseRegex.GetStringJson(ref skuInfoStr, "sku_id"); - wxClientSkuInfo.price = BaseRegex.GetIntJson(ref skuInfoStr, "price"); - wxClientSkuInfo.is_discounted = BaseRegex.GetBoolJson(ref skuInfoStr, "is_discounted"); - wxClientSkuInfo.discounted_price = BaseRegex.GetIntJson(ref skuInfoStr, "discounted_price"); - wxClientSkuInfo.origin_price = BaseRegex.GetIntJson(ref skuInfoStr, "origin_price"); - if (wxClientSkuInfo.price != null && wxClientSkuInfo.is_discounted != null && wxClientSkuInfo.discounted_price != null && wxClientSkuInfo.origin_price != null) - { - wxClientProdInfo.info.sku_list.sku_info.Add(wxClientSkuInfo); - } - skuInfoStr = skuInfoStr.Substring(skuInfoStr.IndexOf("{\"sku_id\"") + "{\"sku_id\"".Length); - } - } - } - catch - { - } - } - - PDDProductInfo prodInfo = new PDDProductInfo() - { - sale_count = dbProd.sale_count.ParseToString(), - sale_count_text = dbProd.sale_count_text, - }; - 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 = dbProd.cat_id.ParseToInt(); - prodInfo.detail.cat_ids = new List(); - //微信商品的类目直接输入,上传的时候不用。 - foreach (var category in wxClientProdInfo.info.category) - { - prodInfo.detail.cat_ids.Add(category.catIdStr.ParseToInt()); - } - 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(); - foreach (var imgItem in wxClientProdInfo.info.head_img) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = imgItem, - type = 1, - }); - } - foreach (var imgItem in wxClientProdInfo.info.detail.detail_img_real) - { - prodInfo.detail.galleries.Add(new gallery_item() - { - url = imgItem, - type = 2, - }); - } - 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 = wxClientProdInfo.info.title; - prodInfo.detail.goods_id = wxClientProdInfo.product_key.product_id.ParseToLong(); - prodInfo.detail.goods_name = wxClientProdInfo.info.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.galleries.FirstOrDefault(g => g.type == 1)?.url; - // 编辑id,随意填写 - prodInfo.detail.id = 0; - // 复用前面已经填写过的 - prodInfo.detail.image_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; - 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 = 0; - // 微信没有 - prodInfo.detail.mall_info = new mall_info_item(); - // 微信没有此处随意填 - prodInfo.detail.market_price = 0; - // 微信没有此处随意填 - prodInfo.detail.max_group_price = 0; - // 微信没有此处随意填 - prodInfo.detail.min_group_price = 0; - 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 = wxClientProdInfo.info.spuCode; - //if (prodInfo.detail.out_goods_sn.IsNullOrEmpty()) - //{ - // convertRst = "货号不存在"; - // return null; - //} - 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 = ""; - 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; - - //if (jstGoodsObj["skuInfo"].IsJTokenNullOrEmpty() || jstGoodsObj["skuInfo"]["goodsSkuDetail"].IsJTokenNullOrEmpty()) - //{ - // convertRst = "缺少sku信息"; - // return null; - //} - prodInfo.detail.sku = new List(); - foreach (var wxEditSkuInfo in wxClientProdInfo.productSkus) - { - var wxDisSku = wxClientProdInfo.info.sku_list.sku_info.FirstOrDefault(s => s.sku_id == wxEditSkuInfo.skuKey.skuId); - var discountedValue = (wxDisSku?.discounted_price).ParseToInt(); - sku_item skuInfo = new sku_item() - { - id = 0, - sku_id = wxEditSkuInfo.skuKey.skuId.ParseToLong(), - sku_sn = null, - carnival_price = 0, - init_quantity = 0, - is_onsale = 1, - limit_quantity = 999999, - multi_price = wxEditSkuInfo.productSkuInfo.salePrice.ParseToInt() - discountedValue, - multi_price_in_yuan = null, - price = wxEditSkuInfo.productSkuInfo.salePrice.ParseToInt() - discountedValue + 100, - price_in_yuan = null, - quantity = wxEditSkuInfo.productSkuInfo?.stockInfo?.stockNum?.ParseToInt(), - reserve_quantity = 0, - weight = 0, - thumb_url = wxEditSkuInfo.productSkuInfo.thumbImg, - thumb_url_file_id = null, - thumb_url_status = null, - thumb_url_is_deleted = null, - quantity_delta = 0, - spec = new List(), - // sku货号下面单独设置 - 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 = "", - }; - //// 聚水潭供应商价加价10%(最低1元)赚取差价 - //int addPrice = (skuInfo.multi_price * 0.1).ParseToInt(); - //if (addPrice < 100) - // addPrice = 100; - //skuInfo.multi_price += addPrice; - //skuInfo.price += addPrice; - if (wxEditSkuInfo.productSkuInfo.saleParam != null) - { - foreach (var wxSpec in wxEditSkuInfo.productSkuInfo.saleParam) - { - skuInfo.spec.Add(new spec_item() - { - parent_id = wxSpec.categorys[0].catId.ParseToLong(), - parent_name = wxSpec.categorys[0].name, - spec_id = wxSpec.categorys[1].catId.ParseToLong(), - spec_name = wxSpec.categorys[1].name, - }); - } - } - else - { - skuInfo.spec.Add(new spec_item() - { - parent_id = 0, - parent_name = "规格", - spec_id = 0, - spec_name = "默认", - }); - } - skuInfo.out_sku_sn = wxEditSkuInfo.productSkuInfo.skuCode; - prodInfo.detail.sku.Add(skuInfo); - } - 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 = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; - 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(); - - if (1 == 1) - { - foreach (var wxProp in wxClientProdInfo.info.param) - { - string name = wxProp.categorys.FirstOrDefault()?.name; - goods_propertie_item propInfo = new goods_propertie_item(); - prodInfo.property.goods_properties.Add(propInfo); - propInfo.name = name; - propInfo.ref_pid = null; - //propInfo.wx_input_type = wxProp.categorys.FirstOrDefault()?.catInfo.inputType; - propInfo.values = new List(); - foreach (var wxPropVal in wxProp.categorys) - { - // 第一个是属性名,装载属性值的时候跳过 - if (wxProp.categorys.IndexOf(wxPropVal) == 0) - continue; - - propInfo.values.Add(new value_item() - { - value = wxPropVal.name.ParseToString(), - raw_value = wxPropVal.name.ParseToString(), - vid = null, - unit = "" - }); - } - } - } - else - { - //outGoodsParam.productAttrs.Add(new osProductAttrParam { attrKey = "品牌", attrValue = "无品牌" }); - } - // 主图 复用前面的 - dbProd.main_img = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1).url; - dbProd.product_json = JsonHelper.SerializeObject(prodInfo); - - return prodInfo; - } - catch (Exception ex) - { - convertRst = "转换错误 " + ex.Message; - return null; - } - } - } + public class PDDProdFormConverter + { + /// + /// 拼多多前端采集转拼多多后台采集数据 + /// + /// + /// + /// + /// + public string PddFrontToPddBackConvert(string outProdJson, bool UpdateOldData = true, string specialProdType = null, bool IsCollectAuthorityUser = false) + { + PDDFrontProductInfo frontProdInfo = null; + try + { + frontProdInfo = JsonHelper.DeserializeJsonToObject(outProdJson); + } + catch (Exception ex) + { + return "转换错误" + ex.Message; + } + if (frontProdInfo == null || frontProdInfo.goods_id == 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.goods.cat_id.ParseToInt(); + prodInfo.detail.cat_ids = new List() { frontProdInfo.goods.cat_id_1.ParseToInt(), frontProdInfo.goods.cat_id_2.ParseToInt(), frontProdInfo.goods.cat_id_3.ParseToInt(), frontProdInfo.goods.cat_id_4.ParseToInt() }; + 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.goods.gallery) + { + if (frontGallery.type == 6) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = frontGallery.url, + type = frontGallery.type, + width = 0, + height = 0, + }); + } + else + { + //string getImgError; + //var image = GetHtml.GetUrlImg(frontGallery.url.Replace("https://", "http://"), out getImgError); + //if (!string.IsNullOrEmpty(getImgError)) + //{ + // return getImgError; + //} + prodInfo.detail.galleries.Add(new gallery_item() + { + url = frontGallery.url, + type = frontGallery.type, + //width = image.Width, + //height = image.Height, + }); + } + 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.goods.share_desc; + prodInfo.detail.goods_id = frontProdInfo.goods.goods_id ?? frontProdInfo.goods_id; + prodInfo.detail.goods_name = frontProdInfo.goods.goods_name; + 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 = frontProdInfo.goods.hd_thumb_url; + prodInfo.detail.id = 0; // 编辑id,随意填写 + prodInfo.detail.image_url = frontProdInfo.goods.image_url; + 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.goods.mall_id; + prodInfo.detail.mall_info = new mall_info_item() { mall_name = frontProdInfo.mall?.mall_name }; + prodInfo.detail.market_price = frontProdInfo.price.line_price; + prodInfo.detail.max_group_price = frontProdInfo.price.max_group_price; + prodInfo.detail.min_group_price = frontProdInfo.price.min_group_price; + 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.goods.share_desc; + 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(); + foreach (var frontSku in frontProdInfo.sku) + { + sku_item skuInfo = new sku_item() + { + id = 0, + sku_id = frontSku.sku_id, + sku_sn = null, + carnival_price = 0, + init_quantity = 0, + is_onsale = 1, + limit_quantity = 999999, + multi_price = (int)(frontSku.group_price.ParseToDecimal() * 100), + multi_price_in_yuan = null, + price = (int)(frontSku.normal_price.ParseToDecimal() * 100), + price_in_yuan = null, + quantity = 0, + reserve_quantity = 0, + weight = 0, + thumb_url = frontSku.thumb_url, + thumb_url_file_id = null, + thumb_url_status = null, + thumb_url_is_deleted = null, + quantity_delta = frontSku.quantity, + 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 = "", + }; + List specIds = frontSku.spec.Split(',').ToList(); + List specKeys = frontSku.spec_keys.Split(';').ToList(); + List specValues = frontSku.spec_values.Split(';').ToList(); + for (int i = 0; i < specIds.Count; i++) + { + skuInfo.spec.Add(new spec_item() + { + parent_name = specKeys[i], + spec_id = specIds[i].ParseToLong(), + spec_name = specValues[i], + }); + } + prodInfo.detail.sku.Add(skuInfo); + } + 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.goods.thumb_url; + 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.goods.property) + { + goods_propertie_item propInfo = new goods_propertie_item(); + propInfo.name = frontProp.key; + propInfo.values = new List(); + foreach (var frontPropValue in frontProp.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.mall?.mall_id + + "&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 ""; + } + + /// + /// 拼多多前端采集转拼多多后台采集数据 + /// + /// + /// + /// + /// + public string PddFrontToPddBackConvert2(string outProdJson, bool UpdateOldData = true, string specialProdType = null, bool IsCollectAuthorityUser = false) + { + PDDFrontProductInfo2 frontProdInfo = null; + try + { + frontProdInfo = JsonHelper.DeserializeJsonToObject(outProdJson); + } + catch (Exception ex) + { + return "转换错误" + ex.Message; + } + if (frontProdInfo == null || frontProdInfo.goods.goods_id == 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.ParseToLong().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.goods.cat_id.ParseToInt(); + prodInfo.detail.cat_ids = new List() { frontProdInfo.goods.cat_id_1.ParseToInt(), frontProdInfo.goods.cat_id_2.ParseToInt(), frontProdInfo.goods.cat_id_3.ParseToInt(), frontProdInfo.goods.cat_id_4.ParseToInt() }; + 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; + if (!frontProdInfo.goods.gallery.Any(g => g.type == 1)) + { + var jsonStr = BaseRegex.GetJsonObjStrJson(ref outProdJson, "carousel_section").OrderByDescending(s => s.Length).FirstOrDefault(); + if (jsonStr != null) + { + var jArrStr = BaseRegex.GetJsonArrStrJson(ref jsonStr, "picture_list").OrderByDescending(s => s.Length).FirstOrDefault(); + if (jArrStr != null) + { + foreach (var jObj in JArray.Parse(jArrStr)) + { + var jStr = JsonHelper.SerializeObject(jObj); + var type = BaseRegex.GetIntJson(ref jStr, "type"); + var img_url = BaseRegex.GetStringJson(ref jStr, "url"); + var id = BaseRegex.GetLongJson(ref jStr, "id"); + var goods_id = BaseRegex.GetLongJson(ref jStr, "goods_id"); + var width = BaseRegex.GetIntJson(ref jStr, "width"); + var height = BaseRegex.GetIntJson(ref jStr, "height"); + var enable_share = BaseRegex.GetIntJson(ref jStr, "enable_share"); + var gallery_pic = BaseRegex.GetIntJson(ref jStr, "gallery_pic"); + if (!img_url.IsNullOrEmpty() && !type.IsNullOrZero()) + { + frontProdInfo.goods.gallery.Add(new PDDFrontProductInfo2_gallery() + { + enable_share = enable_share, + goods_id = goods_id, + width = width, + height = height, + id = id, + type = type, + url = img_url, + priority = frontProdInfo.goods.gallery.Count, + }); + } + } + } + } + } + + if (!frontProdInfo.goods.gallery.Any(g => g.type == 1) && frontProdInfo.goods.gallery.Any(g => g.type == 13)) + { + foreach (var g in frontProdInfo.goods.gallery) + { + if (g.type == 13) + g.type = 1; + } + } + if (!frontProdInfo.goods.gallery.Any(g => g.type == 1) && frontProdInfo.goods.gallery.Any(g => g.type == 2)) + { + foreach (var g in frontProdInfo.goods.gallery.Where(g => g.type == 2) + .OrderBy(g => Math.Abs(100m - 100m * g.width.ParseToDecimal() / g.height.ParseToDecimal(1))).Take(3).ToList()) + { + frontProdInfo.goods.gallery.Add(new PDDFrontProductInfo2_gallery() + { + enable_share = g.enable_share, + goods_id = g.goods_id, + height = g.height, + id = g.id, + priority = g.priority, + type = 1, + url = g.url, + width = g.width, + }); + } + } + prodInfo.detail.galleries = new List(); + int galleryIndex = 0; + foreach (var frontGallery in frontProdInfo.goods.gallery) + { + if (frontGallery.type == 6) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = frontGallery.url, + type = frontGallery.type, + width = 0, + height = 0, + }); + } + else + { + //string getImgError; + //var image = GetHtml.GetUrlImg(frontGallery.url.Replace("https://", "http://"), out getImgError); + //if (!string.IsNullOrEmpty(getImgError)) + //{ + // return getImgError; + //} + prodInfo.detail.galleries.Add(new gallery_item() + { + url = frontGallery.url, + type = frontGallery.type, + //width = image.Width, + //height = image.Height, + }); + } + 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.goods.share_desc; + prodInfo.detail.goods_id = frontProdInfo.goods.goods_id; + prodInfo.detail.goods_name = frontProdInfo.goods.goods_name; + 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 = frontProdInfo.goods.hd_thumb_url; + prodInfo.detail.id = 0; // 编辑id,随意填写 + prodInfo.detail.image_url = frontProdInfo.goods.image_url; + 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.goods.mall_id; + prodInfo.detail.mall_info = new mall_info_item() { mall_name = frontProdInfo.mall_entrance?.mall_data?.mall_name }; + prodInfo.detail.market_price = frontProdInfo.price.line_price; + prodInfo.detail.max_group_price = frontProdInfo.price.max_group_price; + prodInfo.detail.min_group_price = frontProdInfo.price.min_group_price; + 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.goods.share_desc; + 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(); + foreach (var frontSku in frontProdInfo.sku) + { + sku_item skuInfo = new sku_item() + { + id = 0, + sku_id = frontSku.sku_id, + sku_sn = null, + carnival_price = 0, + init_quantity = 0, + is_onsale = 1, + limit_quantity = 999999, + multi_price = (int)frontSku.group_price.ParseToDecimal(), + multi_price_in_yuan = null, + price = (int)frontSku.normal_price.ParseToDecimal(), + price_in_yuan = null, + quantity = 0, + reserve_quantity = 0, + weight = 0, + thumb_url = frontSku.thumb_url, + thumb_url_file_id = null, + thumb_url_status = null, + thumb_url_is_deleted = null, + quantity_delta = frontSku.quantity, + 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 = "", + }; + 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(); + //List specKeys = frontSku.spec_keys.Split(';').ToList(); + //List specValues = frontSku.spec_values.Split(';').ToList(); + //for (int i = 0; i < specIds.Count; i++) + //{ + // skuInfo.spec.Add(new spec_item() + // { + // parent_name = specKeys[i], + // spec_id = specIds[i].ParseToLong(), + // spec_name = specValues[i], + // }); + //} + foreach (var frontSpec in frontSku.specs) + { + skuInfo.spec.Add(new spec_item() + { + parent_id = frontSpec.spec_key_id, + parent_name = frontSpec.spec_key, + spec_id = frontSpec.spec_value_id, + spec_name = frontSpec.spec_value, + }); + } + prodInfo.detail.sku.Add(skuInfo); + } + 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.goods.thumb_url; + 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.goods.goods_property) + { + goods_propertie_item propInfo = new goods_propertie_item(); + propInfo.name = frontProp.key; + propInfo.values = new List(); + foreach (var frontPropValue in frontProp.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.goods?.mall_id + + "&from_shop_name=" + prodInfo.detail.mall_info.mall_name + + "&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 ""; + } + + /// + /// 驼峰命名的一种新的拼多多格式 + /// + /// + /// + /// + /// + /// + public string PddFrontToPddBackConvert3(string outProdJson3, bool UpdateOldData = true, string specialProdType = null, bool IsCollectAuthorityUser = false) + { + initDataObjInfo frontProdInfo = null; + try + { + frontProdInfo = JsonHelper.DeserializeJsonToObject(outProdJson3)?.store?.initDataObj; + } + catch (Exception ex) + { + return "转换错误" + ex.Message; + } + if (frontProdInfo == null || frontProdInfo.goods?.goodsID == null || frontProdInfo.mall?.mallId == null || frontProdInfo.mall?.mallName == null) + { + return "商品数据信息为空"; + } + + KJDDBProduct dbProd = new KJDDBProduct() { size_json = "{}" }; + PDDProductInfo prodInfo = new PDDProductInfo() + { + //source_json = JsonHelper.JObjectParse(outProdJson), + source_json = null, + sale_count = BaseRegex.GetStringJson(ref outProdJson3, "sold_quantity").ParseToLong().ParseToString(), + sale_count_text = BaseRegex.GetStringJson(ref outProdJson3, "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.goods.catID.ParseToInt(); + prodInfo.detail.cat_ids = new List() { frontProdInfo.goods.catID1.ParseToInt(), frontProdInfo.goods.catID2.ParseToInt(), frontProdInfo.goods.catID3.ParseToInt(), frontProdInfo.goods.catID4.ParseToInt() }; + 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 topGallery in frontProdInfo.goods.topGallery) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = topGallery.url, + type = 1, + //width = image.Width, + //height = image.Height, + }); + galleryIndex++; + } + foreach (var detailGallery in frontProdInfo.goods.detailGallery) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = detailGallery.url, + type = 2, + //width = image.Width, + //height = image.Height, + }); + 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.goods.shareDesc; + prodInfo.detail.goods_id = frontProdInfo.goods.goodsID; + prodInfo.detail.goods_name = frontProdInfo.goods.goodsName; + 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 = frontProdInfo.goods.hdThumbUrl; + prodInfo.detail.id = 0; // 编辑id,随意填写 + prodInfo.detail.image_url = frontProdInfo.goods.topGallery.FirstOrDefault()?.url; // frontProdInfo.goods.image_url; + 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.mall.mallId.ParseToLong(); + prodInfo.detail.mall_info = new mall_info_item() { mall_name = frontProdInfo.mall.mallName }; + prodInfo.detail.market_price = (frontProdInfo.goods.linePrice.ParseToDecimal() * 100).ParseToInt(); + prodInfo.detail.max_group_price = frontProdInfo.goods.maxOnSaleGroupPriceInCent; + prodInfo.detail.min_group_price = frontProdInfo.goods.minOnSaleGroupPriceInCent; + 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.goods.shareDesc; + 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(); + foreach (var frontSku in frontProdInfo.goods.skus) + { + sku_item skuInfo = new sku_item() + { + id = 0, + sku_id = frontSku.skuId, + sku_sn = null, + carnival_price = 0, + init_quantity = 0, + is_onsale = 1, + limit_quantity = 999999, + multi_price = (int)(frontSku.groupPrice.ParseToDecimal() * 100), + multi_price_in_yuan = null, + price = (int)(frontSku.normalPrice.ParseToDecimal() * 100), + price_in_yuan = null, + quantity = 0, + reserve_quantity = 0, + weight = 0, + thumb_url = frontSku.thumbUrl, + thumb_url_file_id = null, + thumb_url_status = null, + thumb_url_is_deleted = null, + quantity_delta = frontSku.quantity, + 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 = "", + }; + if ((int)(frontSku.groupPrice.ParseToDecimal() * 100) > 0) + skuInfo.multi_price = Math.Min(skuInfo.multi_price.ParseToInt(), (int)(frontSku.groupPrice.ParseToDecimal() * 100)); + + //List specIds = frontSku.spec.Split(',').ToList(); + //List specKeys = frontSku.spec_keys.Split(';').ToList(); + //List specValues = frontSku.spec_values.Split(';').ToList(); + //for (int i = 0; i < specIds.Count; i++) + //{ + // skuInfo.spec.Add(new spec_item() + // { + // parent_name = specKeys[i], + // spec_id = specIds[i].ParseToLong(), + // spec_name = specValues[i], + // }); + //} + foreach (var frontSpec in frontSku.specs) + { + skuInfo.spec.Add(new spec_item() + { + parent_id = frontSpec.spec_key_id, + parent_name = frontSpec.spec_key, + spec_id = frontSpec.spec_value_id, + spec_name = frontSpec.spec_value, + }); + } + prodInfo.detail.sku.Add(skuInfo); + } + 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.goods.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.goods.goodsProperty) + { + goods_propertie_item propInfo = new goods_propertie_item(); + propInfo.name = frontProp.key; + propInfo.values = new List(); + foreach (var frontPropValue in frontProp.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.mall?.mallId + + "&from_shop_name=" + frontProdInfo.mall?.mallName + + "&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 ""; + } + + + /// + /// 外来格式 中文属性转拼多多格式 + /// + /// + /// + /// + /// + /// + public string PddFrontToPddBackConvertV4(string outProdJson, bool UpdateOldData = true, string specialProdType = null, bool IsCollectAuthorityUser = false) + { + + + PDDFrontProductInfo4 frontProdInfo = null; + try + { + frontProdInfo = JsonHelper.DeserializeJsonToObject(outProdJson); + } + catch (Exception ex) + { + return "转换错误" + ex.Message; + } + if (frontProdInfo == null || frontProdInfo.ProductId == null) + { + return "商品数据信息为空"; + } + + long mallId = Randomx.GetId(10000000, 99999999); + if (!string.IsNullOrEmpty(frontProdInfo.ProductUrl)) + { + mallId = Math.Abs(frontProdInfo.ProductUrl.GetHashCode()); + } + string thumbUrl = frontProdInfo.MainImages.FirstOrDefault(); + 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.Category.ParseToInt(); + prodInfo.detail.cat_ids = new List(); + 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.ProductId.ParseToLong(); + 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 = mallId; + prodInfo.detail.mall_info = new mall_info_item() { mall_name = mallId.ToString() }; + + 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 (KeyValuePair frontSku in frontProdInfo.SKU) + { + 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)(frontSku.Value.Price.ParseToDecimal() * 100), + multi_price_in_yuan = null, + price = (int)(frontSku.Value.Price.ParseToDecimal() * 100 + 100), + price_in_yuan = null, + quantity = 0, + reserve_quantity = 0, + weight = 0, + thumb_url = frontSku.Value.SpecImage, + thumb_url_file_id = null, + thumb_url_status = null, + thumb_url_is_deleted = null, + quantity_delta = frontSku.Value.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 = frontSku.Value.SpecValue.Split(',').ToList(); + foreach (var specItem in specList) + { + string parentName = ""; + foreach (var item in frontProdInfo.Specifications) + { + if (item.Value.Contains(specItem)) + { + parentName = item.Key; + break; + } + } + skuInfo.spec.Add(new spec_item() + { + parent_name = parentName, + spec_name = specItem, + spec_id = null, + }); + } + 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 = 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.Attributes) + { + 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=" + 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格式 + /// + /// + /// + /// + public PDDProductInfo JstPddProdToPddConvert(out string convertRst, KJDDBProduct dbProd) + { + convertRst = ""; + try + { + var prodObj = JsonHelper.JObjectParse(dbProd.product_json); + if (prodObj["pddData"].IsJTokenNullOrEmpty()) + { + convertRst = "缺少指定的数据格式"; + return null; + } + var jstGoodsObj = prodObj["pddData"]; + var jstPddPropMapLst = JsonHelper.DeserializeJsonToList(JsonHelper.SerializeObject(prodObj["pddPropMap"])); + //{"goodsId":"2016474712785620994","warehouseGoodsId":"C7108311198A4217B022DCA87B6A5863","spuCode":"3783056947394249077","skus":[{"skuId":"2016692758292738050","warehouseSkuId":"C742B3FCB0364448AF92332F8F6005A6","skuCode":"ZH-XP-YWQYW-010"},{"skuId":"2016692758317903874","warehouseSkuId":"703E87F1B7774C14923821A57EEE6EFA","skuCode":"ZH-XP-YWQYW-010-111"},{"skuId":"2016692758338875394","warehouseSkuId":"895EDCDF6ECC4FAE8AD4DB9503719002","skuCode":"ZH-XP-YWQYW-010-222"}]} + var jstSecretCodeLst = JsonHelper.JObjectParse(dbProd.sku_secret_json.TrimStart('[').TrimEnd(']')); + + PDDProductInfo prodInfo = new PDDProductInfo() + { + sale_count = dbProd.sale_count.ParseToString(), + sale_count_text = dbProd.sale_count_text, + }; + 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 = jstGoodsObj["catId"].ParseToInt(); + prodInfo.detail.cat_ids = new List(); + var catLst = (jstGoodsObj["categoryData"] as JArray).Select(a => a.ParseToInt()).ToList(); + foreach (var cId in catLst) + { + prodInfo.detail.cat_ids.Add(cId); + } + 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(); + foreach (var imgObj in jstGoodsObj["carouselGallery"]) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = imgObj.ParseToString(), + type = 1, + }); + } + foreach (var imgObj in jstGoodsObj["detailGallery"]) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = imgObj.ParseToString(), + type = 2, + }); + } + 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 = jstGoodsObj["goodsDesc"].ParseToString(); + // 聚水潭为string,散列取数值 + prodInfo.detail.goods_id = jstGoodsObj["itemSpuId"].ParseToString().GetHashCode(); + prodInfo.detail.goods_name = jstGoodsObj["itemName"].ParseToString(); + 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.galleries.FirstOrDefault(g => g.type == 1)?.url; + // 编辑id,随意填写 + prodInfo.detail.id = 0; + // 复用前面已经填写过的 + prodInfo.detail.image_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; + 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 = 0; + // 聚水潭没有 + prodInfo.detail.mall_info = new mall_info_item(); + // 聚水潭没有此处随意填 + prodInfo.detail.market_price = 0; + // 聚水潭没有此处随意填 + prodInfo.detail.max_group_price = 0; + // 聚水潭没有此处随意填 + prodInfo.detail.min_group_price = 0; + 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 = jstSecretCodeLst["goodsId"].ParseToString(); + // 货号直接替换成加密的,注意千万不要再把这个ext_code入库 + dbProd.ext_code = prodInfo.detail.out_goods_sn; + if (prodInfo.detail.out_goods_sn.IsNullOrEmpty()) + { + convertRst = "货号不存在"; + return null; + } + 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 = ""; + 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; + + if (jstGoodsObj["skuInfo"].IsJTokenNullOrEmpty() || jstGoodsObj["skuInfo"]["goodsSkuDetail"].IsJTokenNullOrEmpty()) + { + convertRst = "缺少sku信息"; + return null; + } + prodInfo.detail.sku = new List(); + foreach (JObject jSku in jstGoodsObj["skuInfo"]["goodsSkuDetail"]) + { + sku_item skuInfo = new sku_item() + { + id = 0, + // 聚水潭为string,散列取数值 + sku_id = jSku["baseSkuId"].ParseToString().GetHashCode(), + sku_sn = null, + carnival_price = 0, + init_quantity = 0, + is_onsale = 1, + limit_quantity = 999999, + multi_price = (int)(jSku["supplyPrice"].ParseToDecimal() * 100), + multi_price_in_yuan = null, + price = (int)(jSku["supplyPrice"].ParseToDecimal() * 100 + 100), + price_in_yuan = null, + quantity = jSku["quantity"].ParseToInt(), + reserve_quantity = 0, + weight = (int)(jSku["weight"].ParseToDecimal() * 1000), + thumb_url = jSku["pic"].ParseToString(), + thumb_url_file_id = null, + thumb_url_status = null, + thumb_url_is_deleted = null, + quantity_delta = 0, + spec = new List(), + // sku货号下面单独设置 + 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 = "", + }; + // 聚水潭广告sku价格为0库存不为零的给库存也改为0 + if (skuInfo.multi_price == 0) + { + skuInfo.quantity = 0; + skuInfo.quantity_delta = 0; + } + + // 聚水潭供应商价加价10%(最低1元)赚取差价 + int addPrice = (skuInfo.multi_price * 0.1).ParseToInt(); + if (addPrice < 100) + addPrice = 100; + skuInfo.multi_price += addPrice; + skuInfo.price += addPrice; + foreach (JObject jSpec in jSku["skus"]) + { + skuInfo.spec.Add(new spec_item() + { + parent_id = jSpec["kid"].ParseToLong(), + parent_name = jSpec["k"].ParseToString(), + spec_id = jSpec["vid"].ParseToLong(), + spec_name = jSpec["v"].ParseToString(), + }); + } + var itemNo = jSku["itemNo"].ParseToString(); + var baseSkuId = jSku["baseSkuId"].ParseToString(); + // skuCode可能不唯一,使用skuId取加密后的货号 + //var skuId = jstSecretCodeLst["skus"].FirstOrDefault(s => s["skuCode"].ParseToString() == itemNo)?["skuId"].ParseToString(); + var skuStr = jSku.ParseToString(); + var jstSecretCodeLstSkuStr = jstSecretCodeLst["skus"].ParseToString(); + var skuId = jstSecretCodeLst["skus"].FirstOrDefault(s => s["warehouseSkuId"].ParseToString() == baseSkuId)?["skuId"].ParseToString(); + if (skuId.IsNullOrEmpty() || string.IsNullOrEmpty(itemNo)) + { + convertRst = "SKU货号不存在"; + return null; + } + // 外部编码(货号) + skuInfo.out_sku_sn = skuId; + prodInfo.detail.sku.Add(skuInfo); + } + // 测试发现skuCoke重复可能对推单有影响,先吧skuCode重复的排除掉 + var skuCount = jstGoodsObj["skuInfo"]["goodsSkuDetail"].Select(s => s["baseSkuId"].ParseToString()).Distinct().Count(); + var itemNoCount = jstGoodsObj["skuInfo"]["goodsSkuDetail"].Select(s => s["itemNo"].ParseToString()).Distinct().Count(); + var skusStr = jstGoodsObj["skuInfo"]["goodsSkuDetail"].ParseToString(); + var skuSkuIdStr = string.Join("\r\n", jstGoodsObj["skuInfo"]["goodsSkuDetail"].Select(s => s["baseSkuId"].ParseToString())); + var skuItemNoStr = string.Join("\r\n", jstGoodsObj["skuInfo"]["goodsSkuDetail"].Select(s => s["itemNo"].ParseToString())); + if (skuCount != itemNoCount) + { + //convertRst = "SKU货号重复"; + //return null; + } + 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 = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; + 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(); + + if (!jstGoodsObj["goodsProperties"].IsJTokenNullOrEmpty()) + { + foreach (JObject jProp in jstGoodsObj["goodsProperties"]) + { + string name = ""; + if (!jProp["propName"].IsJTokenNullOrEmpty()) + name = jProp["propName"].ParseToString(); + else + { + try + { + if (jstPddPropMapLst != null) + name = jstPddPropMapLst.FirstOrDefault(p => p.ref_pid.ParseToString() == jProp["refPid"].ParseToString())?.name; + if (string.IsNullOrEmpty(name)) + name = jProp["refPid"].ParseToString(); + } + catch + { + } + } + goods_propertie_item propInfo = new goods_propertie_item(); + prodInfo.property.goods_properties.Add(propInfo); + propInfo.name = name; + propInfo.ref_pid = jProp["refPid"].ParseToInt(); + string propStr = JsonHelper.SerializeObject(jProp); + propInfo.values = new List(); + if (propStr.Contains("multipleValue") && !propStr.Contains("\"multipleValue\":[]")) + { + foreach (var propValueObj in jProp["multipleValue"]) + { + propInfo.values.Add(new value_item() + { + value = propValueObj["label"].ParseToString(), + raw_value = propValueObj["label"].ParseToString(), + vid = propValueObj["value"].ParseToLong(), + unit = "" + }); + } + } + else + { + var label = BaseRegex.GetStringJson(ref propStr, "label"); + var valueId = BaseRegex.GetStringJson(ref propStr, "value").ParseToLong(); + if (string.IsNullOrEmpty(label)) + label = BaseRegex.GetStringJson(ref propStr, "inputValue") + " " + BaseRegex.GetStringJson(ref propStr, "valueUnit"); + label = label.Trim(); + propInfo.values.Add(new value_item() + { + value = label, + raw_value = label, + vid = valueId, + unit = "" + }); + } + } + } + else + { + //outGoodsParam.productAttrs.Add(new osProductAttrParam { attrKey = "品牌", attrValue = "无品牌" }); + } + // 主图 + dbProd.main_img = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1).url; + dbProd.product_json = JsonHelper.SerializeObject(prodInfo); + + return prodInfo; + + //bool isExist = false; + //var existUrl = BaseClass.BuildPDDObjString("product/get_product_list"); + //string existData = UserLogin.GetSignaturex() + "&search_spu=" + prodInfo.detail.goods_id; + //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.mall?.mall_id + + // "&spu_id=" + prodInfo.detail.goods_id.ParseToString() + + // "&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); + + //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 ""; + } + catch (Exception ex) + { + convertRst = "转换错误 " + ex.Message; + return null; + } + } + + /// + /// 微信店铺采集转拼多多 + /// + /// + /// + /// + public PDDProductInfo WXProdToPddConvert(out string convertRst, KJDDBProduct dbProd) + { + convertRst = ""; + try + { + //var prodObj = JsonHelper.JObjectParse(dbProd.product_json); + //if (prodObj["pddData"].IsJTokenNullOrEmpty()) + //{ + // convertRst = "缺少指定的数据格式"; + // return null; + //} + //var jstGoodsObj = prodObj["pddData"]; + //var jstPddPropMapLst = JsonHelper.DeserializeJsonToList(JsonHelper.SerializeObject(prodObj["pddPropMap"])); + ////{"goodsId":"2016474712785620994","warehouseGoodsId":"C7108311198A4217B022DCA87B6A5863","spuCode":"3783056947394249077","skus":[{"skuId":"2016692758292738050","warehouseSkuId":"C742B3FCB0364448AF92332F8F6005A6","skuCode":"ZH-XP-YWQYW-010"},{"skuId":"2016692758317903874","warehouseSkuId":"703E87F1B7774C14923821A57EEE6EFA","skuCode":"ZH-XP-YWQYW-010-111"},{"skuId":"2016692758338875394","warehouseSkuId":"895EDCDF6ECC4FAE8AD4DB9503719002","skuCode":"ZH-XP-YWQYW-010-222"}]} + //var jstSecretCodeLst = JsonHelper.JObjectParse(dbProd.sku_secret_json.TrimStart('[').TrimEnd(']')); + + WXGetEditProductInfoLite wxEditProdInfo = JsonHelper.DeserializeJsonToObject(dbProd.product_json); + + PDDProductInfo prodInfo = new PDDProductInfo() + { + sale_count = dbProd.sale_count.ParseToString(), + sale_count_text = dbProd.sale_count_text, + }; + 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 = dbProd.cat_id.ParseToInt(); + prodInfo.detail.cat_ids = new List(); + //微信商品的类目直接输入,上传的时候不用。 + foreach (var category in wxEditProdInfo.product.info.category) + { + prodInfo.detail.cat_ids.Add(category.catId.ParseToInt()); + } + 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(); + foreach (var imgItem in wxEditProdInfo.product.info.headImg) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = imgItem, + type = 1, + }); + } + foreach (var imgItem in wxEditProdInfo.product.info.detail.detailImg) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = imgItem, + type = 2, + }); + } + 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 = wxEditProdInfo.product.info.title; + prodInfo.detail.goods_id = wxEditProdInfo.product.productKey.productId.ParseToLong(); + prodInfo.detail.goods_name = wxEditProdInfo.product.info.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.galleries.FirstOrDefault(g => g.type == 1)?.url; + // 编辑id,随意填写 + prodInfo.detail.id = 0; + // 复用前面已经填写过的 + prodInfo.detail.image_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; + 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 = 0; + // 微信没有 + prodInfo.detail.mall_info = new mall_info_item(); + // 微信没有此处随意填 + prodInfo.detail.market_price = 0; + // 微信没有此处随意填 + prodInfo.detail.max_group_price = 0; + // 微信没有此处随意填 + prodInfo.detail.min_group_price = 0; + 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 = wxEditProdInfo.product.info.spuCode; + //if (prodInfo.detail.out_goods_sn.IsNullOrEmpty()) + //{ + // convertRst = "货号不存在"; + // return null; + //} + 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 = ""; + 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; + + //if (jstGoodsObj["skuInfo"].IsJTokenNullOrEmpty() || jstGoodsObj["skuInfo"]["goodsSkuDetail"].IsJTokenNullOrEmpty()) + //{ + // convertRst = "缺少sku信息"; + // return null; + //} + prodInfo.detail.sku = new List(); + //foreach (JObject jSku in jstGoodsObj["skuInfo"]["goodsSkuDetail"]) + foreach (var wxEditSkuInfo in wxEditProdInfo.product.productSkus) + { + sku_item skuInfo = new sku_item() + { + id = 0, + sku_id = wxEditSkuInfo.skuKey.skuId.ParseToLong(), + sku_sn = null, + carnival_price = 0, + init_quantity = 0, + is_onsale = 1, + limit_quantity = 999999, + multi_price = wxEditSkuInfo.productSkuInfo.salePrice.ParseToInt(), + multi_price_in_yuan = null, + price = wxEditSkuInfo.productSkuInfo.salePrice.ParseToInt() + 100, + price_in_yuan = null, + quantity = wxEditSkuInfo.productSkuInfo.realStockInfo?.stockNum ?? wxEditSkuInfo.productSkuInfo.stockInfo?.stockNum.ParseToInt(), + reserve_quantity = 0, + weight = 0, + thumb_url = wxEditSkuInfo.productSkuInfo.thumbImg, + thumb_url_file_id = null, + thumb_url_status = null, + thumb_url_is_deleted = null, + quantity_delta = 0, + spec = new List(), + // sku货号下面单独设置 + 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 = "", + }; + //// 聚水潭供应商价加价10%(最低1元)赚取差价 + //int addPrice = (skuInfo.multi_price * 0.1).ParseToInt(); + //if (addPrice < 100) + // addPrice = 100; + //skuInfo.multi_price += addPrice; + //skuInfo.price += addPrice; + foreach (var wxSpec in wxEditSkuInfo.productSkuInfo.saleParam) + { + skuInfo.spec.Add(new spec_item() + { + parent_id = wxSpec.categorys[0].catId.ParseToLong(), + parent_name = wxSpec.categorys[0].name, + spec_id = wxSpec.categorys[1].catId.ParseToLong(), + spec_name = wxSpec.categorys[1].name, + }); + } + skuInfo.out_sku_sn = wxEditSkuInfo.productSkuInfo.skuCode; + prodInfo.detail.sku.Add(skuInfo); + } + 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 = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; + 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(); + + if (1 == 1) + { + foreach (var wxProp in wxEditProdInfo.product.info.param) + { + string name = wxProp.categorys.FirstOrDefault()?.name; + goods_propertie_item propInfo = new goods_propertie_item(); + prodInfo.property.goods_properties.Add(propInfo); + propInfo.name = name; + propInfo.ref_pid = null; + //propInfo.wx_input_type = wxProp.categorys.FirstOrDefault()?.catInfo.inputType; + propInfo.values = new List(); + foreach (var wxPropVal in wxProp.categorys) + { + // 第一个是属性名,装载属性值的时候跳过 + if (wxProp.categorys.IndexOf(wxPropVal) == 0) + continue; + + propInfo.values.Add(new value_item() + { + value = wxPropVal.name.ParseToString(), + raw_value = wxPropVal.name.ParseToString(), + vid = null, + unit = "" + }); + } + } + } + else + { + //outGoodsParam.productAttrs.Add(new osProductAttrParam { attrKey = "品牌", attrValue = "无品牌" }); + } + // 主图 复用前面的 + dbProd.main_img = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1).url; + dbProd.product_json = JsonHelper.SerializeObject(prodInfo); + + return prodInfo; + } + catch (Exception ex) + { + convertRst = "转换错误 " + ex.Message; + return null; + } + } + + /// + /// 1688网页端采集转拼多多 + /// + /// + /// + /// + public PDDProductInfo _1688ClientToPddConvert(out string convertRst, KJDDBProduct dbProd) + { + convertRst = ""; + try + { + var prod_json = dbProd.product_json; + var _1688Json = BaseRegex.GetOneJsonObjStrJson(ref prod_json, "_1688DetailData"); + _1688ClientProductInfo _1688ClentProdInfo = JsonHelper.DeserializeJsonToObject<_1688ClientProductInfo>(_1688Json); + + PDDProductInfo prodInfo = new PDDProductInfo() + { + sale_count = dbProd.sale_count.ParseToString(), + sale_count_text = dbProd.sale_count_text, + }; + 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 = dbProd.cat_id.ParseToInt(); + prodInfo.detail.cat_ids = new List(); + //foreach (var category in _1688EditProdInfo.product.info.category) + //{ + // prodInfo.detail.cat_ids.Add(category.catId.ParseToInt()); + //} + 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(); + foreach (var imgItem in _1688ClentProdInfo.mainImage) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = imgItem, + type = 1, + }); + } + foreach (var imgItem in _1688ClentProdInfo.offerImgList) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = imgItem, + type = 2, + }); + } + 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 = _1688ClentProdInfo.tempModel.offerTitle; + prodInfo.detail.goods_id = _1688ClentProdInfo.tempModel.offerId; + prodInfo.detail.goods_name = _1688ClentProdInfo.tempModel.offerTitle; + 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.galleries.FirstOrDefault(g => g.type == 1)?.url; + // 编辑id,随意填写 + prodInfo.detail.id = 0; + // 复用前面已经填写过的 + prodInfo.detail.image_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; + 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; + // 1688没有 + prodInfo.detail.mall_id = 0; + // 1688没有 + prodInfo.detail.mall_info = new mall_info_item(); + // 1688没有此处随意填 + prodInfo.detail.market_price = 0; + // 1688没有此处随意填 + prodInfo.detail.max_group_price = 0; + // 1688没有此处随意填 + prodInfo.detail.min_group_price = 0; + prodInfo.detail.must_check_type = 0; + prodInfo.detail.name_prefix = ""; + prodInfo.detail.origin_country_id = 0; + prodInfo.detail.origin_country_name = ""; + // 货号 1688没有字段直接标明,可能存在属性里面 + prodInfo.detail.out_goods_sn = (_1688ClentProdInfo.offerDetail?.featureAttributes?.FirstOrDefault(s => s.name == "货号")?.value).ParseToString(); + //if (prodInfo.detail.out_goods_sn.IsNullOrEmpty()) + //{ + // convertRst = "货号不存在"; + // return null; + //} + 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; + // 1688没有 + prodInfo.detail.share_desc = ""; + 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(); + foreach (string skuKey in _1688ClentProdInfo.skuModel.skuInfoMap.Keys) + { + _1688skuInfo _1688skuInfo = _1688ClentProdInfo.skuModel.skuInfoMap[skuKey]; + + sku_item skuInfo = new sku_item() + { + id = 0, + sku_id = _1688skuInfo.skuId.ParseToLong(), + sku_sn = null, + carnival_price = 0, + init_quantity = 0, + is_onsale = 1, + limit_quantity = 999999, + multi_price = (_1688skuInfo.price.ParseToDecimal() * 100 + _1688ClentProdInfo.postFeeValue.ParseToDecimal() * 100).ParseToInt(), + multi_price_in_yuan = null, + price = (_1688skuInfo.price.ParseToDecimal() * 100 + _1688ClentProdInfo.postFeeValue.ParseToDecimal() * 100).ParseToInt() + 100, + price_in_yuan = null, + quantity = _1688skuInfo.canBookCount, + reserve_quantity = 0, + weight = 0, + //thumb_url = _1688skuInfo.productSkuInfo.thumbImg, + thumb_url_file_id = null, + thumb_url_status = null, + thumb_url_is_deleted = null, + quantity_delta = 0, + spec = new List(), + // sku货号 + out_sku_sn = _1688skuInfo.specId, + 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 = "", + }; + //// 聚水潭供应商价加价10%(最低1元)赚取差价 + //int addPrice = (skuInfo.multi_price * 0.1).ParseToInt(); + //if (addPrice < 100) + // addPrice = 100; + //skuInfo.multi_price += addPrice; + //skuInfo.price += addPrice; + foreach (_1688skuProp _1688skuProp in _1688ClentProdInfo.skuModel.skuProps) + { + foreach (_1688skuValue _1688SpecValue in _1688skuProp.value) + { + if ((">" + skuKey + ">").Contains(">" + _1688SpecValue.name + ">")) + { + skuInfo.spec.Add(new spec_item() + { + parent_id = _1688skuProp.fid.ParseToLong(), + parent_name = _1688skuProp.prop, + spec_id = 0, + spec_name = _1688SpecValue.name, + }); + if (!string.IsNullOrEmpty(_1688SpecValue.imageUrl)) + skuInfo.thumb_url = _1688SpecValue.imageUrl; + } + } + } + prodInfo.detail.sku.Add(skuInfo); + } + 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 = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; + 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(); + + if (1 == 1) + { + foreach (_1688featureAttributes _1688Attr in _1688ClentProdInfo.offerDetail.featureAttributes) + { + string name = _1688Attr.name; + goods_propertie_item propInfo = new goods_propertie_item(); + prodInfo.property.goods_properties.Add(propInfo); + propInfo.name = name; + propInfo.ref_pid = null; + //propInfo.wx_input_type = wxProp.categorys.FirstOrDefault()?.catInfo.inputType; + propInfo.values = new List(); + List values = (_1688Attr.values == null || _1688Attr.values.Count() == 0) ? _1688Attr.decisionValues : _1688Attr.values; + foreach (var wxPropVal in values) + { + propInfo.values.Add(new value_item() + { + value = wxPropVal, + raw_value = wxPropVal, + vid = null, + unit = "" + }); + } + } + } + else + { + //outGoodsParam.productAttrs.Add(new osProductAttrParam { attrKey = "品牌", attrValue = "无品牌" }); + } + // 主图 复用前面的 + dbProd.main_img = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1).url; + dbProd.product_json = JsonHelper.SerializeObject(prodInfo); + + return prodInfo; + } + catch (Exception ex) + { + convertRst = "转换错误 " + ex.Message; + return null; + } + } + + /// + /// 1688外部数据转拼多多(万象工具) + /// + /// + /// + /// + public PDDProductInfo _1688OutToPddConvert(out string convertRst, KJDDBProduct dbProd) + { + convertRst = ""; + try + { + var prod_json = dbProd.product_json; + _1688OutProductInfo _1688OutProdInfo = JsonHelper.DeserializeJsonToObject<_1688OutProductInfo>(prod_json); + + PDDProductInfo prodInfo = new PDDProductInfo() + { + sale_count = dbProd.sale_count.ParseToString(), + sale_count_text = dbProd.sale_count_text, + }; + 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 = dbProd.cat_id.ParseToInt(); + prodInfo.detail.cat_ids = new List(); + //foreach (var category in _1688EditProdInfo.product.info.category) + //{ + // prodInfo.detail.cat_ids.Add(category.catId.ParseToInt()); + //} + 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(); + foreach (var imgItem in _1688OutProdInfo.itemImgs) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = imgItem, + type = 1, + }); + } + var desc = _1688OutProdInfo.desc.ParseToString(); + var descLst = desc.Split(new string[] { "src=\"", "\" usemap", "\"/>", "\"" }, StringSplitOptions.RemoveEmptyEntries).ToList(); + foreach (var imgItem in descLst) + { + if (!imgItem.StartsWith("http") || (!imgItem.ToLower().Contains(".jpg") && !imgItem.ToLower().Contains(".jpeg") && !imgItem.ToLower().Contains(".png"))) + continue; + prodInfo.detail.galleries.Add(new gallery_item() + { + url = imgItem, + type = 2, + }); + } + 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 = _1688OutProdInfo.productName; + prodInfo.detail.goods_id = _1688OutProdInfo.productId.ParseToLong(); + prodInfo.detail.goods_name = _1688OutProdInfo.productName; + 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.galleries.FirstOrDefault(g => g.type == 1)?.url; + // 编辑id,随意填写 + prodInfo.detail.id = 0; + // 复用前面已经填写过的 + prodInfo.detail.image_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; + 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; + // 1688没有 + prodInfo.detail.mall_id = 0; + // 1688没有 + prodInfo.detail.mall_info = new mall_info_item(); + // 1688没有此处随意填 + prodInfo.detail.market_price = 0; + // 1688没有此处随意填 + prodInfo.detail.max_group_price = 0; + // 1688没有此处随意填 + prodInfo.detail.min_group_price = 0; + 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 = (_1688OutProdInfo.attribute.FirstOrDefault(a => a.key == "货号")?.value).ParseToString(); + //if (prodInfo.detail.out_goods_sn.IsNullOrEmpty()) + //{ + // convertRst = "货号不存在"; + // return null; + //} + 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; + // 1688没有 + prodInfo.detail.share_desc = ""; + 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(); + if (_1688OutProdInfo.skus == null) + _1688OutProdInfo.skus = new List<_1688Sku>(); + if (_1688OutProdInfo.skus.Count == 0) + { + _1688OutProdInfo.skus.Add(new _1688Sku() + { + skuId = -1, + quantity = 999, + price = (_1688OutProdInfo.priceHigh.ParseToDecimal() * 100).ParseToInt(), + }); + } + foreach (var sku in _1688OutProdInfo.skus) + { + var postFeeValue = (_1688OutProdInfo.deliveryInfo?.carriageList?.Max(c => c.price)).ParseToDecimal(); + + //_1688skuInfo _1688skuInfo = _1688OutProdInfo.skuModel.skuInfoMap[sku]; + + sku_item skuInfo = new sku_item() + { + id = 0, + sku_id = sku.skuId, + sku_sn = null, + carnival_price = 0, + init_quantity = 0, + is_onsale = 1, + limit_quantity = 999999, + multi_price = (sku.price + postFeeValue * 100).ParseToInt(), + multi_price_in_yuan = null, + price = (sku.price + postFeeValue * 100).ParseToInt() + 100, + price_in_yuan = null, + quantity = sku.quantity, + reserve_quantity = 0, + weight = 0, + //thumb_url = _1688skuInfo.productSkuInfo.thumbImg, + thumb_url_file_id = null, + thumb_url_status = null, + thumb_url_is_deleted = null, + quantity_delta = 0, + spec = new List(), + // sku货号 + 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 = "", + }; + //// 聚水潭供应商价加价10%(最低1元)赚取差价 + //int addPrice = (skuInfo.multi_price * 0.1).ParseToInt(); + //if (addPrice < 100) + // addPrice = 100; + //skuInfo.multi_price += addPrice; + //skuInfo.price += addPrice; + foreach (_1688PropsName _1688skuProp in _1688OutProdInfo.propsName) + { + foreach (_1688PropsNameValue _1688skuPropValue in _1688skuProp.values) + { + if ((";" + sku.id + ";").Contains(";" + _1688skuProp.pid + ":" + _1688skuPropValue.vid + ";")) + { + skuInfo.spec.Add(new spec_item() + { + parent_id = _1688skuProp.pid.ParseToLong(), + parent_name = _1688skuProp.pname, + spec_id = _1688skuPropValue.vid.ParseToLong(), + spec_name = _1688skuPropValue.vname, + }); + if (!string.IsNullOrEmpty(_1688skuPropValue.sku_url)) + skuInfo.thumb_url = _1688skuPropValue.sku_url; + } + } + } + if (skuInfo.spec.Count == 0) + skuInfo.spec.Add(new spec_item() + { + parent_id = 0, + parent_name = "款式", + spec_id = 0, + spec_name = "默认", + }); + if (string.IsNullOrEmpty(skuInfo.thumb_url)) + { + skuInfo.thumb_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; + } + prodInfo.detail.sku.Add(skuInfo); + } + 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 = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; + 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(); + + if (1 == 1) + { + foreach (_1688AttributeInfo _1688Attr in _1688OutProdInfo.attribute) + { + // 1688会把商品sku属性放到商品属性里面,需要剔除这个属性 + if (_1688OutProdInfo.propsName.Any(p => p.pname == _1688Attr.key && string.Join(",", p.values.Select(pp => pp.vname)) == _1688Attr.value)) + continue; + + goods_propertie_item propInfo = new goods_propertie_item(); + prodInfo.property.goods_properties.Add(propInfo); + propInfo.name = _1688Attr.key; + propInfo.ref_pid = null; + propInfo.values = new List(); + List values = new List { _1688Attr.value }; + foreach (var wxPropVal in values) + { + propInfo.values.Add(new value_item() + { + value = wxPropVal, + raw_value = wxPropVal, + vid = null, + unit = "" + }); + } + } + } + else + { + //outGoodsParam.productAttrs.Add(new osProductAttrParam { attrKey = "品牌", attrValue = "无品牌" }); + } + // 主图 复用前面的 + dbProd.main_img = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1).url; + dbProd.product_json = JsonHelper.SerializeObject(prodInfo); + + return prodInfo; + } + catch (Exception ex) + { + convertRst = "转换错误 " + ex.Message; + return null; + } + } + + /// + /// 微信商城手机版转拼多多 + /// + /// + /// + /// + public PDDProductInfo WXClientToPddConvert(out string convertRst, KJDDBProduct dbProd) + { + convertRst = ""; + try + { + var wxxdData = JsonHelper.SerializeObject(JsonHelper.JObjectParse(dbProd.product_json)["wxxdData"]); + var baseData = JsonHelper.JObjectParse(dbProd.product_json)["baseData"].ParseToString(); + + var str_lst = BaseRegex.GetJsonArrStrJson(ref baseData, "productSkus"); + try + { + var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault(); + var productSkus = JsonHelper.DeserializeJsonToList(regex_str); + } + catch + { + } + + WXClientProductInfoLite wxClientProdInfo = JsonHelper.DeserializeJsonToObject(wxxdData); + if (wxClientProdInfo.info.sku_list == null) + { + wxClientProdInfo.info.sku_list = new wx_sku(); + } + if (wxClientProdInfo.info.sku_list.sku_info == null) + { + wxClientProdInfo.info.sku_list.sku_info = new List(); + + try + { + if (baseData.Contains("{\"sku_info\"")) + { + var skuInfoStr = baseData.Substring(baseData.IndexOf("{\"sku_info\"")); + if (skuInfoStr.Contains(" KB)")) + skuInfoStr = skuInfoStr.Substring(0, skuInfoStr.IndexOf(" KB)")); + while (skuInfoStr.IndexOf("{\"sku_id\"") >= 0) + { + skuInfoStr = skuInfoStr.Substring(skuInfoStr.IndexOf("{\"sku_id\"")); + var wxClientSkuInfo = new wx_client_sku_info(); + wxClientSkuInfo.sku_id = BaseRegex.GetStringJson(ref skuInfoStr, "sku_id"); + wxClientSkuInfo.price = BaseRegex.GetIntJson(ref skuInfoStr, "price"); + wxClientSkuInfo.is_discounted = BaseRegex.GetBoolJson(ref skuInfoStr, "is_discounted"); + wxClientSkuInfo.discounted_price = BaseRegex.GetIntJson(ref skuInfoStr, "discounted_price"); + wxClientSkuInfo.origin_price = BaseRegex.GetIntJson(ref skuInfoStr, "origin_price"); + if (wxClientSkuInfo.price != null && wxClientSkuInfo.is_discounted != null && wxClientSkuInfo.discounted_price != null && wxClientSkuInfo.origin_price != null) + { + wxClientProdInfo.info.sku_list.sku_info.Add(wxClientSkuInfo); + } + skuInfoStr = skuInfoStr.Substring(skuInfoStr.IndexOf("{\"sku_id\"") + "{\"sku_id\"".Length); + } + } + } + catch + { + } + } + + PDDProductInfo prodInfo = new PDDProductInfo() + { + sale_count = dbProd.sale_count.ParseToString(), + sale_count_text = dbProd.sale_count_text, + }; + 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 = dbProd.cat_id.ParseToInt(); + prodInfo.detail.cat_ids = new List(); + //微信商品的类目直接输入,上传的时候不用。 + foreach (var category in wxClientProdInfo.info.category) + { + prodInfo.detail.cat_ids.Add(category.catIdStr.ParseToInt()); + } + 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(); + foreach (var imgItem in wxClientProdInfo.info.head_img) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = imgItem, + type = 1, + }); + } + foreach (var imgItem in wxClientProdInfo.info.detail.detail_img_real) + { + prodInfo.detail.galleries.Add(new gallery_item() + { + url = imgItem, + type = 2, + }); + } + 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 = wxClientProdInfo.info.title; + prodInfo.detail.goods_id = wxClientProdInfo.product_key.product_id.ParseToLong(); + prodInfo.detail.goods_name = wxClientProdInfo.info.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.galleries.FirstOrDefault(g => g.type == 1)?.url; + // 编辑id,随意填写 + prodInfo.detail.id = 0; + // 复用前面已经填写过的 + prodInfo.detail.image_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; + 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 = 0; + // 微信没有 + prodInfo.detail.mall_info = new mall_info_item(); + // 微信没有此处随意填 + prodInfo.detail.market_price = 0; + // 微信没有此处随意填 + prodInfo.detail.max_group_price = 0; + // 微信没有此处随意填 + prodInfo.detail.min_group_price = 0; + 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 = wxClientProdInfo.info.spuCode; + //if (prodInfo.detail.out_goods_sn.IsNullOrEmpty()) + //{ + // convertRst = "货号不存在"; + // return null; + //} + 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 = ""; + 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; + + //if (jstGoodsObj["skuInfo"].IsJTokenNullOrEmpty() || jstGoodsObj["skuInfo"]["goodsSkuDetail"].IsJTokenNullOrEmpty()) + //{ + // convertRst = "缺少sku信息"; + // return null; + //} + prodInfo.detail.sku = new List(); + foreach (var wxEditSkuInfo in wxClientProdInfo.productSkus) + { + var wxDisSku = wxClientProdInfo.info.sku_list.sku_info.FirstOrDefault(s => s.sku_id == wxEditSkuInfo.skuKey.skuId); + var discountedValue = (wxDisSku?.discounted_price).ParseToInt(); + sku_item skuInfo = new sku_item() + { + id = 0, + sku_id = wxEditSkuInfo.skuKey.skuId.ParseToLong(), + sku_sn = null, + carnival_price = 0, + init_quantity = 0, + is_onsale = 1, + limit_quantity = 999999, + multi_price = wxEditSkuInfo.productSkuInfo.salePrice.ParseToInt() - discountedValue, + multi_price_in_yuan = null, + price = wxEditSkuInfo.productSkuInfo.salePrice.ParseToInt() - discountedValue + 100, + price_in_yuan = null, + quantity = wxEditSkuInfo.productSkuInfo?.stockInfo?.stockNum?.ParseToInt(), + reserve_quantity = 0, + weight = 0, + thumb_url = wxEditSkuInfo.productSkuInfo.thumbImg, + thumb_url_file_id = null, + thumb_url_status = null, + thumb_url_is_deleted = null, + quantity_delta = 0, + spec = new List(), + // sku货号下面单独设置 + 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 = "", + }; + //// 聚水潭供应商价加价10%(最低1元)赚取差价 + //int addPrice = (skuInfo.multi_price * 0.1).ParseToInt(); + //if (addPrice < 100) + // addPrice = 100; + //skuInfo.multi_price += addPrice; + //skuInfo.price += addPrice; + if (wxEditSkuInfo.productSkuInfo.saleParam != null) + { + foreach (var wxSpec in wxEditSkuInfo.productSkuInfo.saleParam) + { + skuInfo.spec.Add(new spec_item() + { + parent_id = wxSpec.categorys[0].catId.ParseToLong(), + parent_name = wxSpec.categorys[0].name, + spec_id = wxSpec.categorys[1].catId.ParseToLong(), + spec_name = wxSpec.categorys[1].name, + }); + } + } + else + { + skuInfo.spec.Add(new spec_item() + { + parent_id = 0, + parent_name = "规格", + spec_id = 0, + spec_name = "默认", + }); + } + skuInfo.out_sku_sn = wxEditSkuInfo.productSkuInfo.skuCode; + prodInfo.detail.sku.Add(skuInfo); + } + 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 = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; + 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(); + + if (1 == 1) + { + foreach (var wxProp in wxClientProdInfo.info.param) + { + string name = wxProp.categorys.FirstOrDefault()?.name; + goods_propertie_item propInfo = new goods_propertie_item(); + prodInfo.property.goods_properties.Add(propInfo); + propInfo.name = name; + propInfo.ref_pid = null; + //propInfo.wx_input_type = wxProp.categorys.FirstOrDefault()?.catInfo.inputType; + propInfo.values = new List(); + foreach (var wxPropVal in wxProp.categorys) + { + // 第一个是属性名,装载属性值的时候跳过 + if (wxProp.categorys.IndexOf(wxPropVal) == 0) + continue; + + propInfo.values.Add(new value_item() + { + value = wxPropVal.name.ParseToString(), + raw_value = wxPropVal.name.ParseToString(), + vid = null, + unit = "" + }); + } + } + } + else + { + //outGoodsParam.productAttrs.Add(new osProductAttrParam { attrKey = "品牌", attrValue = "无品牌" }); + } + // 主图 复用前面的 + dbProd.main_img = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1).url; + dbProd.product_json = JsonHelper.SerializeObject(prodInfo); + + return prodInfo; + } + catch (Exception ex) + { + convertRst = "转换错误 " + ex.Message; + return null; + } + } + } } diff --git a/TEMUKJD/WXForms/ProductForms/WXUserCollectAuthProdListForm.cs b/TEMUKJD/WXForms/ProductForms/WXUserCollectAuthProdListForm.cs index b5d0b1f..399cbb6 100644 --- a/TEMUKJD/WXForms/ProductForms/WXUserCollectAuthProdListForm.cs +++ b/TEMUKJD/WXForms/ProductForms/WXUserCollectAuthProdListForm.cs @@ -30,1253 +30,1246 @@ using Work; namespace TemuKJD.WXForms.ProductForms { - public partial class WXUserCollectAuthProdListForm : BaseGeneralForm - { - ShopLoginInfo shop = null; - public CancellationTokenSource cancellationTokenSource { get; set; } = new CancellationTokenSource(); + public partial class WXUserCollectAuthProdListForm : BaseGeneralForm + { + ShopLoginInfo shop = null; + public CancellationTokenSource cancellationTokenSource { get; set; } = new CancellationTokenSource(); - ConcurrentList lstTemuDbProduct = new ConcurrentList(); - public ConcurrentList lstTemuDBProductSelect { get; set; } = new ConcurrentList(); + ConcurrentList lstTemuDbProduct = new ConcurrentList(); + public ConcurrentList lstTemuDBProductSelect { get; set; } = new ConcurrentList(); - public WXUserCollectAuthProdListForm() - { - InitializeComponent(); - } + public WXUserCollectAuthProdListForm() + { + InitializeComponent(); + } - public WXUserCollectAuthProdListForm(ShopLoginInfo _shop) - { - InitializeComponent(); - shop = _shop; - } + public WXUserCollectAuthProdListForm(ShopLoginInfo _shop) + { + InitializeComponent(); + shop = _shop; + } - private void ProductListForm_Load(object sender, EventArgs e) - { - dtpStart.Value = DateTime.Now.Date.AddMonths(-1); - dtpEnd.Value = DateTime.Now.Date.AddDays(1).AddSeconds(-1); + private void ProductListForm_Load(object sender, EventArgs e) + { + dtpStart.Value = DateTime.Now.Date.AddMonths(-1); + dtpEnd.Value = DateTime.Now.Date.AddDays(1).AddSeconds(-1); - Task.Run(() => - { - string addUserName = BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName; - PDDDBProdListForm.GetPDDProductNotes(new List { cmbNotes }, addUserName); - PDDDBProdListForm.GetPDDProductNotes(new List { cmbBatchEditNotes }, addUserName); - }); + Task.Run(() => + { + string addUserName = BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName; + PDDDBProdListForm.GetPDDProductNotes(new List { cmbNotes }, addUserName); + PDDDBProdListForm.GetPDDProductNotes(new List { cmbBatchEditNotes }, addUserName); + }); - //chkCatBoundLessThan.Visible = false; - //chkCatBoundMoreThan.Visible = false; - //tableLayoutPanel1.SetColumn(lblSourceType, 2); - //tableLayoutPanel1.SetColumn(cmbSourceType, 3); - dgvDbProduct.Columns["colMainImg"].Width = 80; - if (BaseClass.MainPath == "29pdd") - { - chkCatBoundLessThan.Visible = false; - chkCatBoundMoreThan.Visible = false; - lblWxSafe.Visible = false; - cmbWxSafe.Visible = false; - //tableLayoutPanel1.SetColumn(lblSourceType, 0); - //tableLayoutPanel1.SetColumn(cmbSourceType, 1); - dgvDbProduct.Columns["colCatBound"].Visible = false; - dgvDbProduct.Columns["colWxSafe"].Visible = false; - //dgvDbProduct.Columns["colMainImg"].FillWeight = 25; - } + //chkCatBoundLessThan.Visible = false; + //chkCatBoundMoreThan.Visible = false; + //tableLayoutPanel1.SetColumn(lblSourceType, 2); + //tableLayoutPanel1.SetColumn(cmbSourceType, 3); + dgvDbProduct.Columns["colMainImg"].Width = 80; + if (BaseClass.MainPath == "29pdd") + { + chkCatBoundLessThan.Visible = false; + chkCatBoundMoreThan.Visible = false; + lblWxSafe.Visible = false; + cmbWxSafe.Visible = false; + //tableLayoutPanel1.SetColumn(lblSourceType, 0); + //tableLayoutPanel1.SetColumn(cmbSourceType, 1); + dgvDbProduct.Columns["colCatBound"].Visible = false; + dgvDbProduct.Columns["colWxSafe"].Visible = false; + //dgvDbProduct.Columns["colMainImg"].FillWeight = 25; + } - //Task.Run(() => - //{ - // PDDDBProdListForm.GetPDDProductGroup(new List { cmbGroupFilter, }, "", "", BaseClass.UserName); - // GetPddProductCate(); - //}); + //Task.Run(() => + //{ + // PDDDBProdListForm.GetPDDProductGroup(new List { cmbGroupFilter, }, "", "", BaseClass.UserName); + // GetPddProductCate(); + //}); - fillCate(); + fillCate(); - //if (BaseClass.SaLevel == 1 && shop == null) // 一级管理员且不是选品状态 - //{ - // this.dgvDbProduct.Columns["colPriceText"].Visible = true; - //} - //else - //{ - // this.dgvDbProduct.Columns["colPriceText"].Visible = true; - // lblGroup.Visible = false; - //} + //if (BaseClass.SaLevel == 1 && shop == null) // 一级管理员且不是选品状态 + //{ + // this.dgvDbProduct.Columns["colPriceText"].Visible = true; + //} + //else + //{ + // this.dgvDbProduct.Columns["colPriceText"].Visible = true; + // lblGroup.Visible = false; + //} - if (BaseClass.MainPath != "29pdd") - { - this.dgvDbProduct.Columns["colExtCodePrice"].Visible = false; - this.dgvDbProduct.Columns["colEdit"].Visible = false; - } + if (BaseClass.MainPath != "29pdd") + { + this.dgvDbProduct.Columns["colExtCodePrice"].Visible = false; + this.dgvDbProduct.Columns["colEdit"].Visible = false; + } - btnDel.Visible = true; - this.dgvDbProduct.Columns["col_select_product"].Visible = false; - this.dgvDbProduct.Columns["colAddTimes"].Visible = false; + btnDel.Visible = true; + this.dgvDbProduct.Columns["col_select_product"].Visible = false; + this.dgvDbProduct.Columns["colAddTimes"].Visible = false; - this.ucSplitPage1.PageChange += ucSplitPage1_PageChange; - this.dgvDbProduct.AddSelectorColumn("colSelect"); + this.ucSplitPage1.PageChange += ucSplitPage1_PageChange; + this.dgvDbProduct.AddSelectorColumn("colSelect"); - this.dgvDbProduct.AddImgColumn("colSkuReplaceImg", "colSkuReplaceImgUrl"); + this.dgvDbProduct.AddImgColumn("colSkuReplaceImg", "colSkuReplaceImgUrl"); - this.dgvDbProduct.AddMergeColumnHeader(new List() { "colExtCodePrice", "colEdit" }, "货号价格"); - this.dgvDbProduct.AddMergeColumn(new List() { "colExtCodePrice", "colEdit" }); + this.dgvDbProduct.AddMergeColumnHeader(new List() { "colExtCodePrice", "colEdit" }, "货号价格"); + this.dgvDbProduct.AddMergeColumn(new List() { "colExtCodePrice", "colEdit" }); - //this.dtpStart.Value = new DateTime(2026, 3, 12, 0, 0, 0); - //this.dtpEnd.Value = new DateTime(2026, 3, 13, 13, 0, 0); - ucSplitPage1.lblTotal.Visible = false; - ucSplitPage1.cmbPageSize.Items.Clear(); - ucSplitPage1.cmbPageSize.Items.Add(50); - ucSplitPage1.cmbPageSize.Items.Add(100); - ucSplitPage1.cmbPageSize.Items.Add(200); - ucSplitPage1.cmbPageSize.Items.Add(500); - ucSplitPage1.cmbPageSize.Items.Add(1000); - ucSplitPage1.cmbPageSize.DropDownStyle = ComboBoxStyle.DropDownList; - ucSplitPage1.cmbPageSize.SelectedIndex = 0; + //this.dtpStart.Value = new DateTime(2026, 3, 12, 0, 0, 0); + //this.dtpEnd.Value = new DateTime(2026, 3, 13, 13, 0, 0); + ucSplitPage1.lblTotal.Visible = false; + ucSplitPage1.cmbPageSize.Items.Clear(); + ucSplitPage1.cmbPageSize.Items.Add(50); + ucSplitPage1.cmbPageSize.Items.Add(100); + ucSplitPage1.cmbPageSize.Items.Add(200); + ucSplitPage1.cmbPageSize.Items.Add(500); + ucSplitPage1.cmbPageSize.Items.Add(1000); + ucSplitPage1.cmbPageSize.DropDownStyle = ComboBoxStyle.DropDownList; + ucSplitPage1.cmbPageSize.SelectedIndex = 0; - if (/*BaseClass.SaLevel > 0 || */ BaseClass.UserAuthority.ParseToString().Contains("货源选择")) - { - lblSourceType.Visible = true; - cmbSourceType.Visible = true; - //lblGroup.Visible = true; - //cmbGroupFilter.Visible = true; - tableLayoutPanel1.ColumnStyles[9].SizeType = SizeType.Percent; - tableLayoutPanel1.ColumnStyles[9].Width = 20; - } - else - { - tableLayoutPanel1.ColumnStyles[9].SizeType = SizeType.AutoSize; - } + if (/*BaseClass.SaLevel > 0 || */ BaseClass.UserAuthority.ParseToString().Contains("货源选择")) + { + lblSourceType.Visible = true; + cmbSourceType.Visible = true; + //lblGroup.Visible = true; + //cmbGroupFilter.Visible = true; + tableLayoutPanel1.ColumnStyles[9].SizeType = SizeType.Percent; + tableLayoutPanel1.ColumnStyles[9].Width = 20; + } + else + { + tableLayoutPanel1.ColumnStyles[9].SizeType = SizeType.AutoSize; + } - if (BaseClass.GroupId != 3) - { - btnDel.Visible = false; - btnGetProdWxCate.Visible = false; - btnStopStop.Visible = false; - btnImportPddOutData.Visible = false; - btnOut1688ProdSaveDb.Visible = false; - btnAITitleFission.Visible = false; - this.dgvDbProduct.Columns["col_edit"].Visible = false; - } - } + if (BaseClass.GroupId != 3) + { + btnDel.Visible = false; + btnGetProdWxCate.Visible = false; + btnStopStop.Visible = false; + btnImportPddOutData.Visible = false; + btnOut1688ProdSaveDb.Visible = false; + btnAITitleFission.Visible = false; + this.dgvDbProduct.Columns["col_edit"].Visible = false; + } + } - private void btnSearch_Click(object sender, EventArgs e) - { - if (this.ucSplitPage1.CurrentPage != 1) - this.ucSplitPage1.CurrentPage = 1; - else - SearchDbProd(1); - } + private void btnSearch_Click(object sender, EventArgs e) + { + if (this.ucSplitPage1.CurrentPage != 1) + this.ucSplitPage1.CurrentPage = 1; + else + SearchDbProd(1); + } - public void SearchDbProd(int page, string needKeepStatusText = "") - { - if (InvokeRequired) - { - Invoke(new Action(() => - { - this.pbLoading.Visible = true; - this.dgvDbProduct.Rows.Clear(); - lstTemuDbProduct.Clear(); - })); - } - else - { - this.pbLoading.Visible = true; - this.dgvDbProduct.Rows.Clear(); - lstTemuDbProduct.Clear(); - } + public void SearchDbProd(int page, string needKeepStatusText = "") + { + if (InvokeRequired) + { + Invoke(new Action(() => + { + this.pbLoading.Visible = true; + this.dgvDbProduct.Rows.Clear(); + lstTemuDbProduct.Clear(); + })); + } + else + { + this.pbLoading.Visible = true; + this.dgvDbProduct.Rows.Clear(); + lstTemuDbProduct.Clear(); + } - bool isNotCount = true; - if (BaseClass.UserName == "13313717678" || BaseClass.ParentUserName == "13313717678") - { - ucSplitPage1.lblTotal.Visible = true; - isNotCount = false; - } + bool isNotCount = true; + if (BaseClass.UserName == "13313717678" || BaseClass.ParentUserName == "13313717678") + { + ucSplitPage1.lblTotal.Visible = true; + isNotCount = false; + } - Task.Run(() => - { - int pageCount; - int pageSize = 100; - decimal seconds; - Invoke(new Action(() => { pageSize = this.ucSplitPage1.PageSize; })); - var list = GetProductList(out pageCount, out seconds, page, pageSize, isNotCount); - lstTemuDbProduct.AddRange(list); - this.ucSplitPage1.TotalPage = pageCount; + Task.Run(() => + { + int pageCount; + int pageSize = 100; + decimal seconds; + Invoke(new Action(() => { pageSize = this.ucSplitPage1.PageSize; })); + var list = GetProductList(out pageCount, out seconds, page, pageSize, isNotCount); + lstTemuDbProduct.AddRange(list); + this.ucSplitPage1.TotalPage = pageCount; - if (defaultBitmap == null) - defaultBitmap = new Bitmap(80, 80); - // 获取Bitmap的Graphics对象 - using (Graphics g = Graphics.FromImage(defaultBitmap)) - { - // 清除整个Bitmap为白色 - g.Clear(Color.White); - } - foreach (var prod in lstTemuDbProduct.Reverse().ToList()) - { - var catName = GetProdCateName(prod); - Invoke(new Action(() => - { - // 显示的价格需要加价10%最低1元 - decimal price1 = (prod.price_text.Split('-').FirstOrDefault().Trim()).ParseToDecimal() * 100; - decimal price2 = (prod.price_text.Split('-').LastOrDefault().Trim()).ParseToDecimal() * 100; - price1 += Math.Max(100, price1 * 0.1m).ParseToInt(); - price2 += Math.Max(100, price2 * 0.1m).ParseToInt(); - price1 = price1 * 0.01m; - price2 = price2 * 0.01m; - var collectAuthorityTag = "-" + BaseClass.UserName; - if (BaseClass.GroupId != 3) - collectAuthorityTag = "-" + BaseClass.ParentUserName; + if (defaultBitmap == null) + defaultBitmap = new Bitmap(80, 80); + // 获取Bitmap的Graphics对象 + using (Graphics g = Graphics.FromImage(defaultBitmap)) + { + // 清除整个Bitmap为白色 + g.Clear(Color.White); + } + foreach (var prod in lstTemuDbProduct.Reverse().ToList()) + { + var catName = GetProdCateName(prod); + Invoke(new Action(() => + { + // 显示的价格需要加价10%最低1元 + decimal price1 = (prod.price_text.Split('-').FirstOrDefault().Trim()).ParseToDecimal() * 100; + decimal price2 = (prod.price_text.Split('-').LastOrDefault().Trim()).ParseToDecimal() * 100; + price1 += Math.Max(100, price1 * 0.1m).ParseToInt(); + price2 += Math.Max(100, price2 * 0.1m).ParseToInt(); + price1 = price1 * 0.01m; + price2 = price2 * 0.01m; + var collectAuthorityTag = "-" + BaseClass.UserName; + if (BaseClass.GroupId != 3) + collectAuthorityTag = "-" + BaseClass.ParentUserName; - int rowIndex = this.dgvDbProduct.Rows.Add( - false, - prod.id, - prod.from_shop_id, - prod.from_shop_name, - prod.product_name, - prod?.main_img?.Replace("https", "http") + "?imageView2/2/w/90/h/90", - defaultBitmap, // prod.main_img, - prod.sku_img_replace_url, - DataGridViewExtension.defaultBitmap, - prod.spu_id, - prod.spu_id.Replace(collectAuthorityTag, ""), - prod.skc_id, - prod.main_cat_name ?? prod.main_cat_id, - catName, //catName.Split('>').LastOrDefault()?.Trim(), - GlobalConfig.WxCatBoundList.FirstOrDefault(cb => cb.leaf_id == prod.wx_cat_leaf)?.cat_bound, - prod.ext_code, - (prod.secret_spu_id + " " + prod.real_spu_id + " " + prod.real_coid).Trim(), - prod.group, - price1.ToString("f2") + " - " + price2.ToString("f2"), //prod.price_text.Replace("-", " - "), // 母店价格 - prod.ext_code_price * 0.01m, // 货号价格 - "编辑", - prod.select_count, - prod.select_total_count, - prod.sale_count_text, // 销售数量 - prod.notes, - prod.head_words, - prod.end_words, - prod.fission_words.Replace("fission_goods_names:", ""), - prod.product_get_type_text == "厂商直采" ? (prod.product_get_type_text + " " + prod.skc_id).Trim() : - prod.product_get_type_text.Replace("1688厂家", "1688商品").Replace("1688外部数据", "1688商品") - .Replace("已采集数据", "1688商品").Replace("机会商品", "多多商品").Replace("多多外部数据", "多多商品").Replace("微信店采", "微信商品"), - prod.special_prod_type, - prod.wx_safe_status, - prod.add_time.ToString("yy-MM-dd HH:mm"), - prod.mdy_time.ToString("yy-MM-dd HH:mm"), - "编辑", - "删除", - "认领" - ); + int rowIndex = this.dgvDbProduct.Rows.Add( + false, + prod.id, + prod.from_shop_id, + prod.from_shop_name, + prod.product_name, + prod?.main_img?.Replace("https", "http") + "?imageView2/2/w/90/h/90", + defaultBitmap, // prod.main_img, + prod.sku_img_replace_url, + DataGridViewExtension.defaultBitmap, + prod.spu_id, + prod.spu_id.Replace(collectAuthorityTag, ""), + prod.skc_id, + prod.main_cat_name ?? prod.main_cat_id, + catName, //catName.Split('>').LastOrDefault()?.Trim(), + GlobalConfig.WxCatBoundList.FirstOrDefault(cb => cb.leaf_id == prod.wx_cat_leaf)?.cat_bound, + prod.ext_code, + (prod.secret_spu_id + " " + prod.real_spu_id + " " + prod.real_coid).Trim(), + prod.group, + price1.ToString("f2") + " - " + price2.ToString("f2"), //prod.price_text.Replace("-", " - "), // 母店价格 + prod.ext_code_price * 0.01m, // 货号价格 + "编辑", + prod.select_count, + prod.select_total_count, + prod.sale_count_text, // 销售数量 + prod.notes, + prod.head_words, + prod.end_words, + prod.fission_words.Replace("fission_goods_names:", ""), + prod.product_get_type_text == "厂商直采" ? (prod.product_get_type_text + " " + prod.skc_id).Trim() : + prod.product_get_type_text.Replace("1688厂家", "1688商品").Replace("1688外部数据", "1688商品") + .Replace("已采集数据", "1688商品").Replace("机会商品", "多多商品").Replace("多多外部数据", "多多商品").Replace("微信店采", "微信商品"), + prod.special_prod_type, + prod.wx_safe_status, + prod.add_time.ToString("yy-MM-dd HH:mm"), + prod.mdy_time.ToString("yy-MM-dd HH:mm"), + "编辑", + "删除", + "认领" + ); - dgvDbProduct.Rows[rowIndex].Height = dgvDbProduct.Columns["colMainImg"].Width; - })); - } + dgvDbProduct.Rows[rowIndex].Height = dgvDbProduct.Columns["colMainImg"].Width; + })); + } - Invoke(new Action(() => - { - ShowDgvImg(); - this.pbLoading.Visible = false; - this.statusBar.lblTaskStatus.Text = "商品查询完毕"; + Invoke(new Action(() => + { + ShowDgvImg(); + this.pbLoading.Visible = false; + this.statusBar.lblTaskStatus.Text = "商品查询完毕"; #if DEBUG - this.statusBar.lblTaskStatus.Text += ",耗时:" + seconds; + this.statusBar.lblTaskStatus.Text += ",耗时:" + seconds; #endif - this.statusBar.lblTaskStatus.Text += needKeepStatusText; - })); - }); - } - - public static string GetProdCateName(KJDDBProduct prod) - { - string catName = (prod.cat_name ?? prod.cat_id) + "(未识别)"; - if (prod.wx_cat_leaf != null) - { - var catN = GlobalConfig.WxCatList.FirstOrDefault(c => c.cat_id == prod.wx_cat_leaf.ParseToString())?.name; - if (!string.IsNullOrEmpty(catN)) - { - catName = catN; - } - } - if (prod.wx_cat_3 != null) - { - var catN = GlobalConfig.WxCatList.FirstOrDefault(c => c.cat_id == prod.wx_cat_3.ParseToString())?.name; - if (!string.IsNullOrEmpty(catN)) - { - catName = catN + " >> " + catName; - } - } - if (prod.wx_cat_2 != null) - { - var catN = GlobalConfig.WxCatList.FirstOrDefault(c => c.cat_id == prod.wx_cat_2.ParseToString())?.name; - if (!string.IsNullOrEmpty(catN)) - { - catName = catN + " >> " + catName; - } - } - if (prod.wx_cat_1 != null) - { - var catN = GlobalConfig.WxCatList.FirstOrDefault(c => c.cat_id == prod.wx_cat_1.ParseToString())?.name; - if (!string.IsNullOrEmpty(catN)) - { - catName = catN + " >> " + catName; - } - } - return catName; - } - - Bitmap defaultBitmap = null; - void ShowDgvImg() - { - Task.Run(() => - { - foreach (DataGridViewRow row in this.dgvDbProduct.Rows) - { - if (row.Index > 0 && row.Cells["colMainImg"].Displayed == false) - { - Invoke(new Action(() => - { - try - { - row.Cells["colMainImg"].Value = defaultBitmap; - } - catch - { - } - })); - continue; - } - - if (row.Cells["colMainImg"].Value != null && row.Cells["colMainImg"].Value != defaultBitmap) - continue; - - Image image = null; - string imgUrl = row.Cells["colImgUrl"]?.Value.ParseToString(); - string getImgError = ""; - if (!string.IsNullOrWhiteSpace(imgUrl)) - image = GetHtml.GetUrlImg(imgUrl, out getImgError); - if (!string.IsNullOrEmpty(getImgError)) - //BaseMsgForm.ShowError("图片加载失败 " + getImgError); - image = TemuKJD.Properties.Resources.errpic; - - Invoke(new Action(() => - { - try - { - row.Cells["colMainImg"].Value = image; - } - catch - { - } - })); - } - }); - } - - public List GetProductList(out int pageCount, out decimal seconds, int page = 1, int pageSize = 200, bool isNotCount = true) - { - List list = new List(); - pageCount = 1; - seconds = 0; - - var url = BaseClass.BuildPDDObjString("product/get_product_list"); - if (shop != null && shop.DbId.ParseToInt() != 0) - url = BaseClass.BuildPDDObjString("product/get_product_list"); - var data = ""; - - Invoke(new Action(() => - { - var collectAuthorityTag = "-" + BaseClass.UserName; - if (BaseClass.GroupId != 3) - collectAuthorityTag = "-" + BaseClass.ParentUserName; - data = UserLogin.GetSignaturex() + - "&page=" + page + - "&page_size=" + pageSize + - "&search_spu=" + string.Join(",", txtSPU.Text.Trim().Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries).Select(s => s + collectAuthorityTag)) + - "&search_skc=" + txtSKC.Text.Trim() + - "&search_notes=" + cmbNotes.Text.Trim() + - "&search_ext_code=" + txtExtCode.Text.Trim() + - //"&search_group=" + cmbGroupFilter.Text.Trim() + - "&search_prod_name=" + txtProdName.Text.Trim() + - "&wx_safe_status=" + cmbWxSafe.Text.Trim().Replace("安全+未校验", "安全商品,未校验").Replace("违规商品", ""); - data += "&add_user_name=" + (BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName); - if (BaseClass.MainPath == "29wx") - data += "&ban_wx=0"; - if (BaseClass.MainPath == "29pdd") - data += "&ban_pdd=0"; - if (cmbRelation.Text == "否") - data += "&is_relation=0"; - else if (cmbRelation.Text == "是") - data += "&is_relation=1"; - - if (chkTime.Checked) - { - data += "&add_time_begin=" + dtpStart.Value.ToString("yyyy-MM-dd HH:mm:ss"); - data += "&add_time_end=" + dtpEnd.Value.ToString("yyyy-MM-dd HH:mm:ss"); - } - - //if (chkEditTime.Checked) - //{ - // data += "&start_time=" + dtpStart.Value.ToString("yyyy-MM-dd HH:mm:ss"); - // data += "&end_time=" + dtpEnd.Value.ToString("yyyy-MM-dd HH:mm:ss"); - //} - - //if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店") - //{ - // data += "&search_cat1=" + (cmbCat1.Text.Trim() == "全部" ? "" : cmbCat1.Text.Trim()); - // data += "&search_cat=" + (cmbCat2.Text.Trim() == "全部" ? "" : cmbCat2.Text.Trim()); - //} - //else - { - var selectCate1 = GlobalConfig.WxCatList.Where(c => c.level == 1 && (/*cmbCat1.Text.Trim() == cmbCat1.DefaultText ||*/ (";" + cmbCat1.Text.Trim() + ";").Contains(";" + c.name + ";"))).ToList(); - var cates2 = GlobalConfig.WxCatList.Where(c => selectCate1.Any(c1 => c.f_cat_id == c1.cat_id)).ToList(); - var selectCate2 = cates2.Where(c => c.level == 2 && (/*cmbCat2.Text.Trim() == cmbCat2.DefaultText ||*/ (";" + cmbCat2.Text.Trim() + ";").Contains(";" + c.name + ";"))).ToList(); - var cates3 = GlobalConfig.WxCatList.Where(c => selectCate2.Any(c2 => c.f_cat_id == c2.cat_id)).ToList(); - var selectCate3 = cates3.Where(c => c.level == 3 && (/*cmbCat3.Text.Trim() == cmbCat3.DefaultText ||*/ (";" + cmbCat3.Text.Trim() + ";").Contains(";" + c.name + ";"))).ToList(); - - if (!string.IsNullOrEmpty(cmbCat1.Text) && selectCate1?.Count > 0) - data += "&wx_cat_1=" + string.Join(",", selectCate1.Select(c => c.cat_id).ToList()); - //else if (chkSkipQualification.Checked) - //{ - // // 厂商直采普通店铺不要随特殊商品 - // data += "&wx_cat_1=" + string.Join(",", GlobalConfig.WxCatList.Where(c => c.level == 1 && !(c.name == "图书" || c.name == "食品饮料" || c.name == "成人用品")) - // .Select(c => c.cat_id)); - //} - if (!string.IsNullOrEmpty(cmbCat2.Text) && selectCate2?.Count > 0) - data += "&wx_cat_2=" + string.Join(",", selectCate2.Select(c => c.cat_id).ToList()); - if (!string.IsNullOrEmpty(cmbCat3.Text) && selectCate3?.Count > 0) - data += "&wx_cat_3=" + string.Join(",", selectCate3.Select(c => c.cat_id).ToList()); - - if (chkCatBoundMoreThan.Checked || chkCatBoundLessThan.Checked) - { - var catBoundLst = GlobalConfig.WxCatBoundList.ToList(); - if (chkCatBoundMoreThan.Checked) - { - catBoundLst = catBoundLst.Where(cb => cb.cat_bound >= txtCatBoundMoreThan.Text.Trim().ParseToInt()).ToList(); - } - if (chkCatBoundLessThan.Checked) - { - catBoundLst = catBoundLst.Where(cb => cb.cat_bound <= txtCatBoundLessThan.Text.Trim().ParseToInt()).ToList(); - } - data += "&wx_cat_leaf=" + string.Join(",", catBoundLst.Select(c => c.leaf_id).ToList()); - } - - } - - if (!string.IsNullOrEmpty(txtSecretStyleCode.Text.Trim())) - { - data += "&search_secret_spu_ids=" + string.Join(",", txtSecretStyleCode.Text.Trim().Split(new string[] { " ", ",", "," }, StringSplitOptions.RemoveEmptyEntries)); - } - if (!string.IsNullOrEmpty(cmbWxCat.Text)) - { - data += "&has_wx_cat=" + (cmbWxCat.Text.Trim() == "是").ParseToString().ToLower(); - } - if (!string.IsNullOrEmpty(cmbExportToOutServer.Text)) - { - if (cmbExportToOutServer.Text.Trim() == "是") - data += "&send_to_out_server=1"; - else if (cmbExportToOutServer.Text.Trim() == "否") - data += "&send_to_out_server=0"; - else if (cmbExportToOutServer.Text.Trim() == "导出未拉回") - data += "&send_to_out_server=2"; - } - - if (!string.IsNullOrEmpty(cmbSourceType.Text.Trim())) - { - // 采集来源判断 - data += "&product_get_type=" + cmbSourceType.Text.Trim().Replace("已采集数据", "1688外部数据") - .Replace("多多商品", "机会商品,多多外部数据").Replace("1688商品", "1688厂家,1688外部数据").Replace("微信商品", "微信店采"); - } - - if (shop != null && !string.IsNullOrEmpty(shop.ShopId)) - { - data += "&get_select_count=true"; - data += "&select_shop_id=" + shop.ShopId; - } - if (this.cmbSort.Text == "认领总数") - { - data += "&sort_field=select_total_count"; - } - if (!this.txtRealCoid.Text.Trim().IsNullOrEmpty()) - { - data += "&real_coid=" + this.txtRealCoid.Text.Trim(); - } - if (chkWXComplateProd.Checked) - data += "&has_wx_format=1"; - - if (cmbHasFission.Text == "是") - { - data += "&fission_words=fission_goods_names:"; - } - else if (cmbHasFission.Text == "否") - { - data += "&no_fission_words=true"; - } - - if (isNotCount) - data += "&is_not_count=true"; - })); - 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")) - { - Invoke(new Action(() => - { - BaseMsgForm.ShowError("获取商品列表失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg")); - })); - return list; - } - - seconds = BaseRegex.GetDecimalJson(ref html, "seconds"); - int count = BaseRegex.GetIntJson(ref html, "count"); - pageCount = Math.Ceiling(1.0 * count / pageSize).ParseToInt(); - pageCount = Math.Max(pageCount, 1); - if (isNotCount) - pageCount = 1000; - - var jArr = JObject.Parse(html)["data"]; - if (jArr.Count() == 0) - return list; - var sProd = JsonHelper.SerializeObject(jArr); - - try - { - list = JsonHelper.DeserializeJsonToList(sProd); - return list; - } - catch (Exception ex) - { - return new List(); - } - } - - bool first = true; - private void ProductListForm_VisibleChanged(object sender, EventArgs e) - { - if (this.Visible == true && first) - { - first = false; - - this.pbLoading.Visible = true; - SearchDbProd(this.ucSplitPage1.CurrentPage); - } - } - - private void ucSplitPage1_PageChange(object obj) - { - SearchDbProd(this.ucSplitPage1.CurrentPage); - } - - private void pnlEmpty_Click(object sender, EventArgs e) - { - this.cmbCat1.Text = "全部"; - this.cmbCat2.Text = "全部"; - this.cmbCat3.Text = "全部"; - this.txtExtCode.Text = ""; - this.txtProdName.Text = ""; - this.txtSKC.Text = ""; - this.txtSPU.Text = ""; - this.cmbNotes.Text = ""; - this.cmbGroupFilter.Text = ""; - this.cmbSort.Text = "入库时间"; - this.cmbSourceType.Text = ""; - this.cmbWxSafe.Text = "安全+未校验"; - this.cmbWxCat.Text = ""; - this.cmbExportToOutServer.Text = ""; - this.txtSecretStyleCode.Text = ""; - } - - private void cmbCat1_SelectedIndexChanged(object sender, EventArgs e) - { - - } - - private void cmbCat2_SelectedIndexChanged(object sender, EventArgs e) - { - - } - - private void cmbCat3_SelectedIndexChanged(object sender, EventArgs e) - { - - } - - private void cmbCat1_MultiSelectChanged(object sender, EventArgs e) - { - //if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店") - // return; - - cmbCat2.Text = ""; - cmbCat2.Items.Clear(); - cmbCat3.Text = ""; - cmbCat3.Items.Clear(); - var selectCate1 = GlobalConfig.WxCatList.Where(c => c.level == 1 && (cmbCat1.Text.Trim() == cmbCat1.DefaultText || (";" + cmbCat1.Text.Trim() + ";").Contains(";" + c.name + ";"))).ToList(); - var cates2 = GlobalConfig.WxCatList.Where(c => selectCate1.Any(c1 => c.f_cat_id == c1.cat_id)).ToList(); - //foreach (var cate2 in cates2) - //{ - // cmbCat2.Items.Add(cate2.name); - //} - cmbCat2.Items.AddRange(cates2.Select(c => c.name).ToArray()); - } - - private void cmbCat2_MultiSelectChanged(object sender, EventArgs e) - { - //if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店") - // return; - - cmbCat3.Text = ""; - cmbCat3.Items.Clear(); - var selectCate1 = GlobalConfig.WxCatList.Where(c => c.level == 1 && (cmbCat1.Text.Trim() == cmbCat1.DefaultText || (";" + cmbCat1.Text.Trim() + ";").Contains(";" + c.name + ";"))).ToList(); - var cates2 = GlobalConfig.WxCatList.Where(c => selectCate1.Any(c1 => c.f_cat_id == c1.cat_id)).ToList(); - var selectCate2 = cates2.Where(c => c.level == 2 && (cmbCat2.Text.Trim() == cmbCat1.DefaultText || (";" + cmbCat2.Text.Trim() + ";").Contains(c.name))).ToList(); - var cates3 = GlobalConfig.WxCatList.Where(c => selectCate2.Any(c2 => c.f_cat_id == c2.cat_id)).ToList(); - //foreach (var cate3 in cates3) - //{ - // cmbCat3.Items.Add(cate3.name); - //} - cmbCat3.Items.AddRange(cates3.Select(c => c.name).ToArray()); - } - - private void cmbCat3_MultiSelectChanged(object sender, EventArgs e) - { - //var cate1 = GlobalConfig.WxCatList.FirstOrDefault(c => c.level == 1 && c.name == cmbCat1.Text.Trim()); - //var cates2 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == cate1?.cat_id).ToList(); - //var cate2 = cates2.FirstOrDefault(c => c.level == 2 && c.name == cmbCat1.Text.Trim()); - //var cates3 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == cate2?.cat_id).ToList(); - //var cate3 = cates3.FirstOrDefault(c => c.level == 3 && c.name == cmbCat1.Text.Trim()); - } - - private void dgvDbProduct_CellContentClick(object sender, DataGridViewCellEventArgs e) - { - if (e.ColumnIndex < 0 || e.RowIndex < 0) - return; - string headerText = dgvDbProduct.Columns[e.ColumnIndex].HeaderText; - var dbId = dgvDbProduct.Rows[e.RowIndex].Cells["col_db_id"].Value.ParseToString(); - var dbProduct = lstTemuDbProduct.FirstOrDefault(p => p.id.ToString() == dbId); - - switch (headerText) - { - case "删除": - if (BaseMsgForm.ShowConfirm("确定删除商品吗?删除后不可恢复!").DialogResult == DialogResult.Cancel) - return; - DeleteProduct(dbId); - break; - case "详情": - case "编辑备注": - case "编辑/详情": - WXUserCollectAuthProdEditNotesForm editForm = new WXUserCollectAuthProdEditNotesForm(dbProduct); - editForm.ShowDialog(); - dgvDbProduct.Rows[e.RowIndex].Cells["col_notes"].Value = dbProduct.notes; - dgvDbProduct.Rows[e.RowIndex].Cells["col_ext_code"].Value = dbProduct.ext_code; - dgvDbProduct.Rows[e.RowIndex].Cells["colHeadWords"].Value = dbProduct.head_words; - dgvDbProduct.Rows[e.RowIndex].Cells["colEndWords"].Value = dbProduct.end_words; - dgvDbProduct.Rows[e.RowIndex].Cells["colFissionWords"].Value = dbProduct.fission_words.Replace("fission_goods_names:", ""); - dgvDbProduct.Rows[e.RowIndex].Cells["col_product_name"].Value = dbProduct.product_name; - dgvDbProduct.Rows[e.RowIndex].Cells["colSkuReplaceImgUrl"].Value = dbProduct.sku_img_replace_url; - dgvDbProduct.Rows[e.RowIndex].Cells["col_cat_name"].Value = GetProdCateName(dbProduct); - dgvDbProduct.Rows[e.RowIndex].Cells["colMainCate"].Value = dbProduct.main_cat_name; - break; - case "主图": - ShowImgForm imgFrom = new ShowImgForm(dgvDbProduct.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString().Replace("?imageView2/2/w/90/h/90", "")); - imgFrom.ShowDialog(); - break; - case "认领": - //Task.Run(() => { SelectProduct(new KJDDBProduct[] { dbProduct }); }); - break; - case "资料编码/真实上家": - try - { - string url = ""; - if (string.IsNullOrEmpty(dbProduct.real_spu_id) || string.IsNullOrEmpty(dbProduct.real_coid)) - url = "https://sc.scm121.com/manage/goods/qualitySupplier/goodsDetail/" + dbProduct.spu_id + "?itemCoId=" + dbProduct.skc_id + "&noBack=true"; - else - url = "https://sc.scm121.com/manage/goods/qualitySupplier/goodsDetail/" + dbProduct.real_spu_id + "?itemCoId=" + dbProduct.real_coid + "&noBack=true"; - Process.Start(new ProcessStartInfo(url) - { - UseShellExecute = true - }); - } - catch - { - // 可能需要手动指定浏览器路径 - Process.Start(new ProcessStartInfo("https://www.baidu.com") { UseShellExecute = true }); - } - break; - case "": - dgvDbProduct.Rows[e.RowIndex].Cells["colSelect"].Value = !(bool)dgvDbProduct.Rows[e.RowIndex].Cells["colSelect"].Value; - //rowIndex1 = rowIndex2; - //rowIndex2 = e.RowIndex; - //if (IsShiftDown) - //{ - // if (rowIndex1 > -1 && rowIndex2 > -1) - // { - // try - // { - // if (rowIndex1 > rowIndex2) - // { - // for (int i = rowIndex2; i <= rowIndex1; i++) - // { - // dgvDbProduct.Rows[i].Cells["colSelect"].Value = dgvDbProduct.Rows[rowIndex1].Cells["colSelect"].Value; - // } - // } - // else - // { - // for (int i = rowIndex1; i <= rowIndex2; i++) - // { - // dgvDbProduct.Rows[i].Cells["colSelect"].Value = dgvDbProduct.Rows[rowIndex1].Cells["colSelect"].Value; - // } - // } - // } - // catch - // { - // } - // //rowIndex1 = -1; - // //rowIndex2 = -1; - // } - //} - break; - default: - break; - } - } - - private void DeleteProduct(string dbId, bool isUpdate = true) - { - var url = BaseClass.BuildPDDObjString("product/del_db_product"); - var data = UserLogin.GetSignaturex() + - "&db_id=" + dbId; - 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(html) || !html.Contains("\"code\":200")) - { - BaseMsgForm.ShowError("删除商品失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg")); - return; - } - else - { - if (isUpdate) - SearchDbProd(this.ucSplitPage1.CurrentPage); - } - } - - private void btnDel_Click(object sender, EventArgs e) - { - var lstProdId = dgvDbProduct.Rows.Cast().Where(row - => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["col_spu_id"]?.Value.ToString()).ToList(); - var prodList = this.lstTemuDbProduct.Where(p => lstProdId.Contains(p.spu_id)).ToArray(); - - if (BaseMsgForm.ShowConfirm("确定删除商品吗?删除后不可恢复!").DialogResult == DialogResult.Cancel) - return; - this.pbLoading.Visible = true; - this.statusBar.pgbTaskProgress.Maximum = lstProdId.Count; - this.statusBar.UpdateProgressBar(0); - if (cancellationTokenSource != null) - cancellationTokenSource.Cancel(); - cancellationTokenSource = new CancellationTokenSource(); - Task.Run(() => - { - var cancellationToken = cancellationTokenSource.Token; - foreach (var prod in prodList) - { - if (cancellationToken.IsCancellationRequested) - break; - - DeleteProduct(prod.id.ToString(), false); - - Invoke(new Action(() => - { - this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1); - this.statusBar.lblTaskStatus.Text = "正在删除 " + this.statusBar.pgbTaskProgress.Value + "/" + lstProdId.Count; - })); - } - SearchDbProd(this.ucSplitPage1.CurrentPage); - Invoke(new Action(() => - { - pbLoading.Visible = false; - if (!cancellationToken.IsCancellationRequested) - BaseMsgForm.ShowInfo("删除完成!"); - else - BaseMsgForm.ShowInfo("删除终止!"); - })); - }, cancellationTokenSource.Token); - } - - private void dgvDbProduct_Scroll(object sender, ScrollEventArgs e) - { - ShowDgvImg(); - } - - private void btnDelSelect_Click(object sender, EventArgs e) - { - var lstProdId = dgvDbProduct.Rows.Cast().Where(row - => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["col_spu_id"]?.Value.ToString()).ToList(); - var prodList = this.lstTemuDbProduct.Where(p => lstProdId.Contains(p.spu_id)).ToArray(); - - if (BaseMsgForm.ShowConfirm("确定删除商品吗?删除后不可恢复!").DialogResult == DialogResult.Cancel) - return; - this.pbLoading.Visible = true; - this.statusBar.pgbTaskProgress.Maximum = lstProdId.Count; - this.statusBar.UpdateProgressBar(0); - Task.Run(() => - { - foreach (var prod in prodList) - { - DeleteProduct(prod.id.ToString(), false); - - Invoke(new Action(() => - { - this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1); - this.statusBar.lblTaskStatus.Text = "正在删除 " + this.statusBar.pgbTaskProgress.Value + "/" + lstProdId.Count; - })); - } - SearchDbProd(this.ucSplitPage1.CurrentPage); - Invoke(new Action(() => - { - pbLoading.Visible = false; - BaseMsgForm.ShowInfo("删除完成!"); - })); - }); - } - - private void btnStopStop_Click(object sender, EventArgs e) - { - if (cancellationTokenSource != null) - cancellationTokenSource.Cancel(); - Task.Run(() => - { - Thread.Sleep(3000); - Invoke(new Action(() => - { - if (cancellationTokenSource == null || cancellationTokenSource.IsCancellationRequested) - pbLoading.Visible = false; - })); - }); - } - - private void PDDDBProdListForm_KeyDown(object sender, KeyEventArgs e) - { - //switch (e.KeyCode) - //{ - // case Keys.Shift: - // case Keys.ShiftKey: - // case Keys.LShiftKey: - // case Keys.RShiftKey: - // IsShiftDown = true; - // break; - //} - } - - private void PDDDBProdListForm_KeyUp(object sender, KeyEventArgs e) - { - } - - private void cmbSourceType_SelectedIndexChanged(object sender, EventArgs e) - { - fillCate(); - - //if (!string.IsNullOrWhiteSpace(cmbSourceType.Text) && cmbSourceType.Text != "厂商直采") - //{ - // cmbExportToOutServer.Text = ""; - // cmbWxCat.Text = ""; - //} - //else - //{ - // cmbExportToOutServer.Text = "是"; - // cmbWxCat.Text = "是"; - //} - } - - /// - /// 获取商品所有类目 - /// - void GetPddProductCate() - { - var url = BaseClass.BuildObjString("product/get_pdd_product_cates"); - var data = UserLogin.GetSignaturex(); - 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")) - { - BaseMsgForm.ShowError("商品类目获取失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg")); - } - else - { - pdd_product_cates = BaseRegex.GetStringJson(ref html, "data"); - } - - Invoke(new Action(() => - { - fillCate(); - })); - } - - public void fillCate() - { - //if (!string.IsNullOrWhiteSpace(cmbSourceType.Text) && - // cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店") - //{ - // fillPddCate(); - //} - //else - { - fillWxCate(); - } - } - - public string pdd_product_cates = ""; - void fillPddCate() - { - cmbCat1.Items.Clear(); - cmbCat2.Items.Clear(); - cmbCat3.Items.Clear(); - cmbCat1.Text = "全部"; - cmbCat2.Text = "全部"; - cmbCat3.Text = "全部"; - foreach (var item in pdd_product_cates.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) - { - cmbCat1.Items.Add(item); - } - cmbCat1.Items.Add(""); - } - - void fillWxCate() - { - cmbCat1.Items.Clear(); - cmbCat2.Items.Clear(); - cmbCat3.Items.Clear(); - cmbCat1.Text = "全部"; - cmbCat2.Text = "全部"; - cmbCat3.Text = "全部"; - foreach (var cate in GlobalConfig.WxCatList.Where(c => c.level == 1).ToList()) - { - cmbCat1.Items.Add(cate.name); - } - } - - private void chkCatBoundMoreThan_CheckedChanged(object sender, EventArgs e) - { - //txtCatBoundMoreThan.Visible = chkCatBoundMoreThan.Checked; - } - - private void chkCatBoundLessThan_CheckedChanged(object sender, EventArgs e) - { - //txtCatBoundLessThan.Visible = chkCatBoundLessThan.Checked; - } - - private void WXUserProdListForm_FormClosing(object sender, FormClosingEventArgs e) - { - this.Hide(); - e.Cancel = true; - } - - private void btnGetProdWxCate_Click(object sender, EventArgs e) - { - var lstProdId = dgvDbProduct.Rows.Cast().Where(row - => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["col_spu_id"]?.Value.ToString().Split(' ').FirstOrDefault()).ToList(); - var prodList = this.lstTemuDbProduct.Where(p => lstProdId.Contains(p.spu_id)).ToList(); - if (prodList.Count == 0) - { - BaseMsgForm.ShowInfo("请选择商品"); - return; - } - - this.statusBar.pgbTaskProgress.Maximum = prodList.Count; - this.statusBar.UpdateProgressBar(0); - if (cancellationTokenSource != null) - cancellationTokenSource.Cancel(); - cancellationTokenSource = new CancellationTokenSource(); - this.pbLoading.Visible = true; - Task.Run(() => - { - var cancellationToken = cancellationTokenSource.Token; - try - { - GetProdWxCat(prodList, cancellationToken); - } - catch (Exception ex) - { - BaseMsgForm.ShowError(ex.Message); - } - // 刷新结果 - SearchDbProd(this.ucSplitPage1.CurrentPage); - Invoke(new Action(() => - { - pbLoading.Visible = false; - if (!cancellationToken.IsCancellationRequested) - BaseMsgForm.ShowInfo("识别微信类目完成!"); - else - BaseMsgForm.ShowInfo("识别微信类目终止!"); - })); - }, cancellationTokenSource.Token); - } - - void GetProdWxCat(List dbProdLst, CancellationToken cancellationToken) - { - foreach (var prod in dbProdLst) - { - if (cancellationToken.IsCancellationRequested) - break; - - Invoke(new Action(() => - { - this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1); - this.statusBar.lblTaskStatus.Text = "正在识别微信类目 " + this.statusBar.pgbTaskProgress.Value + "/" + dbProdLst.Count; - })); - - var row = dgvDbProduct.Rows.Cast().FirstOrDefault(r => r.Cells["col_spu_id"].Value.ParseToString() == prod.spu_id); - if (row == null || !row.Cells["col_cat_name"].Value.ParseToString().Contains("未识别")) - { - Thread.Sleep(500); - continue; - } - - PDDDBProdListForm.GetProdWxCat(prod, row); - Thread.Sleep(1000); - } - } - - private void btnSelect_Click(object sender, EventArgs e) - { - var lstProdId = dgvDbProduct.Rows.Cast().Where(row - => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["col_spu_id"]?.Value.ToString()).ToList(); - var prodList = this.lstTemuDbProduct.Where(p => lstProdId.Contains(p.spu_id)).ToArray(); - - if (prodList.Count() > 0) - { - this.btnSelect.Enabled = false; - Task.Run(() => - { - SelectProduct(prodList); - Invoke(new Action(() => - { - this.btnSelect.Enabled = true; - BaseMsgForm.ShowInfo("添加成功"); - })); - }); - } - else - { - BaseMsgForm.ShowError("请选择商品!"); - } - } - - void SelectProduct(KJDDBProduct[] prodList) - { - if (WXDBProdUploadForm.Instance != null) - { - foreach (var prod in prodList) - { - var productNameLst = new List() { prod.product_name }; - if (chkFissionProduct.Checked) - { - Invoke(new Action(() => - { - var titleCount = txtFissionProductCount.Text.Trim().ParseToInt(); - if (prod.fission_words.ParseToString().Length > 20 && titleCount > 0) - { - productNameLst = prod.fission_words.Replace("fission_goods_names:", "") - .Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).OrderBy(x => Guid.NewGuid()).Distinct().Take(titleCount) - .ToList(); - } - })); - } - - foreach (var productName in productNameLst) - { - var selectProd = JsonHelper.DeserializeJsonToObject(JsonHelper.SerializeObject(prod)); - selectProd.product_name = productName; - if (chkFissionProduct.Checked) - selectProd.is_fission_title = true; - selectProd.out_product_Id = prod.id.ToString(); - selectProd.id = 1; - if (WXDBProdUploadForm.Instance.lstTemuDBProductSelect.Count > 0) - selectProd.id = WXDBProdUploadForm.Instance.lstTemuDBProductSelect.Max(p => p.id) + 1; - WXDBProdUploadForm.Instance.lstTemuDBProductSelect.Add(selectProd); - } - } - WXDBProdUploadForm.Instance.dbProdList_SaveComplete(WXDBProdUploadForm.Instance.lstTemuDBProductSelect); - } - } - - private void btnImportPddOutData_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(); - pbLoading.Visible = true; - this.statusBar.pgbTaskProgress.Maximum = filePathLst.Count; - this.statusBar.UpdateProgressBar(0); - Task.Run(() => - { - int successNum = 0; - int failedNum = 0; - foreach (var path in filePathLst) - { - string content = ""; - string rst = "商品未识别"; - try - { - using (StreamReader sr = new StreamReader(path, Work.Api.UploadPinduoduoMain.GetFileEncoding(path))) - { - content = sr.ReadToEnd(); - } - - content = JsonHelper.SerializeObject(JsonHelper.JObjectParse(content)); - if (content.Contains("\"spec_keys\"") && content.Contains("\"spec_values\"") && content.Contains("\"is_sku_pre_sale\"")) - { - rst = new PDDProdFormConverter().PddFrontToPddBackConvert(content, true, null, true); - } - //else if (content.Contains("\"destination_url\"") && content.Contains("\"destination_type\"") && content.Contains("\"pre_render_url\"")) - //{ - // rst = new PDDProdFormConverter().PddFrontToPddBackConvert2(content, true, null, true); - //} - //else if (content.Contains("\"goods_id\"") && content.Contains("\"goods_name\"") && content.Contains("\"gallery\"") && - // content.Contains("\"priority\"") && content.Contains("\"enable_share\"") && content.Contains("\"decoration\"") && - // content.Contains("\"goods_property\"") && content.Contains("\"ref_pid\"") && content.Contains("\"sku_id\"") && - // content.Contains("\"quantity\"") && content.Contains("\"specs\"") && content.Contains("\"spec_key\"") && - // content.Contains("\"spec_value\"") && content.Contains("\"group_price\"") && content.Contains("\"sku_price\"") && - // content.Contains("img.pddpic.com") ) - //{ - // rst = new PDDProdFormConverter().PddFrontToPddBackConvert2(content, true, null, true); - //} - 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")) - { - rst = new PDDProdFormConverter().PddFrontToPddBackConvert2(content, true, null, true); - } - 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")) - { - rst = new PDDProdFormConverter().PddFrontToPddBackConvert3(content, 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("导入完成!"); - })); - }); - } - } - - private void btnOutProdSaveDb_Click(object sender, EventArgs e) - { - bool isCollectAuthorityUser = true; - Get1688ProductForm.Out1688ProductImport(isCollectAuthorityUser, this.statusBar, this.pbLoading, OutProdSaveDbCallBack); - } - - void OutProdSaveDbCallBack(object msg) - { - SearchDbProd(1); - } - - private void btnAITitleFission_Click(object sender, EventArgs e) - { - var lstProdId = dgvDbProduct.Rows.Cast().Where(row - => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["col_spu_id"]?.Value.ToString()).ToList(); - if (lstProdId.Count == 0) - { - BaseMsgForm.ShowError("请选择要裂变的商品"); - return; - } - var prodList = lstTemuDbProduct.Where(p => lstProdId.Contains(p.spu_id)).ToList(); - - DouBaoTitleFissionCefForm fissionCefForm = new DouBaoTitleFissionCefForm(prodList); - fissionCefForm.ShowDialog(); - } - - private void btnBatchEditNotes_Click(object sender, EventArgs e) - { - var rows = dgvDbProduct.Rows.Cast().Where(row - => row.Cells["colSelect"]?.Value.ParseToBool() == true); - var lstProdId = rows.Select(r => r.Cells["col_spu_id"]?.Value.ToString()).ToList(); - string newNotes = this.cmbBatchEditNotes.Text.Trim(); - if (BaseMsgForm.ShowConfirm("确定批量编辑备注吗?").DialogResult == DialogResult.Cancel) - return; - if (lstProdId.Count == 0) - { - BaseMsgForm.ShowError("请选择要修改备注的商品"); - return; - } - - this.pbLoading.Visible = true; - Task.Run(() => - { - var prodList = lstTemuDbProduct.Where(p => lstProdId.Contains(p.spu_id)).ToList(); - var url = BaseClass.BuildPDDObjString("product/mdy_db_product"); - var data = UserLogin.GetSignaturex() + - "&in_db_ids=" + string.Join(",", prodList.Select(p => p.id).ToList()) + "¬es=" + newNotes; - var html = GetHtml.PostUtf8(url, data); - if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) - { - BaseMsgForm.ShowError("修改失败"); - } - else - { - //SearchDbProd(this.ucSplitPage1.CurrentPage); - //BaseMsgForm.ShowInfo("修改完成"); - - foreach (var prod in prodList) - { - prod.notes = newNotes; - } - foreach (var row in rows) - { - Invoke(new Action(() => { row.Cells["col_notes"].Value = newNotes; })); - - } - - if (!string.IsNullOrEmpty(newNotes)) - { - string addUserName = BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName; - PDDDBProdNotesManageFrom.AddProductNotes(newNotes, addUserName); - - PDDDBProdListForm.GetPDDProductNotes(new List { cmbNotes }, addUserName); - PDDDBProdListForm.GetPDDProductNotes(new List { cmbBatchEditNotes }, addUserName); - } - } - Invoke(new Action(() => - { - this.pbLoading.Visible = false; - })); - }); - } - - private void btnEditNotes_Click(object sender, EventArgs e) - { - string addUserName = BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName; - PDDDBProdNotesManageFrom groupMf = new PDDDBProdNotesManageFrom(addUserName); - groupMf.ShowDialog(); - - - PDDDBProdListForm.GetPDDProductNotes(new List { cmbNotes }, addUserName); - PDDDBProdListForm.GetPDDProductNotes(new List { cmbBatchEditNotes }, addUserName); - } - - - } + this.statusBar.lblTaskStatus.Text += needKeepStatusText; + })); + }); + } + + public static string GetProdCateName(KJDDBProduct prod) + { + string catName = (prod.cat_name ?? prod.cat_id) + "(未识别)"; + if (prod.wx_cat_leaf != null) + { + var catN = GlobalConfig.WxCatList.FirstOrDefault(c => c.cat_id == prod.wx_cat_leaf.ParseToString())?.name; + if (!string.IsNullOrEmpty(catN)) + { + catName = catN; + } + } + if (prod.wx_cat_3 != null) + { + var catN = GlobalConfig.WxCatList.FirstOrDefault(c => c.cat_id == prod.wx_cat_3.ParseToString())?.name; + if (!string.IsNullOrEmpty(catN)) + { + catName = catN + " >> " + catName; + } + } + if (prod.wx_cat_2 != null) + { + var catN = GlobalConfig.WxCatList.FirstOrDefault(c => c.cat_id == prod.wx_cat_2.ParseToString())?.name; + if (!string.IsNullOrEmpty(catN)) + { + catName = catN + " >> " + catName; + } + } + if (prod.wx_cat_1 != null) + { + var catN = GlobalConfig.WxCatList.FirstOrDefault(c => c.cat_id == prod.wx_cat_1.ParseToString())?.name; + if (!string.IsNullOrEmpty(catN)) + { + catName = catN + " >> " + catName; + } + } + return catName; + } + + Bitmap defaultBitmap = null; + void ShowDgvImg() + { + Task.Run(() => + { + foreach (DataGridViewRow row in this.dgvDbProduct.Rows) + { + if (row.Index > 0 && row.Cells["colMainImg"].Displayed == false) + { + Invoke(new Action(() => + { + try + { + row.Cells["colMainImg"].Value = defaultBitmap; + } + catch + { + } + })); + continue; + } + + if (row.Cells["colMainImg"].Value != null && row.Cells["colMainImg"].Value != defaultBitmap) + continue; + + Image image = null; + string imgUrl = row.Cells["colImgUrl"]?.Value.ParseToString(); + string getImgError = ""; + if (!string.IsNullOrWhiteSpace(imgUrl)) + image = GetHtml.GetUrlImg(imgUrl, out getImgError); + if (!string.IsNullOrEmpty(getImgError)) + //BaseMsgForm.ShowError("图片加载失败 " + getImgError); + image = TemuKJD.Properties.Resources.errpic; + + Invoke(new Action(() => + { + try + { + row.Cells["colMainImg"].Value = image; + } + catch + { + } + })); + } + }); + } + + public List GetProductList(out int pageCount, out decimal seconds, int page = 1, int pageSize = 200, bool isNotCount = true) + { + List list = new List(); + pageCount = 1; + seconds = 0; + + var url = BaseClass.BuildPDDObjString("product/get_product_list"); + if (shop != null && shop.DbId.ParseToInt() != 0) + url = BaseClass.BuildPDDObjString("product/get_product_list"); + var data = ""; + + Invoke(new Action(() => + { + var collectAuthorityTag = "-" + BaseClass.UserName; + if (BaseClass.GroupId != 3) + collectAuthorityTag = "-" + BaseClass.ParentUserName; + data = UserLogin.GetSignaturex() + + "&page=" + page + + "&page_size=" + pageSize + + "&search_spu=" + string.Join(",", txtSPU.Text.Trim().Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries).Select(s => s + collectAuthorityTag)) + + "&search_skc=" + txtSKC.Text.Trim() + + "&search_notes=" + cmbNotes.Text.Trim() + + "&search_ext_code=" + txtExtCode.Text.Trim() + + //"&search_group=" + cmbGroupFilter.Text.Trim() + + "&search_prod_name=" + txtProdName.Text.Trim() + + "&wx_safe_status=" + cmbWxSafe.Text.Trim().Replace("安全+未校验", "安全商品,未校验").Replace("违规商品", ""); + data += "&add_user_name=" + (BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName); + if (BaseClass.MainPath == "29wx") + data += "&ban_wx=0"; + if (BaseClass.MainPath == "29pdd") + data += "&ban_pdd=0"; + if (cmbRelation.Text == "否") + data += "&is_relation=0"; + else if (cmbRelation.Text == "是") + data += "&is_relation=1"; + + if (chkTime.Checked) + { + data += "&add_time_begin=" + dtpStart.Value.ToString("yyyy-MM-dd HH:mm:ss"); + data += "&add_time_end=" + dtpEnd.Value.ToString("yyyy-MM-dd HH:mm:ss"); + } + + //if (chkEditTime.Checked) + //{ + // data += "&start_time=" + dtpStart.Value.ToString("yyyy-MM-dd HH:mm:ss"); + // data += "&end_time=" + dtpEnd.Value.ToString("yyyy-MM-dd HH:mm:ss"); + //} + + //if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店") + //{ + // data += "&search_cat1=" + (cmbCat1.Text.Trim() == "全部" ? "" : cmbCat1.Text.Trim()); + // data += "&search_cat=" + (cmbCat2.Text.Trim() == "全部" ? "" : cmbCat2.Text.Trim()); + //} + //else + { + var selectCate1 = GlobalConfig.WxCatList.Where(c => c.level == 1 && (/*cmbCat1.Text.Trim() == cmbCat1.DefaultText ||*/ (";" + cmbCat1.Text.Trim() + ";").Contains(";" + c.name + ";"))).ToList(); + var cates2 = GlobalConfig.WxCatList.Where(c => selectCate1.Any(c1 => c.f_cat_id == c1.cat_id)).ToList(); + var selectCate2 = cates2.Where(c => c.level == 2 && (/*cmbCat2.Text.Trim() == cmbCat2.DefaultText ||*/ (";" + cmbCat2.Text.Trim() + ";").Contains(";" + c.name + ";"))).ToList(); + var cates3 = GlobalConfig.WxCatList.Where(c => selectCate2.Any(c2 => c.f_cat_id == c2.cat_id)).ToList(); + var selectCate3 = cates3.Where(c => c.level == 3 && (/*cmbCat3.Text.Trim() == cmbCat3.DefaultText ||*/ (";" + cmbCat3.Text.Trim() + ";").Contains(";" + c.name + ";"))).ToList(); + + if (!string.IsNullOrEmpty(cmbCat1.Text) && selectCate1?.Count > 0) + data += "&wx_cat_1=" + string.Join(",", selectCate1.Select(c => c.cat_id).ToList()); + //else if (chkSkipQualification.Checked) + //{ + // // 厂商直采普通店铺不要随特殊商品 + // data += "&wx_cat_1=" + string.Join(",", GlobalConfig.WxCatList.Where(c => c.level == 1 && !(c.name == "图书" || c.name == "食品饮料" || c.name == "成人用品")) + // .Select(c => c.cat_id)); + //} + if (!string.IsNullOrEmpty(cmbCat2.Text) && selectCate2?.Count > 0) + data += "&wx_cat_2=" + string.Join(",", selectCate2.Select(c => c.cat_id).ToList()); + if (!string.IsNullOrEmpty(cmbCat3.Text) && selectCate3?.Count > 0) + data += "&wx_cat_3=" + string.Join(",", selectCate3.Select(c => c.cat_id).ToList()); + + if (chkCatBoundMoreThan.Checked || chkCatBoundLessThan.Checked) + { + var catBoundLst = GlobalConfig.WxCatBoundList.ToList(); + if (chkCatBoundMoreThan.Checked) + { + catBoundLst = catBoundLst.Where(cb => cb.cat_bound >= txtCatBoundMoreThan.Text.Trim().ParseToInt()).ToList(); + } + if (chkCatBoundLessThan.Checked) + { + catBoundLst = catBoundLst.Where(cb => cb.cat_bound <= txtCatBoundLessThan.Text.Trim().ParseToInt()).ToList(); + } + data += "&wx_cat_leaf=" + string.Join(",", catBoundLst.Select(c => c.leaf_id).ToList()); + } + + } + + if (!string.IsNullOrEmpty(txtSecretStyleCode.Text.Trim())) + { + data += "&search_secret_spu_ids=" + string.Join(",", txtSecretStyleCode.Text.Trim().Split(new string[] { " ", ",", "," }, StringSplitOptions.RemoveEmptyEntries)); + } + if (!string.IsNullOrEmpty(cmbWxCat.Text)) + { + data += "&has_wx_cat=" + (cmbWxCat.Text.Trim() == "是").ParseToString().ToLower(); + } + if (!string.IsNullOrEmpty(cmbExportToOutServer.Text)) + { + if (cmbExportToOutServer.Text.Trim() == "是") + data += "&send_to_out_server=1"; + else if (cmbExportToOutServer.Text.Trim() == "否") + data += "&send_to_out_server=0"; + else if (cmbExportToOutServer.Text.Trim() == "导出未拉回") + data += "&send_to_out_server=2"; + } + + if (!string.IsNullOrEmpty(cmbSourceType.Text.Trim())) + { + // 采集来源判断 + data += "&product_get_type=" + cmbSourceType.Text.Trim().Replace("已采集数据", "1688外部数据") + .Replace("多多商品", "机会商品,多多外部数据").Replace("1688商品", "1688厂家,1688外部数据").Replace("微信商品", "微信店采"); + } + + if (shop != null && !string.IsNullOrEmpty(shop.ShopId)) + { + data += "&get_select_count=true"; + data += "&select_shop_id=" + shop.ShopId; + } + if (this.cmbSort.Text == "认领总数") + { + data += "&sort_field=select_total_count"; + } + if (!this.txtRealCoid.Text.Trim().IsNullOrEmpty()) + { + data += "&real_coid=" + this.txtRealCoid.Text.Trim(); + } + if (chkWXComplateProd.Checked) + data += "&has_wx_format=1"; + + if (cmbHasFission.Text == "是") + { + data += "&fission_words=fission_goods_names:"; + } + else if (cmbHasFission.Text == "否") + { + data += "&no_fission_words=true"; + } + + if (isNotCount) + data += "&is_not_count=true"; + })); + 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")) + { + Invoke(new Action(() => + { + BaseMsgForm.ShowError("获取商品列表失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg")); + })); + return list; + } + + seconds = BaseRegex.GetDecimalJson(ref html, "seconds"); + int count = BaseRegex.GetIntJson(ref html, "count"); + pageCount = Math.Ceiling(1.0 * count / pageSize).ParseToInt(); + pageCount = Math.Max(pageCount, 1); + if (isNotCount) + pageCount = 1000; + + var jArr = JObject.Parse(html)["data"]; + if (jArr.Count() == 0) + return list; + var sProd = JsonHelper.SerializeObject(jArr); + + try + { + list = JsonHelper.DeserializeJsonToList(sProd); + return list; + } + catch (Exception ex) + { + return new List(); + } + } + + bool first = true; + private void ProductListForm_VisibleChanged(object sender, EventArgs e) + { + if (this.Visible == true && first) + { + first = false; + + this.pbLoading.Visible = true; + SearchDbProd(this.ucSplitPage1.CurrentPage); + } + } + + private void ucSplitPage1_PageChange(object obj) + { + SearchDbProd(this.ucSplitPage1.CurrentPage); + } + + private void pnlEmpty_Click(object sender, EventArgs e) + { + this.cmbCat1.Text = "全部"; + this.cmbCat2.Text = "全部"; + this.cmbCat3.Text = "全部"; + this.txtExtCode.Text = ""; + this.txtProdName.Text = ""; + this.txtSKC.Text = ""; + this.txtSPU.Text = ""; + this.cmbNotes.Text = ""; + this.cmbGroupFilter.Text = ""; + this.cmbSort.Text = "入库时间"; + this.cmbSourceType.Text = ""; + this.cmbWxSafe.Text = "安全+未校验"; + this.cmbWxCat.Text = ""; + this.cmbExportToOutServer.Text = ""; + this.txtSecretStyleCode.Text = ""; + } + + private void cmbCat1_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void cmbCat2_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void cmbCat3_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void cmbCat1_MultiSelectChanged(object sender, EventArgs e) + { + //if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店") + // return; + + cmbCat2.Text = ""; + cmbCat2.Items.Clear(); + cmbCat3.Text = ""; + cmbCat3.Items.Clear(); + var selectCate1 = GlobalConfig.WxCatList.Where(c => c.level == 1 && (cmbCat1.Text.Trim() == cmbCat1.DefaultText || (";" + cmbCat1.Text.Trim() + ";").Contains(";" + c.name + ";"))).ToList(); + var cates2 = GlobalConfig.WxCatList.Where(c => selectCate1.Any(c1 => c.f_cat_id == c1.cat_id)).ToList(); + //foreach (var cate2 in cates2) + //{ + // cmbCat2.Items.Add(cate2.name); + //} + cmbCat2.Items.AddRange(cates2.Select(c => c.name).ToArray()); + } + + private void cmbCat2_MultiSelectChanged(object sender, EventArgs e) + { + //if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店") + // return; + + cmbCat3.Text = ""; + cmbCat3.Items.Clear(); + var selectCate1 = GlobalConfig.WxCatList.Where(c => c.level == 1 && (cmbCat1.Text.Trim() == cmbCat1.DefaultText || (";" + cmbCat1.Text.Trim() + ";").Contains(";" + c.name + ";"))).ToList(); + var cates2 = GlobalConfig.WxCatList.Where(c => selectCate1.Any(c1 => c.f_cat_id == c1.cat_id)).ToList(); + var selectCate2 = cates2.Where(c => c.level == 2 && (cmbCat2.Text.Trim() == cmbCat1.DefaultText || (";" + cmbCat2.Text.Trim() + ";").Contains(c.name))).ToList(); + var cates3 = GlobalConfig.WxCatList.Where(c => selectCate2.Any(c2 => c.f_cat_id == c2.cat_id)).ToList(); + //foreach (var cate3 in cates3) + //{ + // cmbCat3.Items.Add(cate3.name); + //} + cmbCat3.Items.AddRange(cates3.Select(c => c.name).ToArray()); + } + + private void cmbCat3_MultiSelectChanged(object sender, EventArgs e) + { + //var cate1 = GlobalConfig.WxCatList.FirstOrDefault(c => c.level == 1 && c.name == cmbCat1.Text.Trim()); + //var cates2 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == cate1?.cat_id).ToList(); + //var cate2 = cates2.FirstOrDefault(c => c.level == 2 && c.name == cmbCat1.Text.Trim()); + //var cates3 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == cate2?.cat_id).ToList(); + //var cate3 = cates3.FirstOrDefault(c => c.level == 3 && c.name == cmbCat1.Text.Trim()); + } + + private void dgvDbProduct_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + if (e.ColumnIndex < 0 || e.RowIndex < 0) + return; + string headerText = dgvDbProduct.Columns[e.ColumnIndex].HeaderText; + var dbId = dgvDbProduct.Rows[e.RowIndex].Cells["col_db_id"].Value.ParseToString(); + var dbProduct = lstTemuDbProduct.FirstOrDefault(p => p.id.ToString() == dbId); + + switch (headerText) + { + case "删除": + if (BaseMsgForm.ShowConfirm("确定删除商品吗?删除后不可恢复!").DialogResult == DialogResult.Cancel) + return; + DeleteProduct(dbId); + break; + case "详情": + case "编辑备注": + case "编辑/详情": + WXUserCollectAuthProdEditNotesForm editForm = new WXUserCollectAuthProdEditNotesForm(dbProduct); + editForm.ShowDialog(); + dgvDbProduct.Rows[e.RowIndex].Cells["col_notes"].Value = dbProduct.notes; + dgvDbProduct.Rows[e.RowIndex].Cells["col_ext_code"].Value = dbProduct.ext_code; + dgvDbProduct.Rows[e.RowIndex].Cells["colHeadWords"].Value = dbProduct.head_words; + dgvDbProduct.Rows[e.RowIndex].Cells["colEndWords"].Value = dbProduct.end_words; + dgvDbProduct.Rows[e.RowIndex].Cells["colFissionWords"].Value = dbProduct.fission_words.Replace("fission_goods_names:", ""); + dgvDbProduct.Rows[e.RowIndex].Cells["col_product_name"].Value = dbProduct.product_name; + dgvDbProduct.Rows[e.RowIndex].Cells["colSkuReplaceImgUrl"].Value = dbProduct.sku_img_replace_url; + dgvDbProduct.Rows[e.RowIndex].Cells["col_cat_name"].Value = GetProdCateName(dbProduct); + dgvDbProduct.Rows[e.RowIndex].Cells["colMainCate"].Value = dbProduct.main_cat_name; + break; + case "主图": + ShowImgForm imgFrom = new ShowImgForm(dgvDbProduct.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString().Replace("?imageView2/2/w/90/h/90", "")); + imgFrom.ShowDialog(); + break; + case "认领": + //Task.Run(() => { SelectProduct(new KJDDBProduct[] { dbProduct }); }); + break; + case "资料编码/真实上家": + try + { + string url = ""; + if (string.IsNullOrEmpty(dbProduct.real_spu_id) || string.IsNullOrEmpty(dbProduct.real_coid)) + url = "https://sc.scm121.com/manage/goods/qualitySupplier/goodsDetail/" + dbProduct.spu_id + "?itemCoId=" + dbProduct.skc_id + "&noBack=true"; + else + url = "https://sc.scm121.com/manage/goods/qualitySupplier/goodsDetail/" + dbProduct.real_spu_id + "?itemCoId=" + dbProduct.real_coid + "&noBack=true"; + Process.Start(new ProcessStartInfo(url) + { + UseShellExecute = true + }); + } + catch + { + // 可能需要手动指定浏览器路径 + Process.Start(new ProcessStartInfo("https://www.baidu.com") { UseShellExecute = true }); + } + break; + case "": + dgvDbProduct.Rows[e.RowIndex].Cells["colSelect"].Value = !(bool)dgvDbProduct.Rows[e.RowIndex].Cells["colSelect"].Value; + //rowIndex1 = rowIndex2; + //rowIndex2 = e.RowIndex; + //if (IsShiftDown) + //{ + // if (rowIndex1 > -1 && rowIndex2 > -1) + // { + // try + // { + // if (rowIndex1 > rowIndex2) + // { + // for (int i = rowIndex2; i <= rowIndex1; i++) + // { + // dgvDbProduct.Rows[i].Cells["colSelect"].Value = dgvDbProduct.Rows[rowIndex1].Cells["colSelect"].Value; + // } + // } + // else + // { + // for (int i = rowIndex1; i <= rowIndex2; i++) + // { + // dgvDbProduct.Rows[i].Cells["colSelect"].Value = dgvDbProduct.Rows[rowIndex1].Cells["colSelect"].Value; + // } + // } + // } + // catch + // { + // } + // //rowIndex1 = -1; + // //rowIndex2 = -1; + // } + //} + break; + default: + break; + } + } + + private void DeleteProduct(string dbId, bool isUpdate = true) + { + var url = BaseClass.BuildPDDObjString("product/del_db_product"); + var data = UserLogin.GetSignaturex() + + "&db_id=" + dbId; + 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(html) || !html.Contains("\"code\":200")) + { + BaseMsgForm.ShowError("删除商品失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg")); + return; + } + else + { + if (isUpdate) + SearchDbProd(this.ucSplitPage1.CurrentPage); + } + } + + private void btnDel_Click(object sender, EventArgs e) + { + var lstProdId = dgvDbProduct.Rows.Cast().Where(row + => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["col_spu_id"]?.Value.ToString()).ToList(); + var prodList = this.lstTemuDbProduct.Where(p => lstProdId.Contains(p.spu_id)).ToArray(); + + if (BaseMsgForm.ShowConfirm("确定删除商品吗?删除后不可恢复!").DialogResult == DialogResult.Cancel) + return; + this.pbLoading.Visible = true; + this.statusBar.pgbTaskProgress.Maximum = lstProdId.Count; + this.statusBar.UpdateProgressBar(0); + if (cancellationTokenSource != null) + cancellationTokenSource.Cancel(); + cancellationTokenSource = new CancellationTokenSource(); + Task.Run(() => + { + var cancellationToken = cancellationTokenSource.Token; + foreach (var prod in prodList) + { + if (cancellationToken.IsCancellationRequested) + break; + + DeleteProduct(prod.id.ToString(), false); + + Invoke(new Action(() => + { + this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1); + this.statusBar.lblTaskStatus.Text = "正在删除 " + this.statusBar.pgbTaskProgress.Value + "/" + lstProdId.Count; + })); + } + SearchDbProd(this.ucSplitPage1.CurrentPage); + Invoke(new Action(() => + { + pbLoading.Visible = false; + if (!cancellationToken.IsCancellationRequested) + BaseMsgForm.ShowInfo("删除完成!"); + else + BaseMsgForm.ShowInfo("删除终止!"); + })); + }, cancellationTokenSource.Token); + } + + private void dgvDbProduct_Scroll(object sender, ScrollEventArgs e) + { + ShowDgvImg(); + } + + private void btnDelSelect_Click(object sender, EventArgs e) + { + var lstProdId = dgvDbProduct.Rows.Cast().Where(row + => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["col_spu_id"]?.Value.ToString()).ToList(); + var prodList = this.lstTemuDbProduct.Where(p => lstProdId.Contains(p.spu_id)).ToArray(); + + if (BaseMsgForm.ShowConfirm("确定删除商品吗?删除后不可恢复!").DialogResult == DialogResult.Cancel) + return; + this.pbLoading.Visible = true; + this.statusBar.pgbTaskProgress.Maximum = lstProdId.Count; + this.statusBar.UpdateProgressBar(0); + Task.Run(() => + { + foreach (var prod in prodList) + { + DeleteProduct(prod.id.ToString(), false); + + Invoke(new Action(() => + { + this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1); + this.statusBar.lblTaskStatus.Text = "正在删除 " + this.statusBar.pgbTaskProgress.Value + "/" + lstProdId.Count; + })); + } + SearchDbProd(this.ucSplitPage1.CurrentPage); + Invoke(new Action(() => + { + pbLoading.Visible = false; + BaseMsgForm.ShowInfo("删除完成!"); + })); + }); + } + + private void btnStopStop_Click(object sender, EventArgs e) + { + if (cancellationTokenSource != null) + cancellationTokenSource.Cancel(); + Task.Run(() => + { + Thread.Sleep(3000); + Invoke(new Action(() => + { + if (cancellationTokenSource == null || cancellationTokenSource.IsCancellationRequested) + pbLoading.Visible = false; + })); + }); + } + + private void PDDDBProdListForm_KeyDown(object sender, KeyEventArgs e) + { + //switch (e.KeyCode) + //{ + // case Keys.Shift: + // case Keys.ShiftKey: + // case Keys.LShiftKey: + // case Keys.RShiftKey: + // IsShiftDown = true; + // break; + //} + } + + private void PDDDBProdListForm_KeyUp(object sender, KeyEventArgs e) + { + } + + private void cmbSourceType_SelectedIndexChanged(object sender, EventArgs e) + { + fillCate(); + + //if (!string.IsNullOrWhiteSpace(cmbSourceType.Text) && cmbSourceType.Text != "厂商直采") + //{ + // cmbExportToOutServer.Text = ""; + // cmbWxCat.Text = ""; + //} + //else + //{ + // cmbExportToOutServer.Text = "是"; + // cmbWxCat.Text = "是"; + //} + } + + /// + /// 获取商品所有类目 + /// + void GetPddProductCate() + { + var url = BaseClass.BuildObjString("product/get_pdd_product_cates"); + var data = UserLogin.GetSignaturex(); + 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")) + { + BaseMsgForm.ShowError("商品类目获取失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg")); + } + else + { + pdd_product_cates = BaseRegex.GetStringJson(ref html, "data"); + } + + Invoke(new Action(() => + { + fillCate(); + })); + } + + public void fillCate() + { + //if (!string.IsNullOrWhiteSpace(cmbSourceType.Text) && + // cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店") + //{ + // fillPddCate(); + //} + //else + { + fillWxCate(); + } + } + + public string pdd_product_cates = ""; + void fillPddCate() + { + cmbCat1.Items.Clear(); + cmbCat2.Items.Clear(); + cmbCat3.Items.Clear(); + cmbCat1.Text = "全部"; + cmbCat2.Text = "全部"; + cmbCat3.Text = "全部"; + foreach (var item in pdd_product_cates.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) + { + cmbCat1.Items.Add(item); + } + cmbCat1.Items.Add(""); + } + + void fillWxCate() + { + cmbCat1.Items.Clear(); + cmbCat2.Items.Clear(); + cmbCat3.Items.Clear(); + cmbCat1.Text = "全部"; + cmbCat2.Text = "全部"; + cmbCat3.Text = "全部"; + foreach (var cate in GlobalConfig.WxCatList.Where(c => c.level == 1).ToList()) + { + cmbCat1.Items.Add(cate.name); + } + } + + private void chkCatBoundMoreThan_CheckedChanged(object sender, EventArgs e) + { + //txtCatBoundMoreThan.Visible = chkCatBoundMoreThan.Checked; + } + + private void chkCatBoundLessThan_CheckedChanged(object sender, EventArgs e) + { + //txtCatBoundLessThan.Visible = chkCatBoundLessThan.Checked; + } + + private void WXUserProdListForm_FormClosing(object sender, FormClosingEventArgs e) + { + this.Hide(); + e.Cancel = true; + } + + private void btnGetProdWxCate_Click(object sender, EventArgs e) + { + var lstProdId = dgvDbProduct.Rows.Cast().Where(row + => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["col_spu_id"]?.Value.ToString().Split(' ').FirstOrDefault()).ToList(); + var prodList = this.lstTemuDbProduct.Where(p => lstProdId.Contains(p.spu_id)).ToList(); + if (prodList.Count == 0) + { + BaseMsgForm.ShowInfo("请选择商品"); + return; + } + + this.statusBar.pgbTaskProgress.Maximum = prodList.Count; + this.statusBar.UpdateProgressBar(0); + if (cancellationTokenSource != null) + cancellationTokenSource.Cancel(); + cancellationTokenSource = new CancellationTokenSource(); + this.pbLoading.Visible = true; + Task.Run(() => + { + var cancellationToken = cancellationTokenSource.Token; + try + { + GetProdWxCat(prodList, cancellationToken); + } + catch (Exception ex) + { + BaseMsgForm.ShowError(ex.Message); + } + // 刷新结果 + SearchDbProd(this.ucSplitPage1.CurrentPage); + Invoke(new Action(() => + { + pbLoading.Visible = false; + if (!cancellationToken.IsCancellationRequested) + BaseMsgForm.ShowInfo("识别微信类目完成!"); + else + BaseMsgForm.ShowInfo("识别微信类目终止!"); + })); + }, cancellationTokenSource.Token); + } + + void GetProdWxCat(List dbProdLst, CancellationToken cancellationToken) + { + foreach (var prod in dbProdLst) + { + if (cancellationToken.IsCancellationRequested) + break; + + Invoke(new Action(() => + { + this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1); + this.statusBar.lblTaskStatus.Text = "正在识别微信类目 " + this.statusBar.pgbTaskProgress.Value + "/" + dbProdLst.Count; + })); + + var row = dgvDbProduct.Rows.Cast().FirstOrDefault(r => r.Cells["col_spu_id"].Value.ParseToString() == prod.spu_id); + if (row == null || !row.Cells["col_cat_name"].Value.ParseToString().Contains("未识别")) + { + Thread.Sleep(500); + continue; + } + + PDDDBProdListForm.GetProdWxCat(prod, row); + Thread.Sleep(1000); + } + } + + private void btnSelect_Click(object sender, EventArgs e) + { + var lstProdId = dgvDbProduct.Rows.Cast().Where(row + => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["col_spu_id"]?.Value.ToString()).ToList(); + var prodList = this.lstTemuDbProduct.Where(p => lstProdId.Contains(p.spu_id)).ToArray(); + + if (prodList.Count() > 0) + { + this.btnSelect.Enabled = false; + Task.Run(() => + { + SelectProduct(prodList); + Invoke(new Action(() => + { + this.btnSelect.Enabled = true; + BaseMsgForm.ShowInfo("添加成功"); + })); + }); + } + else + { + BaseMsgForm.ShowError("请选择商品!"); + } + } + + void SelectProduct(KJDDBProduct[] prodList) + { + if (WXDBProdUploadForm.Instance != null) + { + foreach (var prod in prodList) + { + var productNameLst = new List() { prod.product_name }; + if (chkFissionProduct.Checked) + { + Invoke(new Action(() => + { + var titleCount = txtFissionProductCount.Text.Trim().ParseToInt(); + if (prod.fission_words.ParseToString().Length > 20 && titleCount > 0) + { + productNameLst = prod.fission_words.Replace("fission_goods_names:", "") + .Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).OrderBy(x => Guid.NewGuid()).Distinct().Take(titleCount) + .ToList(); + } + })); + } + + foreach (var productName in productNameLst) + { + var selectProd = JsonHelper.DeserializeJsonToObject(JsonHelper.SerializeObject(prod)); + selectProd.product_name = productName; + if (chkFissionProduct.Checked) + selectProd.is_fission_title = true; + selectProd.out_product_Id = prod.id.ToString(); + selectProd.id = 1; + if (WXDBProdUploadForm.Instance.lstTemuDBProductSelect.Count > 0) + selectProd.id = WXDBProdUploadForm.Instance.lstTemuDBProductSelect.Max(p => p.id) + 1; + WXDBProdUploadForm.Instance.lstTemuDBProductSelect.Add(selectProd); + } + } + WXDBProdUploadForm.Instance.dbProdList_SaveComplete(WXDBProdUploadForm.Instance.lstTemuDBProductSelect); + } + } + + private void btnImportPddOutData_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(); + pbLoading.Visible = true; + this.statusBar.pgbTaskProgress.Maximum = filePathLst.Count; + this.statusBar.UpdateProgressBar(0); + Task.Run(() => + { + int successNum = 0; + int failedNum = 0; + foreach (var path in filePathLst) + { + string sourceContent = ""; + string content = ""; + string rst = "商品未识别"; + try + { + + using (StreamReader sr = new StreamReader(path, Work.Api.UploadPinduoduoMain.GetFileEncoding(path))) + { + sourceContent = sr.ReadToEnd(); + } + + content = JsonHelper.SerializeObject(JsonHelper.JObjectParse(content)); + if (content.Contains("\"spec_keys\"") && content.Contains("\"spec_values\"") && content.Contains("\"is_sku_pre_sale\"")) + { + rst = new PDDProdFormConverter().PddFrontToPddBackConvert(content, true, null, true); + } + 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")) + { + rst = new PDDProdFormConverter().PddFrontToPddBackConvert2(content, true, null, true); + } + 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")) + { + rst = new PDDProdFormConverter().PddFrontToPddBackConvert3(content, true, null, true); + } + else if (sourceContent.Contains("\"商品编号\"") && sourceContent.Contains("\"商品链接\"") && sourceContent.Contains("\"标题\"")) + { + rst = new PDDProdFormConverter().PddFrontToPddBackConvertV4(sourceContent, 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("导入完成!"); + })); + }); + } + } + + private void btnOutProdSaveDb_Click(object sender, EventArgs e) + { + bool isCollectAuthorityUser = true; + Get1688ProductForm.Out1688ProductImport(isCollectAuthorityUser, this.statusBar, this.pbLoading, OutProdSaveDbCallBack); + } + + void OutProdSaveDbCallBack(object msg) + { + SearchDbProd(1); + } + + private void btnAITitleFission_Click(object sender, EventArgs e) + { + var lstProdId = dgvDbProduct.Rows.Cast().Where(row + => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["col_spu_id"]?.Value.ToString()).ToList(); + if (lstProdId.Count == 0) + { + BaseMsgForm.ShowError("请选择要裂变的商品"); + return; + } + var prodList = lstTemuDbProduct.Where(p => lstProdId.Contains(p.spu_id)).ToList(); + + DouBaoTitleFissionCefForm fissionCefForm = new DouBaoTitleFissionCefForm(prodList); + fissionCefForm.ShowDialog(); + } + + private void btnBatchEditNotes_Click(object sender, EventArgs e) + { + var rows = dgvDbProduct.Rows.Cast().Where(row + => row.Cells["colSelect"]?.Value.ParseToBool() == true); + var lstProdId = rows.Select(r => r.Cells["col_spu_id"]?.Value.ToString()).ToList(); + string newNotes = this.cmbBatchEditNotes.Text.Trim(); + if (BaseMsgForm.ShowConfirm("确定批量编辑备注吗?").DialogResult == DialogResult.Cancel) + return; + if (lstProdId.Count == 0) + { + BaseMsgForm.ShowError("请选择要修改备注的商品"); + return; + } + + this.pbLoading.Visible = true; + Task.Run(() => + { + var prodList = lstTemuDbProduct.Where(p => lstProdId.Contains(p.spu_id)).ToList(); + var url = BaseClass.BuildPDDObjString("product/mdy_db_product"); + var data = UserLogin.GetSignaturex() + + "&in_db_ids=" + string.Join(",", prodList.Select(p => p.id).ToList()) + "¬es=" + newNotes; + var html = GetHtml.PostUtf8(url, data); + if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) + { + BaseMsgForm.ShowError("修改失败"); + } + else + { + //SearchDbProd(this.ucSplitPage1.CurrentPage); + //BaseMsgForm.ShowInfo("修改完成"); + + foreach (var prod in prodList) + { + prod.notes = newNotes; + } + foreach (var row in rows) + { + Invoke(new Action(() => { row.Cells["col_notes"].Value = newNotes; })); + + } + + if (!string.IsNullOrEmpty(newNotes)) + { + string addUserName = BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName; + PDDDBProdNotesManageFrom.AddProductNotes(newNotes, addUserName); + + PDDDBProdListForm.GetPDDProductNotes(new List { cmbNotes }, addUserName); + PDDDBProdListForm.GetPDDProductNotes(new List { cmbBatchEditNotes }, addUserName); + } + } + Invoke(new Action(() => + { + this.pbLoading.Visible = false; + })); + }); + } + + private void btnEditNotes_Click(object sender, EventArgs e) + { + string addUserName = BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName; + PDDDBProdNotesManageFrom groupMf = new PDDDBProdNotesManageFrom(addUserName); + groupMf.ShowDialog(); + + + PDDDBProdListForm.GetPDDProductNotes(new List { cmbNotes }, addUserName); + PDDDBProdListForm.GetPDDProductNotes(new List { cmbBatchEditNotes }, addUserName); + } + + + } } diff --git a/TEMUKJD/WXForms/ProductForms/WXUserCollectAuthProdListForm.resx b/TEMUKJD/WXForms/ProductForms/WXUserCollectAuthProdListForm.resx index 8ae7193..1d37d6e 100644 --- a/TEMUKJD/WXForms/ProductForms/WXUserCollectAuthProdListForm.resx +++ b/TEMUKJD/WXForms/ProductForms/WXUserCollectAuthProdListForm.resx @@ -117,6 +117,39 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 148, 17 + + + 311, 17 + + + 460, 17 + + + 655, 17 + + + 840, 17 + + + 948, 17 + + + 1061, 17 + + + 1189, 17 + + + 1299, 17 + + + 17, 55 + True diff --git a/Work/Api/UploadPinduoduoMain.cs b/Work/Api/UploadPinduoduoMain.cs index ab82b3b..7ae1bac 100644 --- a/Work/Api/UploadPinduoduoMain.cs +++ b/Work/Api/UploadPinduoduoMain.cs @@ -1174,120 +1174,171 @@ namespace Work.Api public static System.Text.Encoding GetFileEncoding(string filename) { - using (var fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read)) - using (var br = new System.IO.BinaryReader(fs)) - { - var buffer = br.ReadBytes(2); - if (buffer[0] >= 0xEF) - { - if (buffer[0] == 0xEF && buffer[1] == 0xBB) - { - return System.Text.Encoding.UTF8; - } + byte[] bytes = File.ReadAllBytes(filename); + return DetectEncoding(bytes); - if (buffer[0] == 0xFE && buffer[1] == 0xFF) - { - return System.Text.Encoding.BigEndianUnicode; - } + } + /// + /// 检测字节数组的编码 + /// + public static Encoding DetectEncoding(byte[] bytes) + { + if (bytes == null || bytes.Length == 0) + return Encoding.UTF8; - if (buffer[0] == 0xFF && buffer[1] == 0xFE) - { - return System.Text.Encoding.Unicode; - } - } + // ---------- 1. 优先判断 BOM ---------- + Encoding bomEncoding = DetectByBom(bytes); + if (bomEncoding != null) + return bomEncoding; - return GetEncodingWithBomUtf8(fs, System.Text.Encoding.Default); - } + // ---------- 2. 判断是否为合法 UTF-8(无 BOM) ---------- + if (IsValidUtf8(bytes)) + return new UTF8Encoding(false); // 无 BOM 的 UTF-8 - } - private static System.Text.Encoding GetEncodingWithBomUtf8(Stream fs, Encoding defaultEncoding) - { - byte[] unicode = new byte[] { 0xFF, 0xFE, 0x41 }; - byte[] unicodeBig = new byte[] { 0xFE, 0xFF, 0x00 }; + // ---------- 3. 判断是否符合 GBK/GB2312 双字节规则 ---------- + if (IsLikelyGbk(bytes)) + { + // GB18030 兼容 GBK/GB2312,是更安全的选择 + try + { + return Encoding.GetEncoding("GB18030"); + } + catch + { + // 某些精简运行时(如未注册 CodePages Provider)可能取不到, + // 需要在项目里加 + // 并在启动时调用 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + } + } - //带BOM - byte[] utf8 = new byte[] { 0xEF, 0xBB, 0xBF }; - var reVal = defaultEncoding; + // ---------- 4. 兜底 ---------- + return Encoding.Default; // 或者你想要的 fallback,比如 Encoding.UTF8 + } - using (var r = new System.IO.BinaryReader(fs)) - { - byte[] ss = r.ReadBytes(4); - if (ss[0] == 0xFE && ss[1] == 0xFF && ss[2] == 0x00) - { - reVal = Encoding.BigEndianUnicode; - } - else if (ss[0] == 0xFF && ss[1] == 0xFE && ss[2] == 0x41) - { - reVal = Encoding.Unicode; - } - else - { - if (ss[0] == 0xEF && ss[1] == 0xBB && ss[2] == 0xBF) - { - reVal = Encoding.UTF8; - } - else - { - int i; - int.TryParse(fs.Length.ToString(), out i); - ss = r.ReadBytes(i); + /// + /// 根据 BOM 判断编码,没有 BOM 返回 null + /// + private static Encoding DetectByBom(byte[] bytes) + { + if (bytes.Length >= 4 && + bytes[0] == 0x00 && bytes[1] == 0x00 && + bytes[2] == 0xFE && bytes[3] == 0xFF) + return new UTF32Encoding(true, true); // UTF-32 BE - if (IsUtf8Bytes(ss)) - { - reVal = Encoding.UTF8; - } - } - } + if (bytes.Length >= 4 && + bytes[0] == 0xFF && bytes[1] == 0xFE && + bytes[2] == 0x00 && bytes[3] == 0x00) + return new UTF32Encoding(false, true); // UTF-32 LE - return reVal; - } - } + if (bytes.Length >= 3 && + bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) + return new UTF8Encoding(true); // UTF-8 with BOM - /// - /// 判断是否是不带 BOM 的 UTF8 格式 - /// - /// - /// - private static bool IsUtf8Bytes(byte[] data) - { - int charByteCounter = 1;  //计算当前正分析的字符应还有的字节数 - for (int i = 0; i < data.Length; i++) - { - var curByte = data[i]; //当前分析的字节. - if (charByteCounter == 1) - { - if (curByte >= 0x80) - { - //判断当前 - while (((curByte <<= 1) & 0x80) != 0) - { - charByteCounter++; - } - //标记位首位若为非0 则至少以2个1开始 如:110XXXXX...........1111110X  - if (charByteCounter == 1 || charByteCounter > 6) - { - return false; - } - } - } - else - { - //若是UTF-8 此时第一位必须为1 - if ((curByte & 0xC0) != 0x80) - { - return false; - } - charByteCounter--; - } - } - if (charByteCounter > 1) - { - throw new Exception("非预期的byte格式!"); - } - return true; - } + if (bytes.Length >= 2 && + bytes[0] == 0xFE && bytes[1] == 0xFF) + return new UnicodeEncoding(true, true); // UTF-16 BE - public void GetCat() + if (bytes.Length >= 2 && + bytes[0] == 0xFF && bytes[1] == 0xFE) + return new UnicodeEncoding(false, true); // UTF-16 LE + + return null; + } + + /// + /// 严格校验字节序列是否为合法 UTF-8 + /// + private static bool IsValidUtf8(byte[] bytes) + { + int i = 0; + int len = bytes.Length; + bool hasMultiByteSequence = false; + + while (i < len) + { + byte b = bytes[i]; + + if (b <= 0x7F) // 单字节 ASCII + { + i++; + continue; + } + + int extraBytes; + if ((b & 0xE0) == 0xC0) extraBytes = 1; // 110xxxxx + else if ((b & 0xF0) == 0xE0) extraBytes = 2; // 1110xxxx + else if ((b & 0xF8) == 0xF0) extraBytes = 3; // 11110xxx + else return false; // 不合法的起始字节 + + if (i + extraBytes >= len) + return false; // 长度不够 + + for (int j = 1; j <= extraBytes; j++) + { + if ((bytes[i + j] & 0xC0) != 0x80) // 后续字节必须是 10xxxxxx + return false; + } + + hasMultiByteSequence = true; + i += extraBytes + 1; + } + + // 纯 ASCII 内容严格来说 UTF-8/GBK/ASCII 都符合, + // 这里只有出现过合法多字节序列才更有把握判定为 UTF-8。 + // 如果你希望纯 ASCII 也直接归为 UTF-8,可以把下面这行去掉判断直接 return true。 + return hasMultiByteSequence || IsAllAscii(bytes); + } + + private static bool IsAllAscii(byte[] bytes) + { + foreach (byte b in bytes) + { + if (b > 0x7F) return false; + } + return true; + } + + /// + /// 启发式判断是否符合 GBK/GB2312 双字节编码规则 + /// GBK: 首字节 0x81-0xFE,次字节 0x40-0xFE(不含 0x7F) + /// + private static bool IsLikelyGbk(byte[] bytes) + { + int i = 0; + int len = bytes.Length; + bool hasDoubleByte = false; + + while (i < len) + { + byte b = bytes[i]; + + if (b <= 0x7F) // ASCII + { + i++; + continue; + } + + if (b >= 0x81 && b <= 0xFE) + { + if (i + 1 >= len) return false; + + byte b2 = bytes[i + 1]; + if (b2 >= 0x40 && b2 <= 0xFE && b2 != 0x7F) + { + hasDoubleByte = true; + i += 2; + continue; + } + return false; + } + + return false; // 不符合 GBK 规则的字节 + } + + return hasDoubleByte; + } + + public void GetCat() { int CatThreadCount = 20; if (FromTitleToCat.UserApi)