1循环加入发货台功能 2修复部分bug
This commit is contained in:
1 parent
e2b37df00b
commit
41a3cb3e34
16 files changed
+870
-422
No files matched your search
@@ -18,6 +18,7 @@ using TemuKJD.BLL;
|
||||
using TemuKJD.Extension;
|
||||
using TemuKJD.KJDForms.AdminForms;
|
||||
using TemuKJD.KJDForms.ShopForms;
|
||||
using TemuKJD.ToolForms;
|
||||
using Work;
|
||||
|
||||
namespace TemuKJD.KJDForms.ProductForms
|
||||
@@ -45,7 +46,10 @@ namespace TemuKJD.KJDForms.ProductForms
|
||||
dgvStock.AddSelectorColumn("colCheck");
|
||||
dgvStock.AddImgColumn("colProductSkcPic", "colImgUrl");
|
||||
|
||||
joinDeliveryConfig = NaiBa.Util.Helper.ConfigHelper.LoadConfig<JoinDeliveryConfig>("join_delivery_config");
|
||||
if (IsAdmin)
|
||||
joinDeliveryConfig = NaiBa.Util.Helper.ConfigHelper.LoadConfig<JoinDeliveryConfig>("admin_join_delivery_config");
|
||||
else
|
||||
joinDeliveryConfig = NaiBa.Util.Helper.ConfigHelper.LoadConfig<JoinDeliveryConfig>("join_delivery_config");
|
||||
if (joinDeliveryConfig == null)
|
||||
joinDeliveryConfig = new JoinDeliveryConfig();
|
||||
this.txtNotes.Text = joinDeliveryConfig.SearchNotes;
|
||||
@@ -69,7 +73,10 @@ namespace TemuKJD.KJDForms.ProductForms
|
||||
joinDeliveryConfig.RetryInterval = Math.Max(1, this.txtRetryInterval.Text.Trim().ParseToInt());
|
||||
joinDeliveryConfig.SearchAllShop = this.chkSearchAllShop.Checked;
|
||||
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("join_delivery_config", joinDeliveryConfig);
|
||||
if (IsAdmin)
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("admin_join_delivery_config", joinDeliveryConfig);
|
||||
else
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("join_delivery_config", joinDeliveryConfig);
|
||||
}
|
||||
|
||||
private void JoinDeliveryFrom_VisibleChanged(object sender, EventArgs e)
|
||||
@@ -80,6 +87,10 @@ namespace TemuKJD.KJDForms.ProductForms
|
||||
{
|
||||
SearchShop(this.ucSplitPage1.CurrentPage);
|
||||
}
|
||||
else
|
||||
{
|
||||
RefreshShop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,12 +203,91 @@ namespace TemuKJD.KJDForms.ProductForms
|
||||
|
||||
private void btnRefreshShop_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (this.ucSplitPage1.CurrentPage != 1)
|
||||
this.ucSplitPage1.CurrentPage = 1;
|
||||
if (IsAdmin)
|
||||
{
|
||||
if (this.ucSplitPage1.CurrentPage != 1)
|
||||
this.ucSplitPage1.CurrentPage = 1;
|
||||
else
|
||||
SearchShop(1);
|
||||
}
|
||||
else
|
||||
SearchShop(1);
|
||||
{
|
||||
RefreshShop();
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshShop()
|
||||
{
|
||||
// 店铺Id
|
||||
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||||
|
||||
var shopLst = GlobalConfig.ShopLoginList.ToList();
|
||||
if (!string.IsNullOrWhiteSpace(txtShopId.Text))
|
||||
{
|
||||
shopLst = shopLst.Where(s => txtShopId.Text.Contains(s.ShopId)).ToList();
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(txtShopName.Text))
|
||||
{
|
||||
shopLst = shopLst.Where(s => txtShopName.Text.Contains(s.ShopAccount)).ToList();
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(txtNotes.Text))
|
||||
{
|
||||
shopLst = shopLst.Where(s => txtNotes.Text.Contains(s.Notes)).ToList();
|
||||
}
|
||||
|
||||
// 获取被删除的店铺
|
||||
List<DataGridViewRow> dgvRowList = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||||
=> !shopLst.Any(s => s.ShopId == row.Cells["colShopId"]?.Value?.ToString())).ToList();
|
||||
// 更新被删除的店铺列表
|
||||
foreach (var row in dgvRowList)
|
||||
{
|
||||
dgvShop.Rows.Remove(row);
|
||||
}
|
||||
// 绑定其他店铺(含新导入的店铺)
|
||||
foreach (ShopLoginInfo shopEntity in shopLst)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(shopEntity.ShopId))
|
||||
BindShop(shopEntity, selectIds);
|
||||
}
|
||||
}
|
||||
|
||||
private void BindShop(ShopLoginInfo shopEntity, List<string> selectShopId = null)
|
||||
{
|
||||
if (shopEntity == null)
|
||||
return;
|
||||
if (selectShopId == null)
|
||||
selectShopId = new List<string>();
|
||||
|
||||
bool canUse = shopEntity.LoginStatus2 == "国际版在线";
|
||||
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId);
|
||||
if (row == null)
|
||||
{
|
||||
int id = this.dgvShop.Rows.Add(
|
||||
selectShopId.Contains(shopEntity.ShopId) && canUse,
|
||||
shopEntity.UserName,
|
||||
shopEntity.LoginName,
|
||||
shopEntity.ShopId,
|
||||
shopEntity.ShopAccount,
|
||||
shopEntity.Notes,
|
||||
canUse ? "在线" : "掉线",
|
||||
canUse,
|
||||
string.Empty
|
||||
);
|
||||
displayShopStatus(shopEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
row.Cells["colSelect"].Value = selectShopId.Contains(shopEntity.ShopId) && canUse;
|
||||
row.Cells["colLoginName"].Value = shopEntity.LoginName;
|
||||
row.Cells["colShopName"].Value = shopEntity.ShopAccount;
|
||||
row.Cells["colShopNotes"].Value = shopEntity.Notes;
|
||||
row.Cells["colLoginStatus"].Value = canUse ? "在线" : "掉线";
|
||||
displayShopStatus(shopEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void btnEmpty_Click(object sender, EventArgs e)
|
||||
{
|
||||
txtNotes.Text = txtShopId.Text = txtShopName.Text = "";
|
||||
@@ -213,19 +303,19 @@ namespace TemuKJD.KJDForms.ProductForms
|
||||
return;
|
||||
}
|
||||
|
||||
var columns = this.dgvStock.Columns.Cast<DataGridViewColumn>();
|
||||
foreach (var col in columns)
|
||||
{
|
||||
if (col.Name == "colParentStockId" || col.Name == "colStockId")
|
||||
{
|
||||
col.Visible = true;
|
||||
}
|
||||
if (col.Name == "colTodaySaleVolume" || col.Name == "colLastSevenDaysSaleVolume" || col.Name == "colInCartNumber7d" || col.Name == "colSalesInventoryNum"
|
||||
|| col.Name == "colWaitReceiveNum" || col.Name == "colNeedStockUp" || col.Name == "colQualityScore")
|
||||
{
|
||||
col.Visible = false;
|
||||
}
|
||||
}
|
||||
//var columns = this.dgvStock.Columns.Cast<DataGridViewColumn>();
|
||||
//foreach (var col in columns)
|
||||
//{
|
||||
// if (col.Name == "colParentStockId" || col.Name == "colStockId")
|
||||
// {
|
||||
// col.Visible = true;
|
||||
// }
|
||||
// if (col.Name == "colTodaySaleVolume" || col.Name == "colLastSevenDaysSaleVolume" || col.Name == "colInCartNumber7d" || col.Name == "colSalesInventoryNum"
|
||||
// || col.Name == "colWaitReceiveNum" || col.Name == "colNeedStockUp" || col.Name == "colQualityScore")
|
||||
// {
|
||||
// col.Visible = false;
|
||||
// }
|
||||
//}
|
||||
|
||||
lstStockInfo.Clear();
|
||||
dgvStock.Rows.Clear();
|
||||
@@ -271,23 +361,23 @@ namespace TemuKJD.KJDForms.ProductForms
|
||||
continue;
|
||||
|
||||
#region 检测登录
|
||||
if (shop.LoginStatus != "登录成功")
|
||||
if (shop.LoginStatus2 != "国际版在线")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(IsAdmin)
|
||||
if (IsAdmin)
|
||||
{
|
||||
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
ShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
|
||||
}
|
||||
if (shop.LoginStatus != "登录成功")
|
||||
if (shop.LoginStatus2 != "国际版在线")
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopLoginName"].Value.ToString() == shop.LoginName);
|
||||
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colLoginName"].Value.ToString() == shop.LoginName);
|
||||
foreach (var row in rows)
|
||||
{
|
||||
row.Cells["colMessage"].Value = "店铺掉线";
|
||||
@@ -312,6 +402,7 @@ namespace TemuKJD.KJDForms.ProductForms
|
||||
int totalPage = 1;
|
||||
int pageSize = 20;
|
||||
bool isError = false;
|
||||
string errorMsg = "";
|
||||
while (page <= totalPage)
|
||||
{
|
||||
if (cancellationTokenSource.IsCancellationRequested)
|
||||
@@ -319,17 +410,18 @@ namespace TemuKJD.KJDForms.ProductForms
|
||||
|
||||
Thread.Sleep(100 + Randomx.GetId(200));
|
||||
string jsonStr = GetShopStockList2(shop, page, pageSize);
|
||||
if (jsonStr.Contains("指定的值含有无效的控制字符"))
|
||||
{
|
||||
BaseMsgForm.ShowError("店铺" + shop.LoginName + " " + shop.ShopId + "已掉线");
|
||||
isError = true;
|
||||
break;
|
||||
}
|
||||
if (!jsonStr.Contains("\"success\":true"))
|
||||
jsonStr = GetShopStockList2(shop, page, pageSize);
|
||||
if (!jsonStr.Contains("\"success\":true"))
|
||||
{
|
||||
isError = true;
|
||||
var errMsg = BaseRegex.GetStringJson(ref jsonStr, "error_msg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = BaseRegex.GetStringJson(ref jsonStr, "errorMsg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = jsonStr;
|
||||
if (!errorMsg.Contains(errMsg))
|
||||
{
|
||||
errorMsg += " " + errMsg;
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonStr.Contains("\"success\":true"))
|
||||
@@ -360,20 +452,15 @@ namespace TemuKJD.KJDForms.ProductForms
|
||||
sInfo.supplierName,
|
||||
sInfo.subPurchaseOrderSn,
|
||||
sInfo.originalPurchaseOrderSn,
|
||||
sInfo.productSkcPicture.Replace("https", "http"),
|
||||
sInfo.productSkcPicture.Replace("https", "http").Replace("img.kwcdn.com", "img.cdnfe.com"),
|
||||
DataGridViewExtension.defaultBitmap,
|
||||
sInfo.productId,
|
||||
sInfo.productSkcId,
|
||||
sInfo.productName,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
0.0,
|
||||
"",
|
||||
""
|
||||
sInfo.productName, // 标题
|
||||
sInfo.skuQuantityDetailList.Min(s => s.supplierPrice) * 0.01 + "~" + sInfo.skuQuantityDetailList.Max(s => s.supplierPrice) * 0.01,
|
||||
sInfo.skuQuantityTotalInfo.purchasePrice,
|
||||
BaseClass.StampToDateTime((sInfo.purchaseTime.ParseToLong() * 0.001).ParseToInt()).ToString("yyyy/MM/dd HH:mm:ss"),
|
||||
string.IsNullOrEmpty(sInfo.joinDeliverPlatformReason) ? "" : sInfo.joinDeliverPlatformReason
|
||||
);
|
||||
|
||||
dgvStock.Rows[rowId].Height = 60;
|
||||
@@ -402,7 +489,7 @@ namespace TemuKJD.KJDForms.ProductForms
|
||||
{
|
||||
foreach (var row in rows)
|
||||
{
|
||||
row.Cells["colMessage"].Value = "查询失败";
|
||||
row.Cells["colMessage"].Value = "查询失败" + errorMsg;
|
||||
}
|
||||
}
|
||||
}));
|
||||
@@ -433,12 +520,319 @@ namespace TemuKJD.KJDForms.ProductForms
|
||||
page = Math.Max(page, 1);
|
||||
string url = "https://agentseller.temu.com/mms/venom/api/supplier/purchase/manager/querySubOrderList";
|
||||
string body;
|
||||
body = @"{""pageNo"":" + page + @",""pageSize"":" + pageSize + @",""urgencyType"":0,""isCustomGoods"":false,""statusList"":[1]," +
|
||||
body = @"{""pageNo"":" + page + @",""pageSize"":" + pageSize + @",""urgencyType"":0,""isCustomGoods"":false,""statusList"":[1]," +
|
||||
@"""oneDimensionSort"":{""firstOrderByParam"":""expectLatestDeliverTime"",""firstOrderByDesc"":0}}";
|
||||
string refere = "https://agentseller.temu.com/stock/fully-mgt/order-manage";
|
||||
|
||||
return HttpResponseBLL.PostResponse2(shop, url, body, refere);
|
||||
}
|
||||
|
||||
private string JoinDeliveryOrderPlatform(ShopLoginInfo shop, List<string> subPurchaseOrderSnLst)
|
||||
{
|
||||
string url = "https://agentseller.temu.com/mms/venom/api/supplier/purchase/manager/batchJoinDeliveryOrderPlatformV2";
|
||||
string body;
|
||||
body = "{\"joinDeliveryPlatformRequestList\":[";
|
||||
//body += "{\"subPurchaseOrderSn\":\"WB251028608265\"},{\"subPurchaseOrderSn\":\"WB251028208967\"},{\"subPurchaseOrderSn\":\"WB251028438327\"}";
|
||||
foreach (var sn in subPurchaseOrderSnLst)
|
||||
{
|
||||
body += "{\"subPurchaseOrderSn\":\"" + sn + "\"},";
|
||||
}
|
||||
body = body.TrimEnd(',');
|
||||
body += "]}";
|
||||
string refere = "https://agentseller.temu.com/stock/fully-mgt/order-manage";
|
||||
|
||||
return HttpResponseBLL.PostResponse2(shop, url, body, refere);
|
||||
}
|
||||
|
||||
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||||
return;
|
||||
string headerText = dgvShop.Columns[e.ColumnIndex].HeaderText;
|
||||
string loginName = dgvShop.Rows[e.RowIndex].Cells["colLoginName"].Value.ParseToString();
|
||||
string accountId = dgvShop.Rows[e.RowIndex].Cells["colShopId"].Value.ParseToString();
|
||||
ShopLoginInfo shop = null;
|
||||
if (IsAdmin)
|
||||
shop = lstAdminShopInfo.FirstOrDefault(v => v.LoginName == loginName && v.ShopId == accountId);
|
||||
else
|
||||
shop = GlobalConfig.ShopLoginList.FirstOrDefault(v => v.LoginName == loginName && v.ShopId == accountId);
|
||||
|
||||
switch (headerText)
|
||||
{
|
||||
case "登录":
|
||||
case "状态":
|
||||
if (IsAdmin)
|
||||
{
|
||||
AdminShopLoginForm shopLoginForm = new AdminShopLoginForm(shop);
|
||||
shopLoginForm.openType = EnumOpenType.login;
|
||||
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
|
||||
shopLoginForm.ShowDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
|
||||
shopLoginForm.openType = EnumOpenType.login;
|
||||
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
|
||||
shopLoginForm.ShowDialog();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value = !(bool)dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void shopLoginForm_SaveComplete(object obj)
|
||||
{
|
||||
var shop = obj as ShopLoginInfo;
|
||||
if (shop == null)
|
||||
return;
|
||||
|
||||
displayShopStatus(shop);
|
||||
}
|
||||
|
||||
private void dgvStock_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||||
return;
|
||||
string headerText = dgvStock.Columns[e.ColumnIndex].HeaderText;
|
||||
string prodId = dgvStock.Rows[e.RowIndex].Cells["colProductId"].Value.ParseToString();
|
||||
string accountId = dgvStock.Rows[e.RowIndex].Cells["colSupplierId"].Value.ParseToString();
|
||||
|
||||
switch (headerText)
|
||||
{
|
||||
case "Skc图片":
|
||||
string url = dgvStock.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString().Replace("img.kwcdn.com", "img.cdnfe.com");
|
||||
url = url.IndexOf("?") < 0 ? url : url.Substring(0, url.IndexOf("?"));
|
||||
ShowImgForm imgFrom = new ShowImgForm(url);
|
||||
imgFrom.ShowDialog();
|
||||
break;
|
||||
case "":
|
||||
dgvStock.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvStock.Rows[e.RowIndex].Cells["colCheck"].Value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void btnStart_Click(object sender, EventArgs e)
|
||||
{
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
ucGroupBoxEx3.Enabled = false;
|
||||
var hideDateTime = DateTime.Now;
|
||||
Task.Run(() =>
|
||||
{
|
||||
int count = 1;
|
||||
while (cancellationTokenSource != null && !cancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
if(DateTime.Now > hideDateTime)
|
||||
this.pnlMsg.Visible = false;
|
||||
this.statusBar.lblTaskStatus.Text = "正在循环加入发货台,第 " + count + " 次...";
|
||||
count++;
|
||||
}));
|
||||
|
||||
var subPurchaseOrderSnLst = dgvStock.Rows.Cast<DataGridViewRow>().Where(row
|
||||
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colStockId"]?.Value.ToString()).ToList();
|
||||
var subPurchaseOrderLst = lstStockInfo.Where(o => subPurchaseOrderSnLst.Contains(o.subPurchaseOrderSn)).ToList();
|
||||
var canNotJoinDeliverOrderLst = subPurchaseOrderLst.Where(p=>p.isCanJoinDeliverPlatform == false).ToList();
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
foreach (var order in canNotJoinDeliverOrderLst)
|
||||
{
|
||||
subPurchaseOrderLst.Remove(order);
|
||||
var row = dgvStock.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colStockId"].Value.ParseToString() == order.subPurchaseOrderSn);
|
||||
if (row != null)
|
||||
{
|
||||
row.Cells["colMsg"].Value = order.joinDeliverPlatformReason;
|
||||
row.Cells["colCheck"].Value = false;
|
||||
if (order.joinDeliverPlatformReason == "当前备货单已加入发货台,无需重复操作" ||
|
||||
order.joinDeliverPlatformReason == "当前备货单已创建发货单,无需重复操作")
|
||||
{
|
||||
row.Cells["colMsg"].Style.ForeColor = Color.Green;
|
||||
}
|
||||
else
|
||||
{
|
||||
row.Cells["colMsg"].Style.ForeColor = Color.Red;
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
if (subPurchaseOrderLst.Count == 0)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
hideDateTime = DateTime.Now.AddSeconds(5);
|
||||
this.pnlMsg.Visible = true;
|
||||
this.lblMsg.Text = "请选择待加入发货台备货单!";
|
||||
}));
|
||||
}
|
||||
List<ShopLoginInfo> shopLst = new List<ShopLoginInfo>();
|
||||
var shopIdLst = dgvStock.Rows.Cast<DataGridViewRow>().Where(row
|
||||
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colSupplierId"]?.Value.ToString()).Distinct().ToList();
|
||||
if (IsAdmin)
|
||||
{
|
||||
shopLst = this.lstAdminShopInfo.Where(s => shopIdLst.Contains(s.ShopId)).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
shopLst = GlobalConfig.ShopLoginList.Where(s => shopIdLst.Contains(s.ShopId)).ToList();
|
||||
}
|
||||
if (subPurchaseOrderSnLst.Count > 0 && shopLst.Count == 0)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.pnlMsg.Visible = true;
|
||||
this.lblMsg.Text = "选择发货单对应的店铺不存在!";
|
||||
}));
|
||||
}
|
||||
|
||||
if (shopLst.Count > 0 && subPurchaseOrderLst.Count > 0)
|
||||
{
|
||||
List<Task> taskLst = new List<Task>();
|
||||
var shopLstRandom = shopLst.OrderBy(x => Guid.NewGuid()).Take(5); // 每次随机取5个店铺尝试
|
||||
foreach (var shop in shopLst)
|
||||
{
|
||||
var t = Task.Run(() =>
|
||||
{
|
||||
var shopTmp = shop;
|
||||
var orderSubIds = subPurchaseOrderLst
|
||||
.Where(o => shopTmp.ShopId.Contains(o.supplierId.ParseToString()))
|
||||
.Select(o => o.subPurchaseOrderSn).Distinct().ToList();
|
||||
var rows = dgvStock.Rows.Cast<DataGridViewRow>().Where(r => orderSubIds.Contains(r.Cells["colStockId"]?.Value.ToString()));
|
||||
|
||||
if (shop.LoginStatus2 != "国际版在线")
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
foreach (var row in rows)
|
||||
{
|
||||
row.Cells["colMsg"].Value = "店铺掉线";
|
||||
row.Cells["colMsg"].Style.ForeColor = Color.Red;
|
||||
}
|
||||
}));
|
||||
Thread.Sleep(Math.Max(1000, txtRetryInterval.Text.ParseToInt() * 1000));
|
||||
return;
|
||||
}
|
||||
|
||||
//取最大100个商品,因为后台分页最大100每页
|
||||
orderSubIds = orderSubIds.Take(100).ToList();
|
||||
rows = dgvStock.Rows.Cast<DataGridViewRow>().Where(r => orderSubIds.Contains(r.Cells["colStockId"]?.Value.ToString()));
|
||||
|
||||
var joinRst = JoinDeliveryOrderPlatform(shop, orderSubIds);
|
||||
if (!joinRst.Contains("\"success\":true"))
|
||||
{
|
||||
string errMsg = "";
|
||||
if (IsAdmin)
|
||||
{
|
||||
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
|
||||
}
|
||||
if (shop.LoginStatus2 != "国际版在线")
|
||||
{
|
||||
errMsg = "店铺掉线";
|
||||
}
|
||||
else
|
||||
{
|
||||
errMsg = BaseRegex.GetStringJson(ref joinRst, "error_msg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = BaseRegex.GetStringJson(ref joinRst, "errorMsg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = joinRst;
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
foreach (var row in rows)
|
||||
{
|
||||
row.Cells["colMsg"].Value = errMsg;
|
||||
row.Cells["colMsg"].Style.ForeColor = Color.Red;
|
||||
}
|
||||
}));
|
||||
Thread.Sleep(Math.Max(1000, txtRetryInterval.Text.ParseToInt() * 1000));
|
||||
return;
|
||||
}
|
||||
|
||||
if (joinRst.Contains("\"success\":true"))
|
||||
{
|
||||
var jArr = new JArray();
|
||||
try
|
||||
{
|
||||
var jObj = JObject.Parse(joinRst);
|
||||
JoinDeliveryInfo joinDeliveryInfo = JsonHelper.DeserializeJsonToObject<JoinDeliveryInfo>(JsonHelper.SerializeObject(jObj["result"]));
|
||||
if (joinDeliveryInfo.successInfoList.Count > 0)
|
||||
{
|
||||
// 成功不返回列表,失败才返回
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
foreach (var row in rows)
|
||||
{
|
||||
var errInfo = joinDeliveryInfo.errorInfoList.FirstOrDefault(err => err.id == row.Cells["colStockId"].Value.ParseToString());
|
||||
if (errInfo != null)
|
||||
{
|
||||
row.Cells["colMsg"].Value = errInfo.errorMsg;
|
||||
row.Cells["colMsg"].Style.ForeColor = Color.Red;
|
||||
if (!errInfo.errorMsg.Contains("商家备货火爆"))
|
||||
{
|
||||
row.Cells["colCheck"].Value = false;
|
||||
}
|
||||
if (errInfo.errorMsg == "当前备货单已加入发货台,无需重复操作" ||
|
||||
errInfo.errorMsg == "当前备货单已创建发货单,无需重复操作")
|
||||
{
|
||||
row.Cells["colMsg"].Style.ForeColor = Color.Green;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
row.Cells["colMsg"].Value = "备货单加入发货台成功";
|
||||
row.Cells["colMsg"].Style.ForeColor = Color.Green;
|
||||
row.Cells["colCheck"].Value = false;
|
||||
}
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
foreach (var row in rows)
|
||||
{
|
||||
row.Cells["colMsg"].Value = ex.Message;
|
||||
row.Cells["colMsg"].Style.ForeColor = Color.Red;
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
});
|
||||
taskLst.Add(t);
|
||||
}
|
||||
Task.WaitAll(taskLst.ToArray());
|
||||
}
|
||||
Thread.Sleep(Math.Max(1000, txtRetryInterval.Text.ParseToInt() * 1000));
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
ucGroupBoxEx3.Enabled = true;
|
||||
string sRst = "加入发货台已完成!";
|
||||
if (cancellationTokenSource.IsCancellationRequested)
|
||||
sRst = "已取消循环加入发货台!";
|
||||
|
||||
BaseMsgForm.ShowInfo(sRst);
|
||||
this.statusBar.lblTaskStatus.Text = sRst;
|
||||
this.pnlMsg.Visible = false;
|
||||
}));
|
||||
}, cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
private void btnStop_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (cancellationTokenSource != null)
|
||||
cancellationTokenSource.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public class JoinDeliveryConfig
|
||||
@@ -449,7 +843,21 @@ namespace TemuKJD.KJDForms.ProductForms
|
||||
/// <summary>
|
||||
/// 重试加入发货台的时间间隔
|
||||
/// </summary>
|
||||
public int RetryInterval { get; set; } = 1;
|
||||
public int RetryInterval { get; set; } = 5;
|
||||
public bool SearchAllShop { get; set; } = true;
|
||||
}
|
||||
|
||||
public class JoinDeliveryInfo
|
||||
{
|
||||
public bool? isSuccess { get; set; }
|
||||
public List<JoinDeliveryErrorInfo> errorInfoList { get; set; }
|
||||
public List<object> successInfoList { get; set; }
|
||||
}
|
||||
public class JoinDeliveryErrorInfo
|
||||
{
|
||||
public string id { get; set; } // "WB251028608265",
|
||||
public int? errorCode { get; set; } // 60007,
|
||||
public string errorMsg { get; set; } // "商家备货火爆,未成功加入发货台,请稍后重试",
|
||||
public Dictionary<string, string> extraInfoMap { get; set; } // { "productId": "8140094460" }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user