Files
KJD/TEMUKJD/KJDForms/AdminForms/AdminProductPriceCheckForm.cs
T
2025-12-26 09:53:29 +08:00

2606 lines
134 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.BLL;
using TemuKJD.Extension;
using TemuKJD.BaseForms;
using TemuKJD.ToolForms;
using TemuKJD.KJDForms.ShopForms;
using Work;
using TemuKJD.KJDForms.JITForms;
using AllBase.Helper;
using NaiBa.Util;
namespace TemuKJD.KJDForms.AdminForms
{
public partial class AdminProductPriceCheckForm : BaseForm
{
public EnumClientMode ClientMode { get; set; } = EnumClientMode.Admin;
CheckBox chkSelectAll;
PriceCheckConfig priceCheckConfig = null;
ConcurrentList<PriceCheckFilterConfig> lstPriceCheckFilterConfig = new ConcurrentList<PriceCheckFilterConfig>();
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
public ConcurrentList<ShopLoginInfo> lstAdminShopInfo { get; set; } = new ConcurrentList<ShopLoginInfo>();
public ConcurrentList<TemuForChainProductInfo> lstCheckPriceInfo = new ConcurrentList<TemuForChainProductInfo>();
public ConcurrentList<CateSizeWeightConfig> lstCateSizeWeightConfig = new ConcurrentList<CateSizeWeightConfig>();
public AdminProductPriceCheckForm()
{
InitializeComponent();
}
private void AdminProductPriceCheckForm_Load(object sender, EventArgs e)
{
lstPriceCheckFilterConfig = NaiBa.Util.Helper.ConfigHelper.LoadConfig<ConcurrentList<PriceCheckFilterConfig>>("price_check_filter_config");
if (lstPriceCheckFilterConfig == null)
lstPriceCheckFilterConfig = new ConcurrentList<PriceCheckFilterConfig>();
//this.dgvShop.AddSelectorColumn("colSelect");
chkSelectAll = dgvShop.Columns["colSelect"].AddHeaderCheckBox(HorizontalAlignment.Center, 0, 0, null, null, false, null, true);
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
this.dgvPriceCheck.AddSelectorColumn("colCheck");
var chkSelectExtCode = this.dgvExtCode.AddSelectorColumn("colSelectExtCode");
chkSelectExtCode.CheckedChanged += ChkSelectExtCode_CheckedChanged;
this.dgvPriceCheck.AddMergeColumnHeader(new List<string>() { "colOk", "colCancel" }, "同意/拒绝报价");
this.dgvPriceCheck.AddImgColumn("colProductSkcPic", "colImgUrl");
this.colJitStatus.Visible = false;
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;
}
if (BaseClass.SaLevel == 1 && ClientMode == EnumClientMode.Admin)
{
//chkForceRestoreTitle.Visible = true;
}
if (ClientMode != EnumClientMode.Admin)
{
ucSplitPage1.Visible = false;
ucSplitPage1.Visible = false;
chkSearchAllShop.Visible = false;
btnSearchPrice3.Visible = false;
btnStop.Location = btnSearchPrice3.Location;
btnStop.Size = btnSearchPrice3.Size;
}
if (ClientMode == EnumClientMode.ClientJit)
{
this.colJitStatus.Visible = true;
lblJudgeLen.Text = "列表中仅显示需要还原商品";
numJudgeLen.Visible = false;
lblJudgeWeight.Visible = false;
numJudgeWeight.Visible = false;
pnlRestoreSizeAndNumber.Visible = false;
btnRestoreSizeAndNumber.Text = "还原核价设置";
this.numJudgeLen.Value = 26;
this.numJudgeWeight.Value = 201;
this.numLen1.Value = 25;
this.numLen2.Value = 25;
this.numWidth1.Value = 20;
this.numWidth2.Value = 20;
this.numHeight1.Value = 8;
this.numHeight2.Value = 8;
this.numWeight1.Value = 200;
this.numWeight2.Value = 200;
}
if (ClientMode == EnumClientMode.ClientJit)
priceCheckConfig = NaiBa.Util.Helper.ConfigHelper.LoadConfig<PriceCheckConfig>("client_jit_price_check_config");
else if (ClientMode == EnumClientMode.Client)
priceCheckConfig = NaiBa.Util.Helper.ConfigHelper.LoadConfig<PriceCheckConfig>("client_price_check_config");
else
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 chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
if (!chkSelectAll.Checked)
{
foreach (DataGridViewRow row in dgvShop.Rows)
{
row.Cells["colSelect"].Value = false;
}
}
else
{
var list = new List<ShopLoginInfo>();
if (ClientMode == EnumClientMode.Admin)
lstAdminShopInfo.Where(s => s.LoginStatus2 == "国际版在线").ToList();
else if (ClientMode == EnumClientMode.Client)
list = GlobalConfig.ShopLoginList.Where(s => s.LoginStatus2 == "国际版在线").ToList();
else if (ClientMode == EnumClientMode.ClientJit)
list = GlobalConfig.ShopLoginList.Where(s => s.LoginStatus2 == "国际版在线" && s.jit_expire_time >= DateTime.Now.Date).ToList();
foreach (DataGridViewRow row in dgvShop.Rows)
{
if (list.Any(l => l.ShopId == row.Cells["colShopId"]?.Value?.ToString()))
row.Cells["colSelect"].Value = true;
}
}
}
private void ChkSelectExtCode_CheckedChanged(object sender, EventArgs e)
{
FilterRows();
}
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;
if (ClientMode == EnumClientMode.ClientJit)
NaiBa.Util.Helper.ConfigHelper.SaveConfig("client_jit_price_check_config", priceCheckConfig);
else if (ClientMode == EnumClientMode.Client)
NaiBa.Util.Helper.ConfigHelper.SaveConfig("client_price_check_config", priceCheckConfig);
else
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;
if (ClientMode != EnumClientMode.Admin)
{
RefreshShop();
}
else
{
this.pbShopLoading.Visible = true;
SearchShop(this.ucSplitPage1.CurrentPage);
}
}
}
private void btnRefreshShop_Click(object sender, EventArgs e)
{
if (ClientMode != EnumClientMode.Admin)
{
RefreshShop();
}
else
{
if (this.ucSplitPage1.CurrentPage != 1)
this.ucSplitPage1.CurrentPage = 1;
else
SearchShop(1);
}
}
private void RefreshShop()
{
// 店铺Id
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
var shopLst = GlobalConfig.ShopLoginList.ToList();
if (!string.IsNullOrWhiteSpace(txtShopId.Text.Trim()))
{
shopLst = shopLst.Where(s => ("," + txtShopId.Text.Trim() + ",").Contains("," + s.ShopId + ",") || s.ShopId.Contains(txtShopId.Text.Trim())).ToList();
}
if (!string.IsNullOrWhiteSpace(txtShopName.Text.Trim()))
{
shopLst = shopLst.Where(s => ("," + txtShopName.Text.Trim() + ",").Contains("," + s.ShopAccount + ",") || s.ShopAccount.ToLower().Contains(txtShopName.Text.Trim().ToLower())).ToList();
}
if (!string.IsNullOrWhiteSpace(txtNotes.Text.Trim()))
{
shopLst = shopLst.Where(s => ("," + txtNotes.Text.Trim() + ",").Contains("," + s.Notes + ",") || s.Notes.ToLower().Contains(txtNotes.Text.Trim().ToLower())).ToList();
}
// 获取被删除的店铺
List<DataGridViewRow> dgvRowList = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> !shopLst.Any(s => s.ShopId == row.Cells["colShopId"]?.Value?.ToString())).ToList();
// 更新被删除的店铺列表
foreach (var row in dgvRowList)
{
dgvShop.Rows.Remove(row);
}
// 绑定其他店铺(含新导入的店铺)
foreach (ShopLoginInfo shopEntity in shopLst)
{
if (!string.IsNullOrEmpty(shopEntity.ShopId))
BindShop(shopEntity, selectIds);
}
}
private void BindShop(ShopLoginInfo shopEntity, List<string> selectShopId = null)
{
if (shopEntity == null)
return;
if (selectShopId == null)
selectShopId = new List<string>();
bool canUse = shopEntity.LoginStatus2 == "国际版在线";
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId);
if (row == null)
{
int id = this.dgvShop.Rows.Add(
selectShopId.Contains(shopEntity.ShopId) && canUse,
shopEntity.UserName,
shopEntity.LoginName,
shopEntity.ShopId,
shopEntity.ShopAccount,
shopEntity.Notes,
canUse ? "在线" : "掉线",
shopEntity.jit_expire_time >= DateTime.Now.Date ? "可用" : "失效",
canUse,
string.Empty
);
displayShopStatus(shopEntity);
}
else
{
row.Cells["colSelect"].Value = selectShopId.Contains(shopEntity.ShopId) && canUse;
row.Cells["colLoginName"].Value = shopEntity.LoginName;
row.Cells["colShopName"].Value = shopEntity.ShopAccount;
row.Cells["colShopNotes"].Value = shopEntity.Notes;
row.Cells["colLoginStatus"].Value = canUse ? "在线" : "掉线";
row.Cells["colJitStatus"].Value = shopEntity.jit_expire_time >= DateTime.Now.Date ? "可用" : "失效";
displayShopStatus(shopEntity);
}
}
private void ucSplitPage1_PageChange(object obj)
{
SearchShop(this.ucSplitPage1.CurrentPage);
}
public void SearchShop(int page)
{
List<string> userShopIdList = dgvShop.Rows.Cast<DataGridViewRow>()
.Where(r => r.Cells["colSelect"].Value.ParseToBool())
.Select(r => r.Cells["colShopId"].Value.ParseToString() + r.Cells["colUser"].Value.ParseToString()).ToList();
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(
userShopIdList.Contains(shop.ShopId + shop.UserName),
shop.UserName,
shop.LoginName,
shop.ShopId,
shop.ShopAccount,
shop.Notes,
canUse ? "在线" : "掉线",
"Jit",
canUse,
string.Empty
);
displayShopStatus(shop);
}));
}
Invoke(new Action(() =>
{
this.pbShopLoading.Visible = false;
}));
});
}
public List<ShopLoginInfo> AdminGetServerShopLst(out int pageCount, int page = 1, int pageSize = 50)
{
List<ShopLoginInfo> list = new List<ShopLoginInfo>();
pageCount = 1;
var url = BaseClass.BuildObjString("shop/admin_get_shop_list");
if (BaseClass.SaLevel > 1 && !chkSearchAllShop.Checked)
url = BaseClass.BuildObjString("shop/sub_sa_get_select_prod_shop");
var data = UserLogin.GetSignaturex() +
"&page=" + page +
"&page_size=" + pageSize +
"&shop_ids=" + txtShopId.Text.Trim().Trim(',') +
"&shop_names=" + txtShopName.Text.Trim().Trim(',') +
"&search_notes=" + txtNotes.Text.Trim().Trim(',');
if (BaseClass.SaLevel > 1 && !chkSearchAllShop.Checked)
data += "&operate_sub_sa_name=" + BaseClass.UserName;
var html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html)
|| !html.Contains("shop_id") || !html.Contains("shop_account") || !html.Contains("login_pass"))
{
return list;
}
int count = BaseRegex.GetIntJson(ref html, "count");
pageCount = Math.Ceiling(1.0 * count / pageSize).ParseToInt();
pageCount = Math.Max(pageCount, 1);
return ShopBLL.DeserializationShop(html);
}
private void btnEmpty_Click(object sender, EventArgs e)
{
txtNotes.Text = txtShopId.Text = txtShopName.Text = "";
}
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;
}
if (ClientMode == EnumClientMode.ClientJit)
{
var jitRow = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop?.ShopId);
jitRow.Cells["colJitStatus"].Style.ForeColor = JitShopActiveForm.GetJitStatusStyleColor(shop);
}
}
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
string headerText = dgvShop.Columns[e.ColumnIndex].HeaderText;
string loginName = dgvShop.Rows[e.RowIndex].Cells["colLoginName"].Value.ParseToString();
string accountId = dgvShop.Rows[e.RowIndex].Cells["colShopId"].Value.ParseToString();
ShopLoginInfo shop;
if (ClientMode != EnumClientMode.Admin)
shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == accountId);
else
shop = lstAdminShopInfo.FirstOrDefault(s => s.LoginName == loginName && s.ShopId == accountId);
switch (headerText)
{
case "登录":
case "状态":
{
//AdminShopLoginForm shopLoginForm = new AdminShopLoginForm(shop);
//shopLoginForm.openType = EnumOpenType.login;
//shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
//shopLoginForm.ShowDialog();
if (ClientMode == EnumClientMode.Admin)
{
this.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus2 == "国际版在线")
{
AdminShopLoginForm adminLoginForm = new AdminShopLoginForm(shop);
adminLoginForm.openType = EnumOpenType.manage;
adminLoginForm.WindowState = FormWindowState.Maximized;
adminLoginForm.InitUrl = "https://agentseller.temu.com";
adminLoginForm.Show();
}
else
{
AdminShopLoginForm shopLoginForm = new AdminShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
shopLoginForm.ShowDialog();
}
}
else
{
this.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus2 == "国际版在线")
{
ShopLoginForm loginForm = new ShopLoginForm(shop);
loginForm.openType = EnumOpenType.manage;
loginForm.WindowState = FormWindowState.Maximized;
loginForm.InitUrl = "https://agentseller.temu.com";
loginForm.Show();
}
else
{
ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
shopLoginForm.ShowDialog();
}
}
}
break;
case "":
if (ClientMode == EnumClientMode.ClientJit)
{
if (shop != null && shop.jit_expire_time > DateTime.Now.Date)
{
if (shop.LoginStatus2 != "国际版在线")
{
dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value = false;
BaseMsgForm.ShowError("店铺未登录", "JIT商品核价-操作失败");
return;
}
}
else
{
dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value = false;
BaseMsgForm.ShowError("JIT卡密过期或未开通", "JIT商品核价-操作失败");
return;
}
}
dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value = !(bool)dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value;
break;
default:
break;
}
}
private void shopLoginForm_SaveComplete(object obj)
{
//SearchShop(this.ucSplitPage1.CurrentPage);
var shop = obj as ShopLoginInfo;
if (shop == null)
return;
displayShopStatus(shop);
}
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(s => s.ShopId == accountId);
if (ClientMode != EnumClientMode.Admin)
shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == accountId);
switch (headerText)
{
case "规格名称":
if (ClientMode != EnumClientMode.Admin)
{
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"))
{
this.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"))
{
this.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;
TemuForChainProductInfo 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"))
{
this.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"))
{
this.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.btnMutliOk.Visible = true;
this.btnMutliCancel.Visible = true;
this.pnlMutliCancelWithTitleWrong.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.pnlDetailOperate1.Visible = false;
this.btnMutliOk.Visible = false;
this.btnMutliCancel.Visible = false;
this.pnlMutliCancelWithTitleWrong.Visible = true;
this.pnlMutliCancelWithTitleWrong.Location = btnMutliOk.Location;
this.dgvPriceCheck.Columns["colOk"].Visible = false;
this.dgvPriceCheck.Columns["colCancel"].Visible = false;
this.dgvPriceCheck.Columns["colCancelWithTitleWrong"].Visible = true;
SearchPrice("待创建首单");
//SearchPrice("已发布到站点");
}
private void btnSearchPrice3_Click(object sender, EventArgs e)
{
this.pnlDetailOperate1.Visible = false;
this.btnMutliOk.Visible = false;
this.btnMutliCancel.Visible = false;
this.pnlMutliCancelWithTitleWrong.Visible = false;
this.pnlMutliCancelWithTitleWrong.Location = btnMutliOk.Location;
this.dgvPriceCheck.Columns["colOk"].Visible = false;
this.dgvPriceCheck.Columns["colCancel"].Visible = false;
this.dgvPriceCheck.Columns["colCancelWithTitleWrong"].Visible = false;
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();
List<ShopLoginInfo> shops = new List<ShopLoginInfo>();
if (ClientMode == EnumClientMode.Admin)
shops = this.lstAdminShopInfo.Where(s => selectShopIdLst.Contains(s.ShopId)).ToList();
else
shops = GlobalConfig.ShopLoginList.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.dgvPriceCheck.Rows.Clear();
this.dgvExtCode.Rows.Clear();
this.lstCheckPriceInfo.Clear();
this.chkFilterTitle.Checked = false;
this.chkFilterSize.Checked = false;
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.FirstOrDefault(s => shopId == s.ShopId);
if (ClientMode != EnumClientMode.Admin)
shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => shopId == s.ShopId);
if (shop == null)
continue;
this.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);
commonSleep();
if (searchRst.Contains("登录过期") || searchRst.Contains("Invalid Login State"))
{
this.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> extCodeTmpLst = new List<string>();
List<string> spuIdLst = new List<string>();
List<TemuForChainProductInfo> checkPriceInfoTmpLst = new List<TemuForChainProductInfo>();
foreach (var item in jArr)
{
var jStr = JsonHelper.SerializeObject(item);
TemuForChainProductInfo priceInfo = JsonHelper.DeserializeJsonToObject<TemuForChainProductInfo>(jStr);
lstCheckPriceInfo.Add(priceInfo);
checkPriceInfoTmpLst.Add(priceInfo);
extCodeTmpLst.Add(priceInfo.skcList.FirstOrDefault()?.extCode);
spuIdLst.Add(priceInfo.productId.ParseToString());
}
// 获取货号价格
List<TemuDBExtCodePriceInfo> extCodePriceList = GetServerExtCodePriceLst(extCodeTmpLst.Distinct().ToList());
// 获取产品数据库中的成本价格
List<DBProdDraftIdMapUpSpuIdInfo> upProdList = GetUpSpuIdLst(spuIdLst);
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());
//Thread.Sleep(Randomx.GetId(20, 50));
//if (orderPriceRst.Contains("登录过期") || orderPriceRst.Contains("Invalid Login State"))
//{
// this.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 += "¥";
suggestSupplyPrice = "¥" + (reviewInfo.suggestSupplyPrice.ParseToDecimal() / 100).ToString("0.00");
}
// 计算商品进价
var reviewExtCode = priceInfo.skcList.FirstOrDefault()?.extCode;
var extCodePrice = extCodePriceList.FirstOrDefault(p => reviewExtCode == p.ext_code);
var upSpuIdPrice = upProdList.FirstOrDefault(p => priceInfo.productId == p.draft_id);
var original_price = extCodePrice?.original_price / 100m;
if (upSpuIdPrice?.cost_price > 0)
original_price = upSpuIdPrice?.cost_price;
Invoke(new Action(() =>
{
int rowId = this.dgvPriceCheck.Rows.Add(
false,
totalProdIndex,
reviewInfo.priceOrderId,
priceInfo.supplierId,
priceInfo.supplierName,
imgUrl,
DataGridViewExtension.defaultBitmap,
priceInfo.productId,
priceInfo.skcList.FirstOrDefault()?.skcId,
priceInfo.productName,
skuName,
reviewExtCode,
original_price, //extCodePrice == null ? "-" : (extCodePrice.original_price / 100m).ParseToString(),
reviewInfo.productSkuList.FirstOrDefault()?.supplierPriceValue / 100m, //reviewInfo.supplyPrice / 100m,(这个数值temu接口返回的是错的,改价不会改变) //priceInfo.supplierPrice // sku不同价的会被分成多个review,priceInfo此时为价格范围
reviewInfo.suggestSupplyPrice / 100m, //suggestSupplyPrice.ParseToDecimal(),//核价 //reviewInfo.suggestSupplyPrice == null ? "-" : reviewInfo.suggestSupplyPrice.ParseToString(),
"", //新报价
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 (dgvPriceCheck.Rows[rowId].Cells["colExtCodePrice"].Value.ParseToString().IsNullOrEmpty())
// dgvPriceCheck.Rows[rowId].Cells["colExtCodePrice"].Value = "-";
if (CheckRestoreTitleWords(priceInfo.productName))
{
dgvPriceCheck.Rows[rowId].Cells["colProdName"].Style.ForeColor = Color.Red;
}
else
{
dgvPriceCheck.Rows[rowId].Cells["colProdName"].Style.ForeColor = dgvPriceCheck.DefaultCellStyle.ForeColor;
if (chkFilterTitle.Checked)
dgvPriceCheck.Rows[rowId].Visible = false;
}
if (checkRestoreSizeAndNumber(priceInfo))
{
dgvPriceCheck.Rows[rowId].Cells["colSkuName"].Style.ForeColor = Color.Red;
}
else
{
dgvPriceCheck.Rows[rowId].Cells["colSkuName"].Style.ForeColor = dgvPriceCheck.DefaultCellStyle.ForeColor;
}
if (totalProdIndex % 2 == 1)
dgvPriceCheck.Rows[rowId].DefaultCellStyle.BackColor = Color.White;
else
dgvPriceCheck.Rows[rowId].DefaultCellStyle.BackColor = Color.WhiteSmoke;
}));
}
}
}
catch (Exception ex)
{
BaseMsgForm.ShowError("查询商品失败 " + ex.Message);
break;
}
}
}
}
Invoke(new Action(() => {
var extCodeLst = this.dgvPriceCheck.Rows.Cast<DataGridViewRow>()
.Select(r => r.Cells["colExtCode"].Value.ParseToString())
.Where(s => !string.IsNullOrEmpty(s.Trim('-'))).Distinct().ToList();
this.dgvExtCode.Rows.Clear();
foreach (var ext in extCodeLst)
{
var filterConfig = lstPriceCheckFilterConfig.FirstOrDefault(c => c.ExtCode == ext);
var pos = this.dgvExtCode.Rows.Add(
false,
ext,
filterConfig == null ? "" : GetConfigDesStr(filterConfig.Symbol, filterConfig.Price1, filterConfig.Price2)
);
var row = dgvExtCode.Rows[pos];
if ((filterConfig?.Symbol).ParseToString().StartsWith("≥"))
{
row.Cells["colFilterRule"].Style.ForeColor = Color.Green;
}
else if ((filterConfig?.Symbol).ParseToString().StartsWith("≤"))
{
row.Cells["colFilterRule"].Style.ForeColor = Color.Red;
}
else
{
row.Cells["colFilterRule"].Style.ForeColor = Color.Black;
}
}
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],";
else if (type == "已发布到站点")
body += "\"secondarySelectStatusList\":[12],\"supplierTodoTypeList\":[],";
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 HttpResponseBLL.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 HttpResponseBLL.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 HttpResponseBLL.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 HttpResponseBLL.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 HttpResponseBLL.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 HttpResponseBLL.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 HttpResponseBLL.PostResponse2(shop, url, body, referer);
}
private string editPriceProductNameAndEnNameBatchAdd(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"":""优化""},{""editItem"":2,""editAdvice"":""优化""}]}";
string referer = "https://agentseller.temu.com/goods/list?productId=" + productId;
return HttpResponseBLL.PostResponse2(shop, url, body, referer);
}
private string editPriceProductEnNameBatchAdd(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"":2,""editAdvice"":""优化""}]}";
string referer = "https://agentseller.temu.com/goods/list?productId=" + productId;
return HttpResponseBLL.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 HttpResponseBLL.PostResponse2(shop, url, body, referer);
}
private string editPriceProductNameAndEnName(ShopLoginInfo shop, string taskUid, string productId, string productNewName)
{
string url = "https://agentseller.temu.com/visage-agent-seller/product/edit/task/reply";
string body = "";
body = @"{""productId"":" + productId + @",""taskUid"":""" + taskUid + @""",""taskVersion"":0,""refuseEdit"":false," +
@"""productName"":""" + productNewName + @""",""productI18nReqs"":[{""productName"":""" + productNewName + @""",""language"":""en""}]}";
string referer = "https://agentseller.temu.com/goods/edit?from=platform&productId=" + productId + "&taskUid=" + taskUid;
return HttpResponseBLL.PostResponse2(shop, url, body, referer);
}
private string editPriceProductEnName(ShopLoginInfo shop, string taskUid, string productId, string productNewName)
{
string url = "https://agentseller.temu.com/visage-agent-seller/product/edit/task/reply";
string body = "";
body = @"{""productId"":" + productId + @",""taskUid"":""" + taskUid + @""",""taskVersion"":0,""refuseEdit"":false," +
@"""productI18nReqs"":[{""productName"":""" + productNewName + @""",""language"":""en""}]}";
string referer = "https://agentseller.temu.com/goods/edit?from=platform&productId=" + productId + "&taskUid=" + taskUid;
return HttpResponseBLL.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>
public static 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 HttpResponseBLL.PostResponse2(shop, url, body, referer);
}
public static 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 HttpResponseBLL.PostResponse2(shop, url, body, referer);
}
public static 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 HttpResponseBLL.PostResponse2(shop, url, body, refere);
}
public static string queryProductSizeAndWeightConfig(ShopLoginInfo shop, string taskUid, string productId, string catId)
{
string url = "https://agentseller.temu.com/anniston-agent-seller/product/check/common/queryConfig";
string body = "{}";
string referer = "https://agentseller.temu.com/goods/edit?from=platform&productId=" + productId + "&taskUid=" + taskUid;
return HttpResponseBLL.PostResponse2(shop, url, body, referer);
}
public static string queryCatSizeAndWeightConfig(ShopLoginInfo shop, string taskUid, string productId, string catId)
{
string url = "https://agentseller.temu.com/anniston-agent-seller/product/check/common/queryConfig";
url = "https://agentseller.temu.com/anniston-agent-seller/product/check/cat/queryConfig";
string body = "{}";
body = @"{""catId"":" + catId + "}";
string referer = "https://agentseller.temu.com/goods/edit?from=platform&productId=" + productId + "&taskUid=" + taskUid;
referer = "https://agentseller.temu.com/goods/edit?from=productList&productId=" + productId;
return HttpResponseBLL.PostResponse2(shop, url, body, referer);
}
public static 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 HttpResponseBLL.PostResponse2(shop, url, body, referer);
}
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 (ClientMode != EnumClientMode.Admin)
shop = GlobalConfig.ShopLoginList.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 (CheckRestoreTitleWords(pName) || chkForceRestoreTitle.Checked)
{
}
else
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "标题没有可还原的关键字";
}));
continue;
}
var html = "";
var isRestoreEnName = false;
//// 中文标题不为空大概率加了英文标题了,一并还原英文标题
//if (ProductSelectForms.DbProductSelectListManageForm.CountChineseCharacters(pName) <= 0 )
//{
// isRestoreEnName = true;
// //if (chkForceRestoreTitle.Checked) // 强制还原英文标题功能已移除
// // html = editPriceProductEnNameBatchAdd(shop, price.productId.ParseToString());
// //else
// html = editPriceProductNameAndEnNameBatchAdd(shop, price.productId.ParseToString());
//}
if (!isRestoreEnName) // 商品上传时已禁止英文标题头尾词,此处默认只还原商品主标题
{
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":{}}}
string taskUid = "";
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\":1,\"editAdvice\":\"优化\"}]"))
if (string.IsNullOrEmpty(taskUid) || !taskHtml.Contains("\"productEditTaskItems\":[{\"editItem\":1,"))
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "已提交过修改任务或商品有其他修改任务,请在后店铺台终止任务并稍候重试";
}));
continue;
//return; //
}
//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"))
{
this.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();
}
// 还原原始标题
var newProdName = RestoreProductName(pName, txtReplaceText.Text.Trim());
// 测试修改标题最多字符数量
//while (newPName.Length < 500)
//{
// newPName += "长";
//}
if (isRestoreEnName)
{
//if (chkForceRestoreTitle.Checked) // 强制还原英文标题功能已移除
// html = editPriceProductEnName(shop, item.ParseToString(), price.productId.ParseToString(), newProdName);
//else
html = editPriceProductNameAndEnName(shop, taskUid, price.productId.ParseToString(), newProdName);
}
else
html = editPriceProductName(shop, taskUid, price.productId.ParseToString(), newProdName);
Thread.Sleep(Randomx.GetId(25, 75));
commonSleep();
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"))
{
this.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 (ClientMode != EnumClientMode.Admin)
shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == row.Cells["colSupplierId"].Value.ParseToString());
if (shop == null)
continue;
this.rePrice(shop, orderId, row);
commonSleep();
}
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 (ClientMode != EnumClientMode.Admin)
shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == row.Cells["colSupplierId"].Value.ParseToString());
if (shop == null)
continue;
this.applyHighPrice(shop, orderId, row);
commonSleep();
}
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 (ClientMode != EnumClientMode.Admin)
shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == row.Cells["colSupplierId"].Value.ParseToString());
if (shop == null)
continue;
this.cancelLowPrice(shop, orderId, row);
commonSleep();
}
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 static 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;
try
{
var jArr = JObject.Parse(html)["data"];
if (jArr.Count() == 0)
return list;
return JsonHelper.DeserializeJsonToList<TemuDBExtCodePriceInfo>(jArr.ToString());
}
catch (Exception ex)
{
BaseMsgForm.ShowError("获取货号价格失败 " + ex.Message);
return list;
}
}
public static List<DBProdDraftIdMapUpSpuIdInfo> GetUpSpuIdLst(List<string> draftIdList)
{
List<DBProdDraftIdMapUpSpuIdInfo> list = new List<DBProdDraftIdMapUpSpuIdInfo>();
if (draftIdList.Count == 0)
return list;
for (int i = 0; i < draftIdList.Count; i++)
{
draftIdList[i] = draftIdList[i].Replace(",", "").Replace("'", "").Replace("\"", "");
}
var url = BaseClass.BuildObjString("product/get_select_prod_map_up_spu_id_list");
var data = UserLogin.GetSignaturex();
data += "&page=1";
data += "&page_size=200";
data += "&in_draft_ids=" + string.Join(",", draftIdList);
var html = GetHtml.PostUtf8(url, data);
Thread.Sleep(100);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
{
return list;
}
if (!html.Contains("data"))
return list;
try
{
var jArr = JObject.Parse(html)["data"];
if (jArr.Count() == 0)
return list;
return JsonHelper.DeserializeJsonToList<DBProdDraftIdMapUpSpuIdInfo>(jArr.ToString());
}
catch (Exception ex)
{
BaseMsgForm.ShowError("获取商品成本价失败 " + ex.Message);
return list;
}
}
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 (ClientMode != EnumClientMode.Admin)
shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == row.Cells["colSupplierId"].Value.ParseToString());
if (shop == null)
continue;
this.cancelTitleWrongPrice(shop, prodId);
commonSleep();
}
Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "批量作废完成";
this.pbLoading.Visible = false;
}));
});
}
private void chkFilterTitle_CheckedChanged(object sender, EventArgs e)
{
FilterRows();
}
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 CheckRestoreTitleWords(string filterProdName)
{
return filterProdName != RestoreProductName(filterProdName, txtReplaceText.Text.Trim());
}
public static string RestoreProductName(string pName, string replaceTxt = "")
{
string checkChineseName = pName.Replace("适合不同的搭配风格", "").Replace("个", "").Replace("适合不同的搭配场景", "");
bool containsChinese = Regex.IsMatch(checkChineseName, @"[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]");
string newPName = pName;
if ((pName.EndsWith("适合不同的搭配风格") || 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 + "不同的搭配风格")
.Replace("适合不同的搭配场景", "适合" + headword + "不同的搭配场景");
else
newPName = newPName.Replace("适合不同的搭配风格", "Suitable for " + headword + " different matching styles").Trim()
.Replace("适合不同的搭配场景", "Suitable for " + headword + " different matching scenarios").Trim();
}
if ((pName.EndsWith("适合不同的搭配风格") || 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 + "不同的搭配风格")
.Replace("适合不同的搭配场景", "适合" + headword + "不同的搭配场景");
else
newPName = newPName.Replace("适合不同的搭配风格", "Suitable for " + headword + " different matching styles").Trim()
.Replace("适合不同的搭配场景", "Suitable for " + headword + " different matching scenarios").Trim();
}
if (!string.IsNullOrWhiteSpace(replaceTxt))
newPName = newPName.Replace(replaceTxt, "");
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 t = Task.Run(() =>
{
//----------------------------------------------------------------------------------------
// 查询是否有修改记录,如果没有申请新的修改,获取taskId
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 (ClientMode != EnumClientMode.Admin)
shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == price.supplierId.ParseToString());
if (shop == null)
return; // continue;
if (shop.LoginStatus2 != "国际版在线")
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "店铺掉线";
}));
return; //continue;
}
//var pName = price.productName;
if (checkRestoreSizeAndNumber(price))
{
}
else
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "无需还原包装规格尺寸与SKU分类数量";
}));
return; //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 = "已提交过修改任务或商品有其他修改任务,请在后店铺台终止任务并稍候重试";
}));
return; //continue;
}
}
if (!html.Contains("\"success\":true"))
{
if (html.Contains("登录过期") || html.Contains("Invalid Login State"))
{
this.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;
}));
return; //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;
}));
return; // continue;
}
html = editPriceProductQuery(shop, price.productId.ParseToString(), taskUid).ParseToString();
if (html.Contains("This product has pending or in-progress modification tasks"))
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "已提交过修改任务,请在后店铺台终止任务并稍候重试";
}));
return; // continue;
}
if (!html.Contains("\"success\":true"))
{
if (html.Contains("登录过期") || html.Contains("Invalid Login State"))
{
this.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;
}));
return; // 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) * 10;
int width = Randomx.GetId(numWidth1.Value.ParseToInt(), Math.Min(len, numWidth2.Value.ParseToInt() + 1)) * 10;
int height = Randomx.GetId(numHeight1.Value.ParseToInt(), Math.Min(width, numHeight2.Value.ParseToInt() + 1)) * 10;
int weight = Randomx.GetId(numWeight1.Value.ParseToInt(), numWeight2.Value.ParseToInt() + 1) * 1000;
int numberOfPieces = Math.Max(1, numPieces.Value.ParseToInt());
JObject obj = JObject.Parse(html);
var result = JsonHelper.SerializeObject(obj["result"]);
TemuDetailProductInfo prodInfo = JsonHelper.DeserializeJsonToObject<TemuDetailProductInfo>(result);
var catId = Math.Max(0, prodInfo.categories.cat1.catId.ParseToInt());
catId = Math.Max(catId, prodInfo.categories.cat2.catId.ParseToInt());
catId = Math.Max(catId, prodInfo.categories.cat3.catId.ParseToInt());
catId = Math.Max(catId, prodInfo.categories.cat4.catId.ParseToInt());
catId = Math.Max(catId, prodInfo.categories.cat5.catId.ParseToInt());
catId = Math.Max(catId, prodInfo.categories.cat6.catId.ParseToInt());
catId = Math.Max(catId, prodInfo.categories.cat7.catId.ParseToInt());
catId = Math.Max(catId, prodInfo.categories.cat8.catId.ParseToInt());
catId = Math.Max(catId, prodInfo.categories.cat9.catId.ParseToInt());
catId = Math.Max(catId, prodInfo.categories.cat10.catId.ParseToInt());
var cateSizeWeightConfig = lstCateSizeWeightConfig.FirstOrDefault(c => c.catId == catId.ToString());
if (cateSizeWeightConfig == null)
{
var url = BaseClass.BuildObjString("product/get_cate_size_weight_config_v2");
var data = UserLogin.GetSignaturex() +
"&cat_id=" + catId;
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"))
{
try
{
var jArr = JObject.Parse(html)["data"];
cateSizeWeightConfig = JsonHelper.DeserializeJsonToObject<CateSizeWeightConfig>(jArr.ToString());
if (cateSizeWeightConfig != null)
lstCateSizeWeightConfig.Add(cateSizeWeightConfig);
}
catch { }
}
}
if (cateSizeWeightConfig == null)
{
//查询接口尺寸重量限制
html = queryProductSizeAndWeightConfig(shop, taskUid.ParseToString(), price.productId.ParseToString(), catId.ParseToString());
var html1 = queryCatSizeAndWeightConfig(shop, taskUid.ParseToString(), price.productId.ParseToString(), catId.ParseToString());
if (!string.IsNullOrEmpty(html1) && html1.Contains("length"))
html = html1;
//{"success":true,"errorCode":1000000,"errorMsg":null,"result":{"common":{"operatorId":null,"operatorName":null,"operatorType":null,"checkSideRelation":false,"noticeSideEquation":false,"length":{"min":10,"max":2999},"width":{"min":5,"max":2999},"height":{"min":2,"max":2999},"weight":{"min":2000,"max":99999000}}}}
Thread.Sleep(Randomx.GetId(25, 75));
commonSleep();
if (html.Contains("\"success\":true"))
{
try
{
JObject jObj = JObject.Parse(html);
cateSizeWeightConfig = new CateSizeWeightConfig() { catId = catId.ToString() };
if (html.Contains("common"))
{
cateSizeWeightConfig.minLen = jObj["result"]["common"]["length"]["min"].ParseToInt();
cateSizeWeightConfig.maxLen = jObj["result"]["common"]["length"]["max"].ParseToInt();
cateSizeWeightConfig.minWidth = jObj["result"]["common"]["width"]["min"].ParseToInt();
cateSizeWeightConfig.maxWidth = jObj["result"]["common"]["width"]["max"].ParseToInt();
cateSizeWeightConfig.minHeight = jObj["result"]["common"]["height"]["min"].ParseToInt();
cateSizeWeightConfig.maxHeight = jObj["result"]["common"]["height"]["max"].ParseToInt();
cateSizeWeightConfig.minWeight = jObj["result"]["common"]["weight"]["min"].ParseToInt();
cateSizeWeightConfig.maxWeight = jObj["result"]["common"]["weight"]["max"].ParseToInt();
}
else
{
cateSizeWeightConfig.minLen = jObj["result"]["length"]["min"].ParseToInt();
cateSizeWeightConfig.maxLen = jObj["result"]["length"]["max"].ParseToInt();
cateSizeWeightConfig.minWidth = jObj["result"]["width"]["min"].ParseToInt();
cateSizeWeightConfig.maxWidth = jObj["result"]["width"]["max"].ParseToInt();
cateSizeWeightConfig.minHeight = jObj["result"]["height"]["min"].ParseToInt();
cateSizeWeightConfig.maxHeight = jObj["result"]["height"]["max"].ParseToInt();
cateSizeWeightConfig.minWeight = jObj["result"]["weight"]["min"].ParseToInt();
cateSizeWeightConfig.maxWeight = jObj["result"]["weight"]["max"].ParseToInt();
}
lstCateSizeWeightConfig.Add(cateSizeWeightConfig);
var url = BaseClass.BuildObjString("product/add_cate_size_weight_config_v2");
var data = UserLogin.GetSignaturex();
data += "&cat_id=" + catId;
data += "&minLen=" + cateSizeWeightConfig.minLen;
data += "&maxLen=" + cateSizeWeightConfig.maxLen;
data += "&minWidth=" + cateSizeWeightConfig.minWidth;
data += "&maxWidth=" + cateSizeWeightConfig.maxWidth;
data += "&minHeight=" + cateSizeWeightConfig.minHeight;
data += "&maxHeight=" + cateSizeWeightConfig.maxHeight;
data += "&minWeight=" + cateSizeWeightConfig.minWeight;
data += "&maxWeight=" + cateSizeWeightConfig.maxWeight;
html = GetHtml.PostUtf8(url, data);
}
catch { }
}
else
{
if (html.Contains("登录过期") || html.Contains("Invalid Login State"))
{
this.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;
}));
return; //continue;
}
}
if (cateSizeWeightConfig != null)
{
// 设置长宽高
if (len < cateSizeWeightConfig.minLen) len = cateSizeWeightConfig.minLen;
if (len > cateSizeWeightConfig.maxLen) len = cateSizeWeightConfig.maxLen;
if (width < cateSizeWeightConfig.minWidth) width = cateSizeWeightConfig.minWidth;
if (width > cateSizeWeightConfig.maxWidth) width = cateSizeWeightConfig.maxWidth;
if (height < cateSizeWeightConfig.minHeight) height = cateSizeWeightConfig.minHeight;
if (height > cateSizeWeightConfig.maxHeight) height = cateSizeWeightConfig.maxHeight;
if (weight < cateSizeWeightConfig.minWeight) weight = cateSizeWeightConfig.minWeight;
if (weight > cateSizeWeightConfig.maxWeight) weight = cateSizeWeightConfig.maxWeight;
}
//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 + "},";
jStr += " \"productSkuVolumeReq\":{";
jStr += " \"len\":" + len + ",";
jStr += " \"width\":" + width + ",";
jStr += " \"height\":" + height;
jStr += " }";
jStr += "},";
//productSkuMultiPackReq
jStr += "\"productSkuMultiPackReq\":{";
jStr += " \"skuClassification\":1,";
jStr += " \"numberOfPieces\":" + numberOfPieces + ",";
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));
commonSleep();
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"))
{
this.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;
}));
return; //continue;
}
}
catch (Exception ex)
{
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colMsg"].Value = "修改请求失败 " + ex.Message;
}));
return; //continue;
}
});
t.Wait(20000);
}
Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "批量还原尺寸与数量完成";
this.pbLoading.Visible = false;
}));
});
}
/// <summary>
/// 检测是否需要重置尺寸和sku单品数量
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
bool checkRestoreSizeAndNumber(TemuForChainProductInfo 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;
bool isRevers = false;
Invoke(new Action(() => { isRevers = chkLessThan.Checked; }));
if (!isRevers && 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;
else if (isRevers && 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 = "";
}
private void dgvExtCode_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
string headerText = dgvExtCode.Columns[e.ColumnIndex].HeaderText;
var row = dgvExtCode.Rows[e.RowIndex];
switch (headerText)
{
case "":
case "选":
case "货号":
row.Cells["colSelectExtCode"].Value = !row.Cells["colSelectExtCode"].Value.ParseToBool();
FilterRows();
break;
}
}
void FilterRows()
{
var filterExtCodeLst = dgvExtCode.Rows.Cast<DataGridViewRow>()
.Where(r => r.Cells["colSelectExtCode"].Value.ParseToBool() == true)
.Select(r => r.Cells["colFilterExtCode"].Value.ParseToString()).Distinct().ToList();
pbLoading.Visible = true;
Task.Run(() =>
{
foreach (DataGridViewRow row in dgvPriceCheck.Rows)
{
Invoke(new Action(() =>
{
//row.Visible = true;
//row.Cells["colCheck"].Value = false;
bool isVisible = true;
var prodId = row.Cells["colProductId"].Value.ParseToString();
var rowExtCode = row.Cells["colExtCode"].Value.ParseToString();
var rowAdjustPrice = row.Cells["colAdjustPrice"].Value.ParseToDecimal();
// 过滤价格
// 只有有选中数据时才过滤,全不选时不过滤
if (filterExtCodeLst != null && filterExtCodeLst.Count > 0)
{
var filterExtCode = filterExtCodeLst.FirstOrDefault(e => e == rowExtCode);
var filterExtCodeConfig = lstPriceCheckFilterConfig.FirstOrDefault(c => c.ExtCode == rowExtCode);
if (string.IsNullOrWhiteSpace(filterExtCode))
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
isVisible = false;
}
else if (filterExtCodeConfig != null)
{
if (filterExtCodeConfig.Symbol == "≥" && rowAdjustPrice < filterExtCodeConfig.Price1)
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
isVisible = false;
}
if (filterExtCodeConfig.Symbol == "≤" && rowAdjustPrice > filterExtCodeConfig.Price1)
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
isVisible = false;
}
if (filterExtCodeConfig.Symbol.StartsWith("≤") && filterExtCodeConfig.Symbol.EndsWith("≥") &&
rowAdjustPrice > filterExtCodeConfig.Price1 && rowAdjustPrice < filterExtCodeConfig.Price2)
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
isVisible = false;
}
if (filterExtCodeConfig.Symbol.StartsWith("≥") && filterExtCodeConfig.Symbol.EndsWith("≤") &&
(rowAdjustPrice < filterExtCodeConfig.Price1 || rowAdjustPrice > filterExtCodeConfig.Price2))
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
isVisible = false;
}
}
}
// 过滤保留未还原的标题
if (chkFilterTitle.Checked)
{
var pName = row.Cells["colProdName"].Value.ParseToString();
if (!CheckRestoreTitleWords(pName))
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
isVisible = false;
}
else
{
}
}
if (chkFilterSize.Checked)
{
var priceInfo = lstCheckPriceInfo.FirstOrDefault(p => p.productId.ParseToString() == prodId);
if (priceInfo != null)
{
if (!checkRestoreSizeAndNumber(priceInfo))
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
isVisible = false;
}
else
{
}
}
}
if (row.Visible != isVisible)
{
row.Visible = isVisible;
//row.Cells["colCheck"].Value = isVisible;
}
}));
}
Invoke(new Action(() => { pbLoading.Visible = false; }));
});
}
private void btnSaveFilterParams_Click(object sender, EventArgs e)
{
var rows = this.dgvExtCode.Rows.Cast<DataGridViewRow>()
.Where(r => r.Cells["colSelectExtCode"].Value.ParseToBool() == true).ToList();
var extCodeLst = rows.Select(r => r.Cells["colFilterExtCode"].Value.ParseToString()).Distinct().ToList();
if (extCodeLst.Count == 0)
{
BaseMsgForm.ShowError("请查询商品后在左边列表选择货号!");
return;
}
decimal price1 = txtPrice1.Text.ParseToDecimal();
decimal price2 = txtPrice2.Text.ParseToDecimal();
if ((cmbSymbol.Text == "≤ ≥" || cmbSymbol.Text == "≥ ≤") && price2 < price1)
{
BaseMsgForm.ShowError("高价格不能小于低价格");
return;
}
foreach (var extCode in extCodeLst)
{
lstPriceCheckFilterConfig.RemoveAll(p => p.ExtCode == extCode);
var priceParam = new PriceCheckFilterConfig()
{
ExtCode = extCode,
Symbol = cmbSymbol.Text.Trim().IsNullOrEmpty() ? "≥" : cmbSymbol.Text.Trim(),
Price1 = txtPrice1.Text.Trim().ParseToDecimal(),
Price2 = txtPrice2.Text.Trim().ParseToDecimal(),
};
lstPriceCheckFilterConfig.Add(priceParam);
}
NaiBa.Util.Helper.ConfigHelper.SaveConfig("price_check_filter_config", lstPriceCheckFilterConfig);
BaseMsgForm.ShowInfo("选中货号的价格过滤配置已保存!");
foreach (var row in rows)
{
var ext = row.Cells["colFilterExtCode"].Value.ParseToString();
var filterConfig = lstPriceCheckFilterConfig.FirstOrDefault(c => c.ExtCode == ext);
row.Cells["colFilterRule"].Value = filterConfig == null ? null : GetConfigDesStr(filterConfig.Symbol, filterConfig.Price1, filterConfig.Price2);
if ((filterConfig?.Symbol).ParseToString().StartsWith("≥"))
{
row.Cells["colFilterRule"].Style.ForeColor = Color.Green;
}
else if ((filterConfig?.Symbol).ParseToString().StartsWith("≤"))
{
row.Cells["colFilterRule"].Style.ForeColor = Color.Red;
}
else
{
row.Cells["colFilterRule"].Style.ForeColor = Color.Black;
}
}
FilterRows();
}
string GetConfigDesStr(string symbol, decimal price1, decimal price2)
{
if (symbol == "≤")
return "≤" + price1;
else if (symbol == "≥ ≤")
return "≥" + price1 + " 且 ≤" + price2;
else if (symbol == "≤ ≥")
return "≤" + price1 + " 或 ≥" + price2;
return "≥" + price1.ToString();
}
private void btnRestoreFilterParams_Click(object sender, EventArgs e)
{
var rows = this.dgvExtCode.Rows.Cast<DataGridViewRow>()
.Where(r => r.Cells["colSelectExtCode"].Value.ParseToBool() == true).ToList();
var extCodeLst = rows.Select(r => r.Cells["colFilterExtCode"].Value.ParseToString()).Distinct().ToList();
if (extCodeLst.Count == 0)
{
BaseMsgForm.ShowError("请查询商品后在左边列表选择货号!");
return;
}
if (BaseMsgForm.ShowConfirm("确定要清除选中货号的价格过滤配置吗?", "提示").DialogResult == DialogResult.OK)
{
foreach (var extCode in extCodeLst)
{
lstPriceCheckFilterConfig.RemoveAll(p => p.ExtCode == extCode);
}
NaiBa.Util.Helper.ConfigHelper.SaveConfig("price_check_filter_config", lstPriceCheckFilterConfig);
BaseMsgForm.ShowInfo("选中货号的价格过滤配置已清除!");
foreach (var row in rows)
{
row.Cells["colFilterRule"].Value = "";
}
}
FilterRows();
}
private void cmbSymbol_TextChanged(object sender, EventArgs e)
{
if (cmbSymbol.Text == "≤ ≥" || cmbSymbol.Text == "≥ ≤")
{
txtPrice2.Visible = true;
label16.Visible = true;
}
else
{
txtPrice2.Visible = false;
label16.Visible = false;
}
}
private void chkFilterSize_CheckedChanged(object sender, EventArgs e)
{
FilterRows();
}
public static int sleepTime = 300;
void commonSleep()
{
Thread.Sleep(sleepTime);
}
private void numSleep_ValueChanged(object sender, EventArgs e)
{
sleepTime = (this.numSleep.Value * 1000).ParseToInt();
}
void CheckShopLogin(ShopLoginInfo[] shops, bool isShowProgress)
{
if (ClientMode == EnumClientMode.Admin)
AdminShopListForm.Instance.CheckShopLogin(shops, isShowProgress);
else
ShopListForm.Instance.CheckShopLogin(shops, isShowProgress);
}
private void lblJudgeLen_Click(object sender, EventArgs e)
{
chkFilterSize.Checked = !chkFilterSize.Checked;
}
private void chkLessThan_CheckedChanged(object sender, EventArgs e)
{
if(chkLessThan.Checked)
{
lblJudgeLen.Text = "长<";
lblJudgeWeight.Text = "且重<";
lblJudgeLen.ForeColor = lblJudgeWeight.ForeColor = Color.Red;
}
else
{
lblJudgeLen.Text = "长≥";
lblJudgeWeight.Text = "且重≥";
lblJudgeLen.ForeColor = lblJudgeWeight.ForeColor = Color.Black;
}
}
}
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;
}
public class PriceCheckFilterConfig
{
public string ExtCode { get; set; }
public string Symbol { get; set; }
public decimal Price1 { get; set; }
public decimal Price2 { get; set; }
}
public class CateSizeWeightConfig
{
public string catId { get; set; }
public int minLen { get; set; }
public int maxLen { get; set; }
public int minWidth { get; set; }
public int maxWidth { get; set; }
public int minHeight { get; set; }
public int maxHeight { get; set; }
public int minWeight { get; set; }
public int maxWeight { get; set; }
}
}