901 lines
42 KiB
C#
901 lines
42 KiB
C#
using AllBase;
|
|
using AllBase.Helper;
|
|
using AllBase.Model.Result;
|
|
using NaiBa.Util;
|
|
using NaiBa.Util.Extension;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using TemuKJD.BaseForms;
|
|
using TemuKJD.BLL;
|
|
using TemuKJD.Extension;
|
|
using TemuKJD.KJDForms.AdminForms;
|
|
using TemuKJD.KJDForms.ShopForms;
|
|
using TemuKJD.ToolForms;
|
|
using Work;
|
|
|
|
namespace TemuKJD.KJDForms.ProductForms
|
|
{
|
|
public partial class JoinDeliveryForm : BaseForm
|
|
{
|
|
JoinDeliveryConfig joinDeliveryConfig = null;
|
|
public bool IsAdmin = false;
|
|
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
|
|
public ConcurrentList<ShopLoginInfo> lstAdminShopInfo { get; set; } = new ConcurrentList<ShopLoginInfo>();
|
|
/// <summary>
|
|
/// 备货单列表
|
|
/// </summary>
|
|
ConcurrentList<TemuStockInfo> lstStockInfo = new ConcurrentList<TemuStockInfo>();
|
|
|
|
public JoinDeliveryForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void JoinDeliveryFrom_Load(object sender, EventArgs e)
|
|
{
|
|
ucSplitPage1.Visible = IsAdmin;
|
|
btnRefreshShop.Visible = IsAdmin;
|
|
dgvShop.AddSelectorColumn("colSelect");
|
|
dgvStock.AddSelectorColumn("colCheck");
|
|
dgvStock.AddImgColumn("colProductSkcPic", "colImgUrl");
|
|
|
|
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;
|
|
this.txtShopId.Text = joinDeliveryConfig.SearchShopId;
|
|
this.txtShopName.Text = joinDeliveryConfig.SearchShopName;
|
|
this.txtRetryInterval.Text = Math.Max(1, joinDeliveryConfig.RetryInterval).ParseToString();
|
|
this.chkSearchAllShop.Checked = joinDeliveryConfig.SearchAllShop;
|
|
|
|
this.txtNotes.TextChanged += Txt_TextChanged;
|
|
this.txtShopId.TextChanged += Txt_TextChanged;
|
|
this.txtShopName.TextChanged += Txt_TextChanged;
|
|
this.txtRetryInterval.TextChanged += Txt_TextChanged;
|
|
this.chkSearchAllShop.CheckedChanged += Txt_TextChanged;
|
|
}
|
|
|
|
private void Txt_TextChanged(object sender, EventArgs e)
|
|
{
|
|
joinDeliveryConfig.SearchNotes = this.txtNotes.Text.Trim();
|
|
joinDeliveryConfig.SearchShopId = this.txtShopId.Text.Trim();
|
|
joinDeliveryConfig.SearchShopName = this.txtShopName.Text.Trim();
|
|
joinDeliveryConfig.RetryInterval = Math.Max(1, this.txtRetryInterval.Text.Trim().ParseToInt());
|
|
joinDeliveryConfig.SearchAllShop = this.chkSearchAllShop.Checked;
|
|
|
|
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)
|
|
{
|
|
if (this.Visible)
|
|
{
|
|
if (IsAdmin)
|
|
{
|
|
SearchShop(this.ucSplitPage1.CurrentPage);
|
|
}
|
|
else
|
|
{
|
|
FiltShop();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ucSplitPage1_PageChange(object obj)
|
|
{
|
|
if (IsAdmin)
|
|
{
|
|
SearchShop(this.ucSplitPage1.CurrentPage);
|
|
}
|
|
}
|
|
|
|
public void SearchShop(int page)
|
|
{
|
|
List<string> userShopIdList = dgvShop.Rows.Cast<DataGridViewRow>()
|
|
.Where(r => r.Cells["colSelect"].Value.ParseToBool())
|
|
.Select(r => r.Cells["colShopId"].Value.ParseToString() + r.Cells["colUser"].Value.ParseToString()).ToList();
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.pbShopLoading.Visible = true;
|
|
this.dgvShop.Rows.Clear();
|
|
lstAdminShopInfo.Clear();
|
|
}));
|
|
|
|
Task.Run(() =>
|
|
{
|
|
int pageCount;
|
|
var list = AdminGetServerShopLst(out pageCount, page);
|
|
lstAdminShopInfo.AddRange(list);
|
|
this.ucSplitPage1.TotalPage = pageCount;
|
|
|
|
foreach (var shop in lstAdminShopInfo)
|
|
{
|
|
bool canUse = shop.LoginStatus2 == "国际版在线";
|
|
Invoke(new Action(() =>
|
|
{
|
|
int rowIndex = this.dgvShop.Rows.Add(
|
|
userShopIdList.Contains(shop.ShopId + shop.UserName),
|
|
shop.UserName,
|
|
shop.LoginName,
|
|
shop.ShopId,
|
|
shop.ShopAccount,
|
|
shop.Notes,
|
|
canUse ? "在线" : "掉线",
|
|
canUse,
|
|
string.Empty
|
|
);
|
|
displayShopStatus(shop);
|
|
}));
|
|
}
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.pbShopLoading.Visible = false;
|
|
}));
|
|
});
|
|
}
|
|
|
|
void displayShopStatus(ShopLoginInfo shop)
|
|
{
|
|
bool canUse = shop.LoginStatus2 == "国际版在线";
|
|
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colLoginName"].Value.ParseToString() == shop?.LoginName);
|
|
foreach (var row in rows)
|
|
{
|
|
row.Cells["colCanUse"].Value = canUse;
|
|
row.Cells["colLoginStatus"].Value = canUse ? "在线" : "掉线";
|
|
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Green : Color.Red;
|
|
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Green : Color.Red;
|
|
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightGreen : Color.OrangeRed;
|
|
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkGreen : Color.DarkRed;
|
|
}
|
|
}
|
|
|
|
public List<ShopLoginInfo> AdminGetServerShopLst(out int pageCount, int page = 1, int pageSize = 50)
|
|
{
|
|
List<ShopLoginInfo> list = new List<ShopLoginInfo>();
|
|
pageCount = 1;
|
|
|
|
var url = BaseClass.BuildObjString("shop/admin_get_shop_list");
|
|
//if (BaseClass.SaLevel > 1 && !chkSearchAllShop.Checked)
|
|
// url = BaseClass.BuildObjString("shop/sub_sa_get_select_prod_shop");
|
|
var data = UserLogin.GetSignaturex() +
|
|
"&page=" + page +
|
|
"&page_size=" + pageSize +
|
|
"&shop_ids=" + txtShopId.Text.Trim().Trim(',') +
|
|
"&shop_names=" + txtShopName.Text.Trim().Trim(',') +
|
|
"&search_notes=" + txtNotes.Text.Trim().Trim(',');
|
|
//if (BaseClass.SaLevel > 1 && !chkSearchAllShop.Checked)
|
|
// data += "&operate_sub_sa_name=" + BaseClass.UserName;
|
|
var html = GetHtml.PostUtf8(url, data);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
|
html = GetHtml.PostUtf8(url, data);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
|
html = GetHtml.PostUtf8(url, data);
|
|
if (string.IsNullOrEmpty(html)
|
|
|| !html.Contains("shop_id") || !html.Contains("shop_account") || !html.Contains("login_pass"))
|
|
{
|
|
return list;
|
|
}
|
|
|
|
int count = BaseRegex.GetIntJson(ref html, "count");
|
|
pageCount = Math.Ceiling(1.0 * count / pageSize).ParseToInt();
|
|
pageCount = Math.Max(pageCount, 1);
|
|
|
|
return ShopBLL.DeserializationShop(html);
|
|
}
|
|
|
|
private void btnRefreshShop_Click(object sender, EventArgs e)
|
|
{
|
|
pbShopLoading.Visible = true;
|
|
Task.Run(() =>
|
|
{
|
|
ShopListForm.UpdateShop();
|
|
Invoke(new Action(() =>
|
|
{
|
|
FiltShop();
|
|
pbShopLoading.Visible = false;
|
|
}));
|
|
});
|
|
}
|
|
|
|
private void btnSearchShop_Click(object sender, EventArgs e)
|
|
{
|
|
if (IsAdmin)
|
|
{
|
|
if (this.ucSplitPage1.CurrentPage != 1)
|
|
this.ucSplitPage1.CurrentPage = 1;
|
|
else
|
|
SearchShop(1);
|
|
}
|
|
else
|
|
{
|
|
FiltShop();
|
|
}
|
|
}
|
|
|
|
private void FiltShop()
|
|
{
|
|
// 店铺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.Trim()))
|
|
{
|
|
shopLst = shopLst.Where(s => ("," + txtShopId.Text.Trim() + ",").Contains("," + s.ShopId + ",") || s.ShopId.Contains(txtShopId.Text.Trim())).ToList();
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(txtShopName.Text.Trim()))
|
|
{
|
|
shopLst = shopLst.Where(s => ("," + txtShopName.Text.Trim() + ",").Contains("," + s.ShopAccount + ",") || s.ShopAccount.ToLower().Contains(txtShopName.Text.Trim().ToLower())).ToList();
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(txtNotes.Text.Trim()))
|
|
{
|
|
shopLst = shopLst.Where(s => ("," + txtNotes.Text.Trim() + ",").Contains("," + s.Notes + ",") || s.Notes.ToLower().Contains(txtNotes.Text.Trim().ToLower())).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 = "";
|
|
}
|
|
|
|
private void btnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
var lstShopId = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
|
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
|
if (lstShopId.Count == 0)
|
|
{
|
|
BaseMsgForm.ShowInfo("请选择店铺!");
|
|
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;
|
|
// }
|
|
//}
|
|
|
|
lstStockInfo.Clear();
|
|
dgvStock.Rows.Clear();
|
|
|
|
var dgvRows = this.dgvShop.Rows.Cast<DataGridViewRow>();//.Where(r => lstShopId.Contains(r.Cells["colShopId"].Value.ParseToString()));
|
|
foreach (var row in dgvRows)
|
|
{
|
|
row.Cells["colMessage"].Value = "";
|
|
}
|
|
|
|
ucGroupBoxEx3.Enabled = false;
|
|
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
Task.Run(() =>
|
|
{
|
|
var lstShopIdTemp = new List<string>();
|
|
lstShopIdTemp.AddRange(lstShopId);
|
|
int i = 0;
|
|
|
|
foreach (var shopId in lstShopIdTemp)
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
this.statusBar.lblTaskStatus.Text = "正在查询...";
|
|
this.statusBar.pgbTaskProgress.Maximum = lstShopIdTemp.Count;
|
|
this.statusBar.UpdateProgressBar(i + 1);
|
|
i++;
|
|
}));
|
|
|
|
if (cancellationTokenSource.IsCancellationRequested)
|
|
break;
|
|
|
|
ShopLoginInfo shop = null;
|
|
if (IsAdmin)
|
|
{
|
|
shop = this.lstAdminShopInfo.FirstOrDefault(s => s.ShopId == shopId);
|
|
}
|
|
else
|
|
{
|
|
shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
|
}
|
|
if (shop == null)
|
|
continue;
|
|
|
|
#region 检测登录
|
|
if (shop.LoginStatus2 != "国际版在线")
|
|
{
|
|
continue;
|
|
}
|
|
if (IsAdmin)
|
|
{
|
|
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
|
}
|
|
else
|
|
{
|
|
ShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
|
|
}
|
|
if (shop.LoginStatus2 != "国际版在线")
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
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 = "店铺掉线";
|
|
row.Cells["colLoginStatus"].Value = "未登录";
|
|
row.Cells["colCanUse"].Value = false;
|
|
}
|
|
}));
|
|
continue;
|
|
}
|
|
#endregion
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopId"].Value.ToString() == shop.ShopId);
|
|
foreach (var row in rows)
|
|
{
|
|
row.Cells["colMessage"].Value = "正在查询";
|
|
}
|
|
}));
|
|
|
|
int page = 1;
|
|
int totalPage = 1;
|
|
int pageSize = 20;
|
|
bool isError = false;
|
|
string errorMsg = "";
|
|
while (page <= totalPage)
|
|
{
|
|
if (cancellationTokenSource.IsCancellationRequested)
|
|
break;
|
|
|
|
Thread.Sleep(100 + Randomx.GetId(200));
|
|
string 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"))
|
|
{
|
|
var jArr = new JArray();
|
|
try
|
|
{
|
|
var jObj = JObject.Parse(jsonStr);
|
|
jArr = jObj["result"]?["subOrderForSupplierList"] as JArray;
|
|
if (jArr == null)
|
|
jArr = new JArray();
|
|
}
|
|
catch (Exception ex) { BaseMsgForm.ShowError(ex.Message); }
|
|
foreach (var item in jArr)
|
|
{
|
|
string sItem = item.ToString();
|
|
TemuStockInfo sInfo = JsonHelper.DeserializeJsonToObject<TemuStockInfo>(sItem); // 反序列化得到类
|
|
if (sInfo != null)
|
|
{
|
|
lstStockInfo.Add(sInfo);
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
int rowId = this.dgvStock.Rows.Add(
|
|
"",
|
|
true,
|
|
sInfo.supplierId,
|
|
sInfo.supplierName,
|
|
sInfo.subPurchaseOrderSn,
|
|
sInfo.originalPurchaseOrderSn,
|
|
sInfo.productSkcPicture.Replace("https", "http").Replace("img.kwcdn.com", "img.cdnfe.com"),
|
|
DataGridViewExtension.defaultBitmap,
|
|
sInfo.productId,
|
|
sInfo.productSkcId,
|
|
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;
|
|
}));
|
|
}
|
|
}
|
|
|
|
int total = BaseRegex.GetStringJson(ref jsonStr, "total").ParseToInt();
|
|
totalPage = Math.Ceiling(1.0m * total / pageSize).ParseToInt();
|
|
}
|
|
page++;
|
|
}
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopId"].Value.ToString() == shop.ShopId);
|
|
|
|
if (!isError)
|
|
{
|
|
foreach (var row in rows)
|
|
{
|
|
row.Cells["colMessage"].Value = "已查询";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var row in rows)
|
|
{
|
|
row.Cells["colMessage"].Value = "查询失败" + errorMsg;
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
Invoke(new Action(() =>
|
|
{
|
|
ucGroupBoxEx3.Enabled = true;
|
|
string sRst = "查询结束!";
|
|
if (cancellationTokenSource.IsCancellationRequested)
|
|
sRst = "已取消查询!";
|
|
|
|
BaseMsgForm.ShowInfo(sRst);
|
|
this.statusBar.lblTaskStatus.Text = sRst;
|
|
}));
|
|
}, cancellationTokenSource.Token);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 读取待加入发货台
|
|
/// </summary>
|
|
/// <param name="shop"></param>
|
|
/// <param name="page"></param>
|
|
/// <returns></returns>
|
|
private string GetShopStockList2(ShopLoginInfo shop, int page = 1, int pageSize = 20)
|
|
{
|
|
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]," +
|
|
@"""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)
|
|
{
|
|
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
|
if (shop.LoginStatus2 == "国际版在线")
|
|
{
|
|
AdminShopLoginForm adminLoginForm = new AdminShopLoginForm(shop);
|
|
adminLoginForm.openType = EnumOpenType.manage;
|
|
adminLoginForm.WindowState = FormWindowState.Maximized;
|
|
adminLoginForm.InitUrl = "https://agentseller.temu.com";
|
|
adminLoginForm.Show();
|
|
}
|
|
else
|
|
{
|
|
AdminShopLoginForm shopLoginForm = new AdminShopLoginForm(shop);
|
|
shopLoginForm.openType = EnumOpenType.login;
|
|
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
|
|
shopLoginForm.ShowDialog();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
|
if (shop.LoginStatus2 == "国际版在线")
|
|
{
|
|
ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
|
|
shopLoginForm.openType = EnumOpenType.manage;
|
|
shopLoginForm.WindowState = FormWindowState.Maximized;
|
|
shopLoginForm.InitUrl = "https://agentseller.temu.com";
|
|
shopLoginForm.Show();
|
|
}
|
|
else
|
|
{
|
|
ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
|
|
shopLoginForm.openType = EnumOpenType.login;
|
|
shopLoginForm.ShowDialog();
|
|
FiltShop();
|
|
}
|
|
}
|
|
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
|
|
{
|
|
public string SearchShopId { get; set; } = "";
|
|
public string SearchShopName { get; set; } = "";
|
|
public string SearchNotes { get; set; } = "";
|
|
/// <summary>
|
|
/// 重试加入发货台的时间间隔
|
|
/// </summary>
|
|
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" }
|
|
}
|
|
}
|