From ed0feeadf3796a02edc5b7d98af8f85ab3b0a957 Mon Sep 17 00:00:00 2001 From: wule Date: Fri, 17 Apr 2026 20:22:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95=E4=BB=A5=E5=9B=BE=E6=90=9C?= =?UTF-8?q?=E6=AC=BE=E5=8A=9F=E8=83=BD=E5=87=86=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PDDDBProdUserSelectForm.Designer.cs | 90 ++-- .../PDDDBProdUserSelectForm.cs | 482 ++++++++++++++++-- 2 files changed, 505 insertions(+), 67 deletions(-) diff --git a/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.Designer.cs b/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.Designer.cs index 182a54f..6da8735 100644 --- a/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.Designer.cs +++ b/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.Designer.cs @@ -48,7 +48,6 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.chkMultiPcsSku = new TemuKJD.UserComponent.UcCheckBox(this.components); this.txtEndWords = new System.Windows.Forms.TextBox(); this.chkEndWords = new TemuKJD.UserComponent.UcCheckBox(this.components); - this.chkChance = new TemuKJD.UserComponent.UcCheckBox(this.components); this.txtWaitSeconds = new System.Windows.Forms.TextBox(); this.chkRandomCompanyProd = new TemuKJD.UserComponent.UcCheckBox(this.components); this.cmbTextStyle = new System.Windows.Forms.ComboBox(); @@ -146,6 +145,8 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.colCanUse = new System.Windows.Forms.DataGridViewCheckBoxColumn(); this.colRemaining = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.colMessage = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.btnSeachPicUp = new DevComponents.DotNetBar.PanelEx(); + this.txtLowPriceSkuName = new System.Windows.Forms.TextBox(); this.pbSkuImg = new System.Windows.Forms.PictureBox(); this.chk15996 = new TemuKJD.UserComponent.UcCheckBox(this.components); this.chk21365 = new TemuKJD.UserComponent.UcCheckBox(this.components); @@ -153,12 +154,12 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.txtTest20981 = new System.Windows.Forms.TextBox(); this.chkDisturbGoodsName = new TemuKJD.UserComponent.UcCheckBox(this.components); this.btnTest20981 = new DevComponents.DotNetBar.PanelEx(); + this.chkChance = new TemuKJD.UserComponent.UcCheckBox(this.components); this.pbLoading = new System.Windows.Forms.PictureBox(); this.chk22347 = new TemuKJD.UserComponent.UcCheckBox(this.components); this.chkLowPriceSku = new TemuKJD.UserComponent.UcCheckBox(this.components); this.lblLowPriceSkuImg = new System.Windows.Forms.Label(); this.label18 = new System.Windows.Forms.Label(); - this.txtLowPriceSkuName = new System.Windows.Forms.TextBox(); this.txtLowPriceSkuPrice = new System.Windows.Forms.TextBox(); this.label19 = new System.Windows.Forms.Label(); this.dgvSelectProduct = new TemuKJD.UserComponent.DataGridViewEx(); @@ -255,7 +256,6 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.ucGroupBoxEx2.Controls.Add(this.chkMultiPcsSku); this.ucGroupBoxEx2.Controls.Add(this.txtEndWords); this.ucGroupBoxEx2.Controls.Add(this.chkEndWords); - this.ucGroupBoxEx2.Controls.Add(this.chkChance); this.ucGroupBoxEx2.Controls.Add(this.txtWaitSeconds); this.ucGroupBoxEx2.Controls.Add(this.chkRandomCompanyProd); this.ucGroupBoxEx2.Controls.Add(this.cmbTextStyle); @@ -384,19 +384,6 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.chkEndWords.Text = "标题后缀"; this.chkEndWords.UseVisualStyleBackColor = true; // - // chkChance - // - this.chkChance.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.chkChance.Checked = true; - this.chkChance.CheckState = System.Windows.Forms.CheckState.Checked; - this.chkChance.Location = new System.Drawing.Point(960, 22); - this.chkChance.Name = "chkChance"; - this.chkChance.Size = new System.Drawing.Size(77, 21); - this.chkChance.TabIndex = 556; - this.chkChance.Text = "调用新接口"; - this.chkChance.UseVisualStyleBackColor = true; - this.chkChance.CheckedChanged += new System.EventHandler(this.chkChance_CheckedChanged); - // // txtWaitSeconds // this.txtWaitSeconds.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); @@ -1601,6 +1588,8 @@ namespace TemuKJD.PDDForms.ProductSelectForms // // splitContainer2.Panel2 // + this.splitContainer2.Panel2.Controls.Add(this.btnSeachPicUp); + this.splitContainer2.Panel2.Controls.Add(this.txtLowPriceSkuName); this.splitContainer2.Panel2.Controls.Add(this.pbSkuImg); this.splitContainer2.Panel2.Controls.Add(this.chk15996); this.splitContainer2.Panel2.Controls.Add(this.chk21365); @@ -1608,12 +1597,12 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.splitContainer2.Panel2.Controls.Add(this.txtTest20981); this.splitContainer2.Panel2.Controls.Add(this.chkDisturbGoodsName); this.splitContainer2.Panel2.Controls.Add(this.btnTest20981); + this.splitContainer2.Panel2.Controls.Add(this.chkChance); this.splitContainer2.Panel2.Controls.Add(this.pbLoading); this.splitContainer2.Panel2.Controls.Add(this.chk22347); this.splitContainer2.Panel2.Controls.Add(this.chkLowPriceSku); this.splitContainer2.Panel2.Controls.Add(this.lblLowPriceSkuImg); this.splitContainer2.Panel2.Controls.Add(this.label18); - this.splitContainer2.Panel2.Controls.Add(this.txtLowPriceSkuName); this.splitContainer2.Panel2.Controls.Add(this.txtLowPriceSkuPrice); this.splitContainer2.Panel2.Controls.Add(this.label19); this.splitContainer2.Panel2.Controls.Add(this.dgvSelectProduct); @@ -1764,6 +1753,44 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.colMessage.Name = "colMessage"; this.colMessage.ReadOnly = true; // + // btnSeachPicUp + // + this.btnSeachPicUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnSeachPicUp.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnSeachPicUp.Cursor = System.Windows.Forms.Cursors.Hand; + this.btnSeachPicUp.DisabledBackColor = System.Drawing.Color.Empty; + this.btnSeachPicUp.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btnSeachPicUp.Location = new System.Drawing.Point(1143, 335); + this.btnSeachPicUp.Name = "btnSeachPicUp"; + this.btnSeachPicUp.Size = new System.Drawing.Size(83, 23); + this.btnSeachPicUp.Style.Alignment = System.Drawing.StringAlignment.Center; + this.btnSeachPicUp.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); + this.btnSeachPicUp.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); + this.btnSeachPicUp.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder; + this.btnSeachPicUp.Style.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.Dash; + this.btnSeachPicUp.Style.BorderSide = DevComponents.DotNetBar.eBorderSide.None; + this.btnSeachPicUp.Style.ForeColor.Color = System.Drawing.Color.White; + this.btnSeachPicUp.Style.GradientAngle = 90; + this.btnSeachPicUp.StyleMouseOver.Alignment = System.Drawing.StringAlignment.Center; + this.btnSeachPicUp.StyleMouseOver.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255))))); + this.btnSeachPicUp.StyleMouseOver.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255))))); + this.btnSeachPicUp.TabIndex = 845; + this.btnSeachPicUp.Text = "以图搜款"; + this.btnSeachPicUp.Visible = false; + this.btnSeachPicUp.Click += new System.EventHandler(this.btnSeachPicUp_Click); + // + // txtLowPriceSkuName + // + this.txtLowPriceSkuName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.txtLowPriceSkuName.Location = new System.Drawing.Point(97, 50); + this.txtLowPriceSkuName.Margin = new System.Windows.Forms.Padding(0, 2, 0, 2); + this.txtLowPriceSkuName.Name = "txtLowPriceSkuName"; + this.txtLowPriceSkuName.Size = new System.Drawing.Size(50, 23); + this.txtLowPriceSkuName.TabIndex = 662; + this.txtLowPriceSkuName.Text = "福利款"; + this.txtLowPriceSkuName.Visible = false; + this.txtLowPriceSkuName.TextChanged += new System.EventHandler(this.txtLowPriceSkuName_TextChanged); + // // pbSkuImg // this.pbSkuImg.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; @@ -1860,6 +1887,20 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.btnTest20981.Visible = false; this.btnTest20981.Click += new System.EventHandler(this.btnTest20981_Click); // + // chkChance + // + this.chkChance.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.chkChance.Checked = true; + this.chkChance.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkChance.Location = new System.Drawing.Point(359, 51); + this.chkChance.Name = "chkChance"; + this.chkChance.Size = new System.Drawing.Size(77, 21); + this.chkChance.TabIndex = 556; + this.chkChance.Text = "调用新接口"; + this.chkChance.UseVisualStyleBackColor = true; + this.chkChance.Visible = false; + this.chkChance.CheckedChanged += new System.EventHandler(this.chkChance_CheckedChanged); + // // pbLoading // this.pbLoading.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -1887,7 +1928,7 @@ namespace TemuKJD.PDDForms.ProductSelectForms // chkLowPriceSku // this.chkLowPriceSku.AutoSize = true; - this.chkLowPriceSku.Location = new System.Drawing.Point(21, 50); + this.chkLowPriceSku.Location = new System.Drawing.Point(21, 51); this.chkLowPriceSku.Name = "chkLowPriceSku"; this.chkLowPriceSku.Size = new System.Drawing.Size(83, 21); this.chkLowPriceSku.TabIndex = 660; @@ -1922,18 +1963,6 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.label18.Text = "保底价格"; this.label18.Visible = false; // - // txtLowPriceSkuName - // - this.txtLowPriceSkuName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.txtLowPriceSkuName.Location = new System.Drawing.Point(97, 50); - this.txtLowPriceSkuName.Margin = new System.Windows.Forms.Padding(0, 2, 0, 2); - this.txtLowPriceSkuName.Name = "txtLowPriceSkuName"; - this.txtLowPriceSkuName.Size = new System.Drawing.Size(50, 23); - this.txtLowPriceSkuName.TabIndex = 662; - this.txtLowPriceSkuName.Text = "福利款"; - this.txtLowPriceSkuName.Visible = false; - this.txtLowPriceSkuName.TextChanged += new System.EventHandler(this.txtLowPriceSkuName_TextChanged); - // // txtLowPriceSkuPrice // this.txtLowPriceSkuPrice.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -2488,5 +2517,6 @@ namespace TemuKJD.PDDForms.ProductSelectForms private System.Windows.Forms.TextBox txtMultiPcsSku4; private System.Windows.Forms.Label label27; private UserComponent.UcCheckBox chkRelation; + private DevComponents.DotNetBar.PanelEx btnSeachPicUp; } } \ No newline at end of file diff --git a/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.cs b/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.cs index 6ae2cd0..6eb6a50 100644 --- a/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.cs +++ b/TEMUKJD/PDDForms/ProductSelectForms/PDDDBProdUserSelectForm.cs @@ -136,7 +136,10 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.chk21365.Checked = pddUploadRule.sign21365; this.chk22347.Checked = pddUploadRule.sign22347; this.txtAddTimesFake.Text = pddUploadRule.ActivityAddPriceTimes.ParseToString(); + + pddUploadRule.IsLowPriceSku = false; this.chkLowPriceSku.Checked = pddUploadRule.IsLowPriceSku; + this.txtLowPriceSkuName.Text = pddUploadRule.LowPriceSkuName; this.txtLowPriceSkuPrice.Text = pddUploadRule.LowPriceSkuLowestPrice.ParseToString(); this.chkUpgradeVersion.Checked = pddUploadRule.IsUpgradeVersion; @@ -608,19 +611,21 @@ namespace TemuKJD.PDDForms.ProductSelectForms private void btnUpload_Click(object sender, EventArgs e) { - //var DbIdLst = dgvSelectProduct.Rows.Cast().Where(row - // => row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colSelectId"]?.Value.ToString()).ToList(); - //var prodList = this.lstTemuDBProductSelect.Where(p => DbIdLst.Contains(p.id.ParseToString())).ToArray(); - var prodList = lstTemuDBProductSelect.ToList(); - var shopIdLst = dgvShop.Rows.Cast().Where(row - => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList(); + if (prodList.Count() <= 0) + { + BaseMsgForm.ShowError("请选择要上传的商品!"); + return; + } + 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 (chkLowPriceSku.Checked && string.IsNullOrWhiteSpace(pbSkuImg.Tag.ParseToString())) { BaseMsgForm.ShowError("低价sku图片未指定!"); @@ -633,27 +638,16 @@ namespace TemuKJD.PDDForms.ProductSelectForms return; } - - if (prodList.Count() > 0) + this.btnUpload.Enabled = false; + cancellationTokenSource = new CancellationTokenSource(); + Task.Run(() => { - if (PDDShopLoginForm.shopLoginInstance != null && PDDShopLoginForm.shopLoginInstance.IsDisposed != true) - PDDShopLoginForm.shopLoginInstance.Dispose(); - - this.btnUpload.Enabled = false; - cancellationTokenSource = new CancellationTokenSource(); - Task.Run(() => + AddProductArr(prodList, shopIdLst); + Invoke(new Action(() => { - AddProductArr(prodList, shopIdLst); - Invoke(new Action(() => - { - this.btnUpload.Enabled = true; - })); - }, cancellationTokenSource.Token); - } - else - { - BaseMsgForm.ShowError("请选择要上传的商品!"); - } + this.btnUpload.Enabled = true; + })); + }, cancellationTokenSource.Token); } void AddProductArr(List prodSelect1, List shopIdLst) @@ -883,16 +877,6 @@ namespace TemuKJD.PDDForms.ProductSelectForms { dicShopGetCount[shop] = 0; - //while (PDDShopLoginForm.shopLoginInstance != null && !PDDShopLoginForm.shopLoginInstance.IsDisposed) - //{ - // Thread.Sleep(500); - //} - //Thread.Sleep(Randomx.GetId(250, 500)); - //while (PDDShopLoginForm.shopLoginInstance != null && !PDDShopLoginForm.shopLoginInstance.IsDisposed) - //{ - // Thread.Sleep(500); - //} - PDDShopLoginForm loginForm = null; Invoke(new Action(() => { @@ -919,8 +903,6 @@ namespace TemuKJD.PDDForms.ProductSelectForms Invoke(new Action(() => { - //if (PDDShopLoginForm.shopLoginInstance != null) - // PDDShopLoginForm.shopLoginInstance.Close(); if (loginForm != null) loginForm.Close(); })); @@ -7005,6 +6987,8 @@ Content-Type: image/jpeg { if (!cancellationTokenSource.Token.IsCancellationRequested) BaseMsgForm.ShowConfirm("上传完成"); + else + BaseMsgForm.ShowConfirm("上传停止"); this.btnUpload.Enabled = true; })); }, cancellationTokenSource.Token); @@ -8899,6 +8883,430 @@ Content-Type: image/jpeg //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 btnSeachPicUp_Click(object sender, EventArgs e) + { + var prodList = lstTemuDBProductSelect.ToList(); + if (prodList.Count() <= 0) + { + BaseMsgForm.ShowError("请选择要上传的商品!"); + return; + } + + 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 (cancellationTokenSource != null) + cancellationTokenSource.Cancel(); + cancellationTokenSource = new CancellationTokenSource(); + Task.Run(() => + { + try + { + GetShopAndUpProduct(cancellationTokenSource.Token); + } + catch (Exception ex) + { + BaseMsgForm.ShowError("店铺商品上传分配错误:" + ex.Message); + } + Invoke(new Action(() => + { + if (!cancellationTokenSource.IsCancellationRequested) + BaseMsgForm.ShowConfirm("上传完成"); + else + BaseMsgForm.ShowConfirm("上传停止"); + this.btnUpload.Enabled = true; + })); + }, cancellationTokenSource.Token); + + + Task.Run(() => + { + AddProductByChanceImg(shopIdLst); + }, cancellationTokenSource.Token); + } + + + void AddProductByChanceImg(List shopIdLst) + { + Invoke(new Action(() => + { + this.pbLoading.Visible = true; + this.statusBar.lblTaskStatus.Text = "正在上传" + "...".Substring(0, DateTime.Now.Second % 4); + this.statusBar.pgbTaskProgress.Maximum = lstTemuDBProductSelect.Count; + this.statusBar.UpdateProgressBar(0); + })); + + NaiBa.Util.ConcurrentList randomShopLst = new NaiBa.Util.ConcurrentList(); + NaiBa.Util.ConcurrentList currentShopList = new NaiBa.Util.ConcurrentList(); + while (lstTemuDBProductSelect.Count > 0) + { + if (cancellationTokenSource.IsCancellationRequested) + return; + + while (true) + { + if (cancellationTokenSource.IsCancellationRequested) + return; + + Thread.Sleep(500); + + 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(() => { this.statusBar.lblTaskStatus.Text = "请至少勾选一个店铺"; })); + continue; + } + + randomShopLst.AddRange(GlobalConfig.ShopLoginList.Where(s => shopIdLst.Contains(s.ShopId) && s.LoginStatus == "登录成功")); + if (randomShopLst.Count == 0) + { + Invoke(new Action(() => { this.statusBar.lblTaskStatus.Text = "所有店铺都已掉线,请登录店铺"; })); + continue; + } + + break; + } + while (currentShopList.Count >= 5) // 最多5店同传 + { + Thread.Sleep(500); + if (cancellationTokenSource.IsCancellationRequested) + return; + } + + var randomShop = randomShopLst[Randomx.GetId(randomShopLst.Count)]; + while (currentShopList.Any(s => s.ShopId == randomShop.ShopId)) + { + Thread.Sleep(500); + randomShop = randomShopLst[Randomx.GetId(randomShopLst.Count)]; + } + currentShopList.Add(randomShop); + if (cancellationTokenSource.IsCancellationRequested) + break; + + if (lstTemuDBProductSelect.Count <= 0) + { + currentShopList.Remove(randomShop); + break; + } + var prod = lstTemuDBProductSelect[0]; + if (randomShop != null) + { + prod.shop_id = randomShop.ShopId; + prod.shop_account = randomShop.ShopAccount = randomShop.ShopAccount; + } + else + { + currentShopList.Remove(randomShop); + continue; + } + if (cancellationTokenSource.IsCancellationRequested) + break; + + lstTemuDBProductSelect.RemoveAt(0); + NaiBa.Util.Helper.ConfigHelper.SaveConfig("pdd_db_prod_upload_list", this.lstTemuDBProductSelect); + Invoke(new Action(() => + { + lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件"; + })); + + Invoke(new Action(() => + { + this.statusBar.lblTaskStatus.Text = "正在上传" + "...".Substring(0, DateTime.Now.Second % 4); + this.statusBar.pgbTaskProgress.Maximum = lstTemuDBProductSelect.Count + this.statusBar.pgbTaskProgress.Value + 1; + this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1); + })); + + if (prod == null) + { + Invoke(new Action(() => + { + BaseMsgForm.ShowError("商品为空,将为您跳过该商品!"); + })); + currentShopList.Remove(randomShop); + continue; + } + + Invoke(new Action(() => + { + int rowIndex = 0; + this.dgvSelectProduct.Rows.Insert(rowIndex, + true, + prod.id, + prod.shop_id, + prod.shop_account, + "登录", + "进店", + //prod.spu_id, + BaseClass.SaLevel > 0 ? prod.spu_id : prod.spu_id.ParseToString().GetHashCode().ParseToString().Trim('-'), + prod.skc_id, + prod.main_img, + null, + "", + null, + prod.product_name, // 用户端显示商品原名 + prod.cat_name, + //prod.secret_spu_id == null ? prod.ext_code : prod.secret_spu_id, + BaseClass.SaLevel > 0 ? prod.ext_code : prod.ext_code.ParseToString().GetHashCode().ParseToString().Trim('-'), + prod.status, + prod.draft_id, + prod.notes, + (prod.user_notes + " 编辑").Trim(), + "删除", + "", + ""); + + dgvSelectProduct.Rows[rowIndex].Height = 60; + + int maxRowCount = 10000; + while (dgvSelectProduct.Rows.Count > maxRowCount) + { + dgvSelectProduct.Rows.RemoveAt(maxRowCount); + } + })); + + Invoke(new Action(() => + { + //ShowDgvImg(); + this.pbLoading.Visible = false; + })); + + Task.Run(() => + { + DateTime startTime = DateTime.Now; + for (int j = 0; j < 1; j++) + { + var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == prod.shop_id); + if (shop == null) + continue; + + var row = dgvSelectProduct.Rows.Cast().FirstOrDefault(r => + r.Cells["colSelectId"]?.Value.ToString() == prod.id.ToString()); + double duration = 0; + if (row == null) + { + Invoke(new Action(() => + { + BaseMsgForm.ShowError("商品已被清除,将为您跳过该商品!"); + })); + continue; + } + + KJDDBProduct kjdDbProd = prod.kjdDbProduct; + if (kjdDbProd == null) + kjdDbProd = GetProductDetail(prod.out_product_Id.ToString()); + if (!string.IsNullOrEmpty(kjdDbProd.secret_spu_id)) + { + Invoke(new Action(() => { row.Cells["colExtCode"].Value = kjdDbProd.secret_spu_id; })); + } + if (kjdDbProd == null || kjdDbProd.id == 0) + { + if (kjdDbProd?.id == 0) + { + prod.status = "已清除"; + //var empty_url = BaseClass.BuildObjString("product/mdy_user_select_product_status"); + //var empty_data = UserLogin.GetSignaturex() + + // "&select_add_time=" + prod.add_time.ToString("yyyy-MM-dd HH:mm:ss") + + // "&db_id=" + prod.id + + // "&status=已清除"; + //GetHtml.PostUtf8(empty_url, empty_data); + } + + Invoke(new Action(() => + { + if (row.Index >= 0) + { + row.Cells["colOpResult"].Value = "选品数据库商品已被清除"; + if (kjdDbProd?.id == 0) + row.Cells["colStatus"].Value = "已清除"; + } + })); + continue; + } + + int sleepTime = 0; + int sleepTimeTotal = 0; + var result = ""; + try + { + if (!dicShopGetCount.Keys.Contains(shop)) + dicShopGetCount[shop] = 100; + else + dicShopGetCount[shop]++; + if (dicShopGetCount[shop] > 0) + { + dicShopGetCount[shop] = 0; + + PDDShopLoginForm loginForm = null; + Invoke(new Action(() => + { + this.panel1.SendToBack(); + loginForm = new PDDShopLoginForm(shop); + loginForm.TopLevel = false; + loginForm.openType = EnumOpenType.manage; + loginForm.WindowState = FormWindowState.Maximized; + loginForm.InitUrl = "https://mms.pinduoduo.com/home/"; + loginForm.Dock = DockStyle.Fill; + this.panel1.Controls.Add(loginForm); + loginForm.Show(); + })); + sleepTime = Randomx.GetId(4000, 8000); + sleepTimeTotal += sleepTime; + Thread.Sleep(sleepTime); + if (Randomx.GetId(3) > 0) // 后面重试的地方较多,一次获取的token不够了,随机再登录一次 + { + loginForm.cefWebBrowser.Load("https://mms.pinduoduo.com/goods/goods_list?msfrom=mms_sidenav"); + sleepTime = Randomx.GetId(4000, 8000); + sleepTimeTotal += sleepTime; + Thread.Sleep(sleepTime); + } + + Invoke(new Action(() => + { + if (loginForm != null) + loginForm.Close(); + })); + } + + PDDShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false); + if (shop.LoginStatus != "登录成功") + { + Invoke(new Action(() => + { + if (row.Index >= 0) + { + row.Cells["colOpResult"].Value = "店铺掉线"; + } + })); + continue; + } + + if (cancellationTokenSource.IsCancellationRequested) + break; + + //var prodDetailJson = GetHtml.UrlDecode(kjdDbProd.product_json); + //将商品上传 + result = UploadProduct(shop, kjdDbProd, prod, row.Cells["colOpResult"], startTime); + + Invoke(new Action(() => + { + if (chkActivity.Checked) + { + row.Cells["colSkuFakeImgUrl"].Value = kjdDbProd.sku_img_replace_url; + if (row.Displayed) + { + string getImgError = ""; + Image img = GetHtml.GetUrlImg(kjdDbProd.sku_img_replace_url.Replace("https://", "http://"), out getImgError); + if (string.IsNullOrEmpty(getImgError)) + row.Cells["colSkuFakeImg"].Value = img; + } + } + })); + + if (result.Contains("您的店铺操作过于频繁,请稍后操作")) + Thread.Sleep(Randomx.GetId(60000, 90000)); + + if (result.Contains("会话已过期")) + { + if (PDDShopListForm.Instance == null) + { + PDDShopListForm.Instance = new PDDShopListForm(); + } + PDDShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false); + } + } + catch (Exception ex) + { + result = "{\"success\":false,\"status\":\"未上传\",\"errMsg\":\"" + ex.Message + "\"}"; + } + sleepTime = Randomx.GetId(200, 300); + sleepTimeTotal += sleepTime; + Thread.Sleep(sleepTime); + + DateTime endTime = DateTime.Now; + var timeSpan = endTime - startTime; + duration = timeSpan.TotalSeconds; + while (duration < 20) + { + Thread.Sleep(Randomx.GetId(5000, 15000)); + endTime = DateTime.Now; + timeSpan = endTime - startTime; + duration = timeSpan.TotalSeconds; + } + var error = BaseRegex.GetStringJson(ref result, "errMsg"); + if (!result.Contains("\"success\":true") && !result.Contains("上传成功")) + { + if (string.IsNullOrWhiteSpace(error)) + error = result; + Invoke(new Action(() => + { + if (row.Index >= 0) + { + row.Cells["colOpResult"].Value = error + " " + duration.ParseToInt() + "秒"; + } + })); + //continue; + goto UploadEnd; + } + prod.status = BaseRegex.GetStringJson(ref result, "status"); + if (string.IsNullOrWhiteSpace(prod.status)) + prod.status = "待上传"; + var productDraftId = BaseRegex.GetStringJson(ref result, "draftId"); + + Invoke(new Action(() => + { + if (row.Index >= 0) + { + row.Cells["colDraftId"].Value = productDraftId; // 草稿箱id + row.Cells["colAddTime"].Value = DateTime.Now.ToString("yy-MM-dd HH:mm:ss"); + row.Cells["colOpResult"].Value = (prod.status == "已上传" ? "已成功上传" : "已上传 发生错误:") + (" " + error).TrimEnd(' ') + " " + duration.ParseToInt() + "秒"; + row.Cells["colMsg"].Value = prod.status; + } + })); + + UploadEnd:; + + //额外等待时间(无论失败与否) + var waitTime = 0; + Invoke(new Action(() => { waitTime = txtWaitSeconds.Text.Trim().ParseToInt(); })); + if (waitTime > 0) + Thread.Sleep(Randomx.GetId(waitTime * 1000, (waitTime + 10) * 1000)); + + } + currentShopList.Remove(randomShop); + }); + } + + for (int i = 0; i < 200 && currentShopList.Count > 0; i++) + { + Thread.Sleep(1000); + if (cancellationTokenSource.IsCancellationRequested) + break; + } + Invoke(new Action(() => + { + if (cancellationTokenSource.IsCancellationRequested) + BaseMsgForm.ShowInfo("上传停止!"); + else + BaseMsgForm.ShowInfo("上传完成!"); + })); + + Invoke(new Action(() => + { + this.pbLoading.Visible = false; + if (cancellationTokenSource.IsCancellationRequested) + this.statusBar.lblTaskStatus.Text = "上传停止"; + else + this.statusBar.lblTaskStatus.Text = "上传完成"; + //this.statusBar.UpdateProgressBar(lstTemuDBProductSelect.Count); + })); + } } public class AddPriceRule