1383 lines
64 KiB
C#
1383 lines
64 KiB
C#
using AllBase;
|
||
using AllBase.Helper;
|
||
using AllBase.Model.Result;
|
||
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.IO;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Net.Http;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using TemuKJD.Extension;
|
||
using TemuKJD.BaseForms;
|
||
using TemuKJD.KJDForms.ShopForms;
|
||
using TemuKJD.BLL;
|
||
|
||
namespace TemuKJD.KJDForms.ProductForms
|
||
{
|
||
/// <summary>
|
||
/// 销售备货管理
|
||
/// </summary>
|
||
public partial class SaleStockUpForm : BaseForm
|
||
{
|
||
public bool isNewService = false;
|
||
|
||
private CheckBox chkSelectAll = null;
|
||
//private CheckBox chkCheckAll = null;
|
||
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
|
||
|
||
/// <summary>
|
||
/// 取消待创建备货单列表
|
||
/// </summary>
|
||
List<TemuStockInfo> lstStockInfo = new List<TemuStockInfo>();
|
||
/// <summary>
|
||
/// 待备货商品列表
|
||
/// </summary>
|
||
List<WarehouseProductSubOrderInfo> lstSubOrderInfo = new List<WarehouseProductSubOrderInfo>();
|
||
|
||
public SaleStockUpForm()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void StockUpForm_Load(object sender, EventArgs e)
|
||
{
|
||
chkSelectAll = dgvShop.Columns["colSelect"].AddHeaderCheckBox(HorizontalAlignment.Center, 0, 0, null, null, false);
|
||
dgvShop.Columns["colSelect"].HeaderText = "";
|
||
//chkSelectAll.Width = chkSelectAll.Height = 13;
|
||
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
|
||
|
||
this.dgvStock.AddSelectorColumn("colCheck");
|
||
}
|
||
|
||
private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (!chkSelectAll.Checked)
|
||
{
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var list = GlobalConfig.ShopLoginList.Where(s => s.LoginStatus == "登录成功").Select(ss => ss.ShopId);
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (list.Any(l => l == row.Cells["colShopId"]?.Value?.ToString()))
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void StockUpForm_VisibleChanged(object sender, EventArgs e)
|
||
{
|
||
if (Visible == true)
|
||
FiltShop();
|
||
}
|
||
|
||
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)
|
||
{
|
||
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.LoginStatus == "登录成功" && 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.LoginName,
|
||
shopEntity.ShopId,
|
||
shopEntity.ShopAccount,
|
||
shopEntity.Notes,
|
||
canUse ? "在线" : "掉线",
|
||
canUse,
|
||
string.Empty
|
||
);
|
||
row = dgvShop.Rows[id];
|
||
//row.Cells["colLoginStatus"].Style.ForeColor = canUse ? Color.Green : Color.Red;
|
||
(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;
|
||
}
|
||
else
|
||
{
|
||
row.Cells["colSelect"].Value = selectShopId.Contains(shopEntity.ShopId) && canUse;
|
||
row.Cells["colShopLoginName"].Value = shopEntity.LoginName;
|
||
row.Cells["colShopName"].Value = shopEntity.ShopAccount;
|
||
row.Cells["colShopNotes"].Value = shopEntity.Notes;
|
||
row.Cells["colLoginStatus"].Value = canUse ? "在线" : "掉线";
|
||
//row.Cells["colLoginStatus"].Style.ForeColor = canUse ? Color.Green : Color.Red;
|
||
(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;
|
||
row.Cells["colCanUse"].Value = canUse;
|
||
}
|
||
}
|
||
|
||
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 = "";
|
||
}
|
||
|
||
string searchText = txtStockid.Text.Trim();
|
||
//ucGroupBoxEx2.Enabled = false;
|
||
ucGroupBoxEx3.Enabled = false;
|
||
ucGroupBoxEx4.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;
|
||
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if (shop == null)
|
||
continue;
|
||
|
||
#region 检测登录
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
continue;
|
||
}
|
||
if (ShopListForm.Instance == null)
|
||
ShopListForm.Instance = new ShopListForm();
|
||
ShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopLoginName"].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;
|
||
bool isError = false;
|
||
while (page <= totalPage)
|
||
{
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
Thread.Sleep(100 + Randomx.GetId(200));
|
||
string jsonStr = GetShopStockList(shop, page, chkHasCreate.Checked ? "已送货" : "待创建");
|
||
if (jsonStr.Contains("指定的值含有无效的控制字符"))
|
||
{
|
||
BaseMsgForm.ShowError("店铺" + shop.LoginName + " " + shop.ShopId + "已掉线");
|
||
isError = true;
|
||
break;
|
||
}
|
||
if (!jsonStr.Contains("\"success\":true"))
|
||
jsonStr = GetShopStockList(shop, page, chkHasCreate.Checked ? "已送货" : "待创建");
|
||
if (!jsonStr.Contains("\"success\":true"))
|
||
{
|
||
isError = true;
|
||
}
|
||
|
||
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);
|
||
|
||
//string url = sInfo.productSkcPicture.Replace("https", "http");
|
||
//var image = Image.FromStream(WebRequest.Create(url).GetResponse().GetResponseStream());
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
int rowId = this.dgvStock.Rows.Add(
|
||
"",
|
||
true,
|
||
sInfo.supplierId,
|
||
sInfo.supplierName,
|
||
sInfo.subPurchaseOrderSn,
|
||
sInfo.originalPurchaseOrderSn,
|
||
sInfo.productSkcPicture.Replace("https", "http"),
|
||
null,//image,
|
||
sInfo.productId,
|
||
sInfo.productSkcId,
|
||
sInfo.productName,
|
||
"",
|
||
"",
|
||
"",
|
||
"",
|
||
"",
|
||
"",
|
||
0.0,
|
||
"",
|
||
""
|
||
);
|
||
|
||
dgvStock.Rows[rowId].Height = 60;
|
||
}));
|
||
}
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
ShowDgvImg();
|
||
}));
|
||
|
||
int total = BaseRegex.GetStringJson(ref jsonStr, "total").ParseToInt();
|
||
totalPage = Math.Ceiling(total / 20.0).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 = "查询失败";
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
//ucGroupBoxEx2.Enabled = true;
|
||
ucGroupBoxEx3.Enabled = true;
|
||
ucGroupBoxEx4.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 GetShopStockList(ShopLoginInfo shop, int page = 1, string type = "待创建")
|
||
{
|
||
if (isNewService)
|
||
return GetShopStockList2(shop, page, type);
|
||
|
||
page = Math.Max(page, 1);
|
||
string url = "https://seller.kuajingmaihuo.com/oms/bg/venom/api/supplier/purchase/manager/querySubOrderList";
|
||
string body;
|
||
if (type == "已送货")
|
||
body = @"{""pageNo"":" + page + @",""pageSize"":20,""urgencyType"":0,""isCustomGoods"":false,""statusList"":[2],""oneDimensionSort"":{""firstOrderByParam"":""realDeliverTime"",""firstOrderByDesc"":1}}"; //已送货
|
||
else
|
||
body = @"{""pageNo"":" + page + @",""pageSize"":20,""urgencyType"":0,""isCustomGoods"":false,""statusList"":[0],""oneDimensionSort"":{""firstOrderByParam"":""expectLatestDeliverTime"",""firstOrderByDesc"":0}}"; //待创建
|
||
|
||
string refere = "https://seller.kuajingmaihuo.com/main/order-manage";
|
||
|
||
return HttpResponseBLL.PostResponse(shop, url, body,refere);
|
||
}
|
||
|
||
private string GetShopStockList2(ShopLoginInfo shop, int page = 1, string type = "待创建")
|
||
{
|
||
page = Math.Max(page, 1);
|
||
string url = "https://agentseller.temu.com/mms/venom/api/supplier/purchase/manager/querySubOrderList";
|
||
string body;
|
||
if (type == "已送货")
|
||
body = @"{""pageNo"":" + page + @",""pageSize"":20,""urgencyType"":0,""isCustomGoods"":false,""statusList"":[2],""oneDimensionSort"":{""firstOrderByParam"":""realDeliverTime"",""firstOrderByDesc"":1}}"; //已送货
|
||
else
|
||
body = @"{""pageNo"":" + page + @",""pageSize"":20,""urgencyType"":0,""isCustomGoods"":false,""statusList"":[0],""oneDimensionSort"":{""firstOrderByParam"":""expectLatestDeliverTime"",""firstOrderByDesc"":0}}"; //待创建
|
||
|
||
string refere = "https://agentseller.temu.com/stock/fully-mgt/order-manage-urgency";
|
||
|
||
return HttpResponseBLL.PostResponse2(shop, url, body, refere);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 取消待创建备货单 首页--备货单管理--我的备货单
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <param name="subPurchaseOrderSn"></param>
|
||
/// <returns></returns>
|
||
private string CancelSubPurchaseOrder(ShopLoginInfo shop, string subPurchaseOrderSn)
|
||
{
|
||
if (isNewService)
|
||
return CancelSubPurchaseOrder2(shop, subPurchaseOrderSn);
|
||
|
||
string url = "https://seller.kuajingmaihuo.com/oms/bg/venom/api/supplier/purchase/manager/batchCancelSubPurchaseOrder";
|
||
string body = "{\"subPurchaseOrderSnList\":[\"" + subPurchaseOrderSn + "\"]}";
|
||
string refere = "https://seller.kuajingmaihuo.com/main/order-manage";
|
||
|
||
return HttpResponseBLL.PostResponse(shop, url, body, refere);
|
||
}
|
||
|
||
private string CancelSubPurchaseOrder2(ShopLoginInfo shop, string subPurchaseOrderSn)
|
||
{
|
||
string url = "https://agentseller.temu.com/mms/venom/api/supplier/purchase/manager/batchCancelSubPurchaseOrder";
|
||
string body = "{\"subPurchaseOrderSnList\":[\"" + subPurchaseOrderSn + "\"]}";
|
||
string refere = "https://agentseller.temu.com/stock/fully-mgt/order-manage";
|
||
|
||
return HttpResponseBLL.PostResponse2(shop, url, body, refere);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询销售列表
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <param name="page"></param>
|
||
/// <returns></returns>
|
||
private string GetWarehouseList(ShopLoginInfo shop, int page = 1)
|
||
{
|
||
if (isNewService)
|
||
return GetWarehouseList2(shop, page);
|
||
|
||
page = Math.Max(page, 1);
|
||
string url = "https://seller.kuajingmaihuo.com/marvel-mms/cn/api/kiana/venom/sales/management/listWarehouse";
|
||
string body = @"{""pageNo"":" + page + @",""pageSize"":40,""isLack"":0,""selectStatusList"":[12],""priceAdjustRecentDays"":7}";
|
||
string refere = "https://seller.kuajingmaihuo.com/main/sale-manage/main";
|
||
|
||
return HttpResponseBLL.PostResponse(shop, url, body, refere);
|
||
}
|
||
|
||
private string GetWarehouseList2(ShopLoginInfo shop, int page = 1)
|
||
{
|
||
page = Math.Max(page, 1);
|
||
string url = "https://agentseller.temu.com/mms/venom/api/supplier/sales/management/listWarehouse";
|
||
string body = @"{""pageNo"":" + page + @",""pageSize"":10,""isLack"":0,""selectStatusList"":[12],""priceAdjustRecentDays"":7}";
|
||
string refere = "https://agentseller.temu.com/stock/fully-mgt/sale-manage/main";
|
||
|
||
return HttpResponseBLL.PostResponse2(shop, url, body, refere);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询单个商品申请备货条件
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <param name="subOrderInfo"></param>
|
||
/// <returns></returns>
|
||
private string QueryStockBaseInfo(ShopLoginInfo shop, WarehouseProductSubOrderInfo subOrderInfo)
|
||
{
|
||
if (isNewService)
|
||
return QueryStockBaseInfo2(shop, subOrderInfo);
|
||
|
||
string url = "https://seller.kuajingmaihuo.com/oms/bg/venom/api/supplier/sales/management/queryStockBaseInfo";
|
||
string body = "{\"productSkcId\":" + subOrderInfo.productSkcId
|
||
+ ",\"warehouseGroupId\":" + subOrderInfo.warehouseGroupIdList.FirstOrDefault() + "}";
|
||
string refere = "https://seller.kuajingmaihuo.com/main/sale-manage/main";
|
||
return HttpResponseBLL.PostResponse(shop, url, body, refere);
|
||
}
|
||
|
||
private string QueryStockBaseInfo2(ShopLoginInfo shop, WarehouseProductSubOrderInfo subOrderInfo)
|
||
{
|
||
string url = "https://agentseller.temu.com/mms/venom/api/supplier/sales/management/queryStockBaseInfo";
|
||
string body = "{\"productSkcId\":" + subOrderInfo.productSkcId
|
||
+ ",\"warehouseGroupId\":" + subOrderInfo.warehouseGroupIdList.FirstOrDefault() + "}";
|
||
string refere = "https://agentseller.temu.com/stock/fully-mgt/sale-manage/main";
|
||
return HttpResponseBLL.PostResponse2(shop, url, body, refere);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单个商品申请备货
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <param name="subOrderInfo"></param>
|
||
/// <returns></returns>
|
||
private string CreateStockOrder(ShopLoginInfo shop, WarehouseProductSubOrderInfo subOrderInfo)
|
||
{
|
||
if (isNewService)
|
||
return CreateStockOrder2(shop, subOrderInfo);
|
||
|
||
string url = "https://seller.kuajingmaihuo.com/oms/bg/venom/api/supplier/sales/management/createStockOrder";
|
||
string body = "{\"productSkcId\":" + subOrderInfo.productSkcId + "," +
|
||
"\"purchaseDetailList\":[";
|
||
foreach(var sku in subOrderInfo.skuQuantityDetailList)
|
||
{
|
||
if (sku.wantStockUpBound>0)
|
||
body += "{\"productSkuId\":" + sku.productSkuId + ",\"productSkuPurchaseQuantity\":\"" + sku.wantStockUpBound + "\"},";
|
||
}
|
||
body = body.TrimEnd(',');
|
||
body += "],\"warehouseGroupId\":" + subOrderInfo.warehouseGroupIdList.FirstOrDefault() + "}";
|
||
string refere = "https://seller.kuajingmaihuo.com/main/sale-manage/main";
|
||
|
||
return HttpResponseBLL.PostResponse(shop, url, body, refere);
|
||
}
|
||
private string CreateStockOrder2(ShopLoginInfo shop, WarehouseProductSubOrderInfo subOrderInfo)
|
||
{
|
||
string url = "https://agentseller.temu.com/mms/venom/api/supplier/sales/management/createStockOrder";
|
||
string body = "{\"productSkcId\":" + subOrderInfo.productSkcId + "," +
|
||
"\"purchaseDetailList\":[";
|
||
foreach (var sku in subOrderInfo.skuQuantityDetailList)
|
||
{
|
||
if (sku.wantStockUpBound > 0)
|
||
body += "{\"productSkuId\":" + sku.productSkuId + ",\"productSkuPurchaseQuantity\":\"" + sku.wantStockUpBound + "\"},";
|
||
}
|
||
body = body.TrimEnd(',');
|
||
body += "],\"warehouseGroupId\":" + subOrderInfo.warehouseGroupIdList.FirstOrDefault() + "}";
|
||
string refere = "https://agentseller.temu.com/stock/fully-mgt/sale-manage/main";
|
||
|
||
return HttpResponseBLL.PostResponse2(shop, url, body, refere);
|
||
}
|
||
|
||
/// <summary>
|
||
/// qualityScoreEnum = 1 小于60分商品
|
||
/// qualityScoreEnum = 2 60分到70分商品
|
||
/// qualityScoreEnum = 3 70分到90分商品
|
||
/// qualityScoreEnum = 4 90分以上
|
||
/// </summary>
|
||
private string GetQualityInfo2(ShopLoginInfo shop, string productIds, int qualityScoreEnum = 4)
|
||
{
|
||
string url = "https://agentseller.temu.com/bg-luna-agent-seller/goods/quality/supplyChain/qualityMetrics/pageQuery";
|
||
string body = @"{""page"":1,""pageSize"":40,""qualityScoreEnum"":" + qualityScoreEnum + @",""productIds"":[" + productIds + "]}";
|
||
string refere = "https://agentseller.temu.com/main/quality/dashboard";
|
||
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 columnName = dgvShop.Columns[e.ColumnIndex].Name;
|
||
long shopId = dgvShop.Rows[e.RowIndex].Cells["colShopId"].Value.ParseToLong();
|
||
string shopAccount = dgvShop.Rows[e.RowIndex].Cells["colShopName"].Value.ToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId.ToString());
|
||
var row = dgvShop.Rows[e.RowIndex];
|
||
switch (columnName)
|
||
{
|
||
case "colSelect":
|
||
if (row.Cells["colCanUse"].Value.ParseToBool() || row.Cells["colSelect"].Value.ParseToBool())
|
||
{
|
||
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
|
||
|
||
chkSelectAll.CheckedChanged -= chkSelectAll_CheckedChanged;
|
||
if (dgvShop.Rows.Cast<DataGridViewRow>().All(r => r.Cells["colSelect"].Value.ParseToBool()))
|
||
chkSelectAll.Checked = true;
|
||
else
|
||
chkSelectAll.Checked = false;
|
||
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
|
||
}
|
||
else
|
||
{
|
||
BaseMsgForm.ShowInfo("店铺未登录!");
|
||
}
|
||
break;
|
||
case "colLoginStatus":
|
||
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;
|
||
}
|
||
}
|
||
|
||
private void btnStop_Click(object sender, EventArgs e)
|
||
{
|
||
if (cancellationTokenSource != null)
|
||
cancellationTokenSource.Cancel();
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
//ucGroupBoxEx2.Enabled = true;
|
||
ucGroupBoxEx3.Enabled = true;
|
||
ucGroupBoxEx4.Enabled = true;
|
||
}));
|
||
}
|
||
|
||
private void dgvStock_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.RowIndex < 0 || e.ColumnIndex < 0)
|
||
return;
|
||
string columnName = dgvStock.Columns[e.ColumnIndex].Name;
|
||
var row = dgvStock.Rows[e.RowIndex];
|
||
switch (columnName)
|
||
{
|
||
case "colCheck":
|
||
row.Cells["colCheck"].Value = !row.Cells["colCheck"].Value.ParseToBool();
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void btnCancelSubPurchaseOrder_Click(object sender, EventArgs e)
|
||
{
|
||
var lstStockOrderSn = dgvStock.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colStockId"]?.Value.ToString()).ToList();
|
||
var lstStock = lstStockInfo.Where(s => lstStockOrderSn.Contains(s.subPurchaseOrderSn)).ToList();
|
||
if (lstStock.Count == 0)
|
||
{
|
||
BaseMsgForm.ShowInfo("请选择要取消的待创建备货单!");
|
||
return;
|
||
}
|
||
|
||
string searchText = txtStockid.Text.Trim();
|
||
//ucGroupBoxEx2.Enabled = false;
|
||
ucGroupBoxEx3.Enabled = false;
|
||
ucGroupBoxEx4.Enabled = false;
|
||
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
Task.Run(() =>
|
||
{
|
||
int i = 0;
|
||
foreach (var stock in lstStock)
|
||
{
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "正在取消待创建...";
|
||
this.statusBar.pgbTaskProgress.Maximum = lstStock.Count;
|
||
this.statusBar.UpdateProgressBar(i + 1);
|
||
i++;
|
||
}));
|
||
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
var rows = this.dgvStock.Rows.Cast<DataGridViewRow>().Where(r =>
|
||
r.Cells["colStockId"].Value.ToString() == stock.subPurchaseOrderSn);
|
||
|
||
|
||
if (stock.isCancel)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "待创建备货单已取消";
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == stock.supplierId.ToString());
|
||
if (shop == null || shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "店铺掉线或不存在";
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "正在取消";
|
||
}
|
||
}));
|
||
|
||
Thread.Sleep(200 + Randomx.GetId(100));
|
||
//string jsonStr = "{\"success\":true,\"errorCode\":1000000,\"errorMsg\":null,\"result\":{\"isSuccess\":true,\"errorInfoList\":[],\"successInfoList\":[]}}";
|
||
string jsonStr = CancelSubPurchaseOrder(shop, stock.subPurchaseOrderSn);
|
||
bool isError = !jsonStr.Contains("\"success\":true");
|
||
string sErrMsg = BaseRegex.GetStringJson(ref jsonStr, "errorMsg");
|
||
if (!isError)
|
||
{
|
||
try
|
||
{
|
||
var jObj = JObject.Parse(jsonStr);
|
||
var jItem = jObj["result"];
|
||
var subJsonstr = jItem == null ? "" : JsonHelper.SerializeObject(jItem);
|
||
isError = !subJsonstr.Contains("\"isSuccess\":true");
|
||
sErrMsg = BaseRegex.GetStringJson(ref subJsonstr, "errorMsg");
|
||
}
|
||
catch (Exception ex) { }
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (!isError)
|
||
{
|
||
stock.isCancel = true;
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "已取消待创建";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "取消待创建失败:" + sErrMsg;
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
//ucGroupBoxEx2.Enabled = true;
|
||
ucGroupBoxEx3.Enabled = true;
|
||
ucGroupBoxEx4.Enabled = true;
|
||
string sRst = "操作结束(取消待创建)!";
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
sRst = "已取消操作(取消待创建)!";
|
||
|
||
BaseMsgForm.ShowInfo(sRst);
|
||
this.statusBar.lblTaskStatus.Text = sRst;
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
}
|
||
|
||
private void btnListWarehouse_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;
|
||
}
|
||
|
||
lstSubOrderInfo.Clear();
|
||
dgvStock.Rows.Clear();
|
||
|
||
int scale1 = this.txtScale1.Text.ParseToInt();
|
||
int scale2 = this.txtScale2.Text.ParseToInt();
|
||
|
||
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 = "";
|
||
}
|
||
|
||
var columns = this.dgvStock.Columns.Cast<DataGridViewColumn>();
|
||
foreach (var col in columns)
|
||
{
|
||
if (col.Name == "colParentStockId" || col.Name == "colStockId")
|
||
{
|
||
col.Visible = false;
|
||
}
|
||
if (col.Name == "colTodaySaleVolume" || col.Name == "colLastSevenDaysSaleVolume" || col.Name == "colInCartNumber7d" || col.Name == "colSalesInventoryNum"
|
||
|| col.Name == "colWaitReceiveNum" || col.Name == "colNeedStockUp" || col.Name == "colQualityScore")
|
||
{
|
||
col.Visible = true;
|
||
}
|
||
}
|
||
|
||
string searchText = txtStockid.Text.Trim();
|
||
//ucGroupBoxEx2.Enabled = false;
|
||
ucGroupBoxEx3.Enabled = false;
|
||
ucGroupBoxEx4.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;
|
||
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if (shop == null)
|
||
continue;
|
||
|
||
#region 检测登录
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
continue;
|
||
}
|
||
if (ShopListForm.Instance == null)
|
||
ShopListForm.Instance = new ShopListForm();
|
||
ShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopLoginName"].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;
|
||
bool isError = false;
|
||
while (page <= totalPage)
|
||
{
|
||
Thread.Sleep(100 + Randomx.GetId(200));
|
||
string jsonStr = GetWarehouseList(shop, page);
|
||
if (jsonStr.Contains("指定的值含有无效的控制字符"))
|
||
{
|
||
BaseMsgForm.ShowError("店铺" + shop.LoginName + " " + shop.ShopId + "已掉线");
|
||
isError = true;
|
||
break;
|
||
}
|
||
if (!jsonStr.Contains("\"success\":true"))
|
||
jsonStr = GetWarehouseList(shop, page);
|
||
if (!jsonStr.Contains("\"success\":true"))
|
||
{
|
||
isError = true;
|
||
}
|
||
|
||
if (jsonStr.Contains("\"success\":true"))
|
||
{
|
||
var jArr = new JArray();
|
||
try
|
||
{
|
||
var jObj = JObject.Parse(jsonStr);
|
||
jArr = jObj["result"]["subOrderList"] as JArray;
|
||
if (jArr == null)
|
||
jArr = new JArray();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
BaseMsgForm.ShowError(ex.Message);
|
||
}
|
||
|
||
List<WarehouseProductSubOrderInfo> subOrderInfoLstTmp = new List<WarehouseProductSubOrderInfo>();
|
||
foreach (var item in jArr)
|
||
{
|
||
string sItem = item.ToString();
|
||
WarehouseProductSubOrderInfo sInfo = JsonHelper.DeserializeJsonToObject<WarehouseProductSubOrderInfo>(sItem); // 反序列化得到类
|
||
if (sInfo != null)
|
||
{
|
||
foreach(var sku in sInfo.skuQuantityDetailList)
|
||
{
|
||
// 近7日加购>今日销量使用系数2,否则使用系数1
|
||
// 拟申请备货数量=今日销量×系数-仓内可用库存-已发货库存
|
||
// 实际备货数量=平台实际允许数量和拟申请备货数量取小(申请备货时计算)
|
||
int scale = scale1;
|
||
if (rbTodaySaleCount.Checked)
|
||
{
|
||
if (sku.inCartNumber7d.ParseToInt() > sku.todaySaleVolume.ParseToInt())
|
||
{
|
||
scale = scale2;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (sku.inCartNumber7d.ParseToInt() > sku.lastSevenDaysSaleVolume.ParseToInt() / 7.0m)
|
||
{
|
||
scale = scale2;
|
||
}
|
||
}
|
||
if (rbTodaySaleCount.Checked)
|
||
{
|
||
sku.wantStockUpBound = sku.todaySaleVolume.ParseToInt() * scale
|
||
- sku.inventoryNumInfo.warehouseInventoryNum.ParseToInt()
|
||
- sku.inventoryNumInfo.waitReceiveNum.ParseToInt();
|
||
}
|
||
else
|
||
{
|
||
sku.wantStockUpBound = (sku.lastSevenDaysSaleVolume.ParseToInt() / 7.0 * scale
|
||
- sku.inventoryNumInfo.warehouseInventoryNum.ParseToInt()
|
||
- sku.inventoryNumInfo.waitReceiveNum.ParseToInt()).ParseToInt();
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (sku.wantStockUpBound > 0 && sku.wantStockUpBound < this.txtMinBound.Text.ParseToInt())
|
||
sku.wantStockUpBound = this.txtMinBound.Text.ParseToInt();
|
||
}));
|
||
sku.wantStockUpBound = Math.Max(sku.wantStockUpBound, 0);
|
||
}
|
||
if (sInfo.skuQuantityDetailList.Any(s => s.wantStockUpBound > 0))
|
||
sInfo.needStockUp = true;
|
||
else
|
||
sInfo.needStockUp = false;
|
||
subOrderInfoLstTmp.Add(sInfo);
|
||
}
|
||
}
|
||
//获取品质信息------------------------------------------------------------------------
|
||
List<TemuGoodsQualityInfo> qualityInfoLst = new List<TemuGoodsQualityInfo>();
|
||
string productIds = string.Join(",", subOrderInfoLstTmp.Select(o=>o.productId));
|
||
string qualityErr = "";
|
||
try
|
||
{
|
||
for (int j = 1; j <= 4; j++)
|
||
{
|
||
var qualityRst1 = this.GetQualityInfo2(shop, productIds, j);
|
||
if (qualityRst1.Contains("\"success\":true"))
|
||
{
|
||
var jObj = JObject.Parse(qualityRst1);
|
||
string jStr = JsonHelper.SerializeObject(jObj["result"]["pageItems"]);
|
||
qualityInfoLst.AddRange(JsonHelper.DeserializeJsonToList<TemuGoodsQualityInfo>(jStr));
|
||
}
|
||
else
|
||
{
|
||
qualityErr = BaseRegex.GetStringJson(ref qualityRst1, "errorMsg");
|
||
if (string.IsNullOrWhiteSpace(qualityErr))
|
||
qualityErr += BaseRegex.GetStringJson(ref qualityRst1, "error_msg");
|
||
}
|
||
Thread.Sleep(Randomx.GetId(100, 200));
|
||
}
|
||
}
|
||
catch (Exception ex) { qualityErr += "\r\n" + ex.Message; };
|
||
if (qualityErr != "")
|
||
{
|
||
//BaseMsgForm.ShowError("获取商品品质信息失败!" + qualityErr);
|
||
foreach(var order in subOrderInfoLstTmp)
|
||
{
|
||
order.goodsAfsScore = -1;
|
||
order.qltyAfsOrdCnt = -1;
|
||
order.qltyAfsOrdrRate = -1;
|
||
}
|
||
}
|
||
foreach (var qualityInfo in qualityInfoLst)
|
||
{
|
||
var order = subOrderInfoLstTmp.FirstOrDefault(o => o.productId == qualityInfo.productId);
|
||
if (order != null)
|
||
{
|
||
order.goodsAfsScore = qualityInfo.goodsAfsScore;
|
||
order.qltyAfsOrdCnt = qualityInfo.qltyAfsOrdCnt;
|
||
order.qltyAfsOrdrRate = qualityInfo.qltyAfsOrdrRate;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------------------
|
||
lstSubOrderInfo.AddRange(subOrderInfoLstTmp);
|
||
foreach (var sInfo in subOrderInfoLstTmp)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var rowId = this.dgvStock.Rows.Add(
|
||
"",
|
||
true,
|
||
sInfo.supplierId,
|
||
sInfo.supplierName,
|
||
"",//sInfo.subPurchaseOrderSn,
|
||
"",//sInfo.originalPurchaseOrderSn,
|
||
sInfo.productSkcPicture.Replace("https", "http"),
|
||
defaultBitmap,//image,
|
||
sInfo.productId,
|
||
sInfo.productSkcId,
|
||
sInfo.productName,
|
||
"",
|
||
"",
|
||
"",
|
||
sInfo.skuQuantityTotalInfo.inCartNumber7d,
|
||
sInfo.skuQuantityTotalInfo.todaySaleVolume,
|
||
sInfo.skuQuantityTotalInfo.lastSevenDaysSaleVolume,
|
||
sInfo.skuQuantityTotalInfo.inventoryNumInfo.warehouseInventoryNum,
|
||
sInfo.skuQuantityTotalInfo.inventoryNumInfo.waitReceiveNum,
|
||
sInfo.goodsAfsScore == null ? "-" : (Math.Round(sInfo.goodsAfsScore.Value * 10) / 10).ToString(),
|
||
sInfo.qltyAfsOrdrRate == null ? "-" : (Math.Round(sInfo.qltyAfsOrdrRate.Value * 10000) / 100).ToString("0.00"),
|
||
sInfo.qltyAfsOrdCnt == null ? "-" : sInfo.qltyAfsOrdCnt.Value.ToString(),
|
||
sInfo.needStockUp == false ? "无需备货" : "可备货",
|
||
sInfo.goodsAfsScore == -1 ? "获取商品品质信息失败" : ""
|
||
);
|
||
//if (sInfo.goodsAfsScore == -1)
|
||
// sInfo.goodsAfsScore = null;
|
||
if (rowId >= 0)
|
||
dgvStock.Rows[rowId].Height = 60;
|
||
}));
|
||
}
|
||
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
ShowDgvImg();
|
||
}));
|
||
|
||
int total = BaseRegex.GetStringJson(ref jsonStr, "total").ParseToInt();
|
||
totalPage = Math.Ceiling(total / 10.0).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 = "查询失败";
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
//ucGroupBoxEx2.Enabled = true;
|
||
ucGroupBoxEx3.Enabled = true;
|
||
ucGroupBoxEx4.Enabled = true;
|
||
string sRst = "查询结束!";
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
sRst = "已取消查询!";
|
||
|
||
BaseMsgForm.ShowInfo(sRst);
|
||
this.statusBar.lblTaskStatus.Text = sRst;
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
}
|
||
|
||
private void btnStartStockUp_Click(object sender, EventArgs e)
|
||
{
|
||
var lstSkc = dgvStock.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colProdSkc"]?.Value.ToString()).ToList();
|
||
var lstStockUp = lstSubOrderInfo.Where(s => lstSkc.Contains(s.productSkcId.ParseToString())).ToList();
|
||
if (lstStockUp.Count == 0)
|
||
{
|
||
BaseMsgForm.ShowInfo("请选择要创建备货单的商品!");
|
||
return;
|
||
}
|
||
|
||
//ucGroupBoxEx2.Enabled = false;
|
||
ucGroupBoxEx3.Enabled = false;
|
||
ucGroupBoxEx4.Enabled = false;
|
||
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
var minQualityScore = this.txtMinQualityScore.Text.ParseToDecimal();
|
||
if (!chkMinQualityScore.Checked) // 没选最低品质分,即不考虑品质分上货。
|
||
minQualityScore = -100;
|
||
var maxQualityRate = this.txtMaxQualityRate.Text.ParseToDecimal();
|
||
if (!chkMaxQualityRate.Checked) // 没选最高品质售后率,即不考虑品质售后率上货。
|
||
maxQualityRate = 100;
|
||
Task.Run(() =>
|
||
{
|
||
int i = 0;
|
||
foreach (var stockUp in lstStockUp)
|
||
{
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "正在创建备货单...";
|
||
this.statusBar.pgbTaskProgress.Maximum = lstStockUp.Count;
|
||
this.statusBar.UpdateProgressBar(i + 1);
|
||
i++;
|
||
}));
|
||
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
var rows = this.dgvStock.Rows.Cast<DataGridViewRow>().Where(r =>
|
||
r.Cells["colProdSkc"].Value.ToString() == stockUp.productSkcId.ParseToString());
|
||
|
||
|
||
if (stockUp.needStockUp != true)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "无需创建备货单";
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
if (stockUp.goodsAfsScore != null && stockUp.goodsAfsScore < minQualityScore)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "商品品质得分过低,请去网页手动备货";
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
if (stockUp.qltyAfsOrdrRate != null && stockUp.qltyAfsOrdrRate * 100 > maxQualityRate)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "商品品质售后率过高,请去网页手动备货";
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == stockUp.supplierId.ToString());
|
||
if (shop == null || shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "店铺掉线或不存在";
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "正在创建";
|
||
}
|
||
}));
|
||
|
||
Thread.Sleep(200 + Randomx.GetId(100));
|
||
string jsonStr = this.QueryStockBaseInfo(shop, stockUp);
|
||
bool isError = !jsonStr.Contains("\"success\":true");
|
||
string sErrMsg1 = BaseRegex.GetStringJson(ref jsonStr, "errorMsg").ParseToString();
|
||
if (!isError)
|
||
{
|
||
Thread.Sleep(Randomx.GetId(200, 400));
|
||
|
||
var jStr = "";
|
||
try
|
||
{
|
||
var jObj = JObject.Parse(jsonStr);
|
||
var jItem = jObj["result"];
|
||
jStr = jObj["result"].ParseToString();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
BaseMsgForm.ShowError(ex.Message);
|
||
}
|
||
stockBaseInfo sBaseInfo = JsonHelper.DeserializeJsonToObject<stockBaseInfo>(jStr);
|
||
|
||
foreach(var sku in stockUp.skuQuantityDetailList)
|
||
{
|
||
if (sku.wantStockUpBound == 0)
|
||
continue;
|
||
|
||
var sBaseSku = sBaseInfo.purchaseConfigDetailList.FirstOrDefault(s => s.productSkuId == sku.productSkuId);
|
||
if (sBaseSku == null)
|
||
sku.wantStockUpBound = 0;
|
||
|
||
if (sku.wantStockUpBound > sBaseSku.applyUpperBound.ParseToInt())
|
||
{
|
||
sku.wantStockUpBound = sBaseSku.applyUpperBound.ParseToInt();
|
||
//如果强制要求最小数量,且平台可备数量小于最小数量,直接不允许备货
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (sku.wantStockUpBound < this.txtMinBound.Text.ParseToInt() && this.chkIfLessMakeZero.Checked)
|
||
sku.wantStockUpBound = -1;
|
||
}));
|
||
}
|
||
}
|
||
|
||
if (!stockUp.skuQuantityDetailList.Any(s => s.wantStockUpBound > 0))
|
||
{
|
||
//如果已备过货但是还未发出,做一个判断
|
||
isError = true;
|
||
stockUp.needStockUp = false;
|
||
sErrMsg1 += "已达平台备货量上限!已申请过备货";
|
||
}
|
||
else
|
||
{
|
||
jsonStr = this.CreateStockOrder(shop, stockUp);
|
||
isError = !jsonStr.Contains("\"success\":true");
|
||
string sErrMsg2 = BaseRegex.GetStringJson(ref jsonStr, "errorMsg").ParseToString();
|
||
|
||
try
|
||
{
|
||
var jObj2 = JObject.Parse(jsonStr);
|
||
if (jObj2["result"] != null && jObj2["result"]["failDetailList"] != null)
|
||
{
|
||
string failDetailList = (jObj2["result"]["failDetailList"])?.ParseToString();
|
||
if (failDetailList.Length > 5)
|
||
{
|
||
isError = true;
|
||
sErrMsg2 += failDetailList;
|
||
}
|
||
}
|
||
}
|
||
catch { }
|
||
sErrMsg1 += sErrMsg2;
|
||
}
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (!isError)
|
||
{
|
||
stockUp.isStockUp = true;
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "已创建备货单";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "创建备货单失败:" + sErrMsg1;
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
//ucGroupBoxEx2.Enabled = true;
|
||
ucGroupBoxEx3.Enabled = true;
|
||
ucGroupBoxEx4.Enabled = true;
|
||
string sRst = "操作结束(创建备货单)!";
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
sRst = "已取消操作(创建备货单)!";
|
||
|
||
BaseMsgForm.ShowInfo(sRst);
|
||
this.statusBar.lblTaskStatus.Text = sRst;
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
}
|
||
|
||
private void txtMinBound_TextChanged(object sender, EventArgs e)
|
||
{
|
||
this.lblMinBound.Text = "备货量小于" + txtMinBound.Text.ParseToInt() + "按";
|
||
//this.chkIfLessMakeZero.Text = "平台允许备货数量小于" + txtMinBound.Text.ParseToInt() + "不备货";
|
||
}
|
||
|
||
private void chkNewService_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
this.isNewService = ucCheckBox1.Checked;
|
||
}
|
||
|
||
Bitmap defaultBitmap = new Bitmap(80, 80);
|
||
void ShowDgvImg()
|
||
{
|
||
Task.Run(() =>
|
||
{
|
||
foreach (DataGridViewRow row in this.dgvStock.Rows)
|
||
{
|
||
if (row.Index > 0 && row.Cells["colProductSkcPic"].Displayed == false)
|
||
{
|
||
try
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colProductSkcPic"].Value = defaultBitmap;
|
||
}));
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
continue;
|
||
}
|
||
|
||
if (row.Cells["colProductSkcPic"].Value != null && row.Cells["colProductSkcPic"].Value != defaultBitmap)
|
||
continue;
|
||
|
||
Image image = null;
|
||
string imgUrl = row.Cells["colImgUrl"]?.Value.ParseToString();
|
||
string getImgError = "";
|
||
if (!string.IsNullOrWhiteSpace(imgUrl))
|
||
image = GetHtml.GetUrlImg(imgUrl, out getImgError);
|
||
if (!string.IsNullOrEmpty(getImgError))
|
||
//BaseMsgForm.ShowError("图片加载失败 " + getImgError);
|
||
image = TemuKJD.Properties.Resources.errpic;
|
||
|
||
try
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colProductSkcPic"].Value = image;
|
||
}));
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
private void dgvStock_Scroll(object sender, ScrollEventArgs e)
|
||
{
|
||
ShowDgvImg();
|
||
}
|
||
|
||
private void rbTodaySaleCount_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if(rbTodaySaleCount.Checked)
|
||
{
|
||
label101.Text = "备货数量:近7日加购小于今日销量,今日销量 ×";
|
||
label102.Text = "近7日加购大于今日销量,今日销量 ×";
|
||
}
|
||
else
|
||
{
|
||
label101.Text = "备货数量:近7日加购小于7日平均销量,7日平均 ×";
|
||
label102.Text = "近7日加购大于7日平均销量,7日平均 ×";
|
||
}
|
||
}
|
||
|
||
private void btnEmpty_Click(object sender, EventArgs e)
|
||
{
|
||
txtNotes.Text = txtShopId.Text = txtShopName.Text = "";
|
||
FiltShop();
|
||
}
|
||
}
|
||
}
|