diff --git a/TEMUKJD/WXForms/ProductForms/WXProdPreSaleForm.cs b/TEMUKJD/WXForms/ProductForms/WXProdPreSaleForm.cs index 088b4d1..c901d7c 100644 --- a/TEMUKJD/WXForms/ProductForms/WXProdPreSaleForm.cs +++ b/TEMUKJD/WXForms/ProductForms/WXProdPreSaleForm.cs @@ -1743,62 +1743,73 @@ namespace TemuKJD.WXForms.ProductForms } List prodIdLst = new List(); + ConcurrentList tList = new ConcurrentList(); foreach (var row in rowLstTmp) { - var prodId = row.Cells["colDraftId"].Value.ParseToString(); - var skuPricesStr = row.Cells["colSkuMultiPrice"].Value.ParseToString(); - var newPrice = txtPrice.Text.ParseToDecimal(); - - if (dicProductBasePrice.ContainsKey(prodId)) + var t = Task.Run(() => { - Invoke(new Action(() => - { - row.Cells["colOpResult"].Value = "商品改价未还原,跳过"; - })); - continue; - } + var prodId = row.Cells["colDraftId"].Value.ParseToString(); + var skuPricesStr = row.Cells["colSkuMultiPrice"].Value.ParseToString(); + var newPrice = txtPrice.Text.ParseToDecimal(); - var downProdRst = changePrice(shop, prodId, skuPricesStr, (newPrice * 100).ParseToInt()); - Thread.Sleep(Randomx.GetId(200, 500)); - if (!downProdRst.Contains("\"code\":0")) - { - if (downProdRst.Contains("biz magic invalid")) + if (dicProductBasePrice.ContainsKey(prodId)) { - WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false); - if (shop.LoginStatus != "登录成功") + Invoke(new Action(() => { - Invoke(new Action(() => - { - foreach (var r in rowLstTmp) - { - r.Cells["colOpResult"].Value = "店铺掉线"; - } - })); - break; - } + row.Cells["colOpResult"].Value = "商品改价未还原,跳过"; + })); + return; } - var errmsg = BaseRegex.GetStringJson(ref downProdRst, "msg"); - if (string.IsNullOrWhiteSpace(errmsg)) - errmsg = downProdRst; + var downProdRst = changePrice(shop, prodId, skuPricesStr, (newPrice * 100).ParseToInt()); + Thread.Sleep(Randomx.GetId(200, 500)); + if (!downProdRst.Contains("\"code\":0")) + { + if (downProdRst.Contains("biz magic invalid")) + { + WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false); + if (shop.LoginStatus != "登录成功") + { + Invoke(new Action(() => + { + row.Cells["colOpResult"].Value = "店铺掉线"; + })); + return; + } + } - Invoke(new Action(() => + var errmsg = BaseRegex.GetStringJson(ref downProdRst, "msg"); + if (string.IsNullOrWhiteSpace(errmsg)) + errmsg = downProdRst; + Invoke(new Action(() => + { + row.Cells["colOpResult"].Value = "修改价格失败" + errmsg; + })); + } + // 改价成功 + else { - row.Cells["colOpResult"].Value = "修改价格失败" + errmsg; - })); - } - // 改价成功 - else + Invoke(new Action(() => + { + dicProductBasePrice[prodId] = skuPricesStr; + NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_product_base_price", dicProductBasePrice); + row.Cells["colOpResult"].Value = "修改价格成功"; + row.Cells["colPrice"].Value = newPrice; + })); + } + }); + tList.Add(t); + while(tList.Count > 20) { - dicProductBasePrice[prodId] = skuPricesStr; - NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_product_base_price", dicProductBasePrice); - Invoke(new Action(() => - { - row.Cells["colOpResult"].Value = "修改价格成功"; - row.Cells["colPrice"].Value = newPrice; - })); + Thread.Sleep(200); + tList.RemoveAll(ta => ta.IsFaulted || ta.IsCanceled || ta.IsCompleted); } } + while (tList.Count > 0) + { + Thread.Sleep(200); + tList.RemoveAll(ta => ta.IsFaulted || ta.IsCanceled || ta.IsCompleted); + } } } @@ -1949,63 +1960,76 @@ namespace TemuKJD.WXForms.ProductForms continue; } + ConcurrentList tList = new ConcurrentList(); List prodIdLst = new List(); foreach (var row in rowLstTmp) { - var prodId = row.Cells["colDraftId"].Value.ParseToString(); - - if (!dicProductBasePrice.ContainsKey(prodId)) + var t = Task.Run(() => { - Invoke(new Action(() => - { - row.Cells["colOpResult"].Value = "未找到价格修改记录,无法还原,跳过"; - })); - continue; - } - var skuPricesStr = dicProductBasePrice[prodId]; + var prodId = row.Cells["colDraftId"].Value.ParseToString(); - var downProdRst = changePrice(shop, prodId, skuPricesStr, -1, true); - Thread.Sleep(Randomx.GetId(200, 500)); - if (!downProdRst.Contains("\"code\":0")) - { - if (downProdRst.Contains("biz magic invalid")) + if (!dicProductBasePrice.ContainsKey(prodId)) { - WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false); - if (shop.LoginStatus != "登录成功") + Invoke(new Action(() => { - Invoke(new Action(() => - { - foreach (var r in rowLstTmp) - { - r.Cells["colOpResult"].Value = "店铺掉线"; - } - })); - break; - } + row.Cells["colOpResult"].Value = "未找到价格修改记录,无法还原,跳过"; + })); + return; } + var skuPricesStr = dicProductBasePrice[prodId]; - var errmsg = BaseRegex.GetStringJson(ref downProdRst, "msg"); - if (string.IsNullOrWhiteSpace(errmsg)) - errmsg = downProdRst; - - Invoke(new Action(() => + var downProdRst = changePrice(shop, prodId, skuPricesStr, -1, true); + Thread.Sleep(Randomx.GetId(200, 500)); + if (!downProdRst.Contains("\"code\":0")) { - row.Cells["colOpResult"].Value = "还原失败" + errmsg; - })); - } - // 还原价格成功 - else + if (downProdRst.Contains("biz magic invalid")) + { + WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false); + if (shop.LoginStatus != "登录成功") + { + Invoke(new Action(() => + { + row.Cells["colOpResult"].Value = "店铺掉线"; + })); + return; + } + } + + var errmsg = BaseRegex.GetStringJson(ref downProdRst, "msg"); + if (string.IsNullOrWhiteSpace(errmsg)) + errmsg = downProdRst; + + Invoke(new Action(() => + { + row.Cells["colOpResult"].Value = "还原失败" + errmsg; + })); + } + // 还原价格成功 + else + { + Invoke(new Action(() => + { + dicProductBasePrice.Remove(prodId); + NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_product_base_price", dicProductBasePrice); + + row.Cells["colOpResult"].Value = "还原价格成功"; + var skuListObj = JArray.Parse(skuPricesStr); + row.Cells["colPrice"].Value = skuListObj.Min(sk => sk["price"].ParseToInt() * 0.01m) + " - " + skuListObj.Max(sk => sk["price"].ParseToInt() * 0.01m); + })); + } + }); + tList.Add(t); + while (tList.Count > 20) { - dicProductBasePrice.Remove(prodId); - NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_product_base_price", dicProductBasePrice); - Invoke(new Action(() => - { - row.Cells["colOpResult"].Value = "还原价格成功"; - var skuListObj = JArray.Parse(skuPricesStr); - row.Cells["colPrice"].Value = skuListObj.Min(sk => sk["price"].ParseToInt() * 0.01m) + " - " + skuListObj.Max(sk => sk["price"].ParseToInt() * 0.01m); - })); + Thread.Sleep(200); + tList.RemoveAll(ta => ta.IsFaulted || ta.IsCanceled || ta.IsCompleted); } } + while (tList.Count > 0) + { + Thread.Sleep(200); + tList.RemoveAll(ta => ta.IsFaulted || ta.IsCanceled || ta.IsCompleted); + } } } }