899 lines
43 KiB
C#
899 lines
43 KiB
C#
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;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using TemuKJD.BaseForms;
|
|
using TemuKJD.BLL;
|
|
using TemuKJD.Extension;
|
|
using TemuKJD.Helper;
|
|
using Work;
|
|
|
|
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()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
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.BuildObjString("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(() => { 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)
|
|
{
|
|
return false;
|
|
}
|
|
private void CefWebBrowser_AddressChanged(object sender, CefSharp.AddressChangedEventArgs e)
|
|
{
|
|
if (this.Created && !this.Disposing && !this.IsDisposed)
|
|
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)
|
|
{
|
|
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.BuildObjString("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 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)
|
|
{
|
|
Task.Run(() => { });
|
|
//"&product_get_type=" + HttpUtility.UrlEncode("厂商直采", Encoding.UTF8);
|
|
|
|
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(() =>
|
|
{
|
|
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) +
|
|
"&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) +
|
|
"&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);
|
|
|
|
List<string> pIds = new List<string>();
|
|
pIds.AddRange(dgvProduct.Rows.Cast<DataGridViewRow>().Select(r => r.Cells["colProductId"].Value.ParseToString()).ToList());
|
|
foreach (var prodId in pIds)
|
|
{
|
|
if (cancellationTokenSource.IsCancellationRequested)
|
|
break;
|
|
|
|
var row = dgvProduct.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colProductId"].Value.ParseToString() == prodId);
|
|
|
|
if (row == null || row.Index < 0 || row.Cells["colCheck"].Value.ParseToBool() != true)
|
|
continue;
|
|
|
|
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();
|
|
var prodDataJson = JsonHelper.SerializeObject(jObj);
|
|
prod.dbProduct.product_json = "{\"pddData\":" + prodDataJson + ",\"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 { }
|
|
}));
|
|
}
|
|
|
|
if (pIds.IndexOf(prodId) % 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);
|
|
|
|
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.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;
|
|
}
|
|
}
|
|
}
|