diff --git a/TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs b/TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs index bd6664c..862e12a 100644 --- a/TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs +++ b/TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; @@ -44,9 +45,9 @@ namespace TemuKJD.WXForms.ProductForms { public static WXDBProdUploadForm Instance { get; set; } = null; public static ConcurrentList lstWXShopTokenInfo = new ConcurrentList(); - public static ConcurrentList lstTemuDBProductSelect = new ConcurrentList(); + public static ConcurrentList lstTemuDBProductSelect = new ConcurrentList(); - public CancellationTokenSource cancellationTokenSource { get; set; } = null; + public CancellationTokenSource cancellationTokenSource { get; set; } = null; public bool IsWxNotUseSoftwareDefaultAddressOnce { get; set; } = false; ConcurrentList lstAddPriceRule = new ConcurrentList(); @@ -368,12 +369,12 @@ namespace TemuKJD.WXForms.ProductForms { lblHot.Visible = true; cmbHot.Visible = true; - chkFilterViewUv.Visible = true; - //numFilterViewUv.Visible = true; - pnlFilterViewUv.Visible = true; - chkFilterSaleCountNum.Visible = true; - pnlFilterSaleCountNum.Visible = true; - if (!string.IsNullOrWhiteSpace(cmbSourceType.Text)) + chkFilterViewUv.Visible = true; + //numFilterViewUv.Visible = true; + pnlFilterViewUv.Visible = true; + chkFilterSaleCountNum.Visible = true; + pnlFilterSaleCountNum.Visible = true; + if (!string.IsNullOrWhiteSpace(cmbSourceType.Text)) { //lblGroupFilter.Visible = true; //cmbGroupFilter.Visible = true; @@ -382,7 +383,7 @@ namespace TemuKJD.WXForms.ProductForms chkUpdateInDays.Visible = true; txtUpdateInDays.Visible = true; lblUpdateInDays.Visible = true; - } + } if (BaseClass.UserAuthority.Contains("商品采集") || BaseClass.ParentAuthority.Contains("商品采集")) { if (BaseClass.UserAuthority.Contains("学员数据") || BaseClass.ParentAuthority.Contains("学员数据")) @@ -611,9 +612,9 @@ namespace TemuKJD.WXForms.ProductForms RefreshShopLogin(); updateAuthor(); RefreshDbProdGroupAndCate(); - lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件"; + lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件"; - if (!isInit) + if (!isInit) { Task.Run(() => { @@ -852,56 +853,56 @@ namespace TemuKJD.WXForms.ProductForms switch (columnName) { case "colSelect": - //if (row.Cells["colCanUse"].Value.ParseToBool()) - { - row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool(); + //if (row.Cells["colCanUse"].Value.ParseToBool()) + { + row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool(); - chkSelectAll.CheckedChanged -= chkSelectAll_CheckedChanged; - if (dgvShop.Rows.Cast().All(r => r.Cells["colSelect"].Value.ParseToBool())) - chkSelectAll.Checked = true; - else - chkSelectAll.Checked = false; - chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged; - } - //else - //{ - // BaseMsgForm.ShowInfo("店铺未登录!"); - //} + chkSelectAll.CheckedChanged -= chkSelectAll_CheckedChanged; + if (dgvShop.Rows.Cast().All(r => r.Cells["colSelect"].Value.ParseToBool())) + chkSelectAll.Checked = true; + else + chkSelectAll.Checked = false; + chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged; + } + //else + //{ + // BaseMsgForm.ShowInfo("店铺未登录!"); + //} - dicCheckedShopId[row.Cells["colShopId"].Value.ParseToString()] = row.Cells["colSelect"].Value.ParseToBool(); - NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_checked_shop_dic", dicCheckedShopId); - break; + dicCheckedShopId[row.Cells["colShopId"].Value.ParseToString()] = row.Cells["colSelect"].Value.ParseToBool(); + NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_checked_shop_dic", dicCheckedShopId); + break; case "colLoginStatus": + { + if (WXShopListForm.Instance == null) + WXShopListForm.Instance = new WXShopListForm(); + WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false); + WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop); + //shopLoginForm.prodUserSelectForm = this; + if (shop.LoginStatus != "登录成功") { - if (WXShopListForm.Instance == null) - WXShopListForm.Instance = new WXShopListForm(); - WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false); - WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop); - //shopLoginForm.prodUserSelectForm = this; - if (shop.LoginStatus != "登录成功") - { - shopLoginForm.openType = EnumOpenType.login; - shopLoginForm.ShowDialog(); - RefreshShopLogin(); - } - else - { - shopLoginForm.openType = EnumOpenType.manage; - shopLoginForm.WindowState = FormWindowState.Maximized; - shopLoginForm.Show(); - } + shopLoginForm.openType = EnumOpenType.login; + shopLoginForm.ShowDialog(); + RefreshShopLogin(); } - break; - case "colApi": + else { - WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop); shopLoginForm.openType = EnumOpenType.manage; shopLoginForm.WindowState = FormWindowState.Maximized; - //shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/servicemarket/detail?serviceId=3984039898079707139"; - shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/servicemarket/detail?serviceId=4431685489938137094"; shopLoginForm.Show(); } - break; + } + break; + case "colApi": + { + WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop); + shopLoginForm.openType = EnumOpenType.manage; + shopLoginForm.WindowState = FormWindowState.Maximized; + //shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/servicemarket/detail?serviceId=3984039898079707139"; + shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/servicemarket/detail?serviceId=4431685489938137094"; + shopLoginForm.Show(); + } + break; } } @@ -937,24 +938,24 @@ namespace TemuKJD.WXForms.ProductForms case "删除": break; case "登录": - { - WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop); - //shopLoginForm.prodUserSelectForm = this; - shopLoginForm.openType = EnumOpenType.login; - shopLoginForm.ShowDialog(); - RefreshShopLogin(); - } - break; + { + WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop); + //shopLoginForm.prodUserSelectForm = this; + shopLoginForm.openType = EnumOpenType.login; + shopLoginForm.ShowDialog(); + RefreshShopLogin(); + } + break; case "进店": - { - WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop); - //shopLoginForm.prodUserSelectForm = this; - shopLoginForm.openType = EnumOpenType.manage; - shopLoginForm.WindowState = FormWindowState.Maximized; - shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/home"; - shopLoginForm.Show(); - } - break; + { + WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop); + //shopLoginForm.prodUserSelectForm = this; + shopLoginForm.openType = EnumOpenType.manage; + shopLoginForm.WindowState = FormWindowState.Maximized; + shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/home"; + shopLoginForm.Show(); + } + break; case "上传商品Id": //if (!string.IsNullOrEmpty(draftId) && shop != null) //{ @@ -967,17 +968,17 @@ namespace TemuKJD.WXForms.ProductForms //} break; case "图片": - { - ShowImgForm imgFrom = new ShowImgForm(dgvSelectProduct.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString()); - imgFrom.ShowDialog(); - break; - } + { + ShowImgForm imgFrom = new ShowImgForm(dgvSelectProduct.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString()); + imgFrom.ShowDialog(); + break; + } case "SKU替换图": - { - ShowImgForm imgFrom = new ShowImgForm(dgvSelectProduct.Rows[e.RowIndex].Cells["colSkuFakeImgUrl"].Value.ParseToString()); - imgFrom.ShowDialog(); - break; - } + { + ShowImgForm imgFrom = new ShowImgForm(dgvSelectProduct.Rows[e.RowIndex].Cells["colSkuFakeImgUrl"].Value.ParseToString()); + imgFrom.ShowDialog(); + break; + } case "": dgvSelectProduct.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvSelectProduct.Rows[e.RowIndex].Cells["colCheck"].Value; break; @@ -1255,13 +1256,13 @@ namespace TemuKJD.WXForms.ProductForms KJDDBProduct kjdDbProd = selectProd.kjdDbProduct; string errStr = ""; if (kjdDbProd == null) - { + { if (selectProd.db_type == "云端数据") kjdDbProd = GetCloudProductDetail(selectProd, out errStr, true, true); else kjdDbProd = GetProductDetail(selectProd.out_product_Id.ToString(), out errStr, true, true); kjdDbProd.db_type = selectProd.db_type; - } + } if (kjdDbProd == null || kjdDbProd.id == 0) { if (kjdDbProd?.id == 0) @@ -1342,7 +1343,7 @@ namespace TemuKJD.WXForms.ProductForms { WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false); } - endUploadProduct:; + endUploadProduct:; } catch (Exception ex) { @@ -1501,39 +1502,39 @@ namespace TemuKJD.WXForms.ProductForms } } - public static KJDDBProduct GetCloudProductDetail(TemuDBProductSelect selectProd, out string errMsg, bool noViolationProduct = false, bool noBanWx = false) - { - errMsg = ""; + public static KJDDBProduct GetCloudProductDetail(TemuDBProductSelect selectProd, out string errMsg, bool noViolationProduct = false, bool noBanWx = false) + { + errMsg = ""; - if (string.IsNullOrEmpty(selectProd?.spu_id)) - { - errMsg = "产品编号为空"; - return new KJDDBProduct(); - } + if (string.IsNullOrEmpty(selectProd?.spu_id)) + { + errMsg = "产品编号为空"; + return new KJDDBProduct(); + } - var html = CloudGoodsService.GetGoodsDetail(selectProd.spu_id.ParseToLong()); - if (string.IsNullOrEmpty(html) || html.Length < 100) - html = CloudGoodsService.GetGoodsDetail(selectProd.spu_id.ParseToLong()); - if (string.IsNullOrEmpty(html) || html.Length < 100) - { - return null; - } + var html = CloudGoodsService.GetGoodsDetail(selectProd.spu_id.ParseToLong()); + if (string.IsNullOrEmpty(html) || html.Length < 100) + html = CloudGoodsService.GetGoodsDetail(selectProd.spu_id.ParseToLong()); + if (string.IsNullOrEmpty(html) || html.Length < 100) + { + return null; + } - try - { - KJDDBProduct item = JsonHelper.DeserializeJsonToObject(JsonHelper.SerializeObject(selectProd)); - item.product_json = html; + try + { + KJDDBProduct item = JsonHelper.DeserializeJsonToObject(JsonHelper.SerializeObject(selectProd)); + item.product_json = html; item.id = 29; - return item; - } - catch (Exception ex) - { - return null; - } - } + return item; + } + catch (Exception ex) + { + return null; + } + } - public static WXGetEditProductInfoLite GetProductWXComplate(string secret_spu_id, out string errMsg) + public static WXGetEditProductInfoLite GetProductWXComplate(string secret_spu_id, out string errMsg) { errMsg = ""; @@ -1586,25 +1587,28 @@ namespace TemuKJD.WXForms.ProductForms } } - public static string GetEC1ExtCode(string spu_id) - { + public static string GetEC1ExtCode(string spu_id) + { if (spu_id.IsNullOrEmpty()) throw new Exception("货号指定失败,值不能为空!"); if (!spu_id.StartsWith("EC1") && !spu_id.EndsWith("A")) return "EC1" + spu_id + "A"; return spu_id; - } - public static string GetNewExtCode(string spu_id) - { - if (spu_id.IsNullOrEmpty()) - throw new Exception("货号指定失败,值不能为空!"); - if (!spu_id.StartsWith("P1-")) + } + public static string GetNewExtCode(string spu_id) + { + if (spu_id.IsNullOrEmpty()) + throw new Exception("货号指定失败,值不能为空!"); + if (!spu_id.StartsWith("P1-")) return "P1-" + spu_id; return spu_id; - } + } - string UploadProduct(ShopLoginInfo shop, KJDDBProduct dbProd, TemuDBProductSelect selectProd, DataGridViewCell cell, DateTime startTime) + string UploadProduct(ShopLoginInfo shop, KJDDBProduct dbProd, TemuDBProductSelect selectProd, DataGridViewCell cell, DateTime startTime) { + PlatformType Platform = (dbProd.product_get_type_text == "多多" ? PlatformType.PDD : PlatformType.None); + + #region 初始化上传商品对象 // 生成初始化上传商品对象 var upProdInitParam = new WXUploadProductInitParam(); @@ -1685,14 +1689,14 @@ namespace TemuKJD.WXForms.ProductForms { var searchExtCode = dbProd.ext_code; if (dbProd.db_type == "云端数据") - { - dbProd.ext_code = searchExtCode = GetNewExtCode(dbProd.spu_id); - } + { + dbProd.ext_code = searchExtCode = GetNewExtCode(dbProd.spu_id); + } else - { - if (searchExtCode.ParseToString().Length < 10) - searchExtCode = GetEC1ExtCode(dbProd.spu_id); - } + { + if (searchExtCode.ParseToString().Length < 10) + searchExtCode = GetEC1ExtCode(dbProd.spu_id); + } if (dbProd.sku_secret_json != null && dbProd.sku_secret_json.Contains("goodsId")) { var sku_secret_json = dbProd.sku_secret_json; @@ -1888,54 +1892,54 @@ namespace TemuKJD.WXForms.ProductForms if (!string.IsNullOrEmpty(convertRst)) return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}"; } - #endregion + #endregion - #region 云端数据格式转换 - if (dbProd.db_type == "云端数据" && dbProd.product_get_type_text == "多多") - { - string convertRst = ""; + #region 云端数据格式转换 + if (dbProd.db_type == "云端数据" && dbProd.product_get_type_text == "多多") + { + string convertRst = ""; - var content = dbProd.product_json; - if (content.Contains("\"spec_keys\"") && content.Contains("\"spec_values\"") && content.Contains("\"is_sku_pre_sale\"")) - { - convertRst = new PDDProdFormConverter().PddFrontToPddBackConvert(content, true, null, true, false); - } - else if (content.Contains("\"goods_id\"") && content.Contains("\"goods_name\"") && content.Contains("\"gallery\"") && - content.Contains("\"priority\"") && content.Contains("\"enable_share\"") && content.Contains("\"goods_property\"") && - (content.Contains("\"ref_pid\"") || content.Contains("\"goods_property\":[]")) && content.Contains("\"sku_id\"") && content.Contains("\"quantity\"") && - content.Contains("\"specs\"") && content.Contains("\"spec_key\"") && content.Contains("\"spec_value\"") && - content.Contains("\"group_price\"") && content.Contains("img.pddpic.com")) - { - convertRst = new PDDProdFormConverter().PddFrontToPddBackConvert2(content, true, null, true, false); - } - else if (content.Contains("\"mallId\"") && content.Contains("\"mallName\"") && content.Contains("\"goodsId\"") && content.Contains("\"goodsName\"") && - content.Contains("\"catID\"") && content.Contains("\"catID4\"") && content.Contains("\"topGallery\"") && content.Contains("\"detailGallery\"") && - content.Contains("\"shareDesc\"") && content.Contains("\"maxOnSaleGroupPriceInCent\"") && content.Contains("\"shareDesc\"") && - content.Contains("\"specs\"") && content.Contains("\"spec_key\"") && content.Contains("\"spec_value\"") && - content.Contains("\"groupPrice\"") && content.Contains("img.pddpic.com")) - { - convertRst = new PDDProdFormConverter().PddFrontToPddBackConvert3(content, true, null, true, false); - } - else if (content.Contains("\"商品编号\"") && content.Contains("\"商品链接\"") && content.Contains("\"标题\"")) - { - convertRst = new PDDProdFormConverter().PddFrontToPddBackConvertV4(content, true, null, true, false); - } - else - { - convertRst = new PDDProdFormConverter().PddFrontToPddBackConvertFactory("", true, null, true, false, content); - } + var content = dbProd.product_json; + if (content.Contains("\"spec_keys\"") && content.Contains("\"spec_values\"") && content.Contains("\"is_sku_pre_sale\"")) + { + convertRst = new PDDProdFormConverter().PddFrontToPddBackConvert(content, true, null, true, false); + } + else if (content.Contains("\"goods_id\"") && content.Contains("\"goods_name\"") && content.Contains("\"gallery\"") && + content.Contains("\"priority\"") && content.Contains("\"enable_share\"") && content.Contains("\"goods_property\"") && + (content.Contains("\"ref_pid\"") || content.Contains("\"goods_property\":[]")) && content.Contains("\"sku_id\"") && content.Contains("\"quantity\"") && + content.Contains("\"specs\"") && content.Contains("\"spec_key\"") && content.Contains("\"spec_value\"") && + content.Contains("\"group_price\"") && content.Contains("img.pddpic.com")) + { + convertRst = new PDDProdFormConverter().PddFrontToPddBackConvert2(content, true, null, true, false); + } + else if (content.Contains("\"mallId\"") && content.Contains("\"mallName\"") && content.Contains("\"goodsId\"") && content.Contains("\"goodsName\"") && + content.Contains("\"catID\"") && content.Contains("\"catID4\"") && content.Contains("\"topGallery\"") && content.Contains("\"detailGallery\"") && + content.Contains("\"shareDesc\"") && content.Contains("\"maxOnSaleGroupPriceInCent\"") && content.Contains("\"shareDesc\"") && + content.Contains("\"specs\"") && content.Contains("\"spec_key\"") && content.Contains("\"spec_value\"") && + content.Contains("\"groupPrice\"") && content.Contains("img.pddpic.com")) + { + convertRst = new PDDProdFormConverter().PddFrontToPddBackConvert3(content, true, null, true, false); + } + else if (content.Contains("\"商品编号\"") && content.Contains("\"商品链接\"") && content.Contains("\"标题\"")) + { + convertRst = new PDDProdFormConverter().PddFrontToPddBackConvertV4(content, true, null, true, false); + } + else + { + convertRst = new PDDProdFormConverter().PddFrontToPddBackConvertFactory("", true, null, true, false, content); + } - if (!string.IsNullOrEmpty(convertRst) && !convertRst.StartsWith("success")) - return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}"; + if (!string.IsNullOrEmpty(convertRst) && !convertRst.StartsWith("success")) + return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}"; if (convertRst.StartsWith("success")) convertRst = convertRst.Substring("success".Length); dbProd.product_json = convertRst; - } - #endregion + } + #endregion - #region 将产品数据初始化成微信小店支持的参数 - JObject prodJObj = new JObject(); + #region 将产品数据初始化成微信小店支持的参数 + JObject prodJObj = new JObject(); try { prodJObj = JObject.Parse(dbProd.product_json); @@ -2261,37 +2265,42 @@ namespace TemuKJD.WXForms.ProductForms } #endregion + var prodInfo = JsonHelper.DeserializeJsonToObject(dbProd.product_json); + #region 图片盗链映射生成字典(如果有) + Dictionary wxImgMapDic = new Dictionary(StringComparer.OrdinalIgnoreCase); bool isChangeImgDic = false; - Dictionary wxImgMapDic = new Dictionary(); - if (!string.IsNullOrEmpty(dbProd.wx_img_map_json)) - { - try - { - wxImgMapDic = JsonHelper.DeserializeJsonToObject>(dbProd.wx_img_map_json); - } - catch - { - isChangeImgDic = true; - wxImgMapDic = new Dictionary(); - } - } + wxImgMapDic = GetImageCaches(prodInfo); + + + + //Dictionary wxImgMapDic = new Dictionary(); + //if (!string.IsNullOrEmpty(dbProd.wx_img_map_json)) + //{ + // try + // { + // wxImgMapDic = JsonHelper.DeserializeJsonToObject>(dbProd.wx_img_map_json); + // } + // catch + // { + // isChangeImgDic = true; + // wxImgMapDic = new Dictionary(); + // } + //} #endregion #region 提取源商品详情,根据需要生成sku货号 - var prodInfo = JsonHelper.DeserializeJsonToObject(dbProd.product_json); - // 如果没有货号或有相同货号无法区分sku,自定义货号 if (dbProd.db_type == "云端数据") - { - foreach (var sku in prodInfo.detail.sku) - { + { + foreach (var sku in prodInfo.detail.sku) + { var skuId = sku.sku_id; if (skuId.IsNullOrZero()) - skuId = BaseClass.GetLong(string.Join(";", sku.spec.Select(s => s.spec_name))); - sku.out_sku_sn = GetNewExtCode(skuId.ParseToString()); - } - } + skuId = BaseClass.GetLong(string.Join(";", sku.spec.Select(s => s.spec_name))); + sku.out_sku_sn = GetNewExtCode(skuId.ParseToString()); + } + } else if (dbProd.product_get_type_text != "厂商直采") { if (prodInfo.detail.sku.Any(s => s.out_sku_sn.IsNullOrEmpty()) || @@ -2522,8 +2531,10 @@ namespace TemuKJD.WXForms.ProductForms // 获取缓存盗链 主图 if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(gallery_item.url))) { - upProdInitParam.product.info.headImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]); - upProdParam.product.info.headImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]); + Debug.WriteLine("主图:缓存"); + var image = wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]; + upProdInitParam.product.info.headImg.Add(image.PlatformUrl); + upProdParam.product.info.headImg.Add(image.PlatformUrl); continue; } @@ -2533,6 +2544,7 @@ namespace TemuKJD.WXForms.ProductForms } else { + Debug.WriteLine("主图:上传"); // 使用接口链接传主图 var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image"); var upDate = UserLogin.GetSignaturex(); @@ -2560,7 +2572,11 @@ namespace TemuKJD.WXForms.ProductForms { upProdInitParam.product.info.headImg.Add(upImgUrl); upProdParam.product.info.headImg.Add(upImgUrl); - wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl; + wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = new ImageCache + { + Md5 = BaseClass.GetMd5(gallery_item.url), + PlatformUrl = upImgUrl, + }; isChangeImgDic = true; continue; } @@ -2615,7 +2631,12 @@ namespace TemuKJD.WXForms.ProductForms { upProdInitParam.product.info.headImg.Add(upImgUrl); upProdParam.product.info.headImg.Add(upImgUrl); - wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl; + wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = new ImageCache + { + Md5 = BaseClass.GetMd5(gallery_item.url), + PlatformUrl = upImgUrl, + }; + isChangeImgDic = true; continue; } @@ -2706,24 +2727,14 @@ namespace TemuKJD.WXForms.ProductForms } #endregion + + #region 保存缓存盗链图片 - if (isChangeImgDic && dbProd.db_type != "云端数据") { - var url = BaseClass.BuildObjString("product/mdy_pdd_product"); - var data = ""; - Invoke(new Action(() => - { - data = UserLogin.GetSignaturex(); - data += "&spu_id=" + dbProd.spu_id; - data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic); - })); - var html = GetHtml.PostUtf8(url, data); - if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) - html = GetHtml.PostUtf8(url, data); - if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) - html = GetHtml.PostUtf8(url, data); + SaveImageCaches(Platform, wxImgMapDic.Values); isChangeImgDic = false; } + #endregion #region 识别类目 @@ -2771,12 +2782,12 @@ namespace TemuKJD.WXForms.ProductForms foreach (var gallery_item in aiGalleries) // 9张主图 { imgId++; - string getImgError; + string getImgError; var imgUrl = gallery_item.url; - { + { if (!imgUrl.Contains("wxapp") && imgUrl.Contains("mmecimage.cn")) imgUrl = imgUrl.Replace("https://", "http://"); - } + } var image = GetHtml.GetUrlImg(imgUrl, out getImgError); var imageBg = new Bitmap(800, 800); if (!string.IsNullOrEmpty(getImgError) || image == null) @@ -2796,24 +2807,24 @@ namespace TemuKJD.WXForms.ProductForms string imgFullPath = tempImgPath + "\\图片" + imgId + ".jpg"; tempImgFullPathLst.Add(imgFullPath); if (imgId == 1) - { + { try - { - image.Save(imgFullPath, System.Drawing.Imaging.ImageFormat.Jpeg); - } + { + image.Save(imgFullPath, System.Drawing.Imaging.ImageFormat.Jpeg); + } catch - { - // 真实图像失败传假图也能识别 - int fileSize = Randomx.GetId(1024, 10240); - using (BinaryWriter writer = new BinaryWriter(File.Create(imgFullPath))) - { - for (int i = 0; i < fileSize; i++) - { - writer.Write((byte)Randomx.GetId(256)); // 生成0到255之间的随机字节 - } - } - } - } + { + // 真实图像失败传假图也能识别 + int fileSize = Randomx.GetId(1024, 10240); + using (BinaryWriter writer = new BinaryWriter(File.Create(imgFullPath))) + { + for (int i = 0; i < fileSize; i++) + { + writer.Write((byte)Randomx.GetId(256)); // 生成0到255之间的随机字节 + } + } + } + } else { // 只需要传一张真实图像即可 @@ -2933,12 +2944,12 @@ namespace TemuKJD.WXForms.ProductForms } if (rst.Contains("bizuinBrandList")) { - foreach (var jItem in jObj["bizuinBrandList"]) // bizuinBrandList mixBrandList - { - if (jItem["chName"].ParseToString() == spBrandName) - spBrandId = jItem["brandId"].ParseToString(); - } - } + foreach (var jItem in jObj["bizuinBrandList"]) // bizuinBrandList mixBrandList + { + if (jItem["chName"].ParseToString() == spBrandName) + spBrandId = jItem["brandId"].ParseToString(); + } + } } if (spBrandId.IsNullOrEmpty()) @@ -3464,7 +3475,9 @@ namespace TemuKJD.WXForms.ProductForms // 获取缓存盗链 详情图 if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(gallery_item.url))) { - upProdParam.product.info.detail.detailImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]); + Debug.WriteLine("详情图:缓存"); + var image = wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]; + upProdParam.product.info.detail.detailImg.Add(image.PlatformUrl); continue; } @@ -3474,6 +3487,7 @@ namespace TemuKJD.WXForms.ProductForms } else { + Debug.WriteLine("详情图:上传"); // 使用接口链接传详情图 var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image"); var upDate = UserLogin.GetSignaturex(); @@ -3500,7 +3514,11 @@ namespace TemuKJD.WXForms.ProductForms if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl)) { upProdParam.product.info.detail.detailImg.Add(upImgUrl); - wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl; + wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = new ImageCache + { + Md5 = BaseClass.GetMd5(gallery_item.url), + PlatformUrl = upImgUrl, + }; isChangeImgDic = true; continue; } @@ -3554,7 +3572,11 @@ namespace TemuKJD.WXForms.ProductForms if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl)) { upProdParam.product.info.detail.detailImg.Add(upImgUrl); - wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl; + wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = new ImageCache + { + Md5 = BaseClass.GetMd5(gallery_item.url), + PlatformUrl = upImgUrl, + }; isChangeImgDic = true; continue; } @@ -3584,21 +3606,8 @@ namespace TemuKJD.WXForms.ProductForms #endregion #region 保存缓存盗链图片 - if (isChangeImgDic && dbProd.db_type != "云端数据") - { - var url = BaseClass.BuildObjString("product/mdy_pdd_product"); - var data = ""; - Invoke(new Action(() => - { - data = UserLogin.GetSignaturex(); - data += "&spu_id=" + dbProd.spu_id; - data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic); - })); - var html = GetHtml.PostUtf8(url, data); - if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) - html = GetHtml.PostUtf8(url, data); - if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) - html = GetHtml.PostUtf8(url, data); + { + SaveImageCaches(Platform, wxImgMapDic.Values); isChangeImgDic = false; } #endregion @@ -4531,12 +4540,15 @@ namespace TemuKJD.WXForms.ProductForms // 获取缓存盗链 sku图 if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(sku.thumb_url))) { - attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)], }); + Debug.WriteLine("SKU图:缓存"); + var image = wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)]; + attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = image.PlatformUrl, }); continue; } // 使用接口链接传sku图 if (1 == 1 && !sku.thumb_url.Contains("wst.wxapp.tc.qq.com")) { + Debug.WriteLine("SKU图:上传"); var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image"); var upDate = UserLogin.GetSignaturex(); upDate += "&token=" + token.accessToken; @@ -4562,7 +4574,11 @@ namespace TemuKJD.WXForms.ProductForms if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl)) { attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = upImgUrl, }); - wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = upImgUrl; + wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = new ImageCache + { + Md5 = BaseClass.GetMd5(sku.thumb_url), + PlatformUrl = upImgUrl, + }; isChangeImgDic = true; continue; // 传图成功跳过模拟上传 } @@ -4612,7 +4628,11 @@ namespace TemuKJD.WXForms.ProductForms if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl)) { attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = upImgUrl, }); - wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = upImgUrl; + wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = new ImageCache + { + Md5 = BaseClass.GetMd5(sku.thumb_url), + PlatformUrl = upImgUrl, + }; isChangeImgDic = true; continue; } @@ -4658,21 +4678,8 @@ namespace TemuKJD.WXForms.ProductForms #endregion #region 保存缓存盗链图片 - if (isChangeImgDic && dbProd.db_type != "云端数据") { - var url = BaseClass.BuildObjString("product/mdy_pdd_product"); - var data = ""; - Invoke(new Action(() => - { - data = UserLogin.GetSignaturex(); - data += "&spu_id=" + dbProd.spu_id; - data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic); - })); - var html = GetHtml.PostUtf8(url, data); - if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) - html = GetHtml.PostUtf8(url, data); - if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) - html = GetHtml.PostUtf8(url, data); + SaveImageCaches(Platform, wxImgMapDic.Values); isChangeImgDic = false; } #endregion @@ -5302,7 +5309,7 @@ namespace TemuKJD.WXForms.ProductForms foreach (var propParam in upProdParam.product.info.param) { - if (propParam.categorys[0].name.Contains("食品名称") && !propParam.categorys[1].name.Contains("见包装") && !propParam.categorys[1].name.Contains("见外包装") && + if (propParam.categorys[0].name.Contains("食品名称") && !propParam.categorys[1].name.Contains("见包装") && !propParam.categorys[1].name.Contains("见外包装") && !propParam.categorys[1].name.Contains("1") && propParam.categorys[1].name.Length > 5) foodName = "食品名称:" + propParam.categorys[1].name; else if (propParam.categorys[0].name.Contains("生产企业名称") && !propParam.categorys[1].name.Contains("见包装") && !propParam.categorys[1].name.Contains("见外包装")) @@ -5743,9 +5750,9 @@ namespace TemuKJD.WXForms.ProductForms upProdParam.product.info.extraService.freightInsurance = 1; } else - { - upProdParam.product.info.extraService.freightInsurance = 0; - } + { + upProdParam.product.info.extraService.freightInsurance = 0; + } // 假1赔3 if (upProdParam.product.info.category[0].name == "珠宝首饰" || upProdParam.product.info.category[1].name == "时尚饰品") { @@ -5798,21 +5805,8 @@ namespace TemuKJD.WXForms.ProductForms } #region 保存缓存盗链图片 - if (isChangeImgDic && dbProd.db_type != "云端数据") { - var url = BaseClass.BuildObjString("product/mdy_pdd_product"); - var data = ""; - Invoke(new Action(() => - { - data = UserLogin.GetSignaturex(); - data += "&spu_id=" + dbProd.spu_id; - data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic); - })); - var html = GetHtml.PostUtf8(url, data); - if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) - html = GetHtml.PostUtf8(url, data); - if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) - html = GetHtml.PostUtf8(url, data); + SaveImageCaches(Platform, wxImgMapDic.Values); isChangeImgDic = false; } #endregion @@ -6448,17 +6442,17 @@ namespace TemuKJD.WXForms.ProductForms // 微信安全商品检测 data += "&wx_safe_status=" + cmbWxSafe.Text.Trim().Replace("安全+未校验", "安全商品,未校验"); - // 指定天数爆款数据 // 原7天爆款数据 - //if (chkSevenDays.Checked) - // data += "&add_days_less=21"; - if (chkUpdateInDays.Checked) - { - data += "&add_days_less=" + txtUpdateInDays.Text.Trim(); + // 指定天数爆款数据 // 原7天爆款数据 + //if (chkSevenDays.Checked) + // data += "&add_days_less=21"; + if (chkUpdateInDays.Checked) + { + data += "&add_days_less=" + txtUpdateInDays.Text.Trim(); data += "&add_days_less_type=" + (cmbUpdateInDays.Text == "更新" ? "mdy" : "add"); - } + } - // 回采数据 - if (chkWXComplateProd.Checked) + // 回采数据 + if (chkWXComplateProd.Checked) data += "&has_wx_format=1"; // 标题裂变 @@ -6469,7 +6463,7 @@ namespace TemuKJD.WXForms.ProductForms data += "&min_view_uv=" + numFilterViewUv.Value; if (chkFilterSaleCountNum.Checked) - data += "&sale_count_num_more=" + numFilterSaleCountNum.Value; + data += "&sale_count_num_more=" + numFilterSaleCountNum.Value; })); var html = GetHtml.PostUtf8(url, data); //if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) @@ -6687,14 +6681,14 @@ namespace TemuKJD.WXForms.ProductForms NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_select_upload_draft_products", upload_draft_product_lst); }); } - private async void btnClearAll_Click(object sender, EventArgs e) - { - dgvSelectProduct.Rows.Clear(); + private async void btnClearAll_Click(object sender, EventArgs e) + { + dgvSelectProduct.Rows.Clear(); upload_draft_product_lst.Clear(); - NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_select_upload_draft_products", upload_draft_product_lst); - } + NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_select_upload_draft_products", upload_draft_product_lst); + } - private void chkAddMorePriceFirst_CheckedChanged(object sender, EventArgs e) + private void chkAddMorePriceFirst_CheckedChanged(object sender, EventArgs e) { if (IsFormLoad) { @@ -6736,12 +6730,12 @@ namespace TemuKJD.WXForms.ProductForms chkFilterViewUv.Checked = false; numFilterViewUv.Value = 200; if (chkWXComplateProd.Visible == true) chkWXComplateProd.Checked = false; - if (chkRandomFissionProduct.Visible == true) chkRandomFissionProduct.Checked = false; + if (chkRandomFissionProduct.Visible == true) chkRandomFissionProduct.Checked = false; if (txtRandomFissionProductCount.Visible == true) txtRandomFissionProductCount.Text = ""; - int prodCount; + int prodCount; pbSelectProd.Visible = true; Task.Run(() => { @@ -7359,13 +7353,108 @@ namespace TemuKJD.WXForms.ProductForms } int globalShopUploadCntLimitRetryTimes = 5; - private void numJumpCnt_ValueChanged(object sender, EventArgs e) - { + private void numJumpCnt_ValueChanged(object sender, EventArgs e) + { globalShopUploadCntLimitRetryTimes = numJumpCnt.Value.ParseToInt(); - } - } + } - public class WXUpload + /// + /// 获取图片缓存 + /// + /// + private Dictionary GetImageCaches(PDDProductInfo product) + { + Dictionary wxImgMapDic = new Dictionary(StringComparer.OrdinalIgnoreCase); + if (EnvironmentHelper.IsProduction) + { + return wxImgMapDic; + } + List imageUrls = new List(); + imageUrls.AddRange(product.detail.galleries.Where(g => g.type == 1).Take(9).Select(a => a.url)); + var temp_detailGalleries = product.detail.galleries.Where(g => g.type == 2).ToList(); + if (temp_detailGalleries.Count == 0) + temp_detailGalleries.Add(new gallery_item() { type = 2, url = product.detail.galleries.FirstOrDefault(g => g.type == 1)?.url }); + imageUrls.AddRange(temp_detailGalleries.Select(a => a.url)); + + + if (product.detail.sku.FirstOrDefault()?.spec?.Count > 0) + { + imageUrls.AddRange(product.detail.sku.Select(a => a.thumb_url)); + } + + + + List imageUrlMd5s = imageUrls.Select(a => BaseClass.GetMd5(a)).ToList(); + + var url = BaseClass.BuildObjString("ImageCache/GetImageCache");//获取缓存 + var data = JsonConvert.SerializeObject(new + { + md5s = imageUrlMd5s + }); + + var html = GetHtml.PostUtf8(url, data, contentType: "application/json"); + if (string.IsNullOrEmpty(html)) + html = GetHtml.PostUtf8(url, data); + var ret = JsonConvert.DeserializeObject>>(html); + if (ret.Code == 200) + { + foreach (var item in ret.Data) + { + item.IsCache = true; + wxImgMapDic[item.Md5] = item; + } + } + return wxImgMapDic; + } + + /// + /// 保存缓存图片 + /// + /// + /// + private void SaveImageCaches(PlatformType platform, IEnumerable images) + { + if (EnvironmentHelper.IsProduction) + { + return; + } + var url = BaseClass.BuildObjString("ImageCache/AddOrUpdate"); + var data = ""; + data = JsonHelper.SerializeObject(images.Where(a => a.IsCache == false).Select(a => + new + { + md5 = a.Md5, + Platform = platform, + PlatformUrl = a.PlatformUrl + } + )); + + var html = GetHtml.PostUtf8(url, data, contentType: "application/json"); + if (string.IsNullOrEmpty(html)) + html = GetHtml.PostUtf8(url, data); + var ret = JsonConvert.DeserializeObject>(html); + List failed = new List(); + if (ret.Code == 500) + { + if (ret.Data is JArray jArray) + { + failed = jArray.ToObject>() ?? new List(); + } + else if (ret.Data is JValue jValue && jValue.Value is string str) + { + failed.Add(str); + } + } + foreach (ImageCache item in images) + { + item.IsCache = !failed.Contains(item.Md5, StringComparer.OrdinalIgnoreCase); + } + + } + + } + + public class WXUpload { public static string searchProduct(ShopLoginInfo shop, string extCode, string extCode2 = "") { @@ -7868,4 +7957,13 @@ Content-Type: application/octet-stream /// public bool IsUseShanghaiReturnOrderAddress { get; set; } = false; } + + class ImageCache + { + public string Md5 { get; set; } + public int Platform { get; set; } + [JsonProperty("platform_url")] + public string PlatformUrl { get; set; } + public bool IsCache { get; set; } + } }