740 lines
33 KiB
C#
740 lines
33 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.Linq;
|
||
using System.Net;
|
||
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
|
||
{
|
||
public partial class PriceManageForm : BaseForm
|
||
{
|
||
private CheckBox chkSelectAll = null;
|
||
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
|
||
List<TemuPriceAdjustInfo> lstPriceAdjustInfo = new List<TemuPriceAdjustInfo>();
|
||
|
||
public PriceManageForm()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void PriceManageForm_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.dgvAdjust.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.LoginStatus2 == "国际版在线").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 PriceManageForm_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.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 dgvShop_CellClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
string columnName = dgvShop.Columns[e.ColumnIndex].Name;
|
||
switch (columnName)
|
||
{
|
||
case "colSelect":
|
||
dgvShop.CellContentClick -= dgvShop_CellContentClick;
|
||
dgvShop_CellContentClick(sender, e);
|
||
break;
|
||
default:
|
||
dgvShop.CellContentClick -= dgvShop_CellContentClick;
|
||
dgvShop.CellContentClick += dgvShop_CellContentClick;
|
||
break;
|
||
}
|
||
}
|
||
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 btnSearchPrice_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.dgvAdjust.Columns.Cast<DataGridViewColumn>();
|
||
foreach (var col in columns)
|
||
{
|
||
//if (col.Name == "colParentStockId" || col.Name == "colStockId")
|
||
//{
|
||
// col.Visible = true;
|
||
//}
|
||
//if (col.Name == "colTodaySaleVolume" || col.Name == "colInCartNumber7d" || col.Name == "colSalesInventoryNum"
|
||
// || col.Name == "colWaitReceiveNum" || col.Name == "colNeedStockUp")
|
||
//{
|
||
// col.Visible = false;
|
||
//}
|
||
}
|
||
|
||
lstPriceAdjustInfo.Clear();
|
||
dgvAdjust.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 = "";
|
||
}
|
||
|
||
ucGroupBoxEx2.Enabled = false;
|
||
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;
|
||
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if (shop == null)
|
||
continue;
|
||
|
||
#region 检测登录
|
||
if (shop.LoginStatus2 != "国际版在线")
|
||
{
|
||
continue;
|
||
}
|
||
if (ShopListForm.Instance == null)
|
||
ShopListForm.Instance = new ShopListForm();
|
||
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["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;
|
||
string errMsg = "";
|
||
while (page <= totalPage)
|
||
{
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
int tryCount = 0;
|
||
tryAgain:
|
||
Thread.Sleep(100 + Randomx.GetId(200));
|
||
string jsonStr = GetPriceAdjustList(shop, page, chkHasSuccess.Checked ? "已调价" : "待调价");
|
||
if (jsonStr.Contains("指定的值含有无效的控制字符"))
|
||
{
|
||
BaseMsgForm.ShowError("店铺" + shop.LoginName + " " + shop.ShopId + "已掉线");
|
||
isError = true;
|
||
break;
|
||
}
|
||
if (jsonStr.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
|
||
{
|
||
tryCount++;
|
||
Thread.Sleep(Randomx.GetId(500,1000));
|
||
goto tryAgain;
|
||
}
|
||
if (jsonStr.Contains("当前操作人数太多,请稍后重试"))
|
||
{
|
||
}
|
||
if (!jsonStr.Contains("\"success\":true"))
|
||
{
|
||
isError = true;
|
||
string sErr = BaseRegex.GetStringJson(ref jsonStr, "errorMsg");
|
||
if (!string.IsNullOrWhiteSpace(sErr) && !errMsg.Contains(sErr))
|
||
errMsg += sErr + " ";
|
||
page++;
|
||
continue;
|
||
}
|
||
|
||
string snTag = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now).ToString();
|
||
if (jsonStr.Contains("\"success\":true"))
|
||
{
|
||
var jArr = new JArray();
|
||
try
|
||
{
|
||
var jObj = JObject.Parse(jsonStr);
|
||
jArr = jObj["result"]?["list"] as JArray;
|
||
if (jArr == null)
|
||
jArr = new JArray();
|
||
}
|
||
catch (Exception ex) { BaseMsgForm.ShowError(ex.Message); }
|
||
foreach (var item in jArr)
|
||
{
|
||
string sItem = item.ToString();
|
||
TemuPriceAdjustInfo pInfo = JsonHelper.DeserializeJsonToObject<TemuPriceAdjustInfo>(sItem); // 反序列化得到类
|
||
if (pInfo != null && !lstPriceAdjustInfo.Any(a=>a.priceOrderSn == pInfo.priceOrderSn))
|
||
{
|
||
pInfo.snTag = snTag;
|
||
lstPriceAdjustInfo.Add(pInfo);
|
||
|
||
//string url = pInfo.image.Replace("https", "http");
|
||
//var image = Image.FromStream(WebRequest.Create(url).GetResponse().GetResponseStream());
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
int rowId = this.dgvAdjust.Rows.Add(
|
||
true,
|
||
pInfo.supplierId,
|
||
shop.ShopAccount, // pInfo.supplierName, // 列表里取不到,这里取shop里的
|
||
pInfo.priceOrderSn,
|
||
pInfo.image.Replace("https", "http"),
|
||
defaultBitmap,//image, // skc图片
|
||
pInfo.productId,
|
||
pInfo.skcId,
|
||
pInfo.productName + "\r\n" + pInfo.skuSpecs, // 商品标题+sku名称
|
||
string.IsNullOrEmpty(pInfo.activityInvitationName)? "日常价格" : pInfo.activityInvitationName, // 申报价格类型
|
||
pInfo.skuInfoItemList.FirstOrDefault()?.price.ParseToDecimal() / 100, // 当前申报价格
|
||
pInfo.newSupplyPrice?.ParseToDecimal() / 100, // 调整后的申报价格
|
||
pInfo.skuInfoItemList.FirstOrDefault()?.currencyName, // 币种
|
||
pInfo.source, // 申请来源
|
||
"", // 调价类型
|
||
pInfo.adjustReason, // 调价原因
|
||
"" // 操作结果,状态
|
||
);
|
||
|
||
dgvAdjust.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 = "查询失败 " + errMsg;
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
chkHasSuccess.Enabled = true;
|
||
ucGroupBoxEx2.Enabled = true;
|
||
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 GetPriceAdjustList(ShopLoginInfo shop, int page = 1, string type = "待调价")
|
||
{
|
||
page = Math.Max(page, 1);
|
||
//string url = "https://seller.kuajingmaihuo.com/marvel-mms/cn/api/kiana/magneto/price-adjust/page-query";
|
||
string url = "https://agentseller.temu.com/api/kiana/mms/magneto/price-adjust/page-query";
|
||
string body;
|
||
if (type == "待调价")
|
||
body = @"{""pageInfo"":{""pageSize"":10,""pageNo"":" + page + @"},""status"":1,""quickSearch"":[]}";
|
||
else
|
||
body = @"{""pageInfo"":{""pageSize"":10,""pageNo"":" + page + @"},""status"":2,""quickSearch"":[]}";
|
||
|
||
//string refere = "https://seller.kuajingmaihuo.com/main/price-manage/price-adjustment";
|
||
string refere = "https://agentseller.temu.com/main/adjust-price-manage/order-price";
|
||
|
||
//return HttpResponseBLL.PostResponse(shop, url, body, refere);
|
||
return HttpResponseBLL.PostResponse2(shop, url, body, refere);
|
||
}
|
||
|
||
private void panelEx1_Click(object sender, EventArgs e)
|
||
{
|
||
if (cancellationTokenSource != null)
|
||
cancellationTokenSource.Cancel();
|
||
|
||
Task.Run(() => {
|
||
for (int i = 0; i < 100; i++)
|
||
{
|
||
Thread.Sleep(100);
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
ucGroupBoxEx2.Enabled = true;
|
||
ucGroupBoxEx3.Enabled = true;
|
||
}));
|
||
});
|
||
}
|
||
|
||
private void btnStartStockUp_Click(object sender, EventArgs e)
|
||
{
|
||
var lstSn = dgvAdjust.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colPriceOrderSn"]?.Value.ToString()).ToList();
|
||
var lstPriceAdjust = lstPriceAdjustInfo.Where(s => lstSn.Contains(s.priceOrderSn.ParseToString())).ToList();
|
||
if (lstPriceAdjust.Count == 0)
|
||
{
|
||
BaseMsgForm.ShowInfo("请选择要拒绝跟价的商品!");
|
||
return;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(txtScale1.Text.Trim()))
|
||
{
|
||
BaseMsgForm.ShowInfo("请输入拒绝跟价理由!");
|
||
return;
|
||
}
|
||
|
||
ucGroupBoxEx2.Enabled = false;
|
||
ucGroupBoxEx3.Enabled = false;
|
||
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
Task.Run(() =>
|
||
{
|
||
int i = 0;
|
||
foreach (var priceAdjust in lstPriceAdjust)
|
||
{
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "正在创建备货单...";
|
||
this.statusBar.pgbTaskProgress.Maximum = lstPriceAdjust.Count;
|
||
this.statusBar.UpdateProgressBar(i + 1);
|
||
i++;
|
||
}));
|
||
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
var rows = this.dgvAdjust.Rows.Cast<DataGridViewRow>().Where(r =>
|
||
r.Cells["colPriceOrderSn"].Value.ToString() == priceAdjust.priceOrderSn.ParseToString());
|
||
|
||
|
||
if (priceAdjust.isRefuseAdjust == true)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMsg"].Value = "已拒绝跟价";
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == priceAdjust.supplierId.ToString());
|
||
if (shop == null || shop.LoginStatus2 != "国际版在线")
|
||
{
|
||
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));
|
||
|
||
//var adjustLst = lstPriceAdjustInfo.Where(a => a.skuIds == priceAdjust.skuIds && a.isRefuseAdjust == false).ToList();
|
||
//var adjustLst = lstPriceAdjustInfo.Where(a =>
|
||
// priceAdjust.skuInfoItemList.Any(sku => a.skuIds.Contains(sku.productSkuId.ToString())) && a.isRefuseAdjust == false).ToList();
|
||
// 同一页的一起提交
|
||
var adjustLst = lstPriceAdjustInfo.Where(a =>
|
||
a.snTag == priceAdjust.snTag && // 选中商品的同页商品
|
||
lstPriceAdjust.Any(s => s.skcId == a.skcId) && // 该商品也需要有同skc商品被选中
|
||
a.isRefuseAdjust == false).ToList(); // 没有被取消调价过
|
||
var adjustStrLst = adjustLst.Select(s => s.id.ParseToString()).ToList();
|
||
|
||
|
||
string jsonStr = this.refuseAdjust(shop, adjustStrLst, this.txtScale1.Text.Trim());
|
||
bool isError = !jsonStr.Contains("\"success\":true");
|
||
string sErrMsg1 = BaseRegex.GetStringJson(ref jsonStr, "errorMsg").ParseToString();
|
||
if (!isError)
|
||
{
|
||
foreach(var adj in adjustLst)
|
||
{
|
||
adj.isRefuseAdjust = true;
|
||
var rs = this.dgvAdjust.Rows.Cast<DataGridViewRow>().Where(r =>
|
||
r.Cells["colPriceOrderSn"].Value.ToString() == adj.priceOrderSn.ParseToString());
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach(var r in rs)
|
||
r.Cells["colMsg"].Value = "已拒绝跟价";
|
||
}));
|
||
}
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (!isError)
|
||
{
|
||
priceAdjust.isRefuseAdjust = 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;
|
||
string sRst = "操作结束(拒绝跟价)!";
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
sRst = "已取消操作(拒绝跟价)!";
|
||
|
||
BaseMsgForm.ShowInfo(sRst);
|
||
this.statusBar.lblTaskStatus.Text = sRst;
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 拒绝跟价
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <param name="subOrderInfo"></param>
|
||
/// <returns></returns>
|
||
private string refuseAdjust(ShopLoginInfo shop, List<string> adjustIdList, string refuseReason)
|
||
{
|
||
//string url = "https://seller.kuajingmaihuo.com/marvel-mms/cn/api/kiana/gmp/bg/magneto/api/price-adjust/batch/adjust";
|
||
string url = "https://agentseller.temu.com/api/kiana/mms/gmp/bg/magneto/api/price-adjust/batch/adjust";
|
||
string body = "{\"adjustList\":[";
|
||
foreach (var adjustId in adjustIdList)
|
||
{
|
||
body += "{\"adjustId\":" + adjustId + ",\"result\":2,\"reason\":\"" + refuseReason + "\"},";
|
||
}
|
||
body = body.TrimEnd(',');
|
||
body += "]}";
|
||
//string refere = "https://seller.kuajingmaihuo.com/main/price-manage/price-adjustment";
|
||
string refere = "https://agentseller.temu.com/main/adjust-price-manage/order-price";
|
||
|
||
return HttpResponseBLL.PostResponse2(shop, url, body, refere);
|
||
}
|
||
|
||
private void dgvStock_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.RowIndex < 0 || e.ColumnIndex < 0)
|
||
return;
|
||
string columnName = dgvAdjust.Columns[e.ColumnIndex].Name;
|
||
var row = dgvAdjust.Rows[e.RowIndex];
|
||
switch (columnName)
|
||
{
|
||
case "colCheck":
|
||
row.Cells["colCheck"].Value = !row.Cells["colCheck"].Value.ParseToBool();
|
||
break;
|
||
}
|
||
}
|
||
|
||
Bitmap defaultBitmap = new Bitmap(80, 80);
|
||
void ShowDgvImg()
|
||
{
|
||
Task.Run(() =>
|
||
{
|
||
foreach (DataGridViewRow row in this.dgvAdjust.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 dgvAdjust_Scroll(object sender, ScrollEventArgs e)
|
||
{
|
||
ShowDgvImg();
|
||
}
|
||
|
||
private void btnEmpty_Click(object sender, EventArgs e)
|
||
{
|
||
txtNotes.Text = txtShopId.Text = txtShopName.Text = "";
|
||
FiltShop();
|
||
}
|
||
}
|
||
}
|