Files
KJD/TEMUKJD/KJDForms/AdminForms/AdminProductPriceCheckForm.cs
T

1764 lines
86 KiB
C#

using AllBase;
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.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using TemuKJD.Extension;
using TemuKJD.KJDForms.BaseForms;
using TemuKJD.KJDForms.ShopForms;
using TemuKJD.KJDForms.ToolForms;
using Work;
namespace TemuKJD.KJDForms.AdminForms
{
public partial class AdminProductPriceCheckForm : Form
{
PriceCheckConfig priceCheckConfig = null;
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
public List<ShopLoginInfo> lstAdminShopInfo { get; set; } = new List<ShopLoginInfo>();
public List<TemuCheckPriceInfo> lstCheckPriceInfo = new List<TemuCheckPriceInfo>();
public AdminProductPriceCheckForm()
{
InitializeComponent();
}
private void AdminProductPriceCheckForm_Load(object sender, EventArgs e)
{
this.dgvShop.AddSelectorColumn("colSelect");
this.dgvPriceCheck.AddSelectorColumn("colCheck");
this.dgvPriceCheck.AddMergeColumnHeader(new List<string>() { "colOk", "colCancel" }, "同意/拒绝报价");
this.dtpEndTime.Value = DateTime.Now.Date.AddDays(1).AddMilliseconds(-1);
this.dtpStartTime.Value = DateTime.Now.Date.AddDays(-7);
if (BaseClass.SaLevel != 1)
{
//this.chkShowDelete.Visible = false;
//dgvShop.Columns["colSubSa"].Visible = false;
//btnSetSubSa.Visible = false;
}
priceCheckConfig = NaiBa.Util.Helper.ConfigHelper.LoadConfig<PriceCheckConfig>("price_check_config");
if (priceCheckConfig == null)
priceCheckConfig = new PriceCheckConfig();
this.txtNotes.Text = priceCheckConfig.SearchNotes;
this.txtShopId.Text = priceCheckConfig.SearchShopId;
this.txtShopName.Text = priceCheckConfig.SearchShopName;
this.txtPriceDown.Text = priceCheckConfig.PriceDown;
this.chkSearchAllShop.Checked = priceCheckConfig.SearchAllShop;
this.txtNotes.TextChanged += Txt_TextChanged;
this.txtShopId.TextChanged += Txt_TextChanged;
this.txtShopName.TextChanged += Txt_TextChanged;
this.txtPriceDown.TextChanged += Txt_TextChanged;
this.chkSearchAllShop.CheckedChanged += Txt_TextChanged;
}
private void Txt_TextChanged(object sender, EventArgs e)
{
priceCheckConfig.SearchNotes = this.txtNotes.Text.Trim();
priceCheckConfig.SearchShopId = this.txtShopId.Text.Trim();
priceCheckConfig.SearchShopName = this.txtShopName.Text.Trim();
priceCheckConfig.PriceDown = this.txtPriceDown.Text.Trim();
priceCheckConfig.SearchAllShop = this.chkSearchAllShop.Checked;
NaiBa.Util.Helper.ConfigHelper.SaveConfig("price_check_config", priceCheckConfig);
}
//bool firstLoad = true;
private void AdminProductPriceCheckForm_VisibleChanged(object sender, EventArgs e)
{
if (this.Visible /*&& this.firstLoad*/)
{
//firstLoad = false;
this.pbShopLoading.Visible = true;
SearchShop(this.ucSplitPage1.CurrentPage);
}
}
private void btnRefreshShop_Click(object sender, EventArgs e)
{
if (this.ucSplitPage1.CurrentPage != 1)
this.ucSplitPage1.CurrentPage = 1;
else
SearchShop(1);
}
private void ucSplitPage1_PageChange(object obj)
{
SearchShop(this.ucSplitPage1.CurrentPage);
}
public void SearchShop(int page)
{
List<string> shopIdSelectList = GetCheckedShopIdList();
if (InvokeRequired)
{
Invoke(new Action(() =>
{
this.pbShopLoading.Visible = true;
this.dgvShop.Rows.Clear();
lstAdminShopInfo.Clear();
}));
}
else
{
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(
shopIdSelectList.Contains(shop.ShopId + shop.UserName),
shop.UserName,
shop.LoginName,
shop.ShopId,
shop.ShopAccount,
shop.Notes,
canUse ? "在线" : "掉线",
canUse,
string.Empty
);
displayShopStatus(shop);
//var row = dgvShop.Rows[rowIndex];
//(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;
}));
}
Invoke(new Action(() =>
{
this.pbShopLoading.Visible = false;
}));
});
}
private List<string> GetCheckedShopIdList()
{
List<string> shopNameList = new List<string>();
for (int i = 0; i < dgvShop.Rows.Count; i++)
{
if (dgvShop.Rows[i].Cells["colSelect"].Value.ParseToBool())
{
string shopName = dgvShop.Rows[i].Cells["colShopId"].Value.ParseToString();
shopName += dgvShop.Rows[i].Cells["colUser"].Value.ParseToString();
shopNameList.Add(shopName);
}
}
return shopNameList;
}
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 AdminShopListForm.DeserializationShop(html);
}
private void btnEmpty_Click(object sender, EventArgs e)
{
txtNotes.Text = txtShopId.Text = txtShopName.Text = "";
}
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();
var shop = lstAdminShopInfo.FirstOrDefault(v => v.LoginName == loginName && v.ShopId == accountId);
switch (headerText)
{
case "登录":
case "状态":
{
AdminShopLoginForm shopLoginForm = new AdminShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
shopLoginForm.ShowDialog();
}
break;
default:
dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value = !(bool)dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value;
break;
}
}
private void shopLoginForm_SaveComplete(object obj)
{
//SearchShop(this.ucSplitPage1.CurrentPage);
var shop = obj as ShopLoginInfo;
if (shop == null)
return;
displayShopStatus(shop);
}
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;
}
}
private void dgvCheckPrice_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
string headerText = dgvPriceCheck.Columns[e.ColumnIndex].HeaderText;
string orderId = dgvPriceCheck.Rows[e.RowIndex].Cells["colOrderId"].Value.ParseToString();
string prodId = dgvPriceCheck.Rows[e.RowIndex].Cells["colProductId"].Value.ParseToString();
string accountId = dgvPriceCheck.Rows[e.RowIndex].Cells["colSupplierId"].Value.ParseToString();
var shop = lstAdminShopInfo.FirstOrDefault(v => v.ShopId == accountId);
switch (headerText)
{
case "规格名称":
{
var PriceInfo = lstCheckPriceInfo.FirstOrDefault(p => p.productId.ParseToString() == prodId);
if (PriceInfo != null)
{
this.pnlSpecDetail.Visible = true;
string skuName = "";
var prodSkuList = PriceInfo.skcList.FirstOrDefault().skuList;
if (prodSkuList != null)
{
foreach (var sku in prodSkuList)
{
foreach (var prop in sku.productPropertyList)
{
skuName += prop.value + ",";
}
skuName = skuName.TrimEnd(',') + ";";
skuName += " ";
skuName += " 长:" + sku.len.ParseToInt() * 0.1;
skuName += " 宽:" + sku.width.ParseToInt() * 0.1;
skuName += " 高:" + sku.height.ParseToInt() * 0.1;
skuName += " 重:" + sku.weight.ParseToInt() * 0.001;
skuName += "\r\n";
}
}
this.textBox1.Text = skuName;
}
}
break;
case "同意报价":
{
applyHighPrice(shop, orderId, dgvPriceCheck.Rows[e.RowIndex]);
}
break;
case "拒绝报价":
{
cancelLowPrice(shop, orderId, dgvPriceCheck.Rows[e.RowIndex]);
}
break;
case "作废待创建":
{
this.cancelTitleWrongPrice(shop, prodId);
}
break;
case "Skc图片":
string url = dgvPriceCheck.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 "":
// dgvPriceCheck.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvPriceCheck.Rows[e.RowIndex].Cells["colCheck"].Value;
// break;
default:
break;
}
}
private void applyHighPrice(ShopLoginInfo shop, string orderId, DataGridViewRow row)
{
//{"supplierResult":1,"priceOrderId":2508081200527258,"items":[{ "productSkuId":22954374419,"price":14500},{ "productSkuId":11040177436,"price":14500},{ "productSkuId":47081005481,"price":14500},{ "productSkuId":62542358120,"price":14500},{ "productSkuId":70385131590,"price":14500},{ "productSkuId":19665043575,"price":14500},{ "productSkuId":49890165809,"price":14500},{ "productSkuId":31851005577,"price":14500},{ "productSkuId":77977214817,"price":14500},{ "productSkuId":30313877294,"price":14500},{ "productSkuId":55921323568,"price":14500},{ "productSkuId":61553511772,"price":14500},{ "productSkuId":31344600169,"price":14500},{ "productSkuId":79990531362,"price":14500}],"bargainReasonList":[]}
if (shop == null)
return;
TemuSupplierPriceReviewInfo priceReview = null;
foreach (var price in this.lstCheckPriceInfo)
{
if (priceReview != null)
break;
foreach (var Review in price.skcList.FirstOrDefault()?.supplierPriceReviewInfoList)
{
if (Review.priceOrderId.ParseToString() == orderId)
{
priceReview = Review;
break;
}
}
}
if (priceReview == null)
return;
string data = "{\"supplierResult\":1,\"priceOrderId\":" + priceReview.priceOrderId + ",\"items\":[";
foreach (var sku in priceReview.productSkuList)
{
data += "{\"productSkuId\":" + sku.skuId + ",\"price\":" + priceReview.suggestSupplyPrice + "},";
}
data = data.TrimEnd(',');
data += "],\"bargainReasonList\":[]}";
var rst = applyPrice(shop, orderId, data);
if (rst.Contains("登录过期") || rst.Contains("Invalid Login State"))
{
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
Invoke(new Action(() =>
{
displayShopStatus(shop);
}));
}
if (row != null)
{
if (rst.Contains("\"success\":true"))
row.Cells["colMsg"].Value = "已核价";
else
row.Cells["colMsg"].Value = "核价失败" + rst;
}
}
private void rePrice(ShopLoginInfo shop, string orderId, DataGridViewRow row)
{
//{"supplierResult":2,"priceOrderId":2508081238454147,"items":[{"productSkuId":70647701317,"price":18490},{"productSkuId":34466033044,"price":18490},{"productSkuId":34464576879,"price":18490},{"productSkuId":34895719118,"price":18490},{"productSkuId":61915282142,"price":18490},{"productSkuId":76031311695,"price":18490},{"productSkuId":93752826474,"price":18490},{"productSkuId":18180751875,"price":18490},{"productSkuId":65333379322,"price":18490},{"productSkuId":71131751234,"price":18490},{"productSkuId":10651693269,"price":18490},{"productSkuId":89672993631,"price":18490},{"productSkuId":38775502377,"price":18490},{"productSkuId":93279836006,"price":18490},{"productSkuId":77125468089,"price":18490}],"bargainReasonList":[]}
if (shop == null)
return;
TemuSupplierPriceReviewInfo priceReview = null;
foreach (var price in this.lstCheckPriceInfo)
{
if (priceReview != null)
break;
foreach (var Review in price.skcList.FirstOrDefault()?.supplierPriceReviewInfoList)
{
if (Review.priceOrderId.ParseToString() == orderId)
{
priceReview = Review;
break;
}
}
}
if (priceReview == null)
return;
int priceDown = (priceReview.times * this.txtPriceDown.Text.ParseToDecimal() * 100).ParseToInt();
string data = "{\"supplierResult\":2,\"priceOrderId\":" + priceReview.priceOrderId + ",\"items\":[";
foreach (var sku in priceReview.productSkuList)
{
data += "{\"productSkuId\":" + sku.skuId + ",\"price\":" + (priceReview.supplyPrice - priceDown) + "},";
}
data = data.TrimEnd(',');
data += "],\"bargainReasonList\":[]}";
var rst = rePrice(shop, orderId, data);
if (rst.Contains("登录过期") || rst.Contains("Invalid Login State"))
{
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
Invoke(new Action(() =>
{
displayShopStatus(shop);
}));
}
if (row != null)
{
if (rst.Contains("\"success\":true"))
{
row.Cells["colMsg"].Value = "已重新申请价格";
row.Cells["colNewPrice"].Value = (priceReview.supplyPrice - priceDown) / 100.0;
}
else
row.Cells["colMsg"].Value = "重新申请价格失败" + rst;
}
}
private void cancelTitleWrongPrice(ShopLoginInfo shop, string prodId)
{
if (shop == null || string.IsNullOrEmpty(prodId))
return;
var rows = dgvPriceCheck.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colProductId"].Value.ParseToString() == prodId).ToList();
if (rows.Count == 0)
return;
//TemuSupplierPriceReviewInfo priceReview = null;
TemuCheckPriceInfo checkPriceInfo = null;
foreach (var price in this.lstCheckPriceInfo)
{
if (price.productId.ParseToString() == prodId)
{
checkPriceInfo = price;
break;
}
}
if (checkPriceInfo == null)
return;
string data = "{\"adjustReason\":3,\"adjustItems\":[";
data += "{";
data += "\"productName\":\"" + checkPriceInfo.productName + "\",";
data += "\"productSkcId\":" + checkPriceInfo.skcList.FirstOrDefault()?.skcId + ",";
data += "\"skuAdjustList\":[";
foreach (var sku in checkPriceInfo.skcList.FirstOrDefault()?.skuList)
{
// 2是正常状态,3是作废
if (sku.priceReviewStatus != 2)
continue;
data += "{\"targetPriceCurrency\":\"CNY\",\"oldPriceCurrency\":\"CNY\",";
data += "\"oldSupplyPrice\":" + sku.supplierPriceValue.ParseToInt() + ",";
data += "\"skuId\":" + sku.skuId + ",";
//data += "\"targetSupplyPrice\":" + Math.Max(1, sku.supplierPriceValue.ParseToInt() - 1) + ","; // 测试,每次减少1分
data += "\"targetSupplyPrice\":" + 10 + ","; // 作废后价格改为1角钱,看到低价就不会再买
data += "\"syncPurchasePrice\":1},";
}
data = data.TrimEnd(',');
data += "],";
data += "\"productId\":" + checkPriceInfo.productId + ",";
data += "\"supplierId\":" + checkPriceInfo.supplierId;
data += "}]}";
var rst = priceAdjust(shop, data);
if (rst.Contains("登录过期") || rst.Contains("Invalid Login State"))
{
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
Invoke(new Action(() =>
{
displayShopStatus(shop);
}));
}
foreach(var row in rows)
{
if (rst.Contains("\"success\":true"))
{
row.Cells["colMsg"].Value = "已作废商品-价格0.1";
row.Cells["colNewPrice"].Value = 10 / 100.0;
}
else
row.Cells["colMsg"].Value = "作废商品失败" + rst;
}
}
private void cancelLowPrice(ShopLoginInfo shop, string orderId, DataGridViewRow row)
{
if (shop == null)
return;
var rst = this.cancelPrice(shop, orderId);
if (rst.Contains("登录过期") || rst.Contains("Invalid Login State"))
{
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
Invoke(new Action(() =>
{
displayShopStatus(shop);
}));
}
if (row != null)
{
if (rst.Contains("\"success\":true"))
row.Cells["colMsg"].Value = "已拒绝报价";
else
row.Cells["colMsg"].Value = "拒绝报价失败" + rst;
}
}
private void btnSearchPrice_Click(object sender, EventArgs e)
{
this.pnlDetailOperate1.Visible = true;
this.pnlDetailOperate2.Visible = false;
this.dgvPriceCheck.Columns["colOk"].Visible = true;
this.dgvPriceCheck.Columns["colCancel"].Visible = true;
this.dgvPriceCheck.Columns["colCancelWithTitleWrong"].Visible = false;
SearchPrice("待卖家确认");
}
private void btnSearchPrice2_Click(object sender, EventArgs e)
{
this.pnlDetailOperate2.Location = this.pnlDetailOperate1.Location;
this.pnlDetailOperate1.Visible = false;
this.pnlDetailOperate2.Visible = true;
this.dgvPriceCheck.Columns["colOk"].Visible = false;
this.dgvPriceCheck.Columns["colCancel"].Visible = false;
this.dgvPriceCheck.Columns["colCancelWithTitleWrong"].Visible = true;
SearchPrice("待创建首单");
}
private void SearchPrice(string type = "待卖家确认")
{
var selectShopIdLst = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colSelect"].Value.ParseToBool() == true)
.Select(r => r.Cells["colShopId"].Value.ParseToString()).Distinct().ToList();
var shops = this.lstAdminShopInfo.Where(s => selectShopIdLst.Contains(s.ShopId)).ToList();
if (shops.Count == 0)
{
BaseMsgForm.ShowError("没有选择店铺!");
return;
}
if (chkSearchTime.Checked)
{
if (dtpStartTime.Value.Date.AddMonths(3) < dtpEndTime.Value.Date.AddDays(1).AddMilliseconds(-1))
{
BaseMsgForm.ShowError("一次最多只支持查询三个月!");
return;
}
}
this.chkFilter.Checked = false;
this.dgvPriceCheck.Rows.Clear();
this.lstCheckPriceInfo.Clear();
this.pbLoading.Visible = true;
cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
int shopIndex = 0;
int totalProdIndex = 0;
foreach (var shopId in selectShopIdLst)
{
shopIndex++;
var shop = this.lstAdminShopInfo.Where(s => shopId == s.ShopId).ToList().FirstOrDefault();
if (shop == null)
continue;
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus2 != "国际版在线")
{
Invoke(new Action(() =>
{
displayShopStatus(shop);
}));
}
int page = 0;
int totalPage = 1;
int prodIndex = 0;
while (page < totalPage)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
page++;
long startTime = 0, endTime = 0;
if (chkSearchTime.Checked)
{
startTime = BaseClass.DateTimeToTimestampMilliseconds(dtpStartTime.Value.Date);
endTime = BaseClass.DateTimeToTimestampMilliseconds(dtpEndTime.Value.Date.AddDays(1).AddMilliseconds(-1));
}
var searchRst = this.SearchForChainSupplier(shop, page, txtSkcId.Text.Trim().Trim(','), type, startTime, endTime);
if (searchRst.Contains("登录过期") || searchRst.Contains("Invalid Login State"))
{
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
Invoke(new Action(() =>
{
displayShopStatus(shop);
}));
}
if (searchRst.Contains("\"success\":true"))
{
try
{
int total = BaseRegex.GetStringJson(ref searchRst, "total").ParseToInt();
totalPage = Math.Ceiling(total / 100.0).ParseToInt();
var jObj = JObject.Parse(searchRst);
var jArr = jObj["result"]["dataList"] as JArray;
if (jArr == null)
jArr = new JArray();
List<string> extCodeLst = new List<string>();
List<TemuCheckPriceInfo> checkPriceInfoTmpLst = new List<TemuCheckPriceInfo>();
foreach (var item in jArr)
{
var jStr = JsonHelper.SerializeObject(item);
TemuCheckPriceInfo priceInfo = JsonHelper.DeserializeJsonToObject<TemuCheckPriceInfo>(jStr);
lstCheckPriceInfo.Add(priceInfo);
checkPriceInfoTmpLst.Add(priceInfo);
extCodeLst.Add(priceInfo.skcList.FirstOrDefault()?.extCode);
}
List<TemuDBExtCodePriceInfo> extCodePriceList = new List<TemuDBExtCodePriceInfo>();
try
{
extCodePriceList = GetServerExtCodePriceLst(extCodeLst.Distinct().ToList());
}
catch (Exception ex)
{
BaseMsgForm.ShowError("获取货号价格失败 " + ex.Message);
}
foreach (var priceInfo in checkPriceInfoTmpLst)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
prodIndex++;
totalProdIndex++;
Invoke(new Action(() => {
this.statusBar.lblTaskStatus.Text = "正在查询" + type + ",店铺:" + shop.ShopAccount + " " + prodIndex + "/" + total + " 件商品";
this.statusBar.pgbTaskProgress.Maximum = selectShopIdLst.Count;
this.statusBar.UpdateProgressBar(shopIndex);
}));
string imgUrl = priceInfo.skcList.FirstOrDefault()?.previewImgUrlList.FirstOrDefault();
if (imgUrl == null)
imgUrl = "";
imgUrl = imgUrl.Replace("https://", "http://").Replace("img.kwcdn.com", "img.cdnfe.com") + "?imageMogr2/thumbnail/60x";
//string getImgError = "";
//var img = GetHtml.GetUrlImg(imgUrl + "?imageMogr2/thumbnail/60x", out getImgError);
foreach (var reviewInfo in priceInfo.skcList.FirstOrDefault().supplierPriceReviewInfoList)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
if (reviewInfo.status == 3) //放弃调整报价,报价显示已作废
continue;
string skuName = "";
var prodSkuList = reviewInfo.productSkuList;
if (prodSkuList != null)
{
foreach (var sku in prodSkuList)
{
foreach (var prop in sku.productPropertyList)
{
skuName += prop.value + ",";
}
skuName = skuName.TrimEnd(',') + ";";
skuName += "\r\n";
}
}
var suggestSupplyPrice = "-";
if (type == "待卖家确认")
{
var orderPriceRst = "店铺掉线";
if (shop.LoginStatus2 == "国际版在线")
orderPriceRst = GetCheckPrice(shop, reviewInfo.priceOrderId.ParseToString());
if (orderPriceRst.Contains("登录过期") || orderPriceRst.Contains("Invalid Login State"))
{
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
}
reviewInfo.suggestSupplyPrice = BaseRegex.GetIntJson(ref orderPriceRst, "suggestSupplyPrice");
reviewInfo.supplyPrice = BaseRegex.GetIntJson(ref orderPriceRst, "supplyPrice");
suggestSupplyPrice = (reviewInfo.suggestSupplyPrice / 100.0).ToString();
if (suggestSupplyPrice == "0")
suggestSupplyPrice = "获取推荐价格失败,请重试" + orderPriceRst;
else
suggestSupplyPrice += "¥";
}
var reviewExtCode = priceInfo.skcList.FirstOrDefault()?.extCode;
var extCodePrice = extCodePriceList.FirstOrDefault(p => reviewExtCode == p.ext_code);
Thread.Sleep(Randomx.GetId(20, 50));
Invoke(new Action(() =>
{
int rowId = this.dgvPriceCheck.Rows.Add(
false,
totalProdIndex,
reviewInfo.priceOrderId,
priceInfo.supplierId,
priceInfo.supplierName,
imgUrl,
defaultBitmap,
priceInfo.productId,
priceInfo.skcList.FirstOrDefault()?.skcId,
priceInfo.productName,
skuName,
reviewExtCode,
extCodePrice == null ? "-" : (extCodePrice.original_price / 100.0).ParseToString(),
// sku不同价的会被分成多个review,priceInfo此时为价格范围
reviewInfo.productSkuList.FirstOrDefault()?.supplierPrice, //priceInfo.supplierPrice
suggestSupplyPrice,//核价
"", //新报价
reviewInfo.times, // 修改报价次数
BaseClass.StampToDateTime((priceInfo.skcList.FirstOrDefault()?.statusTime.createdTime.ParseToLong() / 1000).ParseToInt()).ToString("yy/MM/dd HH:mm:ss"),
"同意",
"拒绝",
"作废",
""
);
dgvPriceCheck.Rows[rowId].Height = 60;
if (chkFilter.Checked && !CheckContainsWords(priceInfo.productName))
{
dgvPriceCheck.Rows[rowId].Visible = false;
}
if (checkRestoreSizeAndNumber(priceInfo))
{
dgvPriceCheck.Rows[rowId].Cells["colProdName"].Style.ForeColor = Color.Red;
}
else
{
dgvPriceCheck.Rows[rowId].Cells["colProdName"].Style.ForeColor = dgvPriceCheck.DefaultCellStyle.ForeColor;
}
}));
}
this.ShowDgvImg();
}
}
catch (Exception ex)
{
BaseMsgForm.ShowError("查询商品失败 " + ex.Message);
break;
}
}
}
}
Invoke(new Action(() => {
this.pbLoading.Visible = false;
string sRst = type + " 查询结束!";
if (cancellationTokenSource.IsCancellationRequested)
sRst = type + " 已取消查询!";
BaseMsgForm.ShowInfo(sRst);
this.statusBar.lblTaskStatus.Text = sRst;
}));
}, cancellationTokenSource.Token);
}
private string SearchForChainSupplier(ShopLoginInfo shop, int page, string prodSkcIds = null, string type = "待卖家确认", long startTime = 0, long endTime = 0)
{
string url = "https://agentseller.temu.com/api/kiana/mms/robin/searchForChainSupplier";
string body = "";
body = "{\"pageSize\":100,\"pageNum\":" + page + ",";
if (!string.IsNullOrEmpty(txtExtCode.Text.Trim()))
body += "\"skcExtCodeKeyword\":\"" + txtExtCode.Text.Trim() + "\",";
if (startTime != 0 && endTime != 0) // 查询创建时间
body += "\"timeType\":1,\"timeBegin\":" + startTime + ",\"timeEnd\":" + endTime + ",";
if (type == "待卖家确认")
body += "\"priceReviewStatusList\":[1],\"secondarySelectStatusList\":[7],";
else if (type == "待创建首单")
body += "\"secondarySelectStatusList\":[10],";
body += "\"supplierTodoTypeList\":[],";
if (!string.IsNullOrEmpty(prodSkcIds))
body += "\"productSkcIdList\":[" + prodSkcIds + "],";
body = body.TrimEnd(',');
body += "}";
//if (type == "待创建首单")
//{
// body = @"{""pageSize"":100,""pageNum"":" + page + @",""secondarySelectStatusList"":[10],""supplierTodoTypeList"":[]}";
// if (!string.IsNullOrEmpty(prodSkcIds))
// body = @"{""pageSize"":100,""pageNum"":" + page + @",""secondarySelectStatusList"":[10],""supplierTodoTypeList"":[],""productSkcIdList"":[" + prodSkcIds + "]}";
//}
string referer = "https://agentseller.temu.com/newon/product-select";
return KJDHttpResponse.PostResponse2(shop, url, body, referer);
}
private string GetCheckPrice(ShopLoginInfo shop, string orderId)
{
string url = "https://agentseller.temu.com/api/kiana/mms/magneto/api/price-review-order/no-bom/reject-remark";
string body = @"{""orderId"":" + orderId + "}";
string referer = "https://agentseller.temu.com/newon/product-select";
return KJDHttpResponse.PostResponse2(shop, url, body, referer);
}
private string applyPrice(ShopLoginInfo shop, string orderId, string data)
{
string url = "https://agentseller.temu.com/api/kiana/mms/magneto/price/bargain-no-bom";
string body = data;
string referer = "https://agentseller.temu.com/newon/product-select";
return KJDHttpResponse.PostResponse2(shop, url, body, referer);
}
private string rePrice(ShopLoginInfo shop, string orderId, string data)
{
string url = "https://agentseller.temu.com/api/kiana/mms/magneto/price/bargain-no-bom";
string body = data;
string referer = "https://agentseller.temu.com/newon/product-select";
return KJDHttpResponse.PostResponse2(shop, url, body, referer);
}
private string cancelPrice(ShopLoginInfo shop, string orderId)
{
string url = "https://agentseller.temu.com/api/kiana/mms/magneto/api/price-review-order/no-bom/review";
string body = @"{""priceOrderId"":" + orderId + "}";
string referer = "https://agentseller.temu.com/newon/product-select";
return KJDHttpResponse.PostResponse2(shop, url, body, referer);
}
private string priceAdjust(ShopLoginInfo shop, string data)
{
string url = "https://agentseller.temu.com/api/kiana/mms/gmp/bg/magneto/api/price/priceAdjust/gmpProductBatchAdjustPrice";
string body = data;
string referer = "https://agentseller.temu.com/newon/product-select";
return KJDHttpResponse.PostResponse2(shop, url, body, referer);
}
/// <summary>
/// 请求修改标题
/// </summary>
/// <param name="shop"></param>
/// <param name="productId"></param>
/// <returns></returns>
private string editPriceProductNameBatchAdd(ShopLoginInfo shop, string productId)
{
string url = "https://agentseller.temu.com/lich-mms/audit/edit/task/product/batchAdd";
string body = @"{""bizIdType"":1,""bizIds"":["+ productId + @"],""productEditItems"":[{""editItem"":1,""editAdvice"":""优化""}]}";
string referer = "https://agentseller.temu.com/goods/list?productId=" + productId;
return KJDHttpResponse.PostResponse2(shop, url, body, referer);
}
private string editPriceProductName(ShopLoginInfo shop, string taskUid, string productId, string productNewName)
{
string url = "https://agentseller.temu.com/visage-agent-seller/product/edit/task/reply";
//string body = @"{""productId"":4432690492,""taskUid"":""8de73095-733e-4cdf-8fbd-3ddd8d9dff18"",""taskVersion"":0,""refuseEdit"":false,""productName"":""男士轻便 EVA 拖鞋,带钩环后跟带 ,舒适的露趾拖鞋,适合室内和室外使用,家居拖鞋,易于使用的魔鬼毡扣带扣,洞洞鞋,家居拖鞋,带钩环扣件,适合室内和室外使用,带扣凉鞋,后厨工专用鞋简约款两用,适合室内/室外使用,春夏凉鞋,EVA 拖鞋,适合19个不同的搭配风格""}";
string body = @"{""productId"":" + productId + @",""taskUid"":""" + taskUid + @""",""taskVersion"":0,""refuseEdit"":false,""productName"":""" + productNewName + @"""}";
string referer = "https://agentseller.temu.com/goods/edit?from=platform&productId=" + productId + "&taskUid=" + taskUid;
return KJDHttpResponse.PostResponse2(shop, url, body, referer);
}
//申请修改 SKU分类和包装清单 体积与重量 商品名称
//{"bizIdType":1,"bizIds":[8942170367],"productEditItems":[{"editItem":4,"editAdvice":"12345"},{"editItem":8,"editAdvice":"54321"},{"editItem":1,"editAdvice":"33333"}]}
//string body = @"{""bizIdType"":1,""bizIds"":[8942170367],""productEditItems"":[{""editItem"":4,""editAdvice"":""12345""},{""editItem"":8,""editAdvice"":""54321""},{""editItem"":1,""editAdvice"":""33333""}]}";
//HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://agentseller.temu.com/lich-mms/audit/edit/task/product/batchAdd");
//request.Referer = "https://agentseller.temu.com/goods/list";
/// <summary>
/// 请求修改包装规格尺寸与SKU分类数量
/// </summary>
/// <param name="shop"></param>
/// <param name="productId"></param>
/// <returns></returns>
private string editPriceProductSizeAndNumberBatchAdd(ShopLoginInfo shop, string productId)
{
string url = "https://agentseller.temu.com/lich-mms/audit/edit/task/product/batchAdd";
string body = @"{""bizIdType"":1,""bizIds"":[" + productId + @"],""productEditItems"":[{""editItem"":4,""editAdvice"":""优化""},{""editItem"":8,""editAdvice"":""优化""}]}";
string referer = "https://agentseller.temu.com/goods/list?productId=" + productId;
return KJDHttpResponse.PostResponse2(shop, url, body, referer);
}
private string editPriceProductSizeAndNumberTaskQuery(ShopLoginInfo shop, string productId)
{
string url = "https://agentseller.temu.com/lich-mms/audit/edit/task/product/pageQuery";
string body = @"{""page"":1,""pageSize"":10,""editTaskAggStatuses"":[1],""productIdList"":[" + productId + "]}";
string referer = "https://agentseller.temu.com/goods/list";
return KJDHttpResponse.PostResponse2(shop, url, body, referer);
}
private string editPriceProductQuery(ShopLoginInfo shop, string prodId, string taskUid)
{
string url = "https://agentseller.temu.com/visage-agent-seller/product/query";
string body = @"{""productId"":" + prodId + @",""productEditTaskUid"":""" + taskUid + @"""}";
string refere = "https://agentseller.temu.com/goods/edit?from=platform&productId=" + prodId + "&taskUid=" + taskUid;
return KJDHttpResponse.PostResponse2(shop, url, body, refere);
}
private string editPriceProductSizeAndNumber(ShopLoginInfo shop, string taskUid, string productId, string data)
{
string url = "https://agentseller.temu.com/visage-agent-seller/product/edit/task/reply";
//string body = @"{""productId"":4432690492,""taskUid"":""8de73095-733e-4cdf-8fbd-3ddd8d9dff18"",""taskVersion"":0,""refuseEdit"":false,""productName"":""男士轻便 EVA 拖鞋,带钩环后跟带 ,舒适的露趾拖鞋,适合室内和室外使用,家居拖鞋,易于使用的魔鬼毡扣带扣,洞洞鞋,家居拖鞋,带钩环扣件,适合室内和室外使用,带扣凉鞋,后厨工专用鞋简约款两用,适合室内/室外使用,春夏凉鞋,EVA 拖鞋,适合19个不同的搭配风格""}";
string body = ""; //@"{""productId"":" + productId + @",""taskUid"":""" + taskUid + @""",""taskVersion"":0,""refuseEdit"":false,""productName"":""" + productNewName + @"""}";
body = data;
string referer = "https://agentseller.temu.com/goods/edit?from=platform&productId=" + productId + "&taskUid=" + taskUid;
return KJDHttpResponse.PostResponse2(shop, url, body, referer);
}
Bitmap defaultBitmap = new Bitmap(80, 80);
void ShowDgvImg()
{
Task.Run(() =>
{
foreach (DataGridViewRow row in this.dgvPriceCheck.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(() =>
{
if (dgvPriceCheck.Rows.Contains(row))
row.Cells["colProductSkcPic"].Value = image;
}));
}
catch
{
}
}
});
}
private void dgvPriceCheck_Scroll(object sender, ScrollEventArgs e)
{
this.ShowDgvImg();
}
private void btnRestoreProdName_Click(object sender, EventArgs e)
{
var products = this.dgvPriceCheck.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true)
.Select(r => r.Cells["colProductId"].Value.ParseToString());
var prices = this.lstCheckPriceInfo.Where(p => products.Contains(p.productId.ParseToString())).ToList();
if (prices.Count == 0)
{
BaseMsgForm.ShowError("未选择商品");
return;
}
this.statusBar.lblTaskStatus.Text = "正在批量还原标题";
this.pbLoading.Visible = true;
Task.Run(() =>
{
foreach (var price in prices)
{
var rows = this.dgvPriceCheck.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colProductId"].Value.ParseToString() == price.productId.ParseToString()).ToList();
var shop = lstAdminShopInfo.FirstOrDefault(s => s.ShopId == price.supplierId.ParseToString());
if (shop == null)
continue;
if (shop.LoginStatus2 != "国际版在线")
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "店铺掉线";
}));
continue;
}
var pName = price.productName;
if (CheckContainsWords(pName))
{
}
else
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "标题没有可还原的关键字";
}));
continue;
}
var html = editPriceProductNameBatchAdd(shop, price.productId.ParseToString());
//{"success":true,"errorCode":1000000,"errorMsg":null,"result":{"handleFailedList":[{"failedBizId":4432690492,"failedReason":"This product has pending or in-progress modification tasks, cannot initiate again"}],"addFailedList":[{"failedBizId":4432690492,"failedReason":"This product has pending or in-progress modification tasks, cannot initiate again","failedReasonType":8}],"successBizId2TaskUidMap":{}}}
if (html.Contains("This product has pending or in-progress modification tasks"))
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "已提交过修改任务";
}));
continue;
}
if (!html.Contains("\"success\":true"))
{
if (html.Contains("登录过期") || html.Contains("Invalid Login State"))
{
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
Invoke(new Action(() =>
{
displayShopStatus(shop);
}));
}
string sErrMsg = BaseRegex.GetStringJson(ref html, "errorMsg").ParseToString();
if (string.IsNullOrEmpty(sErrMsg))
{
sErrMsg = BaseRegex.GetStringJson(ref html, "error_msg").ParseToString();
}
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "修改请求失败 " + sErrMsg;
}));
continue;
}
try
{
JObject jObj = JObject.Parse(html);
var item = jObj["result"]["successBizId2TaskUidMap"].LastOrDefault().LastOrDefault();
// 还原原始标题
var newPName = RestoreProductName(pName);
html = editPriceProductName(shop, item.ParseToString(), price.productId.ParseToString(), newPName);
Thread.Sleep(Randomx.GetId(25, 75));
if (html.Contains("\"success\":true"))
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "修改请求成功";
}));
}
else
{
if (html.Contains("登录过期") || html.Contains("Invalid Login State"))
{
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
Invoke(new Action(() =>
{
displayShopStatus(shop);
}));
}
string sErrMsg = BaseRegex.GetStringJson(ref html, "errorMsg").ParseToString();
if (string.IsNullOrEmpty(sErrMsg))
sErrMsg = BaseRegex.GetStringJson(ref html, "error_msg").ParseToString();
if (string.IsNullOrEmpty(sErrMsg))
sErrMsg = html;
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "修改请求失败 " + sErrMsg;
}));
continue;
}
}
catch (Exception ex)
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "修改请求失败 " + ex.Message;
}));
continue;
}
}
Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "批量还原标题完成";
this.pbLoading.Visible = false;
}));
});
}
private void btnRePrice_Click(object sender, EventArgs e)
{
var rows = this.dgvPriceCheck.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true).ToList();
if (rows.Count == 0)
{
BaseMsgForm.ShowError("未选择要重新报价的商品!");
return;
}
this.statusBar.lblTaskStatus.Text = "正在批量再次报价";
this.pbLoading.Visible = true;
Task.Run(() =>
{
foreach (var row in rows)
{
var orderId = row.Cells["colOrderId"].Value.ParseToString();
var shop = lstAdminShopInfo.FirstOrDefault(s => s.ShopId == row.Cells["colSupplierId"].Value.ParseToString());
if (shop == null)
continue;
this.rePrice(shop, orderId, row);
}
Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "批量再次报价完成";
this.pbLoading.Visible = false;
}));
});
}
private void btnMutliOk_Click(object sender, EventArgs e)
{
var rows = this.dgvPriceCheck.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true).ToList();
if (rows.Count == 0)
{
BaseMsgForm.ShowError("未选择要重新报价的商品!");
return;
}
this.statusBar.lblTaskStatus.Text = "正在批量同意报价";
this.pbLoading.Visible = true;
Task.Run(() =>
{
foreach (var row in rows)
{
var orderId = row.Cells["colOrderId"].Value.ParseToString();
var shop = lstAdminShopInfo.FirstOrDefault(s => s.ShopId == row.Cells["colSupplierId"].Value.ParseToString());
if (shop == null)
continue;
this.applyHighPrice(shop, orderId, row);
}
Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "批量同意报价完成";
this.pbLoading.Visible = false;
}));
});
}
private void btnMutliCancel_Click(object sender, EventArgs e)
{
var rows = this.dgvPriceCheck.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true).ToList();
if (rows.Count == 0)
{
BaseMsgForm.ShowError("未选择要重新报价的商品!");
return;
}
this.statusBar.lblTaskStatus.Text = "正在批量拒绝报价";
this.pbLoading.Visible = true;
Task.Run(() =>
{
foreach (var row in rows)
{
var orderId = row.Cells["colOrderId"].Value.ParseToString();
var shop = lstAdminShopInfo.FirstOrDefault(s => s.ShopId == row.Cells["colSupplierId"].Value.ParseToString());
if (shop == null)
continue;
this.cancelLowPrice(shop, orderId, row);
}
Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "批量拒绝报价完成";
this.pbLoading.Visible = false;
}));
});
}
private void btnStop_Click(object sender, EventArgs e)
{
if (cancellationTokenSource != null)
cancellationTokenSource.Cancel();
}
public List<TemuDBExtCodePriceInfo> GetServerExtCodePriceLst(List<string> extCodeList)
{
List<TemuDBExtCodePriceInfo> list = new List<TemuDBExtCodePriceInfo>();
for(int i = 0; i< extCodeList.Count; i++)
{
extCodeList[i] = extCodeList[i].Replace(",", "").Replace("'", "").Replace("\"", "");
}
var url = BaseClass.BuildObjString("price/get_price_list");
var data = UserLogin.GetSignaturex();
data += "&page=1";
data += "&page_size=200";
data += "&in_ext_code=" + string.Join(",", extCodeList);
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("\"code\":200"))
{
return list;
}
if (!html.Contains("data"))
return list;
var jArr = JObject.Parse(html)["data"];
if (jArr.Count() == 0)
return list;
return JsonHelper.DeserializeJsonToList<TemuDBExtCodePriceInfo>(jArr.ToString());
}
private void pnlMutliCancelWithTitleWrong_Click(object sender, EventArgs e)
{
var rows = this.dgvPriceCheck.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true).ToList();
if (rows.Count == 0)
{
BaseMsgForm.ShowError("未选择要重新报价的商品!");
return;
}
var productIds = rows.Select(r => r.Cells["colProductId"].Value.ParseToString()).Distinct().ToList();
this.statusBar.lblTaskStatus.Text = "正在批量作废";
this.pbLoading.Visible = true;
Task.Run(() =>
{
foreach (var prodId in productIds)
{
var row = rows.FirstOrDefault(r => r.Cells["colProductId"].Value.ParseToString() == prodId);
if (row == null)
continue;
var shop = lstAdminShopInfo.FirstOrDefault(s => s.ShopId == row.Cells["colSupplierId"].Value.ParseToString());
if (shop == null)
continue;
this.cancelTitleWrongPrice(shop, prodId);
}
Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "批量作废完成";
this.pbLoading.Visible = false;
}));
});
}
private void chkFilter_CheckedChanged(object sender, EventArgs e)
{
if (chkFilter.Checked == false)
{
foreach (DataGridViewRow row in dgvPriceCheck.Rows)
{
row.Visible = true;
}
}
else
{
foreach (DataGridViewRow row in dgvPriceCheck.Rows)
{
var pName = row.Cells["colProdName"].Value.ParseToString();
if (CheckContainsWords(pName))
{
}
else
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
}
}
}
}
bool MouseLeftButtonDown = false;
bool MouseLeftButtonDownCheck = false;
private void dgvPriceCheck_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
MouseLeftButtonDown = false;
}
}
private void dgvPriceCheck_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
MouseLeftButtonDown = true;
string headerText = dgvPriceCheck.Columns[e.ColumnIndex].HeaderText;
switch (headerText)
{
case "":
dgvPriceCheck.Rows[e.RowIndex].Cells["colCheck"].Value = MouseLeftButtonDownCheck =
!(bool)dgvPriceCheck.Rows[e.RowIndex].Cells["colCheck"].Value;
break;
default:
break;
}
}
}
private void dgvPriceCheck_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
MouseLeftButtonDown = false;
}
}
private void dgvPriceCheck_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
if (MouseLeftButtonDown)
{
if (dgvPriceCheck.Columns[e.ColumnIndex].Name == "colCheck") // 选择框文字为空
{
dgvPriceCheck.Rows[e.RowIndex].Cells["colCheck"].Value = MouseLeftButtonDownCheck;
}
}
}
private void dgvPriceCheck_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
{
if (IsShiftDown && e.Row.Visible)
{
e.Row.Cells["colCheck"].Value = e.Row.Selected;
}
}
bool IsShiftDown = false;
private void AdminProductPriceCheckForm_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Shift:
case Keys.ShiftKey:
case Keys.LShiftKey:
case Keys.RShiftKey:
IsShiftDown = true;
break;
}
}
private void AdminProductPriceCheckForm_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Shift:
case Keys.ShiftKey:
case Keys.LShiftKey:
case Keys.RShiftKey:
IsShiftDown = false;
break;
}
}
bool CheckContainsWords(string filterProdName)
{
return filterProdName != RestoreProductName(filterProdName);
}
string RestoreProductName(string pName)
{
string checkChineseName = pName.Replace("适合不同的搭配风格", "").Replace("个", "").Replace("适合不同的搭配场景", "");
bool containsChinese = Regex.IsMatch(checkChineseName, @"[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]");
string newPName = pName;
if (pName.EndsWith("适合不同的搭配风格") && pName.IndexOf("个") < 4 && pName.IndexOf("个") > 0)
{
var headword = pName.Substring(0, pName.IndexOf("个") + 1);
newPName = pName.Substring(pName.IndexOf("个") + "个".Length);
if (containsChinese)
newPName = newPName.Replace("适合不同的搭配风格", "适合" + headword + "不同的搭配风格");
else
newPName = newPName.Replace("适合不同的搭配风格", "Suitable for " + headword + " different matching styles").Trim();
}
if (pName.EndsWith("适合不同的搭配风格") && pName.IndexOf("pcs") < 4 && pName.IndexOf("pcs") > 0)
{
var headword = pName.Substring(0, pName.IndexOf("pcs"));
newPName = pName.Substring(pName.IndexOf("pcs") + "pcs".Length);
if (containsChinese)
newPName = newPName.Replace("适合不同的搭配风格", "适合" + headword + "不同的搭配风格");
else
newPName = newPName.Replace("适合不同的搭配风格", "Suitable for " + headword + " different matching styles").Trim();
}
return newPName;
}
private void btnRestoreSizeAndNumber_Click(object sender, EventArgs e)
{
var products = this.dgvPriceCheck.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true)
.Select(r => r.Cells["colProductId"].Value.ParseToString());
var prices = this.lstCheckPriceInfo.Where(p => products.Contains(p.productId.ParseToString())).ToList();
if (prices.Count == 0)
{
BaseMsgForm.ShowError("未选择商品");
return;
}
this.statusBar.lblTaskStatus.Text = "正在批量还原包装规格尺寸与SKU分类数量";
this.pbLoading.Visible = true;
Task.Run(() =>
{
foreach (var price in prices)
{
var rows = this.dgvPriceCheck.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colProductId"].Value.ParseToString() == price.productId.ParseToString()).ToList();
var shop = lstAdminShopInfo.FirstOrDefault(s => s.ShopId == price.supplierId.ParseToString());
if (shop == null)
continue;
if (shop.LoginStatus2 != "国际版在线")
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "店铺掉线";
}));
continue;
}
//var pName = price.productName;
if (checkRestoreSizeAndNumber(price))
{
}
else
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "无需还原包装规格尺寸与SKU分类数量";
}));
continue;
}
var taskUid = "";
var html = editPriceProductSizeAndNumberBatchAdd(shop, price.productId.ParseToString());
//{"success":true,"errorCode":1000000,"errorMsg":null,"result":{"handleFailedList":[{"failedBizId":4432690492,"failedReason":"This product has pending or in-progress modification tasks, cannot initiate again"}],"addFailedList":[{"failedBizId":4432690492,"failedReason":"This product has pending or in-progress modification tasks, cannot initiate again","failedReasonType":8}],"successBizId2TaskUidMap":{}}}
if (html.Contains("This product has pending or in-progress modification tasks"))
{
var taskHtml = editPriceProductSizeAndNumberTaskQuery(shop, price.productId.ParseToString());
taskUid = BaseRegex.GetStringJson(ref taskHtml, "taskUid");
if (string.IsNullOrEmpty(taskUid) || !taskHtml.Contains("\"productEditTaskItems\":[{\"editItem\":4,\"editAdvice\":\"优化\"},{\"editItem\":8,\"editAdvice\":\"优化\"}]"))
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "已提交过修改任务或商品有其他修改任务";
}));
continue;
}
}
if (!html.Contains("\"success\":true"))
{
if (html.Contains("登录过期") || html.Contains("Invalid Login State"))
{
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
Invoke(new Action(() =>
{
displayShopStatus(shop);
}));
}
string sErrMsg = BaseRegex.GetStringJson(ref html, "errorMsg").ParseToString();
if (string.IsNullOrEmpty(sErrMsg))
{
sErrMsg = BaseRegex.GetStringJson(ref html, "error_msg").ParseToString();
}
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "修改请求失败 " + sErrMsg;
}));
continue;
}
try
{
if (string.IsNullOrEmpty(taskUid))
{
JObject jObj = JObject.Parse(html);
taskUid = jObj["result"]["successBizId2TaskUidMap"].LastOrDefault().LastOrDefault().ParseToString();
}
}
catch (Exception ex)
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "修改请求失败 " + ex.Message;
}));
continue;
}
html = editPriceProductQuery(shop, price.productId.ParseToString(), taskUid);
if (html.Contains("This product has pending or in-progress modification tasks"))
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "已提交过修改任务";
}));
continue;
}
if (!html.Contains("\"success\":true"))
{
if (html.Contains("登录过期") || html.Contains("Invalid Login State"))
{
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
Invoke(new Action(() =>
{
displayShopStatus(shop);
}));
}
string sErrMsg = BaseRegex.GetStringJson(ref html, "errorMsg").ParseToString();
if (string.IsNullOrEmpty(sErrMsg))
{
sErrMsg = BaseRegex.GetStringJson(ref html, "error_msg").ParseToString();
}
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "修改请求失败 " + sErrMsg;
}));
continue;
}
try
{
//int len = Randomx.GetId(15, 31); //300
//int width = Randomx.GetId(10, 15); //200
//int height = Randomx.GetId(5, 10); //100
//int weight = Randomx.GetId(100, 200); //500000
//int numberOfPieces = Randomx.GetId(450, 601);// 单品数量
int len = Randomx.GetId(numLen1.Value.ParseToInt(), numLen2.Value.ParseToInt() + 1);
int width = Randomx.GetId(numWidth1.Value.ParseToInt(), Math.Min(len, numWidth2.Value.ParseToInt() + 1));
int height = Randomx.GetId(numHeight1.Value.ParseToInt(), Math.Min(width, numHeight2.Value.ParseToInt() + 1));
int weight = Randomx.GetId(numWeight1.Value.ParseToInt(), numWeight2.Value.ParseToInt() + 1);
int numberOfPieces = 1;
JObject obj = JObject.Parse(html);
var result = JsonHelper.SerializeObject(obj["result"]);
TemuDetailProductInfo prodInfo = JsonHelper.DeserializeJsonToObject<TemuDetailProductInfo>(result);
//JObject jPost = new JObject();
//jPost.Add("productId", price.productId);
//jPost.Add("taskUid", taskUid.ParseToString());
//jPost.Add("taskVersion", 0);
//jPost.Add("refuseEdit", false);
//var jProductSkcMainReqs = new JArray();
//jPost.Add("productSkcReqs", jProductSkcMainReqs);
//JObject jProductSkcMainReq = new JObject();
//jProductSkcMainReqs.Add(jProductSkcMainReq);
//var jMainProductSkuSpecReqs = new JArray();
//jProductSkcMainReq.Add("mainProductSkuSpecReqs", jMainProductSkuSpecReqs);
//jMainProductSkuSpecReqs.Add(new JObject() {
// new JProperty("parentSpecId",0),
// new JProperty("parentSpecName",""),
// new JProperty("specId",0),
// new JProperty("specName",""),
//});
var jStr = "{";
jStr += "\r\n\"productId\":" + price.productId + ",";
jStr += "\r\n\"taskUid\":\"" + taskUid.ParseToString() + "\",";
jStr += "\r\n\"taskVersion\":" + 0 + ",";
jStr += "\r\n\"refuseEdit\":false,";
jStr += "\r\n\"productSkcReqs\":[{";
jStr += " \r\n\"mainProductSkuSpecReqs\":[{".Trim();
jStr += " \r\n\"parentSpecId\":0,".Trim();
jStr += " \r\n\"parentSpecName\":\"\",".Trim();
jStr += " \r\n\"specId\":0,".Trim();
jStr += " \r\n\"specName\":\"\"".Trim();
jStr += " \r\n}],".Trim();
jStr += " \r\n\"productSkuReqs\":[".Trim();
foreach (var sku in prodInfo.productSkcList.FirstOrDefault().productSkuList)
{
jStr += " \r\n{".Trim();
//productSkuSpecReqs
jStr += " \r\n\"productSkuSpecReqs\":[".Trim();
foreach (var spec in sku.productSkuSpecList)
{
jStr += "{";
jStr += "\"parentSpecId\":" + spec.parentSpecId + ",";
jStr += "\"parentSpecName\":\"" + spec.parentSpecName + "\",";
jStr += "\"specId\":" + spec.specId + ",";
jStr += "\"specName\":\"" + spec.specName + "\",";
var specProp = prodInfo.productSpecPropertyVOS.FirstOrDefault(p => p.parentSpecId == spec.parentSpecId);
if (!string.IsNullOrEmpty(specProp?.valueGroupId.ParseToString()))
jStr += "\"groupId\":" + specProp?.valueGroupId.ParseToString() + ",";
if (!string.IsNullOrEmpty(specProp?.vid.ParseToString()))
jStr += "\"vid\":" + specProp?.vid.ParseToString() + ",";
jStr = jStr.TrimEnd(',');
jStr += "},";
}
jStr = jStr.TrimEnd(',');
jStr += " \r\n],".Trim();
//productSkuWhExtAttrReq
jStr += "\"productSkuWhExtAttrReq\":{";
jStr += " \"productSkuWeightReq\":{\"value\":" + (weight * 1000) + "},";
jStr += " \"productSkuVolumeReq\":{";
jStr += " \"len\":" + (len * 10) + ",";
jStr += " \"width\":" + (width * 10) + ",";
jStr += " \"height\":" + (height * 10);
jStr += " }";
jStr += "},";
//productSkuMultiPackReq
jStr += "\"productSkuMultiPackReq\":{";
jStr += " \"skuClassification\":1,";
jStr += " \"numberOfPieces\":1,";
jStr += " \"pieceUnitCode\":" + Math.Max(1, sku.productSkuMultiPack.pieceUnitCode.ParseToInt()) + ",";
jStr += " \"productSkuNetContentReq\":{";
jStr += " },";
jStr += " \"individuallyPacked\":-1";
jStr += "},";
//productSkuAccessoriesReq
jStr += "\"productSkuAccessoriesReq\":{";
jStr += "\"productSkuAccessories\":[";
jStr += "]";
jStr += "}";
jStr += " \r\n},".Trim();
}
jStr = jStr.TrimEnd(',');
jStr += " \r\n]".Trim();
jStr += "\r\n}]";
jStr += "\r\n}";
var jStrObj = JObject.Parse(jStr);
jStr = JsonHelper.SerializeObject(jStrObj);
html = editPriceProductSizeAndNumber(shop, taskUid.ParseToString(), price.productId.ParseToString(), jStr);
Thread.Sleep(Randomx.GetId(25, 75));
if (html.Contains("\"success\":true"))
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "修改请求成功";
}));
}
else
{
if (html.Contains("登录过期") || html.Contains("Invalid Login State"))
{
AdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
Invoke(new Action(() =>
{
displayShopStatus(shop);
}));
}
string sErrMsg = BaseRegex.GetStringJson(ref html, "errorMsg").ParseToString();
if (string.IsNullOrEmpty(sErrMsg))
sErrMsg = BaseRegex.GetStringJson(ref html, "error_msg").ParseToString();
if (string.IsNullOrEmpty(sErrMsg))
sErrMsg = html;
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "修改请求失败 " + sErrMsg;
}));
continue;
}
}
catch (Exception ex)
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "修改请求失败 " + ex.Message;
}));
continue;
}
}
Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "批量还原尺寸与数量完成";
this.pbLoading.Visible = false;
}));
});
}
/// <summary>
/// 检测是否需要重置尺寸和sku单品数量
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
bool checkRestoreSizeAndNumber(TemuCheckPriceInfo info)
{
//最长边:60 - 100 cm//生成时需转换为mm
//次长边:60 - 90 cm//生成时需转换为mm
//最短边:50 - 80 cm//生成时需转换为mm
//重量:80000 - 99999g //生成时需转换为mg
var skc = info.skcList.FirstOrDefault();
//长宽高超50且重量大于1000克认为是有意改大了参数需要还原
//if (skc.skuList.Any(s => (s.len >= 45 * 10 || s.width >= 45 * 10 || s.height >= 45 * 10) && s.weight >= 1000 * 1000))
// return true;
if (skc.skuList.Any(s => (s.len >= numJudgeLen.Value * 10 || s.width >= numJudgeLen.Value * 10 || s.height >= numJudgeLen.Value * 10) && s.weight >= numJudgeWeight.Value * 1000))
return true;
return false;
}
private void btnClose_Click(object sender, EventArgs e)
{
this.pnlSpecDetail.Visible = false;
}
private void btnResetExtCode_Click(object sender, EventArgs e)
{
this.txtExtCode.Text = this.txtSkcId.Text = "";
}
}
public class PriceCheckConfig
{
public string SearchShopId { get; set; } = "";
public string SearchShopName { get; set; } = "";
public string SearchNotes { get; set; } = "";
/// <summary>
/// 价格不合适时,重新设置价格降价金额(人民币)
/// </summary>
public string PriceDown { get; set; } = "0.1";
public bool SearchAllShop { get; set; } = true;
}
}