1024 lines
49 KiB
C#
1024 lines
49 KiB
C#
using AllBase;
|
|
using AllBase.Model.Result;
|
|
using NaiBa.Util.Extension;
|
|
using NaiBa.Util.Winform.Extension;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using TemuKJD.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");
|
|
|
|
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 dgvAdjust_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 accountId = dgvPriceCheck.Rows[e.RowIndex].Cells["colSupplierId"].Value.ParseToString();
|
|
var shop = lstAdminShopInfo.FirstOrDefault(v => v.ShopId == accountId);
|
|
|
|
switch (headerText)
|
|
{
|
|
case "同意报价":
|
|
{
|
|
applyHighPrice(shop, orderId, dgvPriceCheck.Rows[e.RowIndex]);
|
|
}
|
|
break;
|
|
case "拒绝报价":
|
|
{
|
|
cancelLowPrice(shop, orderId, dgvPriceCheck.Rows[e.RowIndex]);
|
|
}
|
|
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;
|
|
default:
|
|
dgvPriceCheck.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvPriceCheck.Rows[e.RowIndex].Cells["colCheck"].Value;
|
|
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 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)
|
|
{
|
|
SearchPrice("待卖家确认");
|
|
}
|
|
|
|
private void btnSearchPrice2_Click(object sender, EventArgs e)
|
|
{
|
|
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()).ToList();
|
|
var shops = this.lstAdminShopInfo.Where(s => selectShopIdLst.Contains(s.ShopId)).ToList();
|
|
if (shops.Count == 0)
|
|
{
|
|
BaseMsgForm.ShowError("没有选择店铺!");
|
|
return;
|
|
}
|
|
|
|
this.dgvPriceCheck.Rows.Clear();
|
|
this.lstCheckPriceInfo.Clear();
|
|
this.pbLoading.Visible = true;
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
Task.Run(() =>
|
|
{
|
|
foreach (var shopId in selectShopIdLst)
|
|
{
|
|
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++;
|
|
var searchRst = this.SearchForChainSupplier(shop, page, txtSkcId.Text.Trim().Trim(','), type);
|
|
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);
|
|
}
|
|
var extCodePriceList = GetServerExtCodePriceLst(extCodeLst.Distinct().ToList());
|
|
foreach (var priceInfo in checkPriceInfoTmpLst)
|
|
{
|
|
prodIndex++;
|
|
Invoke(new Action(() => {
|
|
this.statusBar.lblTaskStatus.Text = "正在查询" + type + ",共有 " + total + " 件商品";
|
|
this.statusBar.pgbTaskProgress.Maximum = total;
|
|
this.statusBar.UpdateProgressBar(prodIndex);
|
|
}));
|
|
|
|
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,
|
|
prodIndex,
|
|
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, // 修改报价次数
|
|
"同意",
|
|
"拒绝",
|
|
""
|
|
);
|
|
dgvPriceCheck.Rows[rowId].Height = 60;
|
|
}));
|
|
}
|
|
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 = "待卖家确认")
|
|
{
|
|
string url = "https://agentseller.temu.com/api/kiana/mms/robin/searchForChainSupplier";
|
|
string body = "";
|
|
if (type == "待卖家确认")
|
|
{
|
|
body = @"{""pageSize"":100,""pageNum"":" + page + @",""priceReviewStatusList"":[1],""secondarySelectStatusList"":[7],""supplierTodoTypeList"":[]}";
|
|
if (!string.IsNullOrEmpty(prodSkcIds))
|
|
body = @"{""pageSize"":100,""pageNum"":" + page + @",""priceReviewStatusList"":[1],""secondarySelectStatusList"":[7],""supplierTodoTypeList"":[],""productSkcIdList"":["+ prodSkcIds + "]}";
|
|
}
|
|
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 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);
|
|
}
|
|
|
|
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);
|
|
|
|
try
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
if (dgvPriceCheck.Rows.Contains(row))
|
|
row.Cells["colProductSkcPic"].Value = image;
|
|
}));
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void dgvAdjust_Scroll(object sender, ScrollEventArgs e)
|
|
{
|
|
this.ShowDgvImg();
|
|
}
|
|
|
|
private void btnReturnProdName_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.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());
|
|
var html = editPriceProductNameBatchAdd(shop, price.productId.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 ((pName.EndsWith("适合不同的搭配风格") && pName.IndexOf("个") < 4 && pName.IndexOf("个") > 0) ||
|
|
(pName.EndsWith("适合不同的搭配风格") && pName.IndexOf("pcs") < 4 && pName.IndexOf("pcs") > 0))
|
|
{
|
|
}
|
|
else
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
foreach (var row in rows)
|
|
row.Cells["colMsg"].Value = "标题没有可还原的关键字";
|
|
}));
|
|
continue;
|
|
}
|
|
|
|
//{"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 = pName;
|
|
if (pName.EndsWith("适合不同的搭配风格") && pName.IndexOf("个") < 4 && pName.IndexOf("个") > 0)
|
|
{
|
|
var headword = pName.Substring(0, pName.IndexOf("个") + 1);
|
|
newPName = pName.Substring(pName.IndexOf("个") + "个".Length);
|
|
newPName = newPName.Replace("适合不同的搭配风格", "适合" + headword + "不同的搭配风格");
|
|
}
|
|
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);
|
|
newPName = newPName.Replace("适合不同的搭配风格", "适合" + headword + "个不同的搭配风格").Trim();
|
|
}
|
|
|
|
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.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.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.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.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.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.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.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());
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|