2528 lines
130 KiB
C#
2528 lines
130 KiB
C#
using AllBase;
|
|
using AllBase.Model.Result;
|
|
using AllBase.Model.Result.PDDResult;
|
|
using CefSharp;
|
|
using CefSharp.WinForms;
|
|
using NaiBa.CefHelper;
|
|
using NaiBa.CefHelper.Handler;
|
|
using NaiBa.Util;
|
|
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.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using TemuKJD.BaseForms;
|
|
using TemuKJD.BLL;
|
|
using TemuKJD.Extension;
|
|
using TemuKJD.Helper;
|
|
using TemuKJD.PDDForms.ProductSelectForms;
|
|
using TemuKJD.WXForms.ProductForms;
|
|
using Work;
|
|
|
|
namespace TemuKJD.ToolForms
|
|
{
|
|
public partial class GetJuShuitanProdForm : BaseForms.BaseForm
|
|
{
|
|
Dictionary<string, string> dicAfterSale = new Dictionary<string, string>();
|
|
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
|
|
public CancellationTokenSource CancelGetDown { get; set; } = null;
|
|
string InitUrl = "https://sc.scm121.com/suppliersManage/suppliersList/onlineSuppliers";
|
|
public ChromiumWebBrowser cefWebBrowser = null;
|
|
private string currentUrl = "";
|
|
private string currentGetSupplierListParamData = "";
|
|
private string currentGetHotListParamData = "";
|
|
private string currentSupplierName = "";
|
|
private string appVersion = "";
|
|
private string currentSupplierId = "";
|
|
int pageStart = 1;
|
|
int pageEnd = 99999;
|
|
int filterSaleCountDays = 7;
|
|
int filterSaleCount = 100;
|
|
string platformType = "Pinduoduo";
|
|
string jstPddShopId = "";
|
|
int downBeforeDays = 1;
|
|
int downBeforeHours = 0;
|
|
ConcurrentList<JSTListProductInfo> lstJSTListProductInfo = new ConcurrentList<JSTListProductInfo>();
|
|
/// <summary>
|
|
/// 聚水潭已下架sku
|
|
/// </summary>
|
|
ConcurrentList<JSTDownProdSkuInfo> lstJSTDownProdSkuInfo = new ConcurrentList<JSTDownProdSkuInfo>();
|
|
JstDownSkuGetInfo jstDownSkuGetInfo = new JstDownSkuGetInfo();
|
|
|
|
public GetJuShuitanProdForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void GetJuShuitanProdForm_Load(object sender, EventArgs e)
|
|
{
|
|
//this.ucTabControlMetro1.TabPages.Remove(tabPage3);
|
|
|
|
this.splitContainer1.SplitterDistance = 472;
|
|
this.dgvProduct.AddSelectorColumn("colCheck");
|
|
this.dgvProduct.AddImgColumn("colImg", "colImgUrl");
|
|
|
|
this.dgvDownSku.AddSelectorColumn("colDownSelect");
|
|
this.dgvDownSku.AddImgColumn("colDownImg", "colDownImgUrl");
|
|
|
|
downBeforeDays = txtBeforeDay.Text.ParseToInt();
|
|
downBeforeHours = txtBeforeHour.Text.ParseToInt();
|
|
|
|
dtpEndTime.Value = DateTime.Now;
|
|
|
|
lstJSTListProductInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<ConcurrentList<JSTListProductInfo>>("supplier_product_list_" + MainForm.ProcessCount);
|
|
if (lstJSTListProductInfo == null)
|
|
lstJSTListProductInfo = new ConcurrentList<JSTListProductInfo>();
|
|
lstJSTDownProdSkuInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<ConcurrentList<JSTDownProdSkuInfo>>("jst_down_sku_list");
|
|
if (lstJSTDownProdSkuInfo == null)
|
|
lstJSTDownProdSkuInfo = new ConcurrentList<JSTDownProdSkuInfo>();
|
|
jstDownSkuGetInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<JstDownSkuGetInfo>("jst_down_sku_get_info");
|
|
if (jstDownSkuGetInfo == null)
|
|
jstDownSkuGetInfo = new JstDownSkuGetInfo();
|
|
|
|
pbLoading.Visible = true;
|
|
pictureBox1.Visible = true;
|
|
Task.Run(() =>
|
|
{
|
|
int id = 0;
|
|
foreach (var prod in lstJSTListProductInfo)
|
|
{
|
|
id++;
|
|
if (id % 50 == 0)
|
|
Thread.Sleep(1);
|
|
Invoke(new Action(() =>
|
|
{
|
|
var rowId = this.dgvProduct.Rows.Add(
|
|
true,
|
|
prod.itemCoId,
|
|
prod.supplierName,
|
|
prod.id,
|
|
(prod.itemMainImage?.FirstOrDefault()).ParseToString().Replace("https://", "http://"),
|
|
DataGridViewExtension.defaultBitmap,
|
|
prod.itemName,
|
|
prod.saleSeven,
|
|
prod.saleThirty,
|
|
prod.categoryName.IsNullOrEmpty() ? prod?.dbProduct?.cat_id : prod.categoryName,
|
|
(prod?.dbProduct?.price_text).IsNullOrEmpty() ? "预估:" + prod.minSalesPrice + " 采集详情后显示实际值" : prod.dbProduct.price_text,
|
|
"删除",
|
|
prod.getProductMsg
|
|
);
|
|
dgvProduct.Rows[rowId].Height = 60;
|
|
|
|
//if (chanceProductResult.dbProduct != null)
|
|
//{
|
|
// var dbProd = chanceProductResult.dbProduct;
|
|
// var row = dgvChanceProduct.Rows[rowId];
|
|
// row.Cells["colGoodsName"].Value = dbProd.product_name;
|
|
// row.Cells["colCate"].Value = dbProd.cat_name;
|
|
// row.Cells["colPrice"].Value = dbProd.price_text;
|
|
//}
|
|
}));
|
|
}
|
|
Invoke(new Action(() =>
|
|
{
|
|
pbLoading.Visible = false;
|
|
}));
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "上次采集 " + jstDownSkuGetInfo.readPage + "/" + jstDownSkuGetInfo.totalPage + " 页,每页 " + 100;
|
|
}));
|
|
foreach (var downSku in lstJSTDownProdSkuInfo)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
var rowIndex = dgvDownSku.Rows.Add(
|
|
true,
|
|
downSku.spuId,
|
|
downSku.styleCode,
|
|
downSku.itemMainImage.FirstOrDefault().ParseToString(),
|
|
DataGridViewExtension.defaultBitmap,
|
|
downSku.itemName,
|
|
downSku.itemCode,
|
|
downSku.colourSpec,
|
|
downSku.supplierName,
|
|
downSku.supplyPrice,
|
|
downSku.shelvesTime,
|
|
downSku.lastOperator,
|
|
downSku.drpItemStatus,
|
|
"删除",
|
|
downSku.is_in_product_db == 1 ? "" : "产品库不存在,跳过"
|
|
);
|
|
dgvDownSku.Rows[rowIndex].Height = 60;
|
|
}));
|
|
}
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
pictureBox1.Visible = false;
|
|
}));
|
|
});
|
|
|
|
InitCef();
|
|
}
|
|
|
|
void InitCef()
|
|
{
|
|
if (cefWebBrowser == null)
|
|
{
|
|
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(InitUrl, false);
|
|
|
|
CustomResourceRequestHandlerLocal resourceRequestHandler = new CustomResourceRequestHandlerLocal();
|
|
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadComplete;
|
|
resourceRequestHandler.BeforeResourceLoadEvent += RequestHandler_BeforeResourceLoad;
|
|
cefWebBrowser.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
|
|
var lifeSapnHandler = new LifeSpanHandlerLocal(PopWindowType.SelfWindow);
|
|
cefWebBrowser.LifeSpanHandler = lifeSapnHandler;
|
|
cefWebBrowser.KeyboardHandler = new KeyboardHandler();
|
|
cefWebBrowser.FrameLoadEnd += CefWebBrowser_FrameLoadEnd;
|
|
cefWebBrowser.AddressChanged += CefWebBrowser_AddressChanged;
|
|
cefWebBrowser.LoadError += CefWebBrowser_LoadError;
|
|
cefWebBrowser.Dock = DockStyle.Fill;
|
|
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
splitContainer2.Panel2.Controls.Add(cefWebBrowser);
|
|
//cefWebBrowser.Load(shopMainUrl);
|
|
}));
|
|
}
|
|
|
|
Task.Run(() =>
|
|
{
|
|
string serverCookie = "";
|
|
var url = BaseClass.BuildPDDObjString("user/get_scm121_cookie");
|
|
var data = UserLogin.GetSignaturex();
|
|
var result = GetHtml.PostUtf8(url, data);
|
|
if (!result.Contains("\"code\":200"))
|
|
result = GetHtml.PostUtf8(url, data);
|
|
|
|
List<Cookie> cookieLst = new List<Cookie>();
|
|
try
|
|
{
|
|
serverCookie = JsonHelper.SerializeObject(JsonHelper.JObjectParse(result)["cookie"]);
|
|
cookieLst = JsonHelper.DeserializeJsonToList<CefSharp.Cookie>(serverCookie);
|
|
if (cookieLst == null)
|
|
cookieLst = new List<Cookie>();
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
|
|
|
|
// cef138必须init后方可设置或删除cookie
|
|
while (!cefWebBrowser.IsBrowserInitialized || !cefWebBrowser.GetBrowser().MainFrame.IsValid)
|
|
Thread.Sleep(20);
|
|
CEFBrowser.DeleteCookie(cefWebBrowser.GetCookieManager(null));
|
|
|
|
//cef 138 如果没有设置RequestContext 可能为空,直接getCookieManager
|
|
//if (this.openType != EnumOpenType.login)
|
|
{
|
|
//var t = CEFBrowser.SetCookieAsync(JsonHelper.SerializeObject(cookieLst), cefWebBrowser.GetCookieManager(null));
|
|
foreach (var cook in cookieLst)
|
|
{
|
|
var t = CEFBrowser.SetCookieAsync(cook.Domain.Trim('.'), cook.Name + "=" + cook.Value + ";", cefWebBrowser.GetCookieManager(null));
|
|
t.Wait(5000);
|
|
}
|
|
}
|
|
cefWebBrowser.Load(InitUrl);
|
|
});
|
|
}
|
|
private void CefWebBrowser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
|
|
{
|
|
}
|
|
|
|
private void RequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
|
|
{
|
|
if (url.Contains("api/goods/buyer/supplier/goods/list"))
|
|
{
|
|
if (request.Headers.AllKeys.Contains("App-Version"))
|
|
appVersion = request.Headers["App-Version"];
|
|
Task.Run(() => { GetCurrentSupplierSearchData(postData, responseData, request); });
|
|
}
|
|
if (url.Contains("api/goods/freshman/mall/goods/list"))
|
|
{
|
|
|
|
if (request.Headers.AllKeys.Contains("App-Version"))
|
|
appVersion = request.Headers["App-Version"];
|
|
Task.Run(() => { GetCurrentHotSearchData(postData, responseData, request); });
|
|
}
|
|
}
|
|
|
|
void GetCurrentSupplierSearchData(string postData, string responseData, IRequest request)
|
|
{
|
|
currentGetHotListParamData = "";
|
|
currentGetSupplierListParamData = postData;
|
|
currentSupplierId = BaseRegex.GetStringJson(ref postData, "supplierId");
|
|
currentSupplierName = BaseRegex.GetStringJson(ref responseData, "supplierName");
|
|
Invoke(new Action(() =>
|
|
{
|
|
txtSupplierName.Text = currentSupplierName;
|
|
}));
|
|
}
|
|
void GetCurrentHotSearchData(string postData, string responseData, IRequest request)
|
|
{
|
|
currentGetSupplierListParamData = "";
|
|
currentGetHotListParamData = postData;
|
|
currentSupplierId = "";
|
|
currentSupplierName = "";
|
|
Invoke(new Action(() =>
|
|
{
|
|
txtSupplierName.Text = "爆款专区";
|
|
}));
|
|
}
|
|
|
|
private bool RequestHandler_BeforeResourceLoad(object sender, string url, string postData, IRequest request)
|
|
{
|
|
return false;
|
|
}
|
|
private void CefWebBrowser_AddressChanged(object sender, CefSharp.AddressChangedEventArgs e)
|
|
{
|
|
if (this.Created && !this.Disposing && !this.IsDisposed)
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
currentUrl = e.Address;
|
|
txtAddress.Text = e.Address;
|
|
}));
|
|
});
|
|
}
|
|
}
|
|
private void CefWebBrowser_LoadError(object sender, CefSharp.LoadErrorEventArgs e)
|
|
{
|
|
}
|
|
|
|
private void btnImportCookie_Click(object sender, EventArgs e)
|
|
{
|
|
if (!txtCookie.Text.Contains("DISTRYBUTION_TOKEN"))
|
|
{
|
|
BaseMsgForm.ShowError("导入的cookie无效,请重新输入");
|
|
return;
|
|
}
|
|
|
|
Task.Run(() =>
|
|
{
|
|
var t = CEFBrowser.SetCookieAsync("scm121.com", txtCookie.Text, cefWebBrowser.GetCookieManager(null));
|
|
t.Wait(5000);
|
|
cefWebBrowser.Load(InitUrl);
|
|
});
|
|
}
|
|
|
|
private void btnSaveCookie_Click(object sender, EventArgs e)
|
|
{
|
|
List<Cookie> cookieList = CEFBrowser.GetCookieList(".scm121.com", cefWebBrowser.GetCookieManager(null));
|
|
|
|
var url = BaseClass.BuildPDDObjString("user/update_scm121_cookie");
|
|
var data = UserLogin.GetSignaturex();
|
|
data += "&cookie=" + GetHtml.UrlEncodeUtf8(JsonHelper.SerializeObject(cookieList));
|
|
var result = GetHtml.PostUtf8(url, data);
|
|
if (!result.Contains("\"code\":200"))
|
|
result = GetHtml.PostUtf8(url, data);
|
|
|
|
if (result.Contains("\"code\":200"))
|
|
BaseMsgForm.ShowInfo("保存成功");
|
|
else
|
|
BaseMsgForm.ShowInfo("保存失败,请重试");
|
|
}
|
|
|
|
private void btnRefreshCookie_Click(object sender, EventArgs e)
|
|
{
|
|
//var result = GetHtml.PostUtf8("https://api.weixin.qq.com/shop/ec/basics/img/upload?access_token=100_Kn3u6mev0uip-WUPSgxXWHrHldjOP0Ewjw8n18LmGcq2pWbjn4BJukPkGZt0gzgJ1Hd6bRM2TXUDTEhwM7VULSl_P-pVHSVPHlE6ZvdXfD6djB1f2WEibY7jWaZLaD24cBUxLM-mSGxjR7i7IBBeAHDOHH&upload_type=http://img.alicdn.com/imgextra/i2/2215107627344/O1CN01eM6hZu247bV94MWKH_!!2215107627344.jpg&resp_type=1", "");
|
|
InitCef();
|
|
}
|
|
|
|
private void btnPrev_Click(object sender, EventArgs e)
|
|
{
|
|
cefWebBrowser.Back();
|
|
}
|
|
|
|
private void btnNext_Click(object sender, EventArgs e)
|
|
{
|
|
cefWebBrowser.Forward();
|
|
}
|
|
|
|
private void txtAddress_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
if (cefWebBrowser != null)
|
|
{
|
|
cefWebBrowser.Load(txtAddress.Text);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void dgvProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
|
return;
|
|
string headerText = dgvProduct.Columns[e.ColumnIndex].HeaderText;
|
|
var prodId = dgvProduct.Rows[e.RowIndex].Cells["colProductId"].Value.ParseToString();
|
|
var prod = lstJSTListProductInfo.FirstOrDefault(p => p.id == prodId);
|
|
var row = dgvProduct.Rows[e.RowIndex];
|
|
|
|
switch (headerText)
|
|
{
|
|
case "删除":
|
|
//if (BaseMsgForm.ShowConfirm("确定删除商品吗?删除后不可恢复!").DialogResult == DialogResult.Cancel)
|
|
// return;
|
|
//DeleteProduct(dbId);
|
|
dgvProduct.Rows.Remove(row);
|
|
lstJSTListProductInfo.Remove(prod);
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("supplier_product_list_" + MainForm.ProcessCount, lstJSTListProductInfo);
|
|
break;
|
|
case "图片":
|
|
var imgUrl = dgvProduct.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString().Replace("?imageView2/2/w/90/h/90", "");
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic[imgUrl] = imgUrl;
|
|
foreach (var imgPath in prod.itemMainImage)
|
|
{
|
|
dic[imgPath.Replace("https", "http")] = imgPath.Replace("https", "http");
|
|
}
|
|
ShowImgForm imgFrom = new ShowImgForm(imgUrl, dic);
|
|
imgFrom.ShowDialog();
|
|
break;
|
|
case "":
|
|
dgvProduct.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvProduct.Rows[e.RowIndex].Cells["colCheck"].Value;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void btnCollectSupplier_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(currentGetSupplierListParamData))
|
|
{
|
|
BaseMsgForm.ShowError("请在网页上选择要搜索的供应商商品列表页面");
|
|
return;
|
|
}
|
|
if (dgvProduct.Rows.Count > 0)
|
|
{
|
|
if (BaseMsgForm.ShowConfirm("当前列表已有采集数据,是否重新采集?").DialogResult == DialogResult.Cancel)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
this.pbLoading.Visible = true;
|
|
dgvProduct.Rows.Clear();
|
|
lstJSTListProductInfo.Clear();
|
|
//if (cancellationTokenSource == null || cancellationTokenSource.IsCancellationRequested)
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
GetSupplierList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
BaseMsgForm.ShowError(ex.Message);
|
|
}
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.pbLoading.Visible = false;
|
|
//this.statusBar.lblTaskStatus.Text = "正在删除...";
|
|
}));
|
|
}, cancellationTokenSource.Token);
|
|
}
|
|
|
|
void GetSupplierList()
|
|
{
|
|
List<Cookie> cookieList = CEFBrowser.GetCookieList(".scm121.com", cefWebBrowser.GetCookieManager(null));
|
|
var shop = new ShopLoginInfo();
|
|
shop.Cookies = JsonHelper.SerializeObject(cookieList);
|
|
|
|
var Jobj = JsonHelper.JObjectParse(currentGetSupplierListParamData);
|
|
Jobj["pageSize"] = 70;
|
|
int page = pageStart;
|
|
while(page <= pageEnd)
|
|
{
|
|
if (cancellationTokenSource.IsCancellationRequested)
|
|
break;
|
|
|
|
Jobj["pageNum"] = page;
|
|
//Jobj["mallSort"] = "SELL_SEVEN"; // 采集近7日爆品 //CREATED 采集近30日新品
|
|
if (!string.IsNullOrEmpty(platformType))
|
|
Jobj["platformType"] = platformType;
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBar.lblTaskStatus.Text = "正在采集第 " + page + " 页";
|
|
}));
|
|
Thread.Sleep(Randomx.GetId(1000, 2000));
|
|
page++;
|
|
|
|
var lstRst = GetGoodsLst(shop, Jobj);
|
|
if (!lstRst.Contains("\"success\":true"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref lstRst, "message");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = lstRst;
|
|
BaseMsgForm.ShowError("查询错误:" + errMsg);
|
|
return;
|
|
}
|
|
|
|
List<JSTListProductInfo> jstLst = new List<JSTListProductInfo>();
|
|
try
|
|
{
|
|
foreach (var jItem in JsonHelper.JObjectParse(lstRst)["data"])
|
|
{
|
|
JSTListProductInfo jstProd = JsonHelper.DeserializeJsonToObject<JSTListProductInfo>(JsonHelper.SerializeObject(jItem));
|
|
jstProd.jstProductJson = JsonHelper.SerializeObject(jItem);
|
|
jstProd.dbProduct = new KJDDBProduct();
|
|
jstProd.dbProduct.from_shop_id = jstProd.supplierId;
|
|
jstProd.dbProduct.from_shop_name = jstProd.supplierName;
|
|
jstProd.dbProduct.offline_supplier_id = jstProd.offlineSupplierId;
|
|
jstProd.dbProduct.offline_supplier_name = jstProd.offlineSupplierName;
|
|
jstProd.dbProduct.spu_id = jstProd.spuId;
|
|
jstProd.dbProduct.skc_id = jstProd.itemCoId;
|
|
//jstProd.dbProduct.price_text = jstProd.minSalesPrice.ParseToString();
|
|
//jstProd.dbProduct.main_cat_id = jstProd.categoryLv1Id.ParseToString();
|
|
//jstProd.dbProduct.main_cat_name = jstProd.mainCategoryName.ParseToString();
|
|
//jstProd.dbProduct.cat_id = jstProd.categoryLv3Id.ParseToString();
|
|
jstProd.dbProduct.cat_name = jstProd.categoryName.ParseToString();
|
|
jstProd.dbProduct.ext_code = jstProd.styleCode;
|
|
jstProd.dbProduct.product_name = jstProd.itemName;
|
|
jstProd.dbProduct.product_json = "";
|
|
jstProd.dbProduct.size_json = "{}";
|
|
jstProd.dbProduct.main_img = jstProd.itemMainImage?.FirstOrDefault();
|
|
jstProd.dbProduct.sale_count = jstProd.saleSeven;
|
|
jstProd.dbProduct.sale_count_text = string.IsNullOrEmpty(jstProd.saleSevenDesensitized) ? jstProd.saleSeven.ParseToString() : jstProd.saleSevenDesensitized;
|
|
jstProd.dbProduct.product_get_type_text = "厂商直采";
|
|
jstLst.Add(jstProd);
|
|
}
|
|
if (jstLst.Count <= 0)
|
|
break;
|
|
// 经销商销量小于设定值,则单品销量肯定小于设定值,退出
|
|
//jstLst = jstLst.Where(p => p.supplierSaleSeven >= filterSaleCount).ToList();
|
|
//if (jstLst.Count <= 0)
|
|
// break;
|
|
if (filterSaleCountDays == 7)
|
|
jstLst = jstLst.Where(p => p.saleSeven >= filterSaleCount).ToList();
|
|
else
|
|
jstLst = jstLst.Where(p => p.saleThirty >= filterSaleCount).ToList();
|
|
jstLst = jstLst.Where(p => !lstJSTListProductInfo.Any(p1 => p1.id == p.id)).ToList();
|
|
|
|
lstJSTListProductInfo.AddRange(jstLst);
|
|
//var t = Task.Run(() =>
|
|
//{
|
|
Invoke(new Action(() =>
|
|
{
|
|
foreach (var prod in jstLst)
|
|
{
|
|
var id = dgvProduct.Rows.Add(
|
|
true,
|
|
prod.itemCoId,
|
|
prod.supplierName,
|
|
prod.id,
|
|
(prod.itemMainImage?.FirstOrDefault()).ParseToString().Replace("https://", "http://"),
|
|
DataGridViewExtension.defaultBitmap,
|
|
prod.itemName,
|
|
prod.saleSeven,
|
|
prod.saleThirty,
|
|
prod.categoryName,
|
|
"预估:" + prod.minSalesPrice + " 采集详情后显示实际值",
|
|
"删除"
|
|
);
|
|
dgvProduct.Rows[id].Height = 60;
|
|
|
|
}
|
|
}));
|
|
//});
|
|
//t.Wait(5000);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBar.lblTaskStatus.Text = "发生错误 " + ex.Message;
|
|
}));
|
|
Thread.Sleep(2000);
|
|
}
|
|
}
|
|
Invoke(new Action(() =>
|
|
{
|
|
BaseMsgForm.ShowInfo("采集完成");
|
|
}));
|
|
}
|
|
|
|
private void btnCollectHot_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(currentGetHotListParamData))
|
|
{
|
|
BaseMsgForm.ShowError("请在网页上选择爆款列表页面");
|
|
return;
|
|
}
|
|
if (dgvProduct.Rows.Count > 0)
|
|
{
|
|
if (BaseMsgForm.ShowConfirm("当前列表已有采集数据,是否重新采集?").DialogResult == DialogResult.Cancel)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
this.pbLoading.Visible = true;
|
|
dgvProduct.Rows.Clear();
|
|
lstJSTListProductInfo.Clear();
|
|
//if (cancellationTokenSource == null || cancellationTokenSource.IsCancellationRequested)
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
GetHotList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
BaseMsgForm.ShowError(ex.Message);
|
|
}
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.pbLoading.Visible = false;
|
|
//this.statusBar.lblTaskStatus.Text = "正在删除...";
|
|
}));
|
|
}, cancellationTokenSource.Token);
|
|
}
|
|
|
|
void GetHotList()
|
|
{
|
|
List<Cookie> cookieList = CEFBrowser.GetCookieList(".scm121.com", cefWebBrowser.GetCookieManager(null));
|
|
var shop = new ShopLoginInfo();
|
|
shop.Cookies = JsonHelper.SerializeObject(cookieList);
|
|
|
|
var Jobj = JsonHelper.JObjectParse(currentGetHotListParamData);
|
|
Jobj["pageSize"] = 70;
|
|
int page = pageStart;
|
|
while (page <= pageEnd)
|
|
{
|
|
if (cancellationTokenSource.IsCancellationRequested)
|
|
break;
|
|
|
|
Jobj["pageNum"] = page;
|
|
//Jobj["mallSort"] = "SELL_SEVEN";
|
|
if (!string.IsNullOrEmpty(platformType))
|
|
Jobj["platformType"] = platformType;
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBar.lblTaskStatus.Text = "正在采集第 " + page + " 页";
|
|
}));
|
|
Thread.Sleep(Randomx.GetId(1000, 2000));
|
|
page++;
|
|
|
|
var lstRst = GetHotLst(shop, Jobj);
|
|
if (!lstRst.Contains("\"success\":true"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref lstRst, "message");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = lstRst;
|
|
BaseMsgForm.ShowError("查询错误:" + errMsg);
|
|
return;
|
|
}
|
|
|
|
List<JSTListProductInfo> jstLst = new List<JSTListProductInfo>();
|
|
try
|
|
{
|
|
foreach (var jItem in JsonHelper.JObjectParse(lstRst)["data"])
|
|
{
|
|
JSTListProductInfo jstProd = JsonHelper.DeserializeJsonToObject<JSTListProductInfo>(JsonHelper.SerializeObject(jItem));
|
|
jstProd.jstProductJson = JsonHelper.SerializeObject(jItem);
|
|
jstProd.dbProduct = new KJDDBProduct();
|
|
jstProd.dbProduct.from_shop_id = jstProd.supplierName; // jstProd.supplierId;
|
|
jstProd.dbProduct.from_shop_name = jstProd.supplierName;
|
|
jstProd.dbProduct.offline_supplier_id = jstProd.offlineSupplierId;
|
|
jstProd.dbProduct.offline_supplier_name = jstProd.offlineSupplierName;
|
|
jstProd.dbProduct.spu_id = jstProd.spuId;
|
|
jstProd.dbProduct.skc_id = jstProd.itemCoId;
|
|
//jstProd.dbProduct.price_text = jstProd.minSalesPrice.ParseToString();
|
|
//jstProd.dbProduct.main_cat_id = jstProd.categoryLv1Id.ParseToString();
|
|
//jstProd.dbProduct.main_cat_name = jstProd.mainCategoryName.ParseToString();
|
|
//jstProd.dbProduct.cat_id = jstProd.categoryLv3Id.ParseToString();
|
|
jstProd.dbProduct.cat_name = jstProd.categoryName.ParseToString();
|
|
jstProd.dbProduct.ext_code = jstProd.styleCode;
|
|
jstProd.dbProduct.product_name = jstProd.itemName;
|
|
jstProd.dbProduct.product_json = "";
|
|
jstProd.dbProduct.size_json = "{}";
|
|
jstProd.dbProduct.main_img = jstProd.itemMainImage?.FirstOrDefault();
|
|
jstProd.dbProduct.sale_count = jstProd.saleSeven;
|
|
jstProd.dbProduct.sale_count_text = string.IsNullOrEmpty(jstProd.saleSevenDesensitized) ? jstProd.saleSeven.ParseToString() : jstProd.saleSevenDesensitized;
|
|
jstProd.dbProduct.product_get_type_text = "厂商直采";
|
|
jstLst.Add(jstProd);
|
|
}
|
|
if (jstLst.Count <= 0)
|
|
break;
|
|
// 经销商销量小于设定值,则单品销量肯定小于设定值,退出
|
|
//jstLst = jstLst.Where(p => p.supplierSaleSeven >= filterSaleCount).ToList();
|
|
//if (jstLst.Count <= 0)
|
|
// break;
|
|
if (filterSaleCountDays == 7)
|
|
jstLst = jstLst.Where(p => p.saleSeven >= filterSaleCount).ToList();
|
|
else
|
|
jstLst = jstLst.Where(p => p.saleThirty >= filterSaleCount).ToList();
|
|
jstLst = jstLst.Where(p => !lstJSTListProductInfo.Any(p1 => p1.id == p.id)).ToList();
|
|
jstLst = jstLst.Where(p => !p.limitShelvesPlatformList.Contains("WXChannel")).ToList(); // 过滤微信禁售不发货商品
|
|
|
|
// 查询真实上家
|
|
var realCoidRst = BatchQueryRealCoid(shop, string.Join(",", jstLst.Select(j => j.itemSpuId)), "12840800");
|
|
Thread.Sleep(Randomx.GetId(200, 800));
|
|
if (!realCoidRst.Contains("\"success\":true"))
|
|
{
|
|
Thread.Sleep(Randomx.GetId(1000, 2000));
|
|
realCoidRst = BatchQueryRealCoid(shop, string.Join(",", jstLst.Select(j => j.itemSpuId)), "12840800");
|
|
}
|
|
if (!realCoidRst.Contains("\"success\":true"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref realCoidRst, "message");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = realCoidRst;
|
|
BaseMsgForm.ShowError("查询产品源错误:" + errMsg);
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
var realUpObjs = JsonHelper.JObjectParse(realCoidRst)["data"];
|
|
foreach (var realUpObj in realUpObjs)
|
|
{
|
|
var jst = jstLst.FirstOrDefault(j => j.itemSpuId == realUpObj["itemSpuId"].ParseToString());
|
|
if (jst != null)
|
|
{
|
|
jst.dbProduct.real_spu_id = realUpObj["highestSupplierSpuId"].ParseToString();
|
|
jst.dbProduct.real_coid = realUpObj["supplierHierarchyList"].FirstOrDefault(sj => sj["level"].ParseToInt() == 1)["supCoId"].ParseToString();
|
|
}
|
|
}
|
|
jstLst = jstLst.Where(j => !string.IsNullOrEmpty(j.dbProduct.real_coid) && !string.IsNullOrEmpty(j.dbProduct.real_spu_id)).ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
BaseMsgForm.ShowError("查询产品源错误:" + ex.Message);
|
|
return;
|
|
}
|
|
|
|
lstJSTListProductInfo.AddRange(jstLst);
|
|
//var t = Task.Run(() =>
|
|
//{
|
|
Invoke(new Action(() =>
|
|
{
|
|
foreach (var prod in jstLst)
|
|
{
|
|
var id = dgvProduct.Rows.Add(
|
|
true,
|
|
prod.itemCoId,
|
|
prod.supplierName,
|
|
prod.id,
|
|
(prod.itemMainImage?.FirstOrDefault()).ParseToString().Replace("https://", "http://"),
|
|
DataGridViewExtension.defaultBitmap,
|
|
prod.itemName,
|
|
prod.saleSeven,
|
|
prod.saleThirty,
|
|
prod.categoryName,
|
|
"预估:" + prod.minSalesPrice + " 采集详情后显示实际值",
|
|
"删除"
|
|
);
|
|
dgvProduct.Rows[id].Height = 60;
|
|
|
|
}
|
|
}));
|
|
//});
|
|
//t.Wait(5000);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBar.lblTaskStatus.Text = "发生错误 " + ex.Message;
|
|
}));
|
|
Thread.Sleep(2000);
|
|
}
|
|
}
|
|
Invoke(new Action(() =>
|
|
{
|
|
BaseMsgForm.ShowInfo("采集完成");
|
|
}));
|
|
}
|
|
|
|
|
|
private void txtFilterSaleCount_TextChanged(object sender, EventArgs e)
|
|
{
|
|
filterSaleCount = txtFilterSaleCount.Text.Trim().ParseToInt();
|
|
}
|
|
|
|
private void txtPageStart_TextChanged(object sender, EventArgs e)
|
|
{
|
|
pageStart = txtPageStart.Text.Trim().ParseToInt();
|
|
}
|
|
|
|
private void txtPageEnd_TextChanged(object sender, EventArgs e)
|
|
{
|
|
pageEnd = txtPageEnd.Text.Trim().ParseToInt();
|
|
}
|
|
|
|
private void btnStopStop_Click(object sender, EventArgs e)
|
|
{
|
|
if (cancellationTokenSource != null)
|
|
cancellationTokenSource.Cancel();
|
|
Task.Run(() =>
|
|
{
|
|
Thread.Sleep(3000);
|
|
Invoke(new Action(() =>
|
|
{
|
|
if (cancellationTokenSource == null || cancellationTokenSource.IsCancellationRequested)
|
|
pbLoading.Visible = false;
|
|
}));
|
|
});
|
|
}
|
|
|
|
private void btnGetDetail_Click(object sender, EventArgs e)
|
|
{
|
|
if (platformType == "Pinduoduo" || string.IsNullOrEmpty(platformType))
|
|
GetPinDuoduoProd();
|
|
else if (platformType == "Douyin")
|
|
GetDyProd();
|
|
}
|
|
|
|
private void btnSaveDb_Click(object sender, EventArgs e)
|
|
{
|
|
//"&product_get_type=" + HttpUtility.UrlEncode("厂商直采", Encoding.UTF8);
|
|
List<Cookie> cookieList = CEFBrowser.GetCookieList(".scm121.com", cefWebBrowser.GetCookieManager(null));
|
|
var shop = new ShopLoginInfo();
|
|
shop.Cookies = JsonHelper.SerializeObject(cookieList);
|
|
|
|
List<DataGridViewRow> rowLst = new List<DataGridViewRow>();
|
|
rowLst.AddRange(dgvProduct.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true));
|
|
|
|
//if (cancellationTokenSource == null || cancellationTokenSource.IsCancellationRequested)
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
|
|
this.pbLoading.Visible = true;
|
|
var t = Task.Run(() =>
|
|
{
|
|
|
|
foreach (var row in rowLst)
|
|
{
|
|
if (cancellationTokenSource.IsCancellationRequested)
|
|
break;
|
|
|
|
if (row.Index % 20 == 0)
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("supplier_product_list_" + MainForm.ProcessCount, lstJSTListProductInfo);
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBar.lblTaskStatus.Text = "正在入库表格第 " + (row.Index + 1) + " 行数据";
|
|
}));
|
|
|
|
var prodId = row.Cells["colProductId"].Value.ParseToString();
|
|
var prod = lstJSTListProductInfo.FirstOrDefault(c => c.id == prodId);
|
|
if (prod == null || prod.dbProduct == null || prod.dbProduct.product_json.Length < 10)
|
|
continue;
|
|
var dbProd = prod.dbProduct;
|
|
|
|
if (prod.getProductMsg.ParseToString().Contains("入库成功") || prod.getProductMsg.ParseToString().Contains("已存在相同id商品"))
|
|
{
|
|
if (!chkOverride.Checked)
|
|
continue;
|
|
}
|
|
|
|
bool isExist = false;
|
|
var existUrl = BaseClass.BuildPDDObjString("product/get_product_spu_id_list");
|
|
string existData = UserLogin.GetSignaturex() + "&search_spu_ids=" + prod.spuId;
|
|
//if (!string.IsNullOrEmpty(prod.dbProduct.real_spu_id))
|
|
// existData = UserLogin.GetSignaturex() + "&search_spu_ids=" + prod.spuId + "," + prod.dbProduct.real_spu_id;
|
|
string html = GetHtml.PostUtf8(existUrl, existData);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
|
html = GetHtml.PostUtf8(existUrl, existData);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = "入库失败,产品数据库连接失败";
|
|
}));
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
if (html.Contains("\"data\":[") && !html.Contains("\"data\":[]"))
|
|
isExist = true;
|
|
}
|
|
|
|
//var SetPartnerSpuRst = "";
|
|
var url = BaseClass.BuildPDDObjString("product/add_product");
|
|
if (isExist)
|
|
{
|
|
if (chkOverride.Checked)
|
|
{
|
|
url = BaseClass.BuildPDDObjString("product/mdy_product");
|
|
}
|
|
else
|
|
{
|
|
//入库成功 已存在相同id商品
|
|
prod.getProductMsg = "已存在相同id商品,跳过";
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = prod.getProductMsg;
|
|
}));
|
|
continue;
|
|
}
|
|
}
|
|
//else
|
|
{
|
|
////设置分销
|
|
//SetPartnerSpuRst = SetPartnerSpu(shop, prod);
|
|
//for (int i = 0; i < 3 && !SetPartnerSpuRst.Contains("\"success\":true"); i++)
|
|
//{
|
|
// Thread.Sleep(Randomx.GetId(2000, 4000));
|
|
// SetPartnerSpuRst = SetPartnerSpu(shop, prod);
|
|
//}
|
|
//if (!SetPartnerSpuRst.Contains("\"success\":true"))
|
|
//{
|
|
// Invoke(new Action(() =>
|
|
// {
|
|
// row.Cells["colMsg"].Value = "分销设置失败,请下次重试,暂时跳过入库";
|
|
// }));
|
|
// continue;
|
|
//}
|
|
////{"success":true,"total":null,"data":{"message":"成功添加1款分销商品,系统会自动按商品拆分订单并推送给对应供应商","count":1,"shelvesType":"DISTRIBUTION"},"message":null,"code":"0000","hasNext":false,"now":1769330182209,"extra":{}}
|
|
}
|
|
|
|
var data = Work.UserLogin.GetSignaturex() +
|
|
"&from_shop_id=" + prod.dbProduct.from_shop_id +
|
|
"&from_shop_name=" + prod.dbProduct.from_shop_name +
|
|
"&offline_supplier_id=" + prod.dbProduct.offline_supplier_id +
|
|
"&offline_supplier_name=" + prod.dbProduct.offline_supplier_name +
|
|
"&spu_id=" + prod.dbProduct.spu_id.ParseToString() +
|
|
"&skc_id=" + prod.dbProduct.skc_id.ParseToString() +
|
|
"&price_text=" + prod.dbProduct.price_text +
|
|
"&ext_code=" + HttpUtility.UrlEncode(prod.dbProduct.ext_code, Encoding.UTF8) +
|
|
"&product_name=" + HttpUtility.UrlEncode(prod.dbProduct.product_name, Encoding.UTF8) +
|
|
"&product_json=" + HttpUtility.UrlEncode(dbProd.product_json, Encoding.UTF8) +
|
|
"&size_json=" + HttpUtility.UrlEncode(dbProd.size_json, Encoding.UTF8) +
|
|
"&sale_count=" + dbProd.sale_count +
|
|
"&sale_count_text=" + HttpUtility.UrlEncode(dbProd.sale_count_text, Encoding.UTF8) +
|
|
"&main_img=" + HttpUtility.UrlEncode(dbProd.main_img, Encoding.UTF8) +
|
|
"&wx_safe_status=" + HttpUtility.UrlEncode("安全商品", Encoding.UTF8) +
|
|
"&product_get_type=" + HttpUtility.UrlEncode("厂商直采", Encoding.UTF8);
|
|
if (!isExist)
|
|
{
|
|
data += "&main_cat_id=" + prod.dbProduct.main_cat_id +
|
|
"&main_cat_name=" + HttpUtility.UrlEncode(prod.dbProduct.main_cat_name.ParseToString(), Encoding.UTF8) +
|
|
"&cat_id=" + prod.dbProduct.cat_id +
|
|
"&cat_name=" + HttpUtility.UrlEncode((prod.dbProduct.cat_name ?? prod.categoryName).ParseToString(), Encoding.UTF8);
|
|
}
|
|
if (!string.IsNullOrEmpty(prod.dbProduct.real_coid))
|
|
data += "&real_coid=" + prod.dbProduct.real_coid;
|
|
if (!string.IsNullOrEmpty(prod.dbProduct.real_spu_id))
|
|
data += "&real_spu_id=" + prod.dbProduct.real_spu_id;
|
|
//if (SetPartnerSpuRst.Contains("\"success\":true"))
|
|
//{
|
|
// data += "&distribution_set=1";
|
|
//}
|
|
if (prod.dbProduct.distribution_set > 0)
|
|
{
|
|
data += "&distribution_set=1";
|
|
}
|
|
if (dbProd.main_cat_id == "15543" || dbProd.main_cat_name == "书籍/杂志/报纸")
|
|
{
|
|
data += "&special_prod_type=" + HttpUtility.UrlEncode("书籍", Encoding.UTF8);
|
|
}
|
|
|
|
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"))
|
|
{
|
|
string msg = "商品入库失败!请检查网络连接:" + BaseRegex.GetStringJson(ref html, "msg");
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = msg;
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
prod.getProductMsg = "商品入库成功!";
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = prod.getProductMsg;
|
|
}));
|
|
}
|
|
}
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("supplier_product_list_" + MainForm.ProcessCount, lstJSTListProductInfo);
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.pbLoading.Visible = false;
|
|
BaseMsgForm.ShowInfo("商品入库完毕!");
|
|
}));
|
|
}, cancellationTokenSource.Token);
|
|
}
|
|
|
|
private void cmbSaleCount_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void cmbSaleCount_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (cmbSaleCount.Text == "7日销量≥")
|
|
filterSaleCountDays = 7;
|
|
else
|
|
filterSaleCountDays = 30;
|
|
}
|
|
|
|
private void cmbPlatformType_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
//["TouTiaoFXG","Taobao","Pinduoduo","WXChannel"]
|
|
if (cmbPlatformType.Text == "拼多多")
|
|
{
|
|
platformType = "Pinduoduo";
|
|
}
|
|
else if (cmbPlatformType.Text == "抖音")
|
|
{
|
|
platformType = "Douyin";
|
|
}
|
|
else if (cmbPlatformType.Text == "淘宝")
|
|
{
|
|
platformType = "Taobao";
|
|
}
|
|
else if (cmbPlatformType.Text == "微信")
|
|
{
|
|
platformType = "WXChannel";
|
|
}
|
|
else
|
|
{
|
|
platformType = "";
|
|
}
|
|
}
|
|
|
|
int getDetailWait = 1;
|
|
private void GetPinDuoduoProd()
|
|
{
|
|
//https://sc.scm121.com/api/goods/goods/goGoodsPdd/queryBaseData?itemSpuId=26903724F0044AC5976D098842D919E3&shelvesType=DISTRIBUTION&originator=SUPPLIER&itemCoId=14202245
|
|
//https://sc.scm121.com/manage/goods/qualitySupplier/detail/93D12D2BD21649DC8240E2265BE37E2A?showErpList=1
|
|
|
|
this.pbLoading.Visible = true;
|
|
List<Cookie> cookieList = CEFBrowser.GetCookieList(".scm121.com", cefWebBrowser.GetCookieManager(null));
|
|
var shop = new ShopLoginInfo();
|
|
shop.Cookies = JsonHelper.SerializeObject(cookieList);
|
|
|
|
List<DataGridViewRow> rowLst = new List<DataGridViewRow>();
|
|
rowLst.AddRange(dgvProduct.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true));
|
|
|
|
if (cancellationTokenSource != null)
|
|
cancellationTokenSource.Cancel();
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
Task.Run(() =>
|
|
{
|
|
foreach (var row in rowLst)
|
|
{
|
|
if (cancellationTokenSource.IsCancellationRequested)
|
|
break;
|
|
|
|
if (row.Index % 20 == 0)
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("supplier_product_list_" + MainForm.ProcessCount, lstJSTListProductInfo);
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBar.lblTaskStatus.Text = "正在采集表格第 " + (row.Index + 1) + " 行详情数据";
|
|
}));
|
|
|
|
var prodId = row.Cells["colProductId"].Value.ParseToString();
|
|
var prod = lstJSTListProductInfo.FirstOrDefault(c => c.id == prodId);
|
|
|
|
if (chkSkip.Checked)
|
|
{
|
|
// 不存在或已经采集过
|
|
if (prod == null || prod?.dbProduct?.product_json?.ParseToString().Length > 10)
|
|
continue;
|
|
|
|
if (prod.getProductMsg == "商品已存在,跳过详情采集")
|
|
continue;
|
|
if (prod.getProductMsg.ParseToString().Contains("入库成功") || prod.getProductMsg.ParseToString().Contains("已存在相同id商品"))
|
|
continue;
|
|
|
|
bool isExist = false;
|
|
var existUrl = BaseClass.BuildPDDObjString("product/get_product_spu_id_list");
|
|
string existData = UserLogin.GetSignaturex() + "&search_spu_ids=" + prod.spuId;
|
|
//if (!string.IsNullOrEmpty(prod.dbProduct.real_spu_id))
|
|
// existData = UserLogin.GetSignaturex() + "&search_spu_ids=" + prod.spuId + "," + prod.dbProduct.real_spu_id;
|
|
string html = GetHtml.PostUtf8(existUrl, existData);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
|
html = GetHtml.PostUtf8(existUrl, existData);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
|
{
|
|
prod.getProductMsg = "采集详情失败,产品数据库连接失败";
|
|
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
if (html.Contains("\"data\":[") && !html.Contains("\"data\":[]"))
|
|
isExist = true;
|
|
}
|
|
prod.getProductMsg = "商品已存在,跳过详情采集";
|
|
if (isExist)
|
|
{
|
|
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
|
continue;
|
|
}
|
|
}
|
|
Thread.Sleep(Randomx.GetId(500, 1500));
|
|
// 额外休眠
|
|
Thread.Sleep(getDetailWait * 1000);
|
|
|
|
// 爆款专区查询真实供应商coid和供应商退货地址
|
|
if (prod.itemCoId == "12840800" || prod.supplierName == "寻合作-爆款专区")
|
|
{
|
|
if (dicAfterSale.Keys.Contains(prod.dbProduct.skc_id + "->" + prod.dbProduct.real_coid))
|
|
{
|
|
}
|
|
else
|
|
{
|
|
|
|
var urlAfterSale = BaseClass.BuildObjString("product/wx_get_after_sale");
|
|
var dataAfterSale = Work.UserLogin.GetSignaturex() +
|
|
"&coid=" + prod.dbProduct.skc_id + "->" + prod.dbProduct.real_coid;
|
|
var htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
|
if (string.IsNullOrEmpty(htmlAfterSale) || !htmlAfterSale.Contains("\"code\":200"))
|
|
htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
|
if (string.IsNullOrEmpty(htmlAfterSale) || !htmlAfterSale.Contains("\"code\":200"))
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = "爆款售后地址比对失败,请下次重试,暂时跳过入库";
|
|
}));
|
|
continue;
|
|
}
|
|
if (htmlAfterSale.Contains("\"data\":\"\""))
|
|
{
|
|
var afterSaleRst = GetAfterSaleAddress(shop, prod.dbProduct.real_spu_id, prod.dbProduct.spu_id, prod.dbProduct.real_coid, prod.dbProduct.skc_id);
|
|
string address_id = BaseRegex.GetStringJson(ref afterSaleRst, "returnAddressId").ParseToString();
|
|
string middlemanAddressId = BaseRegex.GetStringJson(ref afterSaleRst, "middlemanAddressId").ParseToString();
|
|
if (address_id.IsNullOrEmpty() && middlemanAddressId.IsNullOrEmpty())
|
|
{
|
|
Thread.Sleep(5000);
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = "爆款售后地址获取失败,请下次重试,暂时跳过入库";
|
|
}));
|
|
continue;
|
|
}
|
|
retry:
|
|
var afterSaleMobileRst = "";
|
|
if (!address_id.IsNullOrEmpty())
|
|
afterSaleMobileRst = GetAfterSaleAddressMobile(shop, address_id,
|
|
prod.dbProduct.real_spu_id, prod.dbProduct.spu_id, prod.dbProduct.real_coid, prod.dbProduct.skc_id);
|
|
else
|
|
afterSaleMobileRst = GetAfterSaleAddressMobileById(shop, middlemanAddressId,
|
|
prod.dbProduct.real_spu_id, prod.dbProduct.spu_id, prod.dbProduct.real_coid, prod.dbProduct.skc_id);
|
|
Thread.Sleep(Randomx.GetId(1000, 5000));
|
|
//为了您的数据安全,复制手机号要求验证身份,已发送验证码到您手机:132*****859,请输入验证码后进行确认。
|
|
string tel_number = BaseRegex.GetStringJson(ref afterSaleMobileRst, "data");
|
|
if (tel_number.IsNullOrEmpty())
|
|
{
|
|
if (afterSaleMobileRst.Contains("为了您的数据安全,复制手机号要求验证身份,已发送验证码到您手机"))
|
|
{
|
|
GetJuShuitanAuthForm GetJuShuitanAuthForm = new GetJuShuitanAuthForm();
|
|
GetJuShuitanAuthForm.ShowDialog();
|
|
var authStr = GetJuShuitanAuthForm.authStr;
|
|
var authRst = AuthV2(shop, prod, authStr);
|
|
|
|
if (authRst.Contains("\"success\":true"))
|
|
goto retry;
|
|
else
|
|
{
|
|
if (BaseMsgForm.ShowConfirm("验证码校验失败,是否重试?").DialogResult == DialogResult.OK)
|
|
{
|
|
goto retry;
|
|
}
|
|
}
|
|
}
|
|
|
|
Thread.Sleep(5000);
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = "爆款售后电话获取失败,请下次重试,暂时跳过入库";
|
|
}));
|
|
continue;
|
|
|
|
}
|
|
|
|
//聚水潭退货地址:{"success":true,"total":null,"data":{"supplierReturnAddresses":[{"supplierHierarchyChain":"12840800->14009332","spuId":"C1DE5AF0118D4588B32849FA87610622","hasReturnAddress":true,"currentSupplierName":"寻合作-爆款专区","returnAddress":{"uniqueKey":"12840800-1c6cef6a151608d52f032f03fa59fec9","province":"山东省","city":"聊城市","district":"茌平区","address":"顺河北街与信发路交汇处路北山东名威电子商务","recipientName":"乌先生","street":"信发街道","mobile":"1658***1111","encryptedMobile":"aRwLwihnqaLoahYFJ2+uXw==","returnAddressId":4101,"coId":14009332,"middlemanAddress":false,"middlemanAddressId":null}}]},"message":null,"code":"0000","hasNext":false,"now":1772178142906,"extra":{}}
|
|
//e57获取的地址格式{"address_id":null,"user_name":"孙庆裕","postal_code":null,"province_name":"浙江省","city_name":"金华市","county_name":"义乌市","street_name":"城西街道","detail_info":"城西街道圣达街18号金哥集团2号岗 5号电梯 三楼退件区","tel_number":"13024622251","number":"10010274","name":"义乌芸茄商贸有限公司"}
|
|
|
|
string coid = BaseRegex.GetStringJson(ref afterSaleRst, "supplierHierarchyChain");
|
|
string user_name = BaseRegex.GetStringJson(ref afterSaleRst, "recipientName");
|
|
string province_name = BaseRegex.GetStringJson(ref afterSaleRst, "province");
|
|
string city_name = BaseRegex.GetStringJson(ref afterSaleRst, "city");
|
|
string county_name = BaseRegex.GetStringJson(ref afterSaleRst, "district");
|
|
string street_name = BaseRegex.GetStringJson(ref afterSaleRst, "street");
|
|
string detail_info = BaseRegex.GetStringJson(ref afterSaleRst, "address");
|
|
// 电话号码上面查过立即赋值
|
|
//string tel_number = BaseRegex.GetStringJson(ref afterSaleRst, "mobile");
|
|
string number = prod.dbProduct.real_coid;
|
|
string name = BaseRegex.GetStringJson(ref afterSaleRst, "currentSupplierName");
|
|
|
|
var addressObj = new JObject();
|
|
addressObj.Add("address_id", address_id.IsNullOrEmpty() ? middlemanAddressId : address_id);
|
|
addressObj.Add("user_name", user_name);
|
|
addressObj.Add("postal_code", null);
|
|
addressObj.Add("province_name", province_name);
|
|
addressObj.Add("city_name", city_name);
|
|
addressObj.Add("county_name", county_name);
|
|
addressObj.Add("street_name", street_name);
|
|
addressObj.Add("detail_info", detail_info);
|
|
addressObj.Add("tel_number", tel_number);
|
|
addressObj.Add("number", number);
|
|
addressObj.Add("name", name);
|
|
|
|
if ((address_id + middlemanAddressId).IsNullOrEmpty() || coid.IsNullOrEmpty() || user_name.IsNullOrEmpty() || province_name.IsNullOrEmpty() || city_name.IsNullOrEmpty() ||
|
|
county_name.IsNullOrEmpty() || street_name.IsNullOrEmpty() || detail_info.IsNullOrEmpty() || tel_number.IsNullOrEmpty() || number.IsNullOrEmpty() ||
|
|
name.IsNullOrEmpty())
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = "爆款售后地址获取失败,请下次重试,暂时跳过入库";
|
|
}));
|
|
continue;
|
|
}
|
|
|
|
var urlSaveAfterSale = BaseClass.BuildObjString("product/wx_add_mdy_after_sale");
|
|
var dataSaveAfterSale = Work.UserLogin.GetSignaturex() +
|
|
"&coid=" + coid +
|
|
"&after_sale_json=" + JsonHelper.SerializeObject(addressObj);
|
|
string htmlSaveAfterSale = GetHtml.PostUtf8(urlSaveAfterSale, dataSaveAfterSale);
|
|
if (string.IsNullOrEmpty(htmlSaveAfterSale) || !htmlSaveAfterSale.Contains("\"code\":200"))
|
|
htmlSaveAfterSale = GetHtml.PostUtf8(urlSaveAfterSale, dataSaveAfterSale);
|
|
if (string.IsNullOrEmpty(htmlSaveAfterSale) || !htmlSaveAfterSale.Contains("\"code\":200"))
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = "爆款售后地址保存失败,请下次重试,暂时跳过入库";
|
|
}));
|
|
continue;
|
|
}
|
|
|
|
dicAfterSale[coid] = JsonHelper.SerializeObject(addressObj);
|
|
}
|
|
}
|
|
}
|
|
|
|
//设置分销
|
|
var SetPartnerSpuRst = SetPartnerSpu(shop, prod);
|
|
for (int i = 0; i < 3 && !SetPartnerSpuRst.Contains("\"success\":true"); i++)
|
|
{
|
|
Thread.Sleep(Randomx.GetId(2000, 4000));
|
|
SetPartnerSpuRst = SetPartnerSpu(shop, prod);
|
|
}
|
|
if (!SetPartnerSpuRst.Contains("\"success\":true"))
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = "分销设置失败,请下次重试,暂时跳过入库";
|
|
}));
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
prod.dbProduct.distribution_set = 1;
|
|
}
|
|
//{"success":true,"total":null,"data":{"message":"成功添加1款分销商品,系统会自动按商品拆分订单并推送给对应供应商","count":1,"shelvesType":"DISTRIBUTION"},"message":null,"code":"0000","hasNext":false,"now":1769330182209,"extra":{}}
|
|
|
|
// 先获取Pdd店铺信息
|
|
if (string.IsNullOrEmpty(jstPddShopId))
|
|
{
|
|
var getShopIdRst = GetPddShopId(shop, prod);
|
|
//{"success":true,"total":1,"data":[{"shopId":"20115638","supplierId":"14791477","shopName":"阿杰小铺浦哈哈","shopType":"拼多多","shopTypeKey":"拼多多","shopTypeValue":"拼多多","itemSpuId":null,"shopItemSpuId":null,"shopAuthorizationDate":"2027-01-23 11:17:00","userName":null,"shelvesStatus":false,"updated":null,"sessionStatus":2,"sessionUid":null,"created":null,"hasPermission":true,"enabled":true,"mainSpuId":null,"shelved":false,"appCid":0,"riskVerifyUrl":null,"storeType":"COMMON"}],"message":null,"code":"0000","hasNext":false,"now":1769588598917,"extra":{}}
|
|
jstPddShopId = BaseRegex.GetStringJson(ref getShopIdRst, "shopId");
|
|
}
|
|
|
|
// 采集商品详情
|
|
var getPddDetailRst = GetPddBaseData(shop, prod);
|
|
if (!getPddDetailRst.Contains("\"success\":true"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref getPddDetailRst, "message");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = getPddDetailRst;
|
|
prod.getProductMsg = "采集失败 " + errMsg;
|
|
Invoke(new Action(() =>
|
|
{
|
|
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
|
}));
|
|
continue;
|
|
}
|
|
|
|
try
|
|
{
|
|
var jObj = JsonHelper.JObjectParse(getPddDetailRst)["data"];
|
|
|
|
// 未维护拼多多平台数据的,采集聚水潭拼多多页面基础数据,转化为拼多多数据,给客户上传草稿箱使用
|
|
if (jObj.IsJTokenNullOrEmpty())
|
|
{
|
|
jObj = GetJstPddPageDetail(shop, prod, row);
|
|
if (jObj == null)
|
|
continue;
|
|
}
|
|
|
|
// 未维护拼多多平台数据的,采集聚水潭商品详情页面基础数据,转化为拼多多数据,给客户上传草稿箱使用
|
|
//if (jObj.IsJTokenNullOrEmpty())
|
|
//{
|
|
// jObj = GetJstPageDetail(shop, prod, row);
|
|
// if (jObj == null)
|
|
// continue;
|
|
//}
|
|
|
|
prod.dbProduct.cat_id = jObj["catId"].ParseToString();
|
|
|
|
// 获取属性
|
|
if (prod.dbProduct.cat_id.IsNullOrEmpty())
|
|
prod.dbProduct.cat_id = "1";
|
|
var getPropRst = GetPddProp(shop, prod, prod.dbProduct.cat_id, jstPddShopId);
|
|
if (!getPropRst.Contains("\"success\":true"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref getPropRst, "message");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = getPropRst;
|
|
prod.getProductMsg = "采集失败 " + errMsg;
|
|
Invoke(new Action(() =>
|
|
{
|
|
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
|
}));
|
|
continue;
|
|
}
|
|
List<PDDPropRefPidNameMap> pddPropMap = new List<PDDPropRefPidNameMap>();
|
|
var pddPropObj = JsonHelper.JObjectParse(getPropRst)["data"];
|
|
if (pddPropObj.IsJTokenNullOrEmpty())
|
|
{
|
|
pddPropObj = new JObject();
|
|
}
|
|
if (pddPropObj["properties"].IsJTokenNullOrEmpty())
|
|
{
|
|
pddPropObj["properties"] = new JArray();
|
|
}
|
|
foreach (JObject pObj in pddPropObj["properties"])
|
|
{
|
|
pddPropMap.Add(new PDDPropRefPidNameMap()
|
|
{
|
|
id = pObj["id"].IsJTokenNullOrEmpty() ? new long?() : pObj["id"].ParseToLong(),
|
|
ref_pid = pObj["ref_pid"].IsJTokenNullOrEmpty() ? new long?() : pObj["ref_pid"].ParseToLong(),
|
|
name = pObj["name"].IsJTokenNullOrEmpty() ? null : pObj["name"].ParseToString(),
|
|
name_alias = pObj["name_alias"].IsJTokenNullOrEmpty() ? null : pObj["name_alias"].ParseToString(),
|
|
});
|
|
}
|
|
if (pddPropMap.Count == 0 && 1==2)
|
|
{
|
|
// 取商品属性
|
|
getPropRst = GetPddPropForUpdate(shop, prod, prod.dbProduct.cat_id, jstPddShopId);
|
|
if (!getPropRst.Contains("\"success\":true"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref getPropRst, "message");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = getPropRst;
|
|
prod.getProductMsg = "采集失败 " + errMsg;
|
|
Invoke(new Action(() =>
|
|
{
|
|
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
|
}));
|
|
continue;
|
|
}
|
|
pddPropMap = new List<PDDPropRefPidNameMap>();
|
|
pddPropObj = JsonHelper.JObjectParse(getPropRst)["data"];
|
|
foreach (JObject pObj in pddPropObj["cateAttrList"])
|
|
{
|
|
pddPropMap.Add(new PDDPropRefPidNameMap()
|
|
{
|
|
id = pObj["id"].IsJTokenNullOrEmpty() ? new long?() : pObj["id"].ParseToLong(),
|
|
ref_pid = pObj["ref_pid"].IsJTokenNullOrEmpty() ? new long?() : pObj["ref_pid"].ParseToLong(),
|
|
name = pObj["name"].IsJTokenNullOrEmpty() ? null : pObj["name"].ParseToString(),
|
|
name_alias = pObj["name_alias"].IsJTokenNullOrEmpty() ? null : pObj["name_alias"].ParseToString(),
|
|
});
|
|
}
|
|
}
|
|
// 没有属性的预测属性
|
|
// 不进行类目属性预测
|
|
//var getPropRstV2 = GetPddPropForecastV2(shop, prod, prod.dbProduct.cat_id);
|
|
|
|
prod.dbProduct.main_cat_id = jObj["categoryData"].FirstOrDefault().ParseToString();
|
|
var prodDataJson = JsonHelper.SerializeObject(jObj);
|
|
//if (jObj["pddPropMap"].IsJTokenNullOrEmpty() && !jObj["pddData"]["categoryPropStr"].IsJTokenNullOrEmpty())
|
|
//{
|
|
|
|
//}
|
|
var propMapJson = JsonHelper.SerializeObject(pddPropMap);
|
|
prod.dbProduct.product_json = "{\"pddData\":" + prodDataJson + ",\"pddPropMap\":" + propMapJson + ",\"jstProd\":" + prod.jstProductJson + "}";
|
|
var priceMin = jObj["skuInfo"]["goodsSkuDetail"].Min(s => s["supplyPrice"].ParseToDecimal());
|
|
var priceMax = jObj["skuInfo"]["goodsSkuDetail"].Max(s => s["supplyPrice"].ParseToDecimal());
|
|
prod.dbProduct.price_text = priceMin + "-" + priceMax;
|
|
prod.getProductMsg = "采集成功";
|
|
|
|
MainForm.instance.Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = prod.getProductMsg;
|
|
row.Cells["colCate"].Value = prod.categoryName.IsNullOrEmpty() ? prod?.dbProduct?.cat_id : prod.categoryName;
|
|
row.Cells["colPrice"].Value = prod.dbProduct.price_text;
|
|
}));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
prod.getProductMsg = "采集失败 " + ex.Message;
|
|
Invoke(new Action(() =>
|
|
{
|
|
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
|
}));
|
|
}
|
|
}
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("supplier_product_list_" + MainForm.ProcessCount, lstJSTListProductInfo);
|
|
Invoke(new Action(() =>
|
|
{
|
|
BaseMsgForm.ShowInfo("采集完成");
|
|
pbLoading.Visible = false;
|
|
}));
|
|
}, cancellationTokenSource.Token);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取聚水潭商品详情并转换为聚水潭拼多多商品详情
|
|
/// </summary>
|
|
/// <param name="shop"></param>
|
|
/// <param name="prod"></param>
|
|
/// <param name="row"></param>
|
|
/// <returns></returns>
|
|
private JObject GetJstPageDetail(ShopLoginInfo shop, JSTListProductInfo prod, DataGridViewRow row)
|
|
{
|
|
var detailRst = GetGoodsDetail(shop, prod);
|
|
if (!detailRst.Contains("\"success\":true"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref detailRst, "message");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = detailRst;
|
|
prod.getProductMsg = "采集失败 " + errMsg;
|
|
Invoke(new Action(() =>
|
|
{
|
|
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
|
}));
|
|
return null;
|
|
}
|
|
|
|
try
|
|
{
|
|
var JstData = JsonHelper.JObjectParse(detailRst)["data"];
|
|
var PddData = new JObject();
|
|
PddData["id"] = JstData["supplierId"].ParseToString();
|
|
PddData["coId"] = JstData["coId"].ParseToString();
|
|
PddData["carouselGallery"] = JstData["itemMainImage"];
|
|
PddData["categoryData"] = new JArray() { 1 };
|
|
PddData["catId"] = 1;
|
|
//PddData["detailGallery"] = JstData["itemDetailImages"];
|
|
if (JstData["itemDetailImages"].IsJTokenNullOrEmpty() || JstData["itemDetailImages"].Count() == 0)
|
|
{
|
|
PddData["detailGallery"] = new JArray();
|
|
foreach (var jItem in PddData["carouselGallery"])
|
|
{
|
|
(PddData["detailGallery"] as JArray).Add(jItem);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
PddData["detailGallery"] = new JArray();
|
|
foreach (var jItem in JstData["itemDetailImages"])
|
|
{
|
|
(PddData["detailGallery"] as JArray).Add(jItem["imageUrl"]);
|
|
}
|
|
}
|
|
PddData["goodsDesc"] = JstData["itemName"].ParseToString();
|
|
PddData["goodsName"] = JstData["itemName"].ParseToString();
|
|
PddData["goodsProperties"] = new JArray();
|
|
PddData["marketPrice"] = JstData["maxSupplyPrice"].ParseToDecimal() * 2 + 10;
|
|
PddData["styleCode"] = JstData["styleCode"];
|
|
PddData["itemSpuId"] = JstData["itemSpuId"];
|
|
PddData["skuInfo"] = new JObject();
|
|
(PddData["skuInfo"] as JObject).Add("goodsSkuDetail", new JArray());
|
|
foreach (var jstSkuObj in JstData["itemSkuList"])
|
|
{
|
|
JObject skuObj = new JObject();
|
|
(PddData["skuInfo"]["goodsSkuDetail"] as JArray).Add(skuObj);
|
|
|
|
skuObj["quantity"] = jstSkuObj["stock"];
|
|
skuObj["skus"] = new JArray();
|
|
if (!jstSkuObj["colour"].IsJTokenNullOrEmpty())
|
|
{
|
|
JObject jSpecColor = new JObject();
|
|
(skuObj["skus"] as JArray).Add(jSpecColor);
|
|
jSpecColor["v"] = jstSkuObj["colour"].ParseToString();
|
|
jSpecColor["k"] = "颜色";
|
|
}
|
|
if (!jstSkuObj["spec"].IsJTokenNullOrEmpty())
|
|
{
|
|
JObject jSpecColor = new JObject();
|
|
(skuObj["skus"] as JArray).Add(jSpecColor);
|
|
jSpecColor["v"] = jstSkuObj["spec"].ParseToString();
|
|
jSpecColor["k"] = "尺码";
|
|
}
|
|
skuObj["supplyPrice"] = jstSkuObj["supplyPrice"];
|
|
skuObj["erpSkuStatus"] = jstSkuObj["erpSkuStatus"];
|
|
skuObj["baseSkuId"] = jstSkuObj["id"];
|
|
skuObj["coId"] = jstSkuObj["coId"];
|
|
skuObj["isOnsale"] = 1;
|
|
skuObj["itemNo"] = jstSkuObj["itemCode"].IsJTokenNullOrEmpty() ? jstSkuObj["erpStyleCode"] : jstSkuObj["itemCode"];
|
|
skuObj["pic"] = jstSkuObj["pic"];
|
|
skuObj["jdSkuStatus"] = 1;
|
|
skuObj["limitQuantity"] = 999;
|
|
skuObj["sales"] = 0;
|
|
skuObj["aliSkuStatus"] = 1;
|
|
skuObj["preSaleTime"] = "";
|
|
skuObj["price"] = jstSkuObj["supplyPrice"].ParseToDecimal() + 1;
|
|
skuObj["multiPrice"] = jstSkuObj["supplyPrice"];
|
|
skuObj["id"] = jstSkuObj["id"];
|
|
}
|
|
|
|
PddData["whiteImage"] = JstData["whiteImage"];
|
|
PddData["colourRelation"] = JstData["colourSet"];
|
|
PddData["specRelation"] = JstData["specSet"];
|
|
PddData["itemCoId"] = JstData["itemCoId"];
|
|
PddData["shopTypeEnum"] = "Pinduoduo";
|
|
PddData["forecastMainImage"] = PddData["carouselGallery"].FirstOrDefault();
|
|
PddData["forecastItemName"] = PddData["goodsName"];
|
|
PddData["mainImage"] = PddData["carouselGallery"];
|
|
PddData["leafCategoryId"] = PddData["catId"].ParseToString();
|
|
PddData["itemName"] = PddData["goodsName"];
|
|
PddData["groupPreSaleDay"] = 0;
|
|
PddData["categoryPropStr"] = "[]";
|
|
|
|
return PddData;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private JObject GetJstPddPageDetail(ShopLoginInfo shop, JSTListProductInfo prod, DataGridViewRow row)
|
|
{
|
|
// 获取商品详情
|
|
var detailRst = GetItemSpuInfo(shop, prod);
|
|
if (!detailRst.Contains("\"success\":true"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref detailRst, "message");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = detailRst;
|
|
prod.getProductMsg = "采集失败 " + errMsg;
|
|
Invoke(new Action(() =>
|
|
{
|
|
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
|
}));
|
|
return null;
|
|
}
|
|
|
|
// 获取类目预测
|
|
var cateRst = categoryForecastWithPlatform(shop, prod, jstPddShopId);
|
|
Thread.Sleep(Randomx.GetId(1000, 2000));
|
|
if (!cateRst.Contains("\"success\":true"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref cateRst, "message");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = cateRst;
|
|
prod.getProductMsg = "采集失败 " + errMsg;
|
|
Invoke(new Action(() =>
|
|
{
|
|
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
|
}));
|
|
return null;
|
|
}
|
|
|
|
try
|
|
{
|
|
var JstPddData = JsonHelper.JObjectParse(detailRst)["data"];
|
|
var pddCateForecast = JsonHelper.JObjectParse(cateRst)["data"].FirstOrDefault()?["forecastCategory"] as JArray;
|
|
|
|
var PddData = new JObject();
|
|
PddData["id"] = JstPddData["goodsItemSpu"]["id"].ParseToString();
|
|
PddData["coId"] = JstPddData["goodsItemSpu"]["coId"].ParseToString();
|
|
PddData["carouselGallery"] = JstPddData["goodsItemSpu"]["itemMainImage"];
|
|
PddData["categoryData"] = new JArray();
|
|
foreach (var catItem in pddCateForecast)
|
|
{
|
|
(PddData["categoryData"] as JArray).Add(catItem["categoryId"]);
|
|
}
|
|
PddData["catId"] = (pddCateForecast.LastOrDefault()?["categoryId"]).ParseToLong();
|
|
if (JstPddData["goodsItemPhoto"]["itemDetailImages"].IsJTokenNullOrEmpty() || JstPddData["goodsItemPhoto"]["itemDetailImages"].Count() == 0)
|
|
{
|
|
PddData["detailGallery"] = new JArray();
|
|
foreach (var jItem in PddData["carouselGallery"])
|
|
{
|
|
(PddData["detailGallery"] as JArray).Add(jItem);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
PddData["detailGallery"] = new JArray();
|
|
foreach (var jItem in JstPddData["goodsItemPhoto"]["itemDetailImages"])
|
|
{
|
|
(PddData["detailGallery"] as JArray).Add(jItem["imageUrl"]);
|
|
}
|
|
}
|
|
|
|
PddData["goodsDesc"] = JstPddData["goodsItemSpu"]["itemName"].ParseToString();
|
|
PddData["goodsName"] = JstPddData["goodsItemSpu"]["itemName"].ParseToString();
|
|
PddData["goodsProperties"] = new JArray();
|
|
|
|
// 市场价
|
|
PddData["marketPrice"] = 0;
|
|
|
|
PddData["styleCode"] = JstPddData["goodsItemSpu"]["styleCode"];
|
|
PddData["itemSpuId"] = JstPddData["goodsItemSpu"]["itemSpuId"];
|
|
|
|
PddData["colourRelation"] = new JObject(); // JstPddData["colourSet"];
|
|
PddData["specRelation"] = new JObject(); //JstPddData["specSet"];
|
|
|
|
PddData["skuInfo"] = new JObject();
|
|
(PddData["skuInfo"] as JObject).Add("goodsSkuDetail", new JArray());
|
|
foreach (var jstSkuObjC in JstPddData["colourItemSkus"])
|
|
{
|
|
//string colour = jstSkuObjC["colour"].ParseToString();
|
|
foreach (var jstSkuObj in jstSkuObjC["goodsItemSkus"])
|
|
{
|
|
JObject skuObj = new JObject();
|
|
(PddData["skuInfo"]["goodsSkuDetail"] as JArray).Add(skuObj);
|
|
|
|
skuObj["quantity"] = jstSkuObj["skuStock"];
|
|
skuObj["skus"] = new JArray();
|
|
if (!jstSkuObj["colour"].IsNullOrEmpty())
|
|
{
|
|
JObject jSpecColor = new JObject();
|
|
(skuObj["skus"] as JArray).Add(jSpecColor);
|
|
jSpecColor["v"] = jstSkuObj["colour"].ParseToString();
|
|
jSpecColor["k"] = JstPddData["goodsItemSpu"]["realColorName"].ParseToString().IsNullOrEmpty() ? "颜色" : JstPddData["goodsItemSpu"]["realColorName"];
|
|
(PddData["colourRelation"] as JObject)[jstSkuObj["colour"].ParseToString()] = jstSkuObj["colour"];
|
|
}
|
|
if (!jstSkuObj["spec"].IsJTokenNullOrEmpty())
|
|
{
|
|
JObject jSpecColor = new JObject();
|
|
(skuObj["skus"] as JArray).Add(jSpecColor);
|
|
jSpecColor["v"] = jstSkuObj["spec"].ParseToString();
|
|
jSpecColor["k"] = JstPddData["goodsItemSpu"]["realSpecName"].ParseToString().IsNullOrEmpty() ? "尺码" : JstPddData["goodsItemSpu"]["realSpecName"];
|
|
(PddData["specRelation"] as JObject)[jstSkuObj["spec"].ParseToString()] = jstSkuObj["spec"];
|
|
}
|
|
skuObj["supplyPrice"] = jstSkuObj["supplyPrice"];
|
|
skuObj["erpSkuStatus"] = jstSkuObj["erpSkuStatus"];
|
|
skuObj["baseSkuId"] = jstSkuObj["id"];
|
|
skuObj["coId"] = JstPddData["goodsItemSpu"]["coId"];
|
|
skuObj["isOnsale"] = 1;
|
|
skuObj["itemNo"] = jstSkuObj["itemCode"];
|
|
skuObj["pic"] = jstSkuObj["pic"];
|
|
skuObj["jdSkuStatus"] = 1;
|
|
skuObj["limitQuantity"] = 999;
|
|
skuObj["sales"] = 0;
|
|
skuObj["aliSkuStatus"] = 1;
|
|
skuObj["preSaleTime"] = "";
|
|
skuObj["price"] = jstSkuObj["supplyPrice"].ParseToDecimal() + 1;
|
|
skuObj["multiPrice"] = jstSkuObj["supplyPrice"];
|
|
skuObj["id"] = jstSkuObj["id"];
|
|
|
|
// 市场价
|
|
PddData["marketPrice"] = Math.Max(PddData["marketPrice"].ParseToDecimal(), skuObj["multiPrice"].ParseToDecimal() * 2 + 10);
|
|
}
|
|
}
|
|
|
|
PddData["whiteImage"] = JstPddData["goodsItemPhoto"]["whiteImage"];
|
|
PddData["itemCoId"] = JstPddData["goodsItemSpu"]["coId"].ParseToString();
|
|
PddData["shopTypeEnum"] = "Pinduoduo";
|
|
PddData["forecastMainImage"] = PddData["carouselGallery"].FirstOrDefault();
|
|
PddData["forecastItemName"] = PddData["goodsName"];
|
|
PddData["mainImage"] = PddData["carouselGallery"];
|
|
PddData["leafCategoryId"] = PddData["catId"].ParseToString();
|
|
PddData["itemName"] = PddData["goodsName"];
|
|
PddData["groupPreSaleDay"] = 0;
|
|
PddData["categoryPropStr"] = "[]";
|
|
|
|
return PddData;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
prod.getProductMsg = "详情采集失败:" + ex.Message;
|
|
Invoke(new Action(() =>
|
|
{
|
|
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
|
}));
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private void GetDyProd()
|
|
{
|
|
this.pbLoading.Visible = true;
|
|
//if (cancellationTokenSource == null || cancellationTokenSource.IsCancellationRequested)
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
|
|
Task.Run(() =>
|
|
{
|
|
List<Cookie> cookieList = CEFBrowser.GetCookieList(".scm121.com", cefWebBrowser.GetCookieManager(null));
|
|
var shop = new ShopLoginInfo();
|
|
shop.Cookies = JsonHelper.SerializeObject(cookieList);
|
|
|
|
List<DataGridViewRow> rowLst = new List<DataGridViewRow>();
|
|
rowLst.AddRange(dgvProduct.Rows.Cast<DataGridViewRow>());
|
|
foreach (DataGridViewRow row in rowLst)
|
|
{
|
|
if (cancellationTokenSource.IsCancellationRequested)
|
|
break;
|
|
|
|
if (row.Index < 0 || row.Cells["colCheck"].Value.ParseToBool() != true)
|
|
continue;
|
|
|
|
var prodId = row.Cells["colProductId"].Value.ParseToString();
|
|
var prod = lstJSTListProductInfo.FirstOrDefault(c => c.id == prodId);
|
|
// 不存在或已经采集过
|
|
if (prod == null || prod?.dbProduct?.product_json?.ParseToString().Length > 10)
|
|
continue;
|
|
|
|
Thread.Sleep(Randomx.GetId(500, 1500));
|
|
if (chkSkip.Checked)
|
|
{
|
|
bool isExist = false;
|
|
var existUrl = BaseClass.BuildPDDObjString("product/get_product_list");
|
|
string existData = UserLogin.GetSignaturex() + "&search_spu=" + prod.spuId;
|
|
string html = GetHtml.PostUtf8(existUrl, existData);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
|
html = GetHtml.PostUtf8(existUrl, existData);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = "采集详情失败,产品数据库连接失败";
|
|
}));
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
if (html.Contains("\"data\":[") && !html.Contains("\"data\":[]"))
|
|
isExist = true;
|
|
}
|
|
if (isExist)
|
|
{
|
|
prod.getProductMsg = "商品已存在,跳过详情采集";
|
|
row.Cells["colMsg"].Value = prod.getProductMsg;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
var getDetailRst = GetPddBaseData(shop, prod);
|
|
if (!getDetailRst.Contains("\"success\":true"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref getDetailRst, "message");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = getDetailRst;
|
|
prod.getProductMsg = "采集失败 " + errMsg;
|
|
Invoke(new Action(() =>
|
|
{
|
|
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
|
}));
|
|
continue;
|
|
}
|
|
|
|
try
|
|
{
|
|
var jObj = JsonHelper.JObjectParse(getDetailRst)["data"];
|
|
prod.dbProduct.cat_id = jObj["leafCategoryId"].ParseToString();
|
|
prod.dbProduct.main_cat_id = jObj["categoryData"].FirstOrDefault().ParseToString();
|
|
prod.dbProduct.product_json = "{\"dyData\":" + JsonHelper.SerializeObject(jObj) + ",\"jstProd\":" + prod.jstProductJson + "}";
|
|
var priceMin = jObj["skuInfo"]["goodsSkuDetail"].Min(s => s["supplyPrice"].ParseToDecimal());
|
|
var priceMax = jObj["skuInfo"]["goodsSkuDetail"].Max(s => s["supplyPrice"].ParseToDecimal());
|
|
prod.dbProduct.price_text = priceMin + "-" + priceMax;
|
|
prod.getProductMsg = "采集成功";
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colMsg"].Value = prod.getProductMsg;
|
|
row.Cells["colCate"].Value = prod.categoryName.IsNullOrEmpty() ? prod?.dbProduct?.cat_id : prod.categoryName;
|
|
row.Cells["colPrice"].Value = prod.dbProduct.price_text;
|
|
}));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
prod.getProductMsg = "采集失败 " + ex.Message;
|
|
Invoke(new Action(() =>
|
|
{
|
|
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
|
}));
|
|
}
|
|
|
|
if (rowLst.IndexOf(row) % 20 == 0)
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("supplier_product_list_" + MainForm.ProcessCount, lstJSTListProductInfo);
|
|
}
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("supplier_product_list_" + MainForm.ProcessCount, lstJSTListProductInfo);
|
|
Invoke(new Action(() =>
|
|
{
|
|
BaseMsgForm.ShowInfo("采集完成");
|
|
pbLoading.Visible = false;
|
|
}));
|
|
}, cancellationTokenSource.Token);
|
|
}
|
|
|
|
public string GetGoodsLst(ShopLoginInfo shop, JObject searchDataObj)
|
|
{
|
|
string url = "https://sc.scm121.com/api/goods/buyer/supplier/goods/list";
|
|
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/detail/" + searchDataObj["supplierId"] + "?showErpList=1";
|
|
var lstRst = JSTHttpResponseBLL.JSTPostResponse(shop, url, JsonHelper.SerializeObject(searchDataObj), referer, appVersion);
|
|
for (int i = 0; i < 3 && !lstRst.Contains("\"success\":true"); i++)
|
|
{
|
|
Thread.Sleep(Randomx.GetId(1000, 2000));
|
|
lstRst = JSTHttpResponseBLL.JSTPostResponse(shop, url, JsonHelper.SerializeObject(searchDataObj), referer, appVersion);
|
|
}
|
|
return lstRst;
|
|
}
|
|
|
|
public string GetHotLst(ShopLoginInfo shop, JObject searchDataObj)
|
|
{
|
|
string url = "https://sc.ttdahuo.com/api/goods/freshman/mall/goods/list";
|
|
string referer = "https://sc.ttdahuo.com/findCooperation/newlywedZone";
|
|
var lstRst = JSTHttpResponseBLL.JSTPostResponse(shop, url, JsonHelper.SerializeObject(searchDataObj), referer, appVersion);
|
|
for (int i = 0; i < 3 && !lstRst.Contains("\"success\":true"); i++)
|
|
{
|
|
Thread.Sleep(Randomx.GetId(1000, 2000));
|
|
lstRst = JSTHttpResponseBLL.JSTPostResponse(shop, url, JsonHelper.SerializeObject(searchDataObj), referer, appVersion);
|
|
}
|
|
return lstRst;
|
|
}
|
|
|
|
public string GetPddBaseData(ShopLoginInfo shop, JSTListProductInfo jstLstProd)
|
|
{
|
|
string url = "https://sc.scm121.com/api/goods/goods/goGoodsPdd/queryBaseData?itemSpuId=" + jstLstProd.itemSpuId + "&shelvesType=DISTRIBUTION&originator=SUPPLIER&itemCoId=" + jstLstProd.itemCoId;
|
|
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/detail/" + jstLstProd.supplierId + "?showErpList=1";
|
|
var getDetailRst = JSTHttpResponseBLL.JSTGetResponse(shop, url, referer, appVersion);
|
|
for (int i = 0; i< 3 && !getDetailRst.Contains("\"success\":true"); i++)
|
|
{
|
|
Thread.Sleep(Randomx.GetId(1000, 2000));
|
|
getDetailRst = JSTHttpResponseBLL.JSTGetResponse(shop, url, referer, appVersion);
|
|
}
|
|
return getDetailRst;
|
|
}
|
|
|
|
public string GetGoodsDetail(ShopLoginInfo shop, JSTListProductInfo jstLstProd)
|
|
{
|
|
string url = "https://sc.scm121.com/api/goods/goods/queryGoodsDetail";
|
|
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/goodsDetail/" + jstLstProd.itemSpuId + "?itemCoId=" + jstLstProd.itemCoId + "&noBack=true";
|
|
//data = @"{""itemSpuId"":""0A3A5CC4F524430A9F3D7640BD0D3029"",""itemCoId"":""11596521""}";
|
|
string data = @"{""itemSpuId"":""" + jstLstProd.itemSpuId + @""",""itemCoId"":""" + jstLstProd.itemCoId + @"""}";
|
|
|
|
var detailRst = "";
|
|
for (int i = 0; i < 3 && !detailRst.Contains("\"success\":true"); i++)
|
|
{
|
|
Thread.Sleep(Randomx.GetId(1000, 2000));
|
|
detailRst = JSTHttpResponseBLL.JSTPostResponse(shop, url, data, referer, appVersion);
|
|
}
|
|
return detailRst;
|
|
}
|
|
|
|
public string GetItemSpuInfo(ShopLoginInfo shop, JSTListProductInfo jstLstProd)
|
|
{
|
|
string url = "https://sc.scm121.com/api/goods/shelves/itemSpuShelves/getItemSpuInfo";
|
|
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/goodsDetail/" + jstLstProd.itemSpuId + "?itemCoId=" + jstLstProd.itemCoId + "&noBack=true";
|
|
string data = @"{""itemSpuId"":""" + jstLstProd.itemSpuId + @""",""itemCoId"":""" + jstLstProd.itemCoId + @"""}";
|
|
data = @"{""id"":""" + jstLstProd.itemSpuId + @""",""platformType"":""Pinduoduo"",""shelvesType"":""DISTRIBUTION"",""companyType"":""SUPPLIER"",""itemCoId"":""" +
|
|
jstLstProd.itemCoId + @"""}";
|
|
|
|
var detailRst = "";
|
|
for (int i = 0; i < 3 && !detailRst.Contains("\"success\":true"); i++)
|
|
{
|
|
Thread.Sleep(Randomx.GetId(1000, 2000));
|
|
detailRst = JSTHttpResponseBLL.JSTPostResponse(shop, url, data, referer, appVersion);
|
|
}
|
|
return detailRst;
|
|
}
|
|
|
|
public string categoryForecastWithPlatform(ShopLoginInfo shop, JSTListProductInfo jstLstProd, string shopId)
|
|
{
|
|
string url = "https://sc.scm121.com/api/goods/platform/category/categoryForecastWithPlatform";
|
|
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/goodsDetail/" + jstLstProd.itemSpuId + "?itemCoId=" + jstLstProd.itemCoId + "&noBack=true";
|
|
string data = @"{""itemCoId"":""" + jstLstProd.coId + @""",""itemSpuId"":""" + jstLstProd.itemSpuId +
|
|
@""",""shopId"":""" + shopId + @""",""shopType"":""Pinduoduo"",""itemName"":""" + jstLstProd.itemName + @"""}";
|
|
|
|
var detailRst = "";
|
|
for (int i = 0; i < 3 && !detailRst.Contains("\"success\":true"); i++)
|
|
{
|
|
Thread.Sleep(Randomx.GetId(1000, 2000));
|
|
detailRst = JSTHttpResponseBLL.JSTPostResponse(shop, url, data, referer, appVersion);
|
|
}
|
|
return detailRst;
|
|
}
|
|
|
|
public string GetPddShopId(ShopLoginInfo shop, JSTListProductInfo jstLstProd)
|
|
{
|
|
string url = "https://sc.scm121.com/api/goods/shelves/mxStoresInformation/selectStoresInfo?shopTypeKey=%E6%8B%BC%E5%A4%9A%E5%A4%9A&spuId=" +
|
|
jstLstProd.spuId + "&itemCoId=" + jstLstProd.itemCoId + "&isUpdate=false&pageNum=1&pageSize=20";
|
|
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/detail/" + jstLstProd.supplierId + "?showErpList=1";
|
|
var response = JSTHttpResponseBLL.JSTGetResponse(shop, url, referer, appVersion);
|
|
return response;
|
|
}
|
|
|
|
public string GetPddProp(ShopLoginInfo shop, JSTListProductInfo jstLstProd, string catId, string shopId = "20115638")
|
|
{
|
|
string url = "https://sc.scm121.com/api/goods/shelves/pddShelves/queryGoodsTemplate?catId=" + catId + "&shopId=" + shopId;
|
|
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/detail/" + jstLstProd.supplierId + "?itemCoId=" + jstLstProd.itemCoId + "&noBack=true";
|
|
var response = JSTHttpResponseBLL.JSTGetResponse(shop, url, referer, appVersion);
|
|
return response;
|
|
}
|
|
|
|
public string GetPddPropForUpdate(ShopLoginInfo shop, JSTListProductInfo jstLstProd, string catId, string shopId = "20115638")
|
|
{
|
|
string url = "https://sc.scm121.com/api/goods/supplier/shopManage/querySupplierShopSpuForUpdate";
|
|
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/detail/" + jstLstProd.supplierId + "?showErpList=1";
|
|
string body = @"{""itemSpuId"":""" + jstLstProd.itemSpuId + @""",""shopType"":""Pinduoduo"",""itemCoId"":""" + jstLstProd.itemCoId +
|
|
@""",""companyType"":""SUPPLIER""}";
|
|
var propRst = "";
|
|
for (int i = 0; i < 3 && !propRst.Contains("\"success\":true"); i++)
|
|
{
|
|
Thread.Sleep(Randomx.GetId(1000, 2000));
|
|
propRst = JSTHttpResponseBLL.JSTPostResponse(shop, url, body, referer, appVersion);
|
|
}
|
|
return propRst;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 没有商品属性的,类目属性预测
|
|
/// </summary>
|
|
public string GetPddPropForecastV2(ShopLoginInfo shop, JSTListProductInfo jstProd, string catId, string shopId = "20115638")
|
|
{
|
|
//string url = "https://sc.scm121.com/api/goods/platform/category/categoryPropForecastV2?shopId=20115638&itemSpuId=DD0FCC6A42C94EAC9D2A0BFEBA33A683&itemCoId=10361546&shopType=Pinduoduo&categoryId=10799";
|
|
string url = "https://sc.scm121.com/api/goods/platform/category/categoryPropForecastV2?shopId=" + shopId +
|
|
"&itemSpuId=" + jstProd.itemSpuId + "&itemCoId=" + jstProd.itemCoId + "&shopType=Pinduoduo&categoryId=" + catId;
|
|
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/detail/" + jstProd.supplierId + "?showErpList=1";
|
|
var response = JSTHttpResponseBLL.JSTGetResponse(shop, url, referer, appVersion);
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取真实coid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string QueryRealCoid(ShopLoginInfo shop, JSTListProductInfo jstProd)
|
|
{
|
|
string url = "https://sc.scm121.com/api/goods/goodsQuery/queryGoodsDistributionHierarchyV2";
|
|
string referer = "https://sc.scm121.com/findCooperation/newlywedZone/goodsDetail/" + jstProd.itemSpuId + "?itemCoId=" + jstProd.itemCoId +
|
|
"&lookingFor=findCooperation&noBack=true";
|
|
string data = "[{\"supplierCoId\":\"" + jstProd.itemCoId + "\",\"itemSpuIdList\":[\"" + jstProd.itemSpuId + "\"]}]";
|
|
var response = JSTHttpResponseBLL.JSTPostResponse(shop, url, data, referer, appVersion);
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 批量获取真实coid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string BatchQueryRealCoid(ShopLoginInfo shop, string spuIds, string coid0 = "12840800")
|
|
{
|
|
string url = "https://sc.scm121.com/api/goods/goodsQuery/queryGoodsDistributionHierarchyV2";
|
|
string referer = "https://sc.ttdahuo.com/findCooperation/newlywedZone";
|
|
string data = "[{\"supplierCoId\":\"" + coid0 + "\",\"itemSpuIdList\":[\"" + spuIds.Replace(",", "\",\"") + "\"]}]";
|
|
var response = JSTHttpResponseBLL.JSTPostResponse(shop, url, data, referer, appVersion);
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询供应商售后地址
|
|
/// </summary>
|
|
/// <param name="shop"></param>
|
|
/// <param name="realSpuId">真实spuid</param>
|
|
/// <param name="spuId">爆款spuid</param>
|
|
/// <param name="supCoId1">真实coid</param>
|
|
/// <param name="supCoId0">爆款coid</param>
|
|
/// <returns></returns>
|
|
public string GetAfterSaleAddress(ShopLoginInfo shop, string realSpuId, string spuId, string supCoId1, string supCoId0 = "12840800")
|
|
{
|
|
string url = "https://innerapi.scm121.com/api/aftersale/addresses/queryMultiLevelSupplierReturnAddressWithSwitch";
|
|
string referer = "https://sc.scm121.com/findCooperation/newlywedZone/goodsDetail/" + spuId + "?itemCoId=" + supCoId0 + "&lookingFor=findCooperation&noBack=true";
|
|
string data = @"{""params"":[{""supplierHierarchyInfos"":[{""supCoId"":""" + supCoId0 + @""",""level"":0},{""supCoId"":""" + supCoId1 +
|
|
@""",""level"":1}],""spuId"":""" + realSpuId + @"""}]}";
|
|
var response = JSTHttpResponseBLL.JSTPostResponse(shop, url, data, referer, appVersion);
|
|
return response;
|
|
}
|
|
|
|
public string GetAfterSaleAddressMobile(ShopLoginInfo shop, string addressId, string realSpuId, string spuId, string realCoid, string supCoId = "12840800")
|
|
{
|
|
string url = "https://sc.scm121.com/api/company/phoneQuery/aftersale/supplier/getReturnPhone?returnAddressId=" + addressId + "&supplierCoId=" + realCoid;
|
|
string referer = "https://sc.scm121.com/findCooperation/newlywedZone/goodsDetail/" + spuId + "?itemCoId=" + supCoId + "&lookingFor=findCooperation&noBack=true";
|
|
|
|
var response = JSTHttpResponseBLL.JSTGetResponse(shop, url, referer, appVersion);
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取供应商退货地址中的手机号
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetAfterSaleAddressMobileById(ShopLoginInfo shop, string Id, string realSpuId, string spuId, string realCoid, string supCoId = "12840800")
|
|
{
|
|
string url = "https://innerapi.scm121.com/api/aftersale/middleman/addresses/queryPhone?id=" + Id;
|
|
string referer = "https://sc.scm121.com/findCooperation/newlywedZone/goodsDetail/" + spuId + "?itemCoId=" + supCoId + "&lookingFor=findCooperation&noBack=true";
|
|
// "https://sc.scm121.com/findCooperation/newlywedZone/goodsDetail/ ?itemCoId= &lookingFor=findCooperation&noBack=true
|
|
|
|
var response = JSTHttpResponseBLL.JSTGetResponse(shop, url, referer, appVersion);
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置分销
|
|
/// </summary>
|
|
/// <param name="shop"></param>
|
|
/// <param name="jstProd"></param>
|
|
/// <returns></returns>
|
|
public string SetPartnerSpu(ShopLoginInfo shop, JSTListProductInfo jstProd)
|
|
{
|
|
string url = "https://sc.scm121.com/api/goods/buyer/partnerSpu/add";
|
|
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/detail/" + jstProd.supplierId + "?showErpList=1";
|
|
string data = @"{""shelvesType"":""DISTRIBUTION"",""spuIdList"":[{""itemCoId"":""" + jstProd.itemCoId + @""",""spuId"":""" + jstProd.spuId + @"""}],""itemSource"":""GYL""}";
|
|
var response = JSTHttpResponseBLL.JSTPostResponse(shop, url, data, referer, appVersion);
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取手机号查询授权
|
|
/// </summary>
|
|
/// <param name="shop"></param>
|
|
/// <param name="jstProd"></param>
|
|
/// <param name="authStr"></param>
|
|
/// <returns></returns>
|
|
public string AuthV2(ShopLoginInfo shop, JSTListProductInfo jstProd, string authStr)
|
|
{
|
|
string url = "https://sc.scm121.com/api/company/open/auth/grantAuthV2";
|
|
string referer = "https://sc.scm121.com/findCooperation/newlywedZone/goodsDetail/" + jstProd.spuId + "?itemCoId=" + jstProd.itemCoId +
|
|
"&lookingFor=findCooperation&noBack=true";
|
|
string data = @"{""code"":""" + authStr + @""",""sensitiveOperationErrorCode"":""50716""}";
|
|
var response = JSTHttpResponseBLL.JSTPostResponse(shop, url, data, referer, appVersion);
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取下架sku列表信息
|
|
/// </summary>
|
|
/// <param name="shop"></param>
|
|
/// <param name="startTime"></param>
|
|
/// <param name="endTime"></param>
|
|
/// <param name="pageNum"></param>
|
|
/// <param name="pageSize"></param>
|
|
/// <returns></returns>
|
|
public string GetDownSkuLst(ShopLoginInfo shop, DateTime startTime, DateTime endTime, int pageNum, int pageSize)
|
|
{
|
|
string url = "https://sc.scm121.com/api/goods/goChannelPartnerSku/queryChannelPartnerSkuList";
|
|
string referer = "https://sc.scm121.com/manage/goods/distributionGoodsManage/sku?skuDrpItemStatus=true";
|
|
//string body = @"{""startTime"":""2026-01-30 00:00:00"",""endTime"":""2026-02-24 23:59:59"",""pageSize"":20,""pageNum"":1,""isAllChangePriceItemCode"":false,""skuDrpItemStatus"":""FOR_SHELVED"",""allRegulatePriceChangeSku"":false,""checkHasData"":false}";
|
|
string body =
|
|
@"{""startTime"":""" + startTime.ToString("yyyy-MM-dd HH:mm:ss") +
|
|
@""",""endTime"":""" + endTime.ToString("yyyy-MM-dd HH:mm:ss") +
|
|
@""",""pageSize"":" + pageSize + @",""pageNum"":" + Math.Max(1, pageNum) + @",""isAllChangePriceItemCode"":false," +
|
|
@"""skuDrpItemStatus"":""FOR_SHELVED"",""allRegulatePriceChangeSku"":false,""checkHasData"":false}";
|
|
var lstRst = "";
|
|
for (int i = 0; i < 3 && !lstRst.Contains("\"success\":true"); i++)
|
|
{
|
|
if (i > 0)
|
|
Thread.Sleep(Randomx.GetId(1000, 2000));
|
|
lstRst = JSTHttpResponseBLL.JSTPostResponse(shop, url, body, referer, appVersion);
|
|
}
|
|
return lstRst;
|
|
}
|
|
|
|
private void btnSearchTitle_Click(object sender, EventArgs e)
|
|
{
|
|
pbLoading.Visible = true;
|
|
Task.Run(() =>
|
|
{
|
|
foreach (DataGridViewRow row in dgvProduct.Rows)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
|
|
row.Visible = (row.Cells["colGoodsName"].Value.ParseToString().Contains(txtTitle.Text.Trim()) || txtTitle.Text.Trim() == "");
|
|
if (row.Visible == false)
|
|
row.Cells["colCheck"].Value = false;
|
|
|
|
}));
|
|
}
|
|
Invoke(new Action(() =>
|
|
{
|
|
pbLoading.Visible = false;
|
|
}));
|
|
});
|
|
}
|
|
|
|
private void btnCancelSelect_Click(object sender, EventArgs e)
|
|
{
|
|
Task.Run(() => {
|
|
|
|
foreach(DataGridViewRow row in dgvProduct.Rows)
|
|
{
|
|
if (row.Cells["colMsg"].Value.ParseToString().Contains("入库成功") || row.Cells["colMsg"].Value.ParseToString().Contains("已存在相同id商品"))
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
row.Cells["colcheck"].Value = false;
|
|
}));
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void btnGetDownSku_Click(object sender, EventArgs e)
|
|
{
|
|
if (!cefWebBrowser.Address.StartsWith("https://sc.scm121.com/manage/goods/distributionGoodsManage/") &&
|
|
!cefWebBrowser.Address.StartsWith("https://sc.scm121.com/suppliersManage/suppliersList/onlineSuppliers"))
|
|
{
|
|
BaseMsgForm.ShowError("请将网页切换到分销页面!");
|
|
return;
|
|
}
|
|
|
|
if (CancelGetDown != null)
|
|
CancelGetDown.Cancel();
|
|
CancelGetDown = new CancellationTokenSource();
|
|
pictureBox1.Visible = true;
|
|
Task.Run(() =>
|
|
{
|
|
GetDownSku(CancelGetDown);
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
if (jstDownSkuGetInfo.status != "done")
|
|
BaseMsgForm.ShowError("采集并同步产品中断!");
|
|
else
|
|
BaseMsgForm.ShowInfo("采集并同步产品完成!");
|
|
pictureBox1.Visible = false;
|
|
}));
|
|
}, CancelGetDown.Token);
|
|
}
|
|
|
|
DateTime startTime = new DateTime(2026,1,28);
|
|
DateTime endTime;
|
|
void GetDownSku(CancellationTokenSource cancelGetDown)
|
|
{
|
|
List<Cookie> cookieList = CEFBrowser.GetCookieList(".scm121.com", cefWebBrowser.GetCookieManager(null));
|
|
var shop = new ShopLoginInfo();
|
|
shop.Cookies = JsonHelper.SerializeObject(cookieList);
|
|
|
|
|
|
int total, page, totalPage = jstDownSkuGetInfo.totalPage;
|
|
int startPage = jstDownSkuGetInfo.readPage;
|
|
int pageSize = 100;
|
|
#if DEBUG
|
|
pageSize = 100;
|
|
#endif
|
|
for (page = startPage; page < 999999; page++)
|
|
{
|
|
if (cancelGetDown.IsCancellationRequested)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "采集终止 " + page + "/" + totalPage + " 页,每页 " + pageSize;
|
|
}));
|
|
return;
|
|
}
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "正在采集 " + page + "/" + totalPage + " 页,每页 " + pageSize;
|
|
}));
|
|
|
|
var rst = GetDownSkuLst(shop, startTime, endTime, page, pageSize);
|
|
Thread.Sleep(5000);
|
|
if (!rst.Contains("\"success\":true"))
|
|
{
|
|
Thread.Sleep(5000);
|
|
rst = GetDownSkuLst(shop, startTime, endTime, page, pageSize);
|
|
}
|
|
if (!rst.Contains("\"success\":true"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref rst, "message");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = rst;
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "查询下架列表失败:" + errMsg;
|
|
}));
|
|
return;
|
|
}
|
|
|
|
total = BaseRegex.GetIntJson(ref rst, "total");
|
|
totalPage = Math.Ceiling(1.0m * total / pageSize).ParseToInt();
|
|
try
|
|
{
|
|
var jsonStr = JsonHelper.SerializeObject(JsonHelper.JObjectParse(rst)["data"]);
|
|
List<JSTDownProdSkuInfo> jstDownProdSkuLst = JsonHelper.DeserializeJsonToList<JSTDownProdSkuInfo>(jsonStr);
|
|
List<JSTDownProdSkuInfo> jstDownProdSkuGetExistLst = JsonHelper.DeserializeJsonToList<JSTDownProdSkuInfo>(jsonStr);
|
|
jstDownProdSkuLst = jstDownProdSkuLst.Where(sku => !lstJSTDownProdSkuInfo.Any(s => s.itemCode == sku.itemCode)).ToList();
|
|
|
|
var url = BaseClass.BuildPDDObjString("product/get_product_spu_id_list");
|
|
var data = UserLogin.GetSignaturex();
|
|
data += "&search_spu_ids=" + string.Join(",", jstDownProdSkuLst.Select(s => s.spuId).Distinct());
|
|
var result = GetHtml.PostUtf8(url, data);
|
|
if (!result.Contains("\"code\":200"))
|
|
result = GetHtml.PostUtf8(url, data);
|
|
if (!result.Contains("\"code\":200"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref rst, "message");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = rst;
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "查询错误:" + errMsg;
|
|
}));
|
|
return;
|
|
}
|
|
List<KJDDBProduct> dbProdLst = JsonHelper.DeserializeJsonToList<KJDDBProduct>(JsonHelper.JObjectParse(result)["data"].ParseToString());
|
|
|
|
// 查询下架库有没有
|
|
url = BaseClass.BuildPDDObjString("product/get_prod_down_sku_lst_by_sku_codes");
|
|
data = UserLogin.GetSignaturex();
|
|
data += "&search_spu_ids=" + string.Join(",", jstDownProdSkuGetExistLst.Select(s => s.spuId).Distinct());
|
|
data += "&search_sku_codes=" + string.Join(",", jstDownProdSkuGetExistLst.Select(s => s.itemCode).Distinct());
|
|
result = GetHtml.PostUtf8(url, data);
|
|
if (!result.Contains("\"code\":200"))
|
|
result = GetHtml.PostUtf8(url, data);
|
|
if (!result.Contains("\"code\":200"))
|
|
{
|
|
var errMsg = BaseRegex.GetStringJson(ref result, "msg");
|
|
if (string.IsNullOrEmpty(errMsg))
|
|
errMsg = result;
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "查询下架库错误:" + errMsg;
|
|
}));
|
|
return;
|
|
}
|
|
List<JSTDownProdSkuInfo> downSkuExistLst = JsonHelper.DeserializeJsonToList<JSTDownProdSkuInfo>(JsonHelper.JObjectParse(result)["data"].ParseToString());
|
|
if (chkSkipDownSearch.Checked && downSkuExistLst.Count > 0 && downSkuExistLst.All(se => se.add_time < DateTime.Now.AddDays(-downBeforeDays).AddHours(-downBeforeHours)))
|
|
{
|
|
// 存在之前采集的数据,说明已查询完最新数据,跳出
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "增量采集完成 " + page + "/" + totalPage + " 页,每页 " + pageSize;
|
|
}));
|
|
goto endDownSearch;
|
|
}
|
|
|
|
foreach (var dbProdLite in dbProdLst)
|
|
{
|
|
string errMsg;
|
|
var dbProd = WXDBProdUploadForm.GetProductDetail(dbProdLite.id.ParseToString(), out errMsg);
|
|
if (!string.IsNullOrEmpty(errMsg) || dbProd == null)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "商品详情读取失败 " + errMsg;
|
|
}));
|
|
return;
|
|
}
|
|
var secretSkuLst = dbProd.sku_secret_json;
|
|
|
|
JObject jstSecretCodeLst = new JObject();
|
|
try
|
|
{
|
|
jstSecretCodeLst = JsonHelper.JObjectParse(dbProd.sku_secret_json.TrimStart('[').TrimEnd(']'));
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
var secret_spu_id = dbProd.secret_spu_id;
|
|
if (secret_spu_id.IsNullOrEmpty() && jstSecretCodeLst !=null)
|
|
{
|
|
secret_spu_id = jstSecretCodeLst["goodsId"].ParseToString();
|
|
}
|
|
|
|
JObject prodJObj = new JObject();
|
|
try
|
|
{
|
|
prodJObj = JObject.Parse(dbProd.product_json);
|
|
foreach (var skuObj in prodJObj["pddData"]["skuInfo"]["goodsSkuDetail"])
|
|
{
|
|
var itemNo = skuObj["itemNo"].ParseToString();
|
|
foreach (var downSku in jstDownProdSkuLst)
|
|
{
|
|
if (downSku.colourSpec == "圆形黄色小号")
|
|
{
|
|
|
|
}
|
|
if (downSku.itemCode == itemNo && downSku.spuId == dbProd.spu_id)
|
|
{
|
|
skuObj["quantity"] = 0;
|
|
downSku.secret_spu_id = secret_spu_id;
|
|
|
|
try
|
|
{
|
|
var secret_sku_id = jstSecretCodeLst?["skus"]?.FirstOrDefault(s => s["skuCode"].ParseToString() == downSku.itemCode)?["skuId"].ParseToString();
|
|
downSku.secret_sku_id = secret_sku_id;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
dbProd.product_json = JsonHelper.SerializeObject(prodJObj);
|
|
url = BaseClass.BuildPDDObjString("product/mdy_product");
|
|
var prodNewData = Work.UserLogin.GetSignaturex() +
|
|
"&product_json=" + HttpUtility.UrlEncode(dbProd.product_json, Encoding.UTF8) + "&spu_id=" + dbProd.spu_id;
|
|
var html = "";
|
|
for (int i = 0; i< 3 && !html.Contains("\"code\":200"); i++ )
|
|
{
|
|
html = GetHtml.PostUtf8(url, prodNewData);
|
|
}
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
|
{
|
|
errMsg = BaseRegex.GetStringJson(ref html, "msg");
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "商品详情转换/更新保存失败 " + errMsg;
|
|
}));
|
|
return;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "商品详情转换/更新失败 " + ex.Message;
|
|
}));
|
|
return;
|
|
}
|
|
}
|
|
|
|
foreach (var downSku in jstDownProdSkuLst)
|
|
{
|
|
if (dbProdLst.Any(p => p.spu_id == downSku.spuId))
|
|
downSku.is_in_product_db = 1;
|
|
|
|
// 1.先显示下架sku
|
|
lstJSTDownProdSkuInfo.Add(downSku);
|
|
Invoke(new Action(() =>
|
|
{
|
|
var rowIndex = dgvDownSku.Rows.Add(
|
|
true,
|
|
downSku.spuId,
|
|
downSku.styleCode,
|
|
downSku.itemMainImage.FirstOrDefault().ParseToString(),
|
|
DataGridViewExtension.defaultBitmap,
|
|
downSku.itemName,
|
|
downSku.itemCode,
|
|
downSku.colourSpec,
|
|
downSku.supplierName,
|
|
downSku.supplyPrice,
|
|
downSku.shelvesTime,
|
|
downSku.lastOperator,
|
|
downSku.drpItemStatus,
|
|
"删除",
|
|
downSku.is_in_product_db == 1 ? "已更新库存产品" : "产品库不存在,跳过"
|
|
);
|
|
dgvDownSku.Rows[rowIndex].Height = 60;
|
|
}));
|
|
|
|
// 2.再入下架sku库
|
|
// 产品库没有这个商品,直接跳过
|
|
if (downSku.is_in_product_db != 1)
|
|
continue;
|
|
// 产品库有这个商品,继续判断下架库是否有
|
|
var downSkuExist = downSkuExistLst.FirstOrDefault(p => p.spuId == downSku.spuId && p.itemCode == downSku.itemCode);
|
|
if (downSkuExist != null)
|
|
{
|
|
if (chkSkipDownSearch.Checked && downSkuExist.add_time < DateTime.Now.AddDays(-downBeforeDays).AddHours(-downBeforeHours))
|
|
{
|
|
// 存在之前采集的数据,说明已查询完最新数据,跳出
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "增量采集完成 " + page + "/" + totalPage + " 页,每页 " + pageSize;
|
|
}));
|
|
goto endDownSearch;
|
|
}
|
|
|
|
// 下架库里已存在,就跳过。
|
|
//if (downSku.is_in_product_db == 1)
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
// 入下架库
|
|
url = BaseClass.BuildPDDObjString("product/add_prod_down_sku");
|
|
var prodNewData = Work.UserLogin.GetSignaturex() +
|
|
"&itemMainImage=" + HttpUtility.UrlEncode(string.Join(",", downSku.itemMainImage), Encoding.UTF8) +
|
|
"&itemName=" + HttpUtility.UrlEncode(downSku.itemName, Encoding.UTF8) +
|
|
"&styleCode=" + HttpUtility.UrlEncode(downSku.styleCode, Encoding.UTF8) +
|
|
"&itemCode=" + HttpUtility.UrlEncode(downSku.itemCode, Encoding.UTF8) +
|
|
"&colourSpec=" + HttpUtility.UrlEncode(downSku.colourSpec, Encoding.UTF8) +
|
|
"&supplyPrice=" + downSku.supplyPrice.ParseToString() +
|
|
"&supplierName=" + downSku.supplierName +
|
|
"&shelvesTime=" + downSku.shelvesTime +
|
|
"&supplierCoId=" + downSku.supplierCoId +
|
|
"&coId=" + downSku.coId + // 此处coId数值与供应商商品列表的coId不同,注意区分
|
|
"&spuId=" + downSku.spuId +
|
|
"&partnerSkuId=" + downSku.partnerSkuId +
|
|
"&partnerSpuId=" + downSku.partnerSpuId +
|
|
"&supplierId=" + downSku.supplierId +
|
|
"&drpItemStatus=" + downSku.drpItemStatus +
|
|
"&lastOperator=" + downSku.lastOperator +
|
|
"&itemSpuIdMd5=" + downSku.itemSpuIdMd5 +
|
|
"&secret_spu_id=" + downSku.secret_spu_id +
|
|
"&secret_sku_id=" + downSku.secret_sku_id +
|
|
"&is_in_product_db=" + downSku.is_in_product_db;
|
|
var html = "";
|
|
for (int i = 0; i < 5 && (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")); i++)
|
|
{
|
|
html = GetHtml.PostUtf8(url, prodNewData);
|
|
if (html.Contains("数据已存在"))
|
|
break;
|
|
}
|
|
if (html.Contains("数据已存在"))
|
|
{
|
|
// 数据已存在的暂时跳过不处理
|
|
}
|
|
else if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
|
{
|
|
// 入库失败终止
|
|
string errMsg = BaseRegex.GetStringJson(ref html, "msg");
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "下架商品Sku入库失败 " + errMsg;
|
|
}));
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (page % 5 == 4 || !rst.Contains("\"hasNext\":true"))
|
|
{
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("jst_down_sku_list", lstJSTDownProdSkuInfo);
|
|
jstDownSkuGetInfo.readPage = page;
|
|
jstDownSkuGetInfo.totalPage = totalPage;
|
|
jstDownSkuGetInfo.status = "reading";
|
|
jstDownSkuGetInfo.lastReadDate = DateTime.Now.Date;
|
|
jstDownSkuGetInfo.totalCount = total;
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("jst_down_sku_get_info", jstDownSkuGetInfo);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "采集失败 " + ex.Message;
|
|
}));
|
|
return;
|
|
}
|
|
|
|
if (!rst.Contains("\"hasNext\":true"))
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "采集完成 " + page + "/" + totalPage + " 页,每页 " + pageSize;
|
|
}));
|
|
goto endDownSearch;
|
|
}
|
|
}
|
|
|
|
endDownSearch:
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("jst_down_sku_list", lstJSTDownProdSkuInfo);
|
|
jstDownSkuGetInfo.readPage = 0;
|
|
jstDownSkuGetInfo.status = "done";
|
|
jstDownSkuGetInfo.lastReadDate = DateTime.Now.Date;
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("jst_down_sku_get_info", jstDownSkuGetInfo);
|
|
}
|
|
|
|
private void dtpStartTime_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
startTime = dtpStartTime.Value;
|
|
}
|
|
|
|
private void dtpEndTime_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
endTime = dtpEndTime.Value;
|
|
}
|
|
|
|
private void txtBeforeDay_TextChanged(object sender, EventArgs e)
|
|
{
|
|
downBeforeDays = txtBeforeDay.Text.ParseToInt();
|
|
downBeforeHours = txtBeforeHour.Text.ParseToInt();
|
|
}
|
|
|
|
private void btnResetCache_Click(object sender, EventArgs e)
|
|
{
|
|
if (BaseMsgForm.ShowConfirm("确定清除采集缓存吗?再次采集将从第一页开始!").DialogResult == DialogResult.OK)
|
|
{
|
|
dgvDownSku.Rows.Clear();
|
|
lstJSTDownProdSkuInfo = new ConcurrentList<JSTDownProdSkuInfo>();
|
|
jstDownSkuGetInfo = new JstDownSkuGetInfo();
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("jst_down_sku_list", lstJSTDownProdSkuInfo);
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("jst_down_sku_get_info", jstDownSkuGetInfo);
|
|
this.statusBarUserControl1.lblTaskStatus.Text = "准备就绪";
|
|
}
|
|
}
|
|
|
|
private void btnStopGetDownSku_Click(object sender, EventArgs e)
|
|
{
|
|
if (CancelGetDown != null)
|
|
CancelGetDown.Cancel();
|
|
}
|
|
|
|
private void chkSkip_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void txtWaitSeconds_TextChanged(object sender, EventArgs e)
|
|
{
|
|
getDetailWait = txtWaitSeconds.Text.ParseToInt();
|
|
}
|
|
|
|
private void btnExportCookie_Click(object sender, EventArgs e)
|
|
{
|
|
List<Cookie> cookieList = CEFBrowser.GetCookieList(".scm121.com", cefWebBrowser.GetCookieManager(null));
|
|
var shop = new ShopLoginInfo();
|
|
shop.Cookies = JsonHelper.SerializeObject(cookieList);
|
|
|
|
List<CefSharp.Cookie> cooks = null;
|
|
try { cooks = JsonHelper.DeserializeJsonToList<CefSharp.Cookie>(shop.Cookies); } catch (Exception ex) { }
|
|
if (cooks == null)
|
|
cooks = new List<CefSharp.Cookie>();
|
|
|
|
string cookJs = "";
|
|
var keys = new string[] { "acw_tc", "DISTRYBUTION_TOKEN" };
|
|
foreach (var shopCook in cooks)
|
|
{
|
|
var cookie = shopCook.Name + "=" + shopCook.Value;
|
|
if (!keys.Any(k => cookie.StartsWith(k)))
|
|
continue;
|
|
cookJs += "\r\ndocument.cookie='" + cookie.Substring(0, Math.Max(0, cookie.IndexOf("="))) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';";
|
|
}
|
|
foreach (var shopCook in cooks)
|
|
{
|
|
var cookie = shopCook.Name + "=" + shopCook.Value;
|
|
if (!keys.Any(k => cookie.StartsWith(k)))
|
|
continue;
|
|
cookJs += "\r\ndocument.cookie='" + cookie + "; domain=.scm121.com; expires=" +
|
|
DateTime.Now.AddMonths(1).ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss 'UTC'", new DateTimeFormatInfo()) + "; path=/';";
|
|
}
|
|
cookJs += "\r\nsetTimeout(() => { window.location.href='https://sc.scm121.com/suppliersManage/suppliersList/onlineSuppliers'; }, 200)";
|
|
Clipboard.SetDataObject(cookJs);
|
|
BaseMsgForm.ShowInfo("复制成功");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 记录获取聚水潭下架sku的信息
|
|
/// </summary>
|
|
public class JstDownSkuGetInfo
|
|
{
|
|
public int readPage { get; set; } = 1;
|
|
public int totalPage { get; set; } = 1;
|
|
/// <summary>
|
|
/// done reading
|
|
/// </summary>
|
|
public string status { get; set; } = "done";
|
|
public int totalCount { get; set; } = 999999;
|
|
public DateTime lastReadDate { get; set; } = DateTime.MinValue;
|
|
}
|
|
}
|