厂商采集拼多多采集及入库
This commit is contained in:
1 parent
1b15eda63c
commit
3996dcce09
16 files changed
+1723
-569
No files matched your search
@@ -1,8 +1,11 @@
|
||||
using AllBase;
|
||||
using AllBase.Model.Result;
|
||||
using CefSharp;
|
||||
using CefSharp.WinForms;
|
||||
using NaiBa.CefHelper;
|
||||
using NaiBa.CefHelper.Handler;
|
||||
using NaiBa.Util;
|
||||
using NaiBa.Util.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -14,6 +17,8 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TemuKJD.BaseForms;
|
||||
using TemuKJD.BLL;
|
||||
using TemuKJD.Extension;
|
||||
using TemuKJD.Helper;
|
||||
using Work;
|
||||
|
||||
@@ -21,9 +26,20 @@ namespace TemuKJD.ToolForms
|
||||
{
|
||||
public partial class GetJuShuitanProdForm : BaseForms.BaseForm
|
||||
{
|
||||
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
|
||||
string InitUrl = "https://sc.scm121.com/suppliersManage/suppliersList/onlineSuppliers";
|
||||
public ChromiumWebBrowser cefWebBrowser = null;
|
||||
private string currentUrl = "";
|
||||
private string currentGetListData = "";
|
||||
private string currentSupplierName = "";
|
||||
private string appVersion = "";
|
||||
private string currentSupplierId = "";
|
||||
int pageStart = 1;
|
||||
int pageEnd = 9999;
|
||||
int filterSaleCountDays = 7;
|
||||
int filterSaleCount = 100;
|
||||
string platformType = "Pinduoduo";
|
||||
ConcurrentList<JSTListProductInfo> lstJSTListProductInfo = new ConcurrentList<JSTListProductInfo>();
|
||||
|
||||
public GetJuShuitanProdForm()
|
||||
{
|
||||
@@ -32,6 +48,56 @@ namespace TemuKJD.ToolForms
|
||||
|
||||
private void GetJuShuitanProdForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.splitContainer1.SplitterDistance = 472;
|
||||
this.dgvProduct.AddSelectorColumn("colCheck");
|
||||
this.dgvProduct.AddImgColumn("colImg", "colImgUrl");
|
||||
|
||||
var tmpProductLst = NaiBa.Util.Helper.ConfigHelper.LoadConfig<List<JSTListProductInfo>>("supplier_product_list_" + MainForm.ProcessCount);
|
||||
if (tmpProductLst == null)
|
||||
tmpProductLst = new List<JSTListProductInfo>();
|
||||
lstJSTListProductInfo.AddRange(tmpProductLst);
|
||||
pbLoading.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.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;
|
||||
}));
|
||||
});
|
||||
|
||||
InitCef();
|
||||
}
|
||||
|
||||
@@ -56,7 +122,7 @@ namespace TemuKJD.ToolForms
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
splitContainer1.Panel1.Controls.Add(cefWebBrowser);
|
||||
splitContainer2.Panel2.Controls.Add(cefWebBrowser);
|
||||
//cefWebBrowser.Load(shopMainUrl);
|
||||
}));
|
||||
}
|
||||
@@ -107,6 +173,23 @@ namespace TemuKJD.ToolForms
|
||||
|
||||
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(() => { GetCurrentSearchData(postData, responseData, request); });
|
||||
}
|
||||
}
|
||||
|
||||
void GetCurrentSearchData(string postData, string responseData, IRequest request)
|
||||
{
|
||||
currentGetListData = postData;
|
||||
currentSupplierId = BaseRegex.GetStringJson(ref postData, "supplierId");
|
||||
currentSupplierName = BaseRegex.GetStringJson(ref responseData, "supplierName");
|
||||
Invoke(new Action(() => {
|
||||
txtSupplierName.Text = currentSupplierName;
|
||||
}));
|
||||
}
|
||||
|
||||
private bool RequestHandler_BeforeResourceLoad(object sender, string url, string postData, IRequest request)
|
||||
@@ -156,7 +239,652 @@ namespace TemuKJD.ToolForms
|
||||
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 btnCollect_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(currentGetListData))
|
||||
{
|
||||
BaseMsgForm.ShowError("请在网页上选择要搜索的供应商商品列表页面");
|
||||
return;
|
||||
}
|
||||
|
||||
this.pbLoading.Visible = true;
|
||||
dgvProduct.Rows.Clear();
|
||||
lstJSTListProductInfo.Clear();
|
||||
if (cancellationTokenSource == null || cancellationTokenSource.IsCancellationRequested)
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
GetProdList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BaseMsgForm.ShowError(ex.Message);
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.pbLoading.Visible = false;
|
||||
//this.statusBar.lblTaskStatus.Text = "正在删除...";
|
||||
}));
|
||||
}, cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
void GetProdList()
|
||||
{
|
||||
List<Cookie> cookieList = CEFBrowser.GetCookieList(".scm121.com", cefWebBrowser.GetCookieManager(null));
|
||||
var shop = new ShopLoginInfo();
|
||||
shop.Cookies = JsonHelper.SerializeObject(cookieList);
|
||||
|
||||
var Jobj = JsonHelper.JObjectParse(currentGetListData);
|
||||
Jobj["pageSize"] = 70;
|
||||
int page = pageStart;
|
||||
while(page <= pageEnd)
|
||||
{
|
||||
if (cancellationTokenSource.IsCancellationRequested)
|
||||
break;
|
||||
|
||||
Jobj["pageNum"] = page;
|
||||
Jobj["mallSort"] = "SELL_SEVEN";
|
||||
Jobj["platformType"] = platformType;
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.statusBar.lblTaskStatus.Text = "正在采集第 " + page + " 页";
|
||||
}));
|
||||
Thread.Sleep(Randomx.GetId(1000, 2000));
|
||||
page++;
|
||||
|
||||
string url = "https://sc.scm121.com/api/goods/buyer/supplier/goods/list";
|
||||
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/detail/" + Jobj["supplierId"] + "?showErpList=1";
|
||||
var lstRst = JSTHttpResponseBLL.JSTPostResponse(shop, url, JsonHelper.SerializeObject(Jobj), 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(Jobj), referer, appVersion);
|
||||
}
|
||||
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.coId;
|
||||
//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);
|
||||
foreach (var prod in jstLst)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
var id = dgvProduct.Rows.Add(
|
||||
true,
|
||||
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;
|
||||
}));
|
||||
}
|
||||
}
|
||||
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")
|
||||
GetPinDuoduoProd();
|
||||
else if (platformType == "douyin")
|
||||
GetDyProd();
|
||||
}
|
||||
|
||||
private void btnSaveDb_Click(object sender, EventArgs e)
|
||||
{
|
||||
//"&product_get_type=" + HttpUtility.UrlEncode("厂商直采", Encoding.UTF8);
|
||||
|
||||
ConcurrentList<DataGridViewRow> rowLst = new ConcurrentList<DataGridViewRow>();
|
||||
rowLst.AddRange(dgvProduct.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true));
|
||||
|
||||
this.pbLoading.Visible = true;
|
||||
Task.Run(() =>
|
||||
{
|
||||
List<Cookie> cookieList = CEFBrowser.GetCookieList(".scm121.com", cefWebBrowser.GetCookieManager(null));
|
||||
var shop = new ShopLoginInfo();
|
||||
shop.Cookies = JsonHelper.SerializeObject(cookieList);
|
||||
|
||||
foreach (var row in rowLst)
|
||||
{
|
||||
if (cancellationTokenSource.IsCancellationRequested)
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
bool isExist = false;
|
||||
var existUrl = BaseClass.BuildObjString("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;
|
||||
}
|
||||
|
||||
var SetPartnerSpuRst = "";
|
||||
var url = BaseClass.BuildObjString("product/add_product");
|
||||
if (isExist)
|
||||
{
|
||||
if (chkOverride.Checked)
|
||||
{
|
||||
url = BaseClass.BuildObjString("product/mdy_product");
|
||||
}
|
||||
else
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
row.Cells["colMsg"].Value = "已存在相同id商品,跳过";
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetPartnerSpuRst = SetPartnerSpu(shop, prod);
|
||||
//{"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 +
|
||||
"&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) +
|
||||
"&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) +
|
||||
"&main_img=" + HttpUtility.UrlEncode(dbProd.main_img, Encoding.UTF8) +
|
||||
"&product_get_type=" + HttpUtility.UrlEncode("厂商直采", Encoding.UTF8);
|
||||
if (SetPartnerSpuRst.Contains("\"success\":true"))
|
||||
{
|
||||
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
|
||||
{
|
||||
string msg = "商品入库成功!";
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
row.Cells["colMsg"].Value = msg;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
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 = "douyin";
|
||||
}
|
||||
else if (cmbPlatformType.Text == "淘宝")
|
||||
{
|
||||
platformType = "Taobao";
|
||||
}
|
||||
else if (cmbPlatformType.Text == "微信")
|
||||
{
|
||||
platformType = "WXChannel";
|
||||
}
|
||||
else
|
||||
{
|
||||
platformType = "Pinduoduo";
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
|
||||
ConcurrentList<DataGridViewRow> rowLst = new ConcurrentList<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.BuildObjString("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;
|
||||
}
|
||||
prod.getProductMsg = "商品已存在,跳过详情采集";
|
||||
if (isExist)
|
||||
{
|
||||
try { row.Cells["colMsg"].Value = prod.getProductMsg; } catch { }
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
string url = "https://sc.scm121.com/api/goods/goods/goGoodsPdd/queryBaseData?itemSpuId=" + prod.itemSpuId + "&shelvesType=DISTRIBUTION&originator=SUPPLIER&itemCoId=" + prod.itemCoId;
|
||||
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/detail/" + prod.supplierId + "?showErpList=1";
|
||||
var getDetailRst = JSTHttpResponseBLL.JSTGetResponse(shop, url, referer, appVersion);
|
||||
if (!getDetailRst.Contains("\"success\":true"))
|
||||
getDetailRst = JSTHttpResponseBLL.JSTGetResponse(shop, url, referer, appVersion);
|
||||
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["catId"].ParseToString();
|
||||
prod.dbProduct.main_cat_id = jObj["categoryData"].FirstOrDefault().ParseToString();
|
||||
prod.dbProduct.product_json = "{\"pddData\":" + 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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
ConcurrentList<DataGridViewRow> rowLst = new ConcurrentList<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.BuildObjString("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;
|
||||
}
|
||||
}
|
||||
|
||||
string url = "https://sc.scm121.com/api/goods/goods/goGoodsDouyin/queryBaseData?itemSpuId=" + prod.itemSpuId + "&shelvesType=DISTRIBUTION&originator=SUPPLIER&itemCoId=" + prod.itemCoId;
|
||||
string referer = "https://sc.scm121.com/manage/goods/qualitySupplier/detail/" + prod.supplierId + "?showErpList=1";
|
||||
var getDetailRst = JSTHttpResponseBLL.JSTGetResponse(shop, url, referer, appVersion);
|
||||
if (!getDetailRst.Contains("\"success\":true"))
|
||||
getDetailRst = JSTHttpResponseBLL.JSTGetResponse(shop, url, referer);
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user