From 81d5107b326691ce6fc3e262879800facf9dc995 Mon Sep 17 00:00:00 2001 From: wule_5900x Date: Mon, 30 Mar 2026 02:32:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=BC=E5=A4=9A=E5=A4=9A=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TEMUKJD/BLL/Pdd/PddApi.cs | 34 + .../PDDDBProdUserSelectForm.Designer.cs | 36 +- .../PDDDBProdUserSelectForm.cs | 1208 ++++++++++++----- 3 files changed, 945 insertions(+), 333 deletions(-) diff --git a/TEMUKJD/BLL/Pdd/PddApi.cs b/TEMUKJD/BLL/Pdd/PddApi.cs index 6c0bd44..129a288 100644 --- a/TEMUKJD/BLL/Pdd/PddApi.cs +++ b/TEMUKJD/BLL/Pdd/PddApi.cs @@ -19,6 +19,13 @@ namespace TemuKJD.BLL.PddApi Data["access_token"] = shop.AccessToken; } + public string PddGoodsAdd() + { + string type = "pdd.goods.add"; + string html = PddApiRequest(type, Data); + return html; + } + public string PddGoodsDetailGet() { string type = "pdd.goods.detail.get"; @@ -40,6 +47,33 @@ namespace TemuKJD.BLL.PddApi return html; } + public string PddGoodsImageUpload() + { + string type = "pdd.goods.image.upload"; + string html = PddApiRequest(type, Data); + return html; + } + + public string PddGoodsSpecGet() + { + string type = "pdd.goods.spec.get"; + string html = PddApiRequest(type, Data); + return html; + } + public string PddGoodsSpecIdGet() + { + string type = "pdd.goods.spec.id.get"; + string html = PddApiRequest(type, Data); + return html; + } + + public string PddGoodsCatRuleGet() + { + string type = "pdd.goods.cat.rule.get"; + string html = PddApiRequest(type, Data); + return html; + } + /// /// /// diff --git a/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.Designer.cs b/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.Designer.cs index 7aa2fa9..e3e0f9a 100644 --- a/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.Designer.cs +++ b/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.Designer.cs @@ -38,6 +38,7 @@ namespace TemuKJD.PDDForms.ProductSelectForms System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.ucGroupBoxEx2 = new TemuKJD.UserComponent.UcGroupBoxEx(this.components); + this.btnApiUpload = new DevComponents.DotNetBar.PanelEx(); this.label7 = new System.Windows.Forms.Label(); this.txtWaitSeconds = new System.Windows.Forms.TextBox(); this.label6 = new System.Windows.Forms.Label(); @@ -209,6 +210,7 @@ namespace TemuKJD.PDDForms.ProductSelectForms | System.Windows.Forms.AnchorStyles.Right))); this.ucGroupBoxEx2.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); this.ucGroupBoxEx2.BorderStyle = TemuKJD.UserComponent.UcGroupBoxEx.GroupBoxBorderStyle.ROUND; + this.ucGroupBoxEx2.Controls.Add(this.btnApiUpload); this.ucGroupBoxEx2.Controls.Add(this.label7); this.ucGroupBoxEx2.Controls.Add(this.txtWaitSeconds); this.ucGroupBoxEx2.Controls.Add(this.label6); @@ -261,6 +263,32 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.ucGroupBoxEx2.TabStop = false; this.ucGroupBoxEx2.Text = "商品上传"; // + // btnApiUpload + // + this.btnApiUpload.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnApiUpload.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnApiUpload.Cursor = System.Windows.Forms.Cursors.Hand; + this.btnApiUpload.DisabledBackColor = System.Drawing.Color.Empty; + this.btnApiUpload.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btnApiUpload.Location = new System.Drawing.Point(965, 67); + this.btnApiUpload.Name = "btnApiUpload"; + this.btnApiUpload.Size = new System.Drawing.Size(84, 23); + this.btnApiUpload.Style.Alignment = System.Drawing.StringAlignment.Center; + this.btnApiUpload.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); + this.btnApiUpload.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); + this.btnApiUpload.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder; + this.btnApiUpload.Style.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.Dash; + this.btnApiUpload.Style.BorderSide = DevComponents.DotNetBar.eBorderSide.None; + this.btnApiUpload.Style.ForeColor.Color = System.Drawing.Color.White; + this.btnApiUpload.Style.GradientAngle = 90; + this.btnApiUpload.StyleMouseOver.Alignment = System.Drawing.StringAlignment.Center; + this.btnApiUpload.StyleMouseOver.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255))))); + this.btnApiUpload.StyleMouseOver.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255))))); + this.btnApiUpload.TabIndex = 742; + this.btnApiUpload.Text = "接口上传"; + this.btnApiUpload.Visible = false; + this.btnApiUpload.Click += new System.EventHandler(this.btnApiUpload_Click); + // // label7 // this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); @@ -280,7 +308,8 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.txtWaitSeconds.Name = "txtWaitSeconds"; this.txtWaitSeconds.Size = new System.Drawing.Size(32, 23); this.txtWaitSeconds.TabIndex = 728; - this.txtWaitSeconds.Text = "100"; + this.txtWaitSeconds.Text = "10"; + this.txtWaitSeconds.TextChanged += new System.EventHandler(this.txtWaitSeconds_TextChanged); // // label6 // @@ -393,7 +422,7 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.btnStop.CanvasColor = System.Drawing.SystemColors.Control; this.btnStop.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; this.btnStop.DisabledBackColor = System.Drawing.Color.Empty; - this.btnStop.Location = new System.Drawing.Point(965, 68); + this.btnStop.Location = new System.Drawing.Point(965, 110); this.btnStop.Margin = new System.Windows.Forms.Padding(4, 2, 2, 2); this.btnStop.Name = "btnStop"; this.btnStop.Size = new System.Drawing.Size(84, 23); @@ -598,7 +627,7 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.btnClearDgv.CanvasColor = System.Drawing.SystemColors.Control; this.btnClearDgv.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; this.btnClearDgv.DisabledBackColor = System.Drawing.Color.Empty; - this.btnClearDgv.Location = new System.Drawing.Point(965, 96); + this.btnClearDgv.Location = new System.Drawing.Point(879, 110); this.btnClearDgv.Margin = new System.Windows.Forms.Padding(4, 2, 2, 2); this.btnClearDgv.Name = "btnClearDgv"; this.btnClearDgv.Size = new System.Drawing.Size(84, 23); @@ -1929,5 +1958,6 @@ namespace TemuKJD.PDDForms.ProductSelectForms private System.Windows.Forms.Label label8; private System.Windows.Forms.PictureBox pictureBox1; private UserComponent.UcCheckBox chkSkipQualification; + private DevComponents.DotNetBar.PanelEx btnApiUpload; } } \ No newline at end of file diff --git a/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.cs b/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.cs index 3fe2327..4f3149f 100644 --- a/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.cs +++ b/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.cs @@ -27,7 +27,6 @@ using AllBase.Model.Result.PDDResult; using AllBase.Model.Param.PDDProdParam; using CefSharp; using TemuKJD.BLL.PddApi; -using Work.Api; namespace TemuKJD.PDDForms.ProductSelectForms { @@ -179,29 +178,29 @@ namespace TemuKJD.PDDForms.ProductSelectForms void InitPddToken() { - //var url = "https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/list?userName=pdd用户"; - ////var rst = WXHttpResponseBLL.e57PostResponse(url, "&warehouseNum=123456&shopId=46568955", ""); - //var rst = WXHttpResponseBLL.e57GetResponse(url, ""); - //if (rst.Contains("\"code\":0")) - //{ - // foreach (var shopObj in JsonHelper.JObjectParse(rst)["list"].FirstOrDefault()) - // { - // var jStr = shopObj.ParseToString(); - // string shopName = BaseRegex.GetStringJson(ref jStr, "shopName"); - // string accessToken = BaseRegex.GetStringJson(ref jStr, "accessToken"); + var url = "https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/list?userName=pdd用户"; + //var rst = WXHttpResponseBLL.e57PostResponse(url, "&warehouseNum=123456&shopId=46568955", ""); + var rst = WXHttpResponseBLL.e57GetResponse(url, ""); + if (rst.Contains("\"code\":0")) + { + foreach (var shopObj in JsonHelper.JObjectParse(rst)["list"].FirstOrDefault()) + { + var jStr = shopObj.ParseToString(); + string shopName = BaseRegex.GetStringJson(ref jStr, "shopName"); + string accessToken = BaseRegex.GetStringJson(ref jStr, "accessToken"); - // var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopAccount == shopName); - // if (shop != null) - // { - // shop.ApiAuthInfoList = new List(); - // shop.ApiAuthInfoList.Add(new AuthInfo { AccessToken = accessToken }); - // } + var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopAccount == shopName); + if (shop != null) + { + shop.ApiAuthInfoList = new List(); + shop.ApiAuthInfoList.Add(new AuthInfo { AccessToken = accessToken }); + } - // //var shop = GlobalConfig.ShopLoginList.First(s => s.ShopAccount == "阿杰小铺浦哈哈"); - // //shop.ApiAuthInfoList = new List(); - // //shop.ApiAuthInfoList.Add(new AuthInfo { AccessToken = "9ebbf9cc47834f7685af90c87cea1c7d4ff8d3dc" }); - // } - //} + //var shop = GlobalConfig.ShopLoginList.First(s => s.ShopAccount == "阿杰小铺浦哈哈"); + //shop.ApiAuthInfoList = new List(); + //shop.ApiAuthInfoList.Add(new AuthInfo { AccessToken = "9ebbf9cc47834f7685af90c87cea1c7d4ff8d3dc" }); + } + } } private void chkSelectAll_CheckedChanged(object sender, EventArgs e) @@ -1435,18 +1434,18 @@ namespace TemuKJD.PDDForms.ProductSelectForms var index = 0; foreach(var specInfo in skuInfo.spec) { - long id = 0; + long parent_id = 0; try { - id = specNameDic.FirstOrDefault(s => s.Value == specInfo.parent_name).Key; + parent_id = specNameDic.FirstOrDefault(s => s.Value == specInfo.parent_name).Key; } catch { } - if (id == 0) - id = specNameDic.ToList()[index].Key; + if (parent_id == 0) + parent_id = specNameDic.ToList()[index].Key; - specInfo.parent_id = id; + specInfo.parent_id = parent_id; specInfo.spec_id = prodInfo.detail.sku.FirstOrDefault(s => s.spec[index].spec_name == specInfo.spec_name && s.spec[index].spec_id > 0)?.spec[index].spec_id; if (specInfo.spec_id == null || specInfo.spec_id == 0) @@ -1690,309 +1689,8 @@ namespace TemuKJD.PDDForms.ProductSelectForms } } - // 处理材质成分特殊格式 - var propMaterial = prodInfo.property.goods_properties.FirstOrDefault(p => p.name == "材质成分"); - var propTempMaterial = prodCatTemplateInfo.modules.FirstOrDefault()?.propertys.FirstOrDefault(p => p.name_alias == "材质成分"); - if (propMaterial != null && propMaterial.values[0].value.Contains("%") && propTempMaterial?.control_type == 18) - { - foreach (var value_item in propMaterial.values) - { - string propMaterialValue = value_item.value; - var numPercent = BaseRegex.GetMatchRegex(ref propMaterialValue, "\\d+(\\.\\d+)?%").Cast().FirstOrDefault().ParseToString(); - if (!string.IsNullOrEmpty(numPercent)) - { - value_item.value = value_item.value.Replace(numPercent, ""); - value_item.raw_value = value_item.raw_value.Replace(numPercent, ""); - value_item.table_info_vo = new table_info_vo_info() { table_value_list = new List(), }; - value_item.table_info_vo.table_value_list.Add(new table_value_info() - { - column_type = 1, - unit = "%", - value = numPercent.Replace("%", "") - }); - } - } - } - // 处理前端采集无vid的问题 - foreach (var propInfo in prodInfo.property.goods_properties) - { - if (propInfo.ref_pid == null) - { - var propTemp = prodCatTemplateInfo.modules.FirstOrDefault()?.propertys.FirstOrDefault(p => p.name_alias == propInfo.name); - if (propTemp != null) - { - propInfo.ref_pid = propTemp.ref_pid; - foreach (var valItem in propInfo.values) - { - if (valItem.vid == null) - { - var valTemp = propTemp.values.content.FirstOrDefault(c => c.value == valItem.value); - if (valTemp != null) - valItem.vid = valTemp.vid; - } - } - } - } - } - - prodParam.goods_properties = new List(); // 商品属性,通过接口获取商品模板并做匹配 - var goods_properties = new List(); // 商品属性,暂存 - //step1(共3个step)通过商品属性获取二级必填属性 - for (int i = 0; i < prodInfo.property.goods_properties.Count; i++) - { - var propInfo = prodInfo.property.goods_properties[i]; - - var propTemp = prodCatTemplateInfo.modules.FirstOrDefault()?.propertys.FirstOrDefault(p => p.ref_pid == propInfo.ref_pid); - if (propTemp == null) - continue; - - var prop = new goods_property_param() - { - template_pid = propTemp.id, - template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, - ref_pid = propInfo.ref_pid, - pid = propTemp.pid, - vid = propInfo.values.FirstOrDefault()?.vid, - value = "", - value_unit = "", - content = (propInfo.values.FirstOrDefault()?.value).ParseToString(), - }; - if (propInfo.values.FirstOrDefault()?.table_info_vo?.table_value_list?.FirstOrDefault() != null) - { - prop.table_info_dto = new table_info_dto_param() { table_value_list = new List() }; - foreach (var table_value_param in propInfo.values.FirstOrDefault()?.table_info_vo?.table_value_list) - { - prop.table_info_dto.table_value_list.Add(new table_value_param() - { - unit = table_value_param.unit, - value = table_value_param.value, - }); - } - } - - Invoke(new Action(() => - { - if (cell != null) - { - cell.Value = "正在编辑商品属性"; - } - })); - List goods_property_param_lst = new List(); - goods_property_param_lst.Add(prop); - while (goods_property_param_lst.Count > 0) - { - var prop1 = goods_property_param_lst[0]; - string catId = prodParam.cat_id.ParseToString(); - string template_pid = prop1.template_pid.ParseToString(); - string vid = prop1.vid.ParseToString(); - string goodsId = prodParam.goods_id.ToString(); - string prop_sub_template_html = get_sub_property_template(shop, catId, template_pid, vid, goodsId, prodParam.goods_commit_id, prodInfo.chance_tab); - goods_property_param_lst.Remove(prop1); - - if (!prop_sub_template_html.Contains("\"success\":true")) - continue; - try - { - //template_module_vos - prop_sub_template_html = GetHtml.Unicode2String(prop_sub_template_html); - JObject prop_sub_template_obj = JObject.Parse(prop_sub_template_html); - string prop_sub_template_json = JsonHelper.SerializeObject(prop_sub_template_obj["result"]["template_module_vos"]); - var subTempLst = JsonHelper.DeserializeJsonToList(prop_sub_template_json); - if (subTempLst.Count > 0 && subTempLst.FirstOrDefault().propertys.Count > 0) - { - foreach (var subProperty in subTempLst.FirstOrDefault().propertys) - { - //if (!prodInfo.property.goods_properties.Any(p => p.ref_pid == subProperty.ref_pid) && subProperty.required && subProperty.values.content.Count == 1) - //{ - // prodInfo.property.goods_properties.Add(new goods_propertie_item() - // { - - // }); - //} - prodCatTemplateInfo.modules.FirstOrDefault()?.propertys.RemoveAll(p => p.ref_pid == subProperty.ref_pid); // 如果有二级属性,先要把原来的一级属性删掉 - - if (subProperty.values?.content?.Count > 1) - { - } - - if (subProperty.required && subProperty.values?.content?.Count == 1) - { - var propNew = new goods_property_param() - { - template_pid = subProperty.id, - template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, - ref_pid = subProperty.ref_pid, - pid = subProperty.pid, - vid = subProperty.values.content[0].vid, - value = "", - value_unit = "", - content = "", - }; - goods_property_param_lst.Add(propNew); - } - } - prodCatTemplateInfo.modules.FirstOrDefault()?.propertys.AddRange(subTempLst.FirstOrDefault()?.propertys); - } - else - { - continue; - } - //if (subTempLst == null) - //{ - // return "商品获取失败!商品属性格式模板获取失败!"; - //} - } - catch (Exception ex) - { - //转换失败也不要取消,会上传到草稿箱 - //return "编辑失败 " + ex.Message; - continue; - } - } - } - //step2(共3个step)通过商品属性填写新建商品属性 - foreach (var propInfo in prodInfo.property.goods_properties) - { - var propTemp = prodCatTemplateInfo.modules.FirstOrDefault()?.propertys.FirstOrDefault(p => p.ref_pid == propInfo.ref_pid); - if (propTemp == null) - continue; - - if (propInfo.name == "鞋底厚度") - { - //if (!propTemp.values.content.Any(c => c.value == propInfo.values.)) - if (!propInfo.values.All(v => propTemp.values.content.Any(c => c.value == v.value))) - { - continue; - } - } - - if (propInfo.name == "品牌" && propInfo.values.FirstOrDefault()?.value == "其他家") - { - propInfo.values.FirstOrDefault().value = "无品牌/无注册商标"; - propInfo.values.FirstOrDefault().raw_value = "无品牌/无注册商标"; - propInfo.values.FirstOrDefault().vid = 4643510; - } - - if (propInfo.name == "适用人群") - { - //if (!propInfo.values.All(v => propTemp.values.content.Any(c => c.value == v.value))) - //{ - // continue; - //} - var propTempValue = propTemp.values.content.FirstOrDefault(v => propInfo.values.Any(pv => v.value.Contains(pv.value))); - if (propTempValue == null) - propTempValue = propTemp.values.content.FirstOrDefault(v => propInfo.values.Any(pv => v.value.Contains(pv.value))); - if (propTempValue == null) - continue; - propInfo.values.FirstOrDefault().value = propTempValue.value; - propInfo.values.FirstOrDefault().raw_value = propTempValue.value; - propInfo.values.FirstOrDefault().vid = propTempValue.vid; - } - - //var prop = new goods_property_param() - var prop = new goods_spec_property_param() - { - template_pid = propTemp.id, - template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, - ref_pid = propInfo.ref_pid, - pid = propTemp.pid, - vid = propInfo.values.FirstOrDefault()?.vid, - value = "", - value_unit = "", - content = (propInfo.values.FirstOrDefault()?.value).ParseToString(), - }; - if (propInfo.values.FirstOrDefault()?.table_info_vo?.table_value_list?.FirstOrDefault() != null) - { - prop.table_info_dto = new table_info_dto_param() { table_value_list = new List() }; - foreach (var table_value_param in propInfo.values.FirstOrDefault()?.table_info_vo?.table_value_list) - { - prop.table_info_dto.table_value_list.Add(new table_value_param() - { - unit = table_value_param.unit, - value = table_value_param.value, - }); - } - } - goods_properties.Add(prop); - } - //step3(共3个step)如果有遗漏的必填(required)商品属性,按默认值填写 - foreach (var propTemp in prodCatTemplateInfo.modules.FirstOrDefault()?.propertys) - { - if (propTemp.required && !goods_properties.Any(p=>p.ref_pid == propTemp.ref_pid)) - { - var contentOther = propTemp.values.content.FirstOrDefault(c => c.value == "其他"); - if (contentOther != null) - { - //var prop = new goods_property_param() - var prop = new goods_spec_property_param() - { - template_pid = propTemp.id, - template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, - ref_pid = propTemp.ref_pid, - pid = propTemp.pid, - vid = contentOther.vid, - value = "", - value_unit = "", - content = contentOther.value, - }; - goods_properties.Add(prop); - } - else if (propTemp.name_alias == "成分含量") - { - var contentValue = propTemp.values.content.FirstOrDefault(v => v.value.Contains("以下")); - if (contentValue != null) - { - var prop = new goods_spec_property_param() - { - template_pid = propTemp.id, - template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, - ref_pid = propTemp.ref_pid, - pid = propTemp.pid, - vid = contentValue.vid, - value = "", - value_unit = "", - content = contentValue.value, - }; - goods_properties.Add(prop); - } - } - else if (propTemp.show_type == 1 && propTemp.values.content.Count == 1) // 二级关联属性 - { - var prop = new goods_spec_property_param() - { - template_pid = propTemp.id, - template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, - ref_pid = propTemp.ref_pid, - pid = propTemp.pid, - vid = propTemp.values.content.FirstOrDefault().vid, - value = "", - value_unit = "", - content = propTemp.values.content.FirstOrDefault().value, - }; - goods_properties.Add(prop); - } - } - } - foreach (var prodTempInfo in prodCatTemplateInfo.modules.FirstOrDefault()?.propertys) - { - var prop = goods_properties.FirstOrDefault(p => p.ref_pid == prodTempInfo.ref_pid); - if (prop == null) - { - prop = new goods_spec_property_param() - { - template_pid = prodTempInfo.id, - template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, - ref_pid = prodTempInfo.ref_pid, - pid = prodTempInfo.pid, - value = "", - value_unit = "", - content = "", - }; - } - prodParam.goods_properties.Add(prop); - } - - //foreach (var spec_prop in prodInfo.property.) + // 匹配商品属性 // 重要 + MatchPddProperty(shop, prodParam, prodInfo, prodCatTemplateInfo, cell); prodParam.goods_srv_templates = prodInfo.detail.goods_srv_templates; prodParam.goods_type = prodInfo.detail.goods_type; @@ -6899,6 +6597,856 @@ Content-Type: image/jpeg return "{\"success\":false,\"error_msg\"\"接口转换商品失败 " + ex.Message + "\"}"; } } + + private void btnApiUpload_Click(object sender, EventArgs e) + { + var shopIdLst = dgvShop.Rows.Cast().Where(row + => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList(); + if (shopIdLst.Count <= 0) + { + BaseMsgForm.ShowError("未勾选上传店铺!"); + return; + } + + if (lstTemuDBProductSelect.Count == 0) + { + BaseMsgForm.ShowError("请选择要上传的商品!"); + return; + } + + if (chkLowPriceSku.Checked && string.IsNullOrWhiteSpace(pbSkuImg.Tag.ParseToString())) + { + BaseMsgForm.ShowError("低价sku图片未指定!"); + return; + } + + if (chkUpgradeVersion.Checked && string.IsNullOrWhiteSpace(pbUpgradeVersion.Tag.ParseToString())) + { + BaseMsgForm.ShowError("升级版sku叠加图片未指定!"); + return; + } + + this.btnUpload.Enabled = false; + cancellationTokenSource = new CancellationTokenSource(); + Task.Run(() => + { + GetShopAndUpProduct(); + Invoke(new Action(() => + { + this.btnUpload.Enabled = true; + })); + }, cancellationTokenSource.Token); + } + + void GetShopAndUpProduct() + { + NaiBa.Util.ConcurrentList currentUpShopLst = new NaiBa.Util.ConcurrentList(); + while (lstTemuDBProductSelect.Count > 0) + { + var shopIdLst = dgvShop.Rows.Cast().Where(row + => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList(); + if (shopIdLst.Count <= 0) + { + Invoke(new Action(() => { statusBar.lblTaskStatus.Text = "请选择上传店铺!"; })); + Thread.Sleep(500); + continue; + } + Invoke(new Action(() => { statusBar.lblTaskStatus.Text = "正在上传!"; })); + + // 指定店铺数量同时上货 + if(currentUpShopLst.Count >= 10) + { + Thread.Sleep(500); + continue; + } + + // 选出一个勾选且空闲的店铺 + var selectShopLst = GlobalConfig.ShopLoginList.Where(s => shopIdLst.Contains(s.ShopId)); + var canUpShop = selectShopLst.OrderBy(x => Randomx.GetId(int.MaxValue)).FirstOrDefault(s => !currentUpShopLst.Contains(s)); + if (canUpShop == null) + { + Thread.Sleep(500); + continue; + } + currentUpShopLst.Add(canUpShop); + + // 每次挑选列表第一件商品 + var selectProd = lstTemuDBProductSelect.FirstOrDefault(); + selectProd.shop_id = canUpShop.ShopId; + selectProd.shop_account = canUpShop.ShopAccount; + lstTemuDBProductSelect.Remove(selectProd); + NaiBa.Util.Helper.ConfigHelper.SaveConfig("pdd_db_prod_upload_list", this.lstTemuDBProductSelect); + Invoke(new Action(() => + { + lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件"; + })); + // 开启一个上传线程 + Task.Run(() => + { + string result; + try + { + ApiUploadProduct(canUpShop, selectProd); + } + catch (Exception ex) + { + result = "{\"success\":false,\"status\":\"未上传\",\"errMsg\":\"" + ex.Message + "\"}"; + } + // 额外休眠 + Thread.Sleep(1000 * WaitUploadTime); + // 店铺移出上货队列,等待下次随机 + currentUpShopLst.Remove(canUpShop); + + }, cancellationTokenSource.Token); + } + } + + string ApiUploadProduct(ShopLoginInfo shop, TemuDBProductSelect selectProd) + { + DataGridViewRow row = null; + DataGridViewCell cell = null; + Invoke(new Action(() => + { + int rowIndex = 0; + this.dgvSelectProduct.Rows.Insert(rowIndex, + true, + selectProd.id, + selectProd.shop_id, + selectProd.shop_account, + "登录", + "进店", + //prod.spu_id, + BaseClass.SaLevel > 0 ? selectProd.spu_id : selectProd.spu_id.ParseToString().GetHashCode().ParseToString().Trim('-'), + selectProd.skc_id, + selectProd.main_img, + null, + "", + null, + selectProd.product_name, // 用户端显示商品原名 + selectProd.cat_name, + //prod.secret_spu_id == null ? prod.ext_code : prod.secret_spu_id, + BaseClass.SaLevel > 0 ? selectProd.ext_code : selectProd.ext_code.ParseToString().GetHashCode().ParseToString().Trim('-'), + selectProd.status, + selectProd.draft_id, + selectProd.notes, + (selectProd.user_notes + " 编辑").Trim(), + "删除", + "", + ""); + row = dgvSelectProduct.Rows[rowIndex]; + cell = row.Cells["colOpResult"]; + row.Height = 60; + + int maxRowCount = 10000; + while (dgvSelectProduct.Rows.Count > maxRowCount) + { + dgvSelectProduct.Rows.RemoveAt(maxRowCount); + } + })); + + KJDDBProduct dbProd = selectProd.kjdDbProduct; + if (dbProd == null) + dbProd = GetProductDetail(selectProd.out_product_Id.ToString()); + if (!string.IsNullOrEmpty(dbProd.secret_spu_id)) + { + Invoke(new Action(() => { row.Cells["colExtCode"].Value = dbProd.secret_spu_id; })); + } + if (dbProd == null || dbProd.id == 0) + { + if (selectProd?.id == 0) + { + Invoke(new Action(() => { row.Cells["colStatus"].Value = "已清除"; })); + selectProd.status = "已清除"; + } + return "数据库商品获取失败"; + } + + #region 将聚水潭产品数据格式进行转换成pdd格式统一上传,匹配加密的spuCode和skuCoke + if (dbProd.product_get_type_text == "厂商直采" && dbProd.sku_secret_json != null && dbProd.sku_secret_json.Contains("goodsId")) + { + string convertRst = ""; + var pProd = new PDDProdFormConverter().JstPddProdToPddConvert(out convertRst, dbProd); + if (!string.IsNullOrEmpty(convertRst)) + return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}"; + } + #endregion + + PDDProductInfo prodInfo = null; + prodInfo = JsonHelper.DeserializeJsonToObject(dbProd.product_json); + + var pddApi = new PddApi(shop); + // 主图 + string carousel_gallery = ""; + foreach (var img in prodInfo.detail.galleries.Where(g => g.type ==1).ToList()) + { + string errMsg = ""; + var imgBase64 = WXForms.ProductForms.WXDBProdUploadForm.GetImgBase64ForApi(out errMsg, img.url, false, false); + if (!string.IsNullOrEmpty(errMsg)) + { + return errMsg; + } + + var pddUpImgApi = new PddApi(shop); + pddUpImgApi.Data["image"] = "data:image/jpeg;base64," + imgBase64; + var pddUpImgApiRst = pddUpImgApi.PddGoodsImageUpload(); + if (!pddUpImgApiRst.Contains("\"goods_image_upload_response\"")) + { + errMsg = BaseRegex.GetStringJson(ref pddUpImgApiRst, "error_msg"); + if (string.IsNullOrEmpty(errMsg)) + errMsg = pddUpImgApiRst; + return errMsg; + } + carousel_gallery += "\"" + BaseRegex.GetStringJson(ref pddUpImgApiRst, "image_url") + "\","; + } + pddApi.Data["carousel_gallery"] = "[" + carousel_gallery.Trim(',') + "]"; + + pddApi.Data["cat_id"] = prodInfo.detail.cat_id; + + var pddAddressApi = new PddApi(shop); + pddAddressApi.Data["page"] = 1; + var pddAddressApiRst = pddAddressApi.PddGoodsLogisticsTemplateGet(); + if (!pddAddressApiRst.Contains("\"goods_logistics_template_get_response\"")) + { + var errMsg = BaseRegex.GetStringJson(ref pddAddressApiRst, "error_msg"); + if (string.IsNullOrEmpty(errMsg)) + errMsg = pddAddressApiRst; + return errMsg; + } + var template_id = BaseRegex.GetStringJson(ref pddAddressApiRst, "template_id"); + if (template_id == null) + { + return "运费模板获取失败,请检查是否有运费模板!"; + } + pddApi.Data["cost_template_id"] = template_id; + + pddApi.Data["country_id"] = 0; + //pddApi.Data["delivery_type"] = 1; // delivery_type INTEGER 非必填 发货方式。0:无物流发货;1:有物流发货。 + + // 详情图 + string detail_gallery = ""; + foreach (var img in prodInfo.detail.galleries.Where(g => g.type == 2).ToList()) + { + string errMsg = ""; + var imgBase64 = WXForms.ProductForms.WXDBProdUploadForm.GetImgBase64ForApi(out errMsg, img.url, false, false); + if (!string.IsNullOrEmpty(errMsg)) + { + return errMsg; + } + + var pddUpImgApi = new PddApi(shop); + pddUpImgApi.Data["image"] = "data:image/jpeg;base64," + imgBase64; + var pddUpImgApiRst = pddUpImgApi.PddGoodsImageUpload(); + if (!pddUpImgApiRst.Contains("\"goods_image_upload_response\"")) + { + errMsg = BaseRegex.GetStringJson(ref pddUpImgApiRst, "error_msg"); + if (string.IsNullOrEmpty(errMsg)) + errMsg = pddUpImgApiRst; + return errMsg; + } + detail_gallery += "\"" + BaseRegex.GetStringJson(ref pddUpImgApiRst, "image_url") + "\","; + } + pddApi.Data["detail_gallery"] = "[" + detail_gallery.Trim(',') + "]"; + + if (!string.IsNullOrEmpty(prodInfo.detail.goods_desc)) + pddApi.Data["goods_desc"] = prodInfo.detail.goods_desc; + pddApi.Data["goods_name"] = prodInfo.detail.goods_name; + + //todo 非必填 + pddApi.Data["goods_properties"] = new object(); + + pddApi.Data["goods_type"] = 1; + if (!string.IsNullOrEmpty(prodInfo.detail.image_url)) + pddApi.Data["image_url"] = prodInfo.detail.image_url; + pddApi.Data["is_folt"] = false; // 假一赔十 + pddApi.Data["is_pre_sale"] = false; // 预售 + pddApi.Data["is_refundable"] = false; // 7天无理由退换货 + + pddApi.Data["market_price"] = prodInfo.detail.market_price; + pddApi.Data["out_goods_id"] = prodInfo.detail.out_goods_sn; + pddApi.Data["second_hand"] = false; // 是否二手商品 + pddApi.Data["shipment_limit_second"] = 172800; + + // 厂商直采获取推单运费模板 + #region 厂商直采获取推单运费模板,计算运费加价。 + Invoke(new Action(() => + { + if (cell != null) + { + cell.Value = "正在选取运费模板"; + } + })); + + var shippingTemplateJson = ""; + var shipPrice = 0; + + if (dbProd.product_get_type_text == "厂商直采" && dbProd.wx_cat_leaf != null) + { + var urlShipping = BaseClass.BuildWXObjString("product/wx_get_shipping_template"); + var dataShipping = Work.UserLogin.GetSignaturex() + + "&coid=" + dbProd.skc_id; + var htmlShipping = GetHtml.PostUtf8(urlShipping, dataShipping); + if (string.IsNullOrEmpty(htmlShipping) || !htmlShipping.Contains("\"code\":200")) + htmlShipping = GetHtml.PostUtf8(urlShipping, dataShipping); + if (string.IsNullOrEmpty(htmlShipping) || !htmlShipping.Contains("\"code\":200")) + { + } + else + { + if (htmlShipping.Contains("\"data\":\"\"")) + { + } + else + { + try + { + shippingTemplateJson = JsonHelper.SerializeObject(JsonHelper.JObjectParse(htmlShipping)["data"]); + } + catch + { + + } + } + } + + if (string.IsNullOrEmpty(shippingTemplateJson)) + { + // 获取运费模板 + var urlShip = BaseClass.BuildWXObjString("product/e57_get_freight_template"); + var dataShip = Work.UserLogin.GetSignaturex() + "&coid=" + dbProd.skc_id; + var shipRst = GetHtml.PostUtf8(urlShip, dataShip); + if (string.IsNullOrEmpty(shipRst) || !shipRst.Contains("\"code\":0")) + shipRst = GetHtml.PostUtf8(urlShipping, dataShipping); + if (!shipRst.Contains("\"code\":0")) + { + var errMsg = BaseRegex.GetStringJson(ref shipRst, "msg"); + if (string.IsNullOrEmpty(errMsg)) + errMsg = shipRst; + return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"运费模板获取失败 " + errMsg + "\"}"; + } + try + { + //[{"id":"204","warehouseNum":"15016108","freightType":0,"provinces":"香港特别行政区,台湾省,澳门特别行政区","freightPrice":9999900,"createBy":"vmslin","createTime":"2026-01-30T16:45:03+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:45:03+08:00"},{"id":"205","warehouseNum":"15016108","freightType":3,"provinces":"海南省,新疆维吾尔自治区,西藏自治区,内蒙古自治区","freightPrice":1530,"createBy":"vmslin","createTime":"2026-01-30T16:45:51+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:45:51+08:00"},{"id":"206","warehouseNum":"15016108","freightType":1,"provinces":"北京市,上海市","freightPrice":410,"createBy":"vmslin","createTime":"2026-01-30T16:46:04+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:46:04+08:00"},{"id":"207","warehouseNum":"15016108","freightType":1,"provinces":"安徽省,重庆市,福建省,广东省,甘肃省,广西壮族自治区,贵州省,河北省,湖北省,黑龙江省,河南省,湖南省,吉林省,江苏省,江西省,辽宁省,宁夏回族自治区,青海省,四川省,山东省,山西省,陕西省,天津市,云南省,浙江省","freightPrice":310,"createBy":"vmslin","createTime":"2026-01-30T16:46:17+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:46:17+08:00"}] + shippingTemplateJson = JsonHelper.SerializeObject(JsonHelper.JObjectParse(shipRst)["data"]); + if (shipRst.Contains("\"code\":0") && !string.IsNullOrEmpty(shippingTemplateJson)) + { + urlShipping = BaseClass.BuildWXObjString("product/wx_add_mdy_shipping_template"); + dataShipping = Work.UserLogin.GetSignaturex() + + "&coid=" + dbProd.skc_id + + "&shipping_template_json=" + shippingTemplateJson; + htmlShipping = GetHtml.PostUtf8(urlShipping, dataShipping); + if (string.IsNullOrEmpty(htmlShipping) || !htmlShipping.Contains("\"code\":200")) + htmlShipping = GetHtml.PostUtf8(urlShipping, dataShipping); + } + } + catch (Exception ex) + { + } + } + + if (!string.IsNullOrEmpty(shippingTemplateJson)) + { + try + { + int count = 0; + var shipObjs = JArray.Parse(shippingTemplateJson); + foreach (var shipObj in shipObjs) + { + var provincesStr = shipObj["provinces"].ParseToString(); + if (provincesStr.Split(',').Length > count) + { + count = provincesStr.Split(',').Length; + shipPrice = shipObj["freightPrice"].ParseToInt(); + } + } + } + catch (Exception ex) + { + return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"运费模板获取失败 " + ex.Message + "\"}"; + } + } + if (shipPrice <= 0) + { + return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"运费模板获取失败 未获取到\"}"; + } + } + #endregion + + #region 生成一组正常加价后的sku + var skuApiString = ""; + long? minPrice = 99999999; + long? maxPrice = 0; + int marketPrice = prodInfo.detail.market_price.ParseToInt(); + List addPriceSkuInfoLst = new List(); + foreach (var sku in prodInfo.detail.sku) + { + var skuInfo = JsonHelper.DeserializeJsonToObject(JsonHelper.SerializeObject(sku)); + skuInfo.is_onsale = skuInfo.is_onsale != null ? skuInfo.is_onsale : 1; + skuInfo.limit_quantity = 999; // 只入参999 + skuInfo.multi_price = (sku.multi_price * this.txtAddTimes.Text.Trim().ParseToDecimal() + this.txtAddMorePrice.Text.Trim().ParseToDecimal() * 100).ParseToInt(); + skuInfo.price = (sku.price * this.txtAddTimes.Text.Trim().ParseToDecimal() + this.txtAddMorePrice.Text.Trim().ParseToDecimal() * 100).ParseToInt(); + //厂商直采的上家缺货则保持缺货。 + if (skuInfo.quantity != 0) + skuInfo.quantity = txtStockNum.Text.Trim().ParseToInt(); + + skuInfo.multi_price += shipPrice; + skuInfo.price += shipPrice; + + if (isAddMorePriceFirst) // 先加后乘 + skuInfo.multi_price = ((sku.multi_price + this.txtAddMorePrice.Text.Trim().ParseToDecimal() * 100) * this.txtAddTimes.Text.Trim().ParseToDecimal()).ParseToInt(); + skuInfo.price = skuInfo.multi_price + Math.Max(100, this.txtSinglePriceAdd.Text.Trim().ParseToDecimal() * 100).ParseToInt(); + //阶梯式加价,如果命中则按阶梯式加价进行 + if (isStepAddPrice) + { + foreach (var addPrice in lstAddPriceRule) + { + if (sku.multi_price > addPrice.MoreThanPrice * 100 && sku.multi_price <= addPrice.LessThanPrice * 100) + { + if (isAddMorePriceFirst) // 先加后乘 + skuInfo.multi_price = ((sku.multi_price + addPrice.AddMorePrice * 100) * addPrice.AddPriceTimes).ParseToInt(); + else + skuInfo.multi_price = (sku.multi_price * addPrice.AddPriceTimes + addPrice.AddMorePrice * 100).ParseToInt(); + skuInfo.price = skuInfo.multi_price + Math.Max(100, addPrice.SinglePriceAdd * 100).ParseToInt(); ; + break; + } + } + } + addPriceSkuInfoLst.Add(skuInfo); + + if (marketPrice < skuInfo.price + 1000) + { + marketPrice = skuInfo.price.ParseToInt() + 1000; + pddApi.Data["market_price"] = marketPrice; + } + } + #endregion + + if (dbProd.product_get_type_text == "厂商直采") + { + PddApi PddGoodsSpecGetApi = new PddApi(shop); + PddGoodsSpecGetApi.Data["cat_id"] = prodInfo.detail.cat_id; + var PddGoodsSpecGetApiRst = PddGoodsSpecGetApi.PddGoodsSpecGet(); + if (!PddGoodsSpecGetApiRst.Contains("\"goods_spec_get_response\"")) + { + var errMsg = BaseRegex.GetStringJson(ref PddGoodsSpecGetApiRst, "error_msg"); + if (string.IsNullOrEmpty(errMsg)) + errMsg = PddGoodsSpecGetApiRst; + return errMsg; + } + + Dictionary specNameDic = new Dictionary(); + foreach (var jObj in JsonHelper.JObjectParse(PddGoodsSpecGetApiRst)["goods_spec_get_response"]["goods_spec_list"]) + { + string specStr = JsonHelper.SerializeObject(jObj); + var parent_spec_id = BaseRegex.GetLongJson(ref specStr, "parent_spec_id"); + var parent_spec_name = BaseRegex.GetStringJson(ref specStr, "parent_spec_name"); + specNameDic[parent_spec_id] = parent_spec_name; + } + + for (int i = 0; i < addPriceSkuInfoLst.Count; i++) + { + for (int j = 0; j < addPriceSkuInfoLst[i].spec.Count; j++) + { + var specInfo = addPriceSkuInfoLst[i].spec[j]; + long parent_id = 0; + try + { + parent_id = specNameDic.FirstOrDefault(s => s.Value == specInfo.parent_name).Key; + } + catch + { + } + if (parent_id == 0) + parent_id = specNameDic.ToList()[j].Key; + specInfo.parent_id = parent_id; + + + PddApi PddGoodsSpecIdGetApi = new PddApi(shop); + PddGoodsSpecIdGetApi.Data["parent_spec_id"] = parent_id; + PddGoodsSpecIdGetApi.Data["spec_name"] = specInfo.spec_name; + var PddGoodsSpecIdGetApiRst = PddGoodsSpecIdGetApi.PddGoodsSpecIdGet(); + if (!PddGoodsSpecIdGetApiRst.Contains("\"goods_spec_id_get_response\"")) + { + var errMsg = BaseRegex.GetStringJson(ref PddGoodsSpecIdGetApiRst, "error_msg"); + if (string.IsNullOrEmpty(errMsg)) + errMsg = PddGoodsSpecIdGetApiRst; + return errMsg; + } + specInfo.spec_id = BaseRegex.GetLongJson(ref PddGoodsSpecIdGetApiRst, "spec_id"); + } + } + } + + // 拼接sku,计算最高价格和最低价格 + for (int i = 0; i < addPriceSkuInfoLst.Count; i++) + { + string spec = ""; + for (int j = 0; j < addPriceSkuInfoLst[i].spec.Count; j++) + { + spec += "," + addPriceSkuInfoLst[i].spec[j].spec_id; + } + spec = spec.Trim(','); + + string errMsg = ""; + var imgBase64 = WXForms.ProductForms.WXDBProdUploadForm.GetImgBase64ForApi(out errMsg, addPriceSkuInfoLst[i].thumb_url, false, false); + if (!string.IsNullOrEmpty(errMsg)) + { + return errMsg; + } + + var pddUpImgApi = new PddApi(shop); + pddUpImgApi.Data["image"] = "data:image/jpeg;base64," + imgBase64; + var pddUpImgApiRst = pddUpImgApi.PddGoodsImageUpload(); + if (!pddUpImgApiRst.Contains("\"goods_image_upload_response\"")) + { + errMsg = BaseRegex.GetStringJson(ref pddUpImgApiRst, "error_msg"); + if (string.IsNullOrEmpty(errMsg)) + errMsg = pddUpImgApiRst; + return errMsg; + } + addPriceSkuInfoLst[i].thumb_url = BaseRegex.GetStringJson(ref pddUpImgApiRst, "image_url"); + + skuApiString += ",{\"is_onsale\":" + addPriceSkuInfoLst[i].is_onsale + ",\"limit_quantity\":" + addPriceSkuInfoLst[i].limit_quantity + + ",\"price\":\"" + addPriceSkuInfoLst[i].price + "\",\"weight\":1000,\"multi_price\":\"" + addPriceSkuInfoLst[i].multi_price + + "\",\"thumb_url\":\"" + addPriceSkuInfoLst[i].thumb_url + "\",\"out_sku_sn\":\"" + addPriceSkuInfoLst[i].out_sku_sn + + "\",\"quantity\":" + addPriceSkuInfoLst[i].quantity + ",\"spec_id_list\":\"[" + spec + "]\"}"; + if (addPriceSkuInfoLst[i].multi_price > maxPrice) + maxPrice = addPriceSkuInfoLst[i].multi_price; + if (addPriceSkuInfoLst[i].multi_price < minPrice) + minPrice = addPriceSkuInfoLst[i].multi_price; + } + pddApi.Data.Remove("goods_properties"); + pddApi.Data["sku_list"] = "[" + skuApiString.Trim(',') + "]"; + + //满两件折扣,todo通过pdd.goods.cat.rule.get查询具体规则 + pddApi.Data["two_pieces_discount"] = 99; + + int retryTimes = 20; + retry: + var upLoadRst = pddApi.PddGoodsAdd(); + retryTimes--; + if (upLoadRst.Contains("该分类下只能选择7天无理由退货")) + { + pddApi.Data["is_refundable"] = true; + goto retry; + } + + + return "上传成功"; + } + + public void MatchPddProperty(ShopLoginInfo shop, PDDProductUploadParam prodParam, PDDProductInfo prodInfo, PDDProductTemplateInfo prodCatTemplateInfo, DataGridViewCell cell) + { + // 处理材质成分特殊格式 + var propMaterial = prodInfo.property.goods_properties.FirstOrDefault(p => p.name == "材质成分"); + var propTempMaterial = prodCatTemplateInfo.modules.FirstOrDefault()?.propertys.FirstOrDefault(p => p.name_alias == "材质成分"); + if (propMaterial != null && propMaterial.values[0].value.Contains("%") && propTempMaterial?.control_type == 18) + { + foreach (var value_item in propMaterial.values) + { + string propMaterialValue = value_item.value; + var numPercent = BaseRegex.GetMatchRegex(ref propMaterialValue, "\\d+(\\.\\d+)?%").Cast().FirstOrDefault().ParseToString(); + if (!string.IsNullOrEmpty(numPercent)) + { + value_item.value = value_item.value.Replace(numPercent, ""); + value_item.raw_value = value_item.raw_value.Replace(numPercent, ""); + value_item.table_info_vo = new table_info_vo_info() { table_value_list = new List(), }; + value_item.table_info_vo.table_value_list.Add(new table_value_info() + { + column_type = 1, + unit = "%", + value = numPercent.Replace("%", "") + }); + } + } + } + // 处理前端采集无vid的问题 + foreach (var propInfo in prodInfo.property.goods_properties) + { + if (propInfo.ref_pid == null) + { + var propTemp = prodCatTemplateInfo.modules.FirstOrDefault()?.propertys.FirstOrDefault(p => p.name_alias == propInfo.name); + if (propTemp != null) + { + propInfo.ref_pid = propTemp.ref_pid; + foreach (var valItem in propInfo.values) + { + if (valItem.vid == null) + { + var valTemp = propTemp.values.content.FirstOrDefault(c => c.value == valItem.value); + if (valTemp != null) + valItem.vid = valTemp.vid; + } + } + } + } + } + + prodParam.goods_properties = new List(); // 商品属性,通过接口获取商品模板并做匹配 + var goods_properties = new List(); // 商品属性,暂存 + //step1(共3个step)通过商品属性获取二级必填属性 + for (int i = 0; i < prodInfo.property.goods_properties.Count; i++) + { + var propInfo = prodInfo.property.goods_properties[i]; + + var propTemp = prodCatTemplateInfo.modules.FirstOrDefault()?.propertys.FirstOrDefault(p => p.ref_pid == propInfo.ref_pid); + if (propTemp == null) + continue; + + var prop = new goods_property_param() + { + template_pid = propTemp.id, + template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, + ref_pid = propInfo.ref_pid, + pid = propTemp.pid, + vid = propInfo.values.FirstOrDefault()?.vid, + value = "", + value_unit = "", + content = (propInfo.values.FirstOrDefault()?.value).ParseToString(), + }; + if (propInfo.values.FirstOrDefault()?.table_info_vo?.table_value_list?.FirstOrDefault() != null) + { + prop.table_info_dto = new table_info_dto_param() { table_value_list = new List() }; + foreach (var table_value_param in propInfo.values.FirstOrDefault()?.table_info_vo?.table_value_list) + { + prop.table_info_dto.table_value_list.Add(new table_value_param() + { + unit = table_value_param.unit, + value = table_value_param.value, + }); + } + } + + Invoke(new Action(() => + { + if (cell != null) + { + cell.Value = "正在编辑商品属性"; + } + })); + List goods_property_param_lst = new List(); + goods_property_param_lst.Add(prop); + while (goods_property_param_lst.Count > 0) + { + var prop1 = goods_property_param_lst[0]; + string catId = prodParam.cat_id.ParseToString(); + string template_pid = prop1.template_pid.ParseToString(); + string vid = prop1.vid.ParseToString(); + string goodsId = prodParam.goods_id.ToString(); + // 模拟接口,获取关联属性 + string prop_sub_template_html = get_sub_property_template(shop, catId, template_pid, vid, goodsId, prodParam.goods_commit_id, prodInfo.chance_tab); + goods_property_param_lst.Remove(prop1); + + if (!prop_sub_template_html.Contains("\"success\":true")) + continue; + try + { + //template_module_vos + prop_sub_template_html = GetHtml.Unicode2String(prop_sub_template_html); + JObject prop_sub_template_obj = JObject.Parse(prop_sub_template_html); + string prop_sub_template_json = JsonHelper.SerializeObject(prop_sub_template_obj["result"]["template_module_vos"]); + var subTempLst = JsonHelper.DeserializeJsonToList(prop_sub_template_json); + if (subTempLst.Count > 0 && subTempLst.FirstOrDefault().propertys.Count > 0) + { + foreach (var subProperty in subTempLst.FirstOrDefault().propertys) + { + //if (!prodInfo.property.goods_properties.Any(p => p.ref_pid == subProperty.ref_pid) && subProperty.required && subProperty.values.content.Count == 1) + //{ + // prodInfo.property.goods_properties.Add(new goods_propertie_item() + // { + + // }); + //} + prodCatTemplateInfo.modules.FirstOrDefault()?.propertys.RemoveAll(p => p.ref_pid == subProperty.ref_pid); // 如果有二级属性,先要把原来的一级属性删掉 + + if (subProperty.values?.content?.Count > 1) + { + } + + if (subProperty.required && subProperty.values?.content?.Count == 1) + { + var propNew = new goods_property_param() + { + template_pid = subProperty.id, + template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, + ref_pid = subProperty.ref_pid, + pid = subProperty.pid, + vid = subProperty.values.content[0].vid, + value = "", + value_unit = "", + content = "", + }; + goods_property_param_lst.Add(propNew); + } + } + prodCatTemplateInfo.modules.FirstOrDefault()?.propertys.AddRange(subTempLst.FirstOrDefault()?.propertys); + } + else + { + continue; + } + //if (subTempLst == null) + //{ + // return "商品获取失败!商品属性格式模板获取失败!"; + //} + } + catch (Exception ex) + { + //转换失败也不要取消,会上传到草稿箱 + //return "编辑失败 " + ex.Message; + continue; + } + } + } + //step2(共3个step)通过商品属性填写新建商品属性 + foreach (var propInfo in prodInfo.property.goods_properties) + { + var propTemp = prodCatTemplateInfo.modules.FirstOrDefault()?.propertys.FirstOrDefault(p => p.ref_pid == propInfo.ref_pid); + if (propTemp == null) + continue; + + if (propInfo.name == "鞋底厚度") + { + //if (!propTemp.values.content.Any(c => c.value == propInfo.values.)) + if (!propInfo.values.All(v => propTemp.values.content.Any(c => c.value == v.value))) + { + continue; + } + } + + if (propInfo.name == "品牌" && propInfo.values.FirstOrDefault()?.value == "其他家") + { + propInfo.values.FirstOrDefault().value = "无品牌/无注册商标"; + propInfo.values.FirstOrDefault().raw_value = "无品牌/无注册商标"; + propInfo.values.FirstOrDefault().vid = 4643510; + } + + if (propInfo.name == "适用人群") + { + //if (!propInfo.values.All(v => propTemp.values.content.Any(c => c.value == v.value))) + //{ + // continue; + //} + var propTempValue = propTemp.values.content.FirstOrDefault(v => propInfo.values.Any(pv => v.value.Contains(pv.value))); + if (propTempValue == null) + propTempValue = propTemp.values.content.FirstOrDefault(v => propInfo.values.Any(pv => v.value.Contains(pv.value))); + if (propTempValue == null) + continue; + propInfo.values.FirstOrDefault().value = propTempValue.value; + propInfo.values.FirstOrDefault().raw_value = propTempValue.value; + propInfo.values.FirstOrDefault().vid = propTempValue.vid; + } + + //var prop = new goods_property_param() + var prop = new goods_spec_property_param() + { + template_pid = propTemp.id, + template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, + ref_pid = propInfo.ref_pid, + pid = propTemp.pid, + vid = propInfo.values.FirstOrDefault()?.vid, + value = "", + value_unit = "", + content = (propInfo.values.FirstOrDefault()?.value).ParseToString(), + }; + if (propInfo.values.FirstOrDefault()?.table_info_vo?.table_value_list?.FirstOrDefault() != null) + { + prop.table_info_dto = new table_info_dto_param() { table_value_list = new List() }; + foreach (var table_value_param in propInfo.values.FirstOrDefault()?.table_info_vo?.table_value_list) + { + prop.table_info_dto.table_value_list.Add(new table_value_param() + { + unit = table_value_param.unit, + value = table_value_param.value, + }); + } + } + goods_properties.Add(prop); + } + //step3(共3个step)如果有遗漏的必填(required)商品属性,按默认值填写 + foreach (var propTemp in prodCatTemplateInfo.modules.FirstOrDefault()?.propertys) + { + if (propTemp.required && !goods_properties.Any(p => p.ref_pid == propTemp.ref_pid)) + { + var contentOther = propTemp.values.content.FirstOrDefault(c => c.value == "其他"); + if (contentOther != null) + { + //var prop = new goods_property_param() + var prop = new goods_spec_property_param() + { + template_pid = propTemp.id, + template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, + ref_pid = propTemp.ref_pid, + pid = propTemp.pid, + vid = contentOther.vid, + value = "", + value_unit = "", + content = contentOther.value, + }; + goods_properties.Add(prop); + } + else if (propTemp.name_alias == "成分含量") + { + var contentValue = propTemp.values.content.FirstOrDefault(v => v.value.Contains("以下")); + if (contentValue != null) + { + var prop = new goods_spec_property_param() + { + template_pid = propTemp.id, + template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, + ref_pid = propTemp.ref_pid, + pid = propTemp.pid, + vid = contentValue.vid, + value = "", + value_unit = "", + content = contentValue.value, + }; + goods_properties.Add(prop); + } + } + else if (propTemp.show_type == 1 && propTemp.values.content.Count == 1) // 二级关联属性 + { + var prop = new goods_spec_property_param() + { + template_pid = propTemp.id, + template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, + ref_pid = propTemp.ref_pid, + pid = propTemp.pid, + vid = propTemp.values.content.FirstOrDefault().vid, + value = "", + value_unit = "", + content = propTemp.values.content.FirstOrDefault().value, + }; + goods_properties.Add(prop); + } + } + } + foreach (var prodTempInfo in prodCatTemplateInfo.modules.FirstOrDefault()?.propertys) + { + var prop = goods_properties.FirstOrDefault(p => p.ref_pid == prodTempInfo.ref_pid); + if (prop == null) + { + prop = new goods_spec_property_param() + { + template_pid = prodTempInfo.id, + template_module_id = prodCatTemplateInfo.modules.FirstOrDefault().id, + ref_pid = prodTempInfo.ref_pid, + pid = prodTempInfo.pid, + value = "", + value_unit = "", + content = "", + }; + } + prodParam.goods_properties.Add(prop); + } + + //foreach (var spec_prop in prodInfo.property.sku_properties) ... + } + + int WaitUploadTime = 10; + private void txtWaitSeconds_TextChanged(object sender, EventArgs e) + { + WaitUploadTime = txtWaitSeconds.Text.ParseToInt(); + } } public class AddPriceRule