微信商品回采功能
This commit is contained in:
1 parent
3db584fe1e
commit
d9900452f2
35 files changed
+4850
-696
No files matched your search
@@ -3,7 +3,9 @@ using AllBase.Helper;
|
||||
using AllBase.Model.Param.PDDProdParam;
|
||||
using AllBase.Model.Result;
|
||||
using AllBase.Model.Result.PDDResult;
|
||||
using AllBase.Model.Result.WXResult;
|
||||
using NaiBa.Util.Extension;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -14,8 +16,9 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TemuKJD.BaseForms;
|
||||
using TemuKJD.BLL;
|
||||
using TemuKJD.PDDForms.AdminForms;
|
||||
using TemuKJD.PDDForms.ProductThirdSelectForms;
|
||||
using TemuKJD.WXForms.AdminForms;
|
||||
using TemuKJD.WXForms.ProductForms;
|
||||
using Work;
|
||||
|
||||
namespace TemuKJD.WXForms.ShopForms
|
||||
@@ -25,5 +28,153 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
public delegate void InfoReceivedHandler(string information);
|
||||
public event InfoReceivedHandler OnInfoReceived;
|
||||
|
||||
public string getProduct(string sProdId, string supplierId, bool notSaveDb = false)
|
||||
{
|
||||
var prodId = sProdId.ParseToLong();
|
||||
if (prodId <= 0)
|
||||
{
|
||||
MainForm.instance.Invoke(new Action(() =>
|
||||
{
|
||||
BaseMsgForm.ShowError("商品Id不存在!");
|
||||
}));
|
||||
return "failed";
|
||||
}
|
||||
//var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == supplierId.ParseToString());
|
||||
var shop = WXAdminShopListForm.lstAdminShopInfo.FirstOrDefault(s => s.ShopId == supplierId.ParseToString());
|
||||
if (shop == null)
|
||||
shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == supplierId.ParseToString());
|
||||
if (string.IsNullOrEmpty(supplierId) || shop == null)
|
||||
{
|
||||
MainForm.instance.Invoke(new Action(() =>
|
||||
{
|
||||
BaseMsgForm.ShowError("店铺不存在!");
|
||||
}));
|
||||
return "failed";
|
||||
}
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
var msg = getPDDProductWidthEdit(shop, sProdId);
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
if (!msg.StartsWith("success") && !msg.StartsWith("商品回采保存成功"))
|
||||
{
|
||||
MainForm.instance.Invoke(new Action(() =>
|
||||
{
|
||||
BaseMsgForm.ShowError(msg);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
MainForm.instance.Invoke(new Action(() =>
|
||||
{
|
||||
BaseMsgForm.ShowInfo(msg);
|
||||
}));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
public string getPDDProductWidthEdit(ShopLoginInfo shop, string prodId)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
string getEditProdRst = "";
|
||||
try
|
||||
{
|
||||
getEditProdRst = WXUpload.getEditProductV2(shop, prodId);
|
||||
Thread.Sleep(Randomx.GetId(50, 100));
|
||||
if (getEditProdRst.Contains("biz magic invalid"))
|
||||
{
|
||||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||||
}
|
||||
if (!getEditProdRst.Contains("\"success\":true"))
|
||||
{
|
||||
var errmsg = BaseRegex.GetStringJson(ref getEditProdRst, "msg");
|
||||
if (string.IsNullOrWhiteSpace(errmsg))
|
||||
errmsg = getEditProdRst;
|
||||
if (shop.LoginStatus != "登录成功")
|
||||
errmsg = "店铺掉线";
|
||||
|
||||
return "商品回采失败!" + errmsg;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//OnInfoReceived("商品获取失败!商品数据格式获取失败!" + ex.Message);
|
||||
return "商品回采失败!商品数据格式获取失败!" + ex.Message;
|
||||
}
|
||||
|
||||
WXGetEditProductInfoLite wxProdInfoLite = null;
|
||||
try
|
||||
{
|
||||
wxProdInfoLite = JsonHelper.DeserializeJsonToObject<WXGetEditProductInfoLite>(getEditProdRst);
|
||||
var wxProdInfoLiteStr = JsonHelper.SerializeObject(wxProdInfoLite);
|
||||
if (string.IsNullOrWhiteSpace(wxProdInfoLite.product.info.spuCode))
|
||||
{
|
||||
return "商品回采失败:外部编码采集失败,跳过";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "商品回采失败:格式转换失败 " + ex.Message;
|
||||
}
|
||||
|
||||
|
||||
// 查询商品库有没有
|
||||
var url = BaseClass.BuildPDDObjString("product/get_product_spu_id_list");
|
||||
Thread.Sleep(200);
|
||||
var data = UserLogin.GetSignaturex();
|
||||
data += "&search_secret_spu_ids=" + wxProdInfoLite.product.info.spuCode;
|
||||
data += "&wx_safe_status=" + "安全商品,未校验";
|
||||
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 result, "msg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = result;
|
||||
return "查询回采商品错误:" + errMsg;
|
||||
}
|
||||
List<KJDDBProduct> complateDbProdExistLst = JsonHelper.DeserializeJsonToList<KJDDBProduct>(JsonHelper.JObjectParse(result)["data"].ParseToString());
|
||||
if (complateDbProdExistLst.Count == 0)
|
||||
{
|
||||
return "回采商品不存在";
|
||||
}
|
||||
|
||||
|
||||
url = BaseClass.BuildPDDObjString("product/add_prod_wx_complate");
|
||||
Thread.Sleep(200);
|
||||
data = UserLogin.GetSignaturex();
|
||||
data += "&secret_spu_id=" + wxProdInfoLite.product.info.spuCode;
|
||||
data += "&spu_id=" + complateDbProdExistLst[0].spu_id;
|
||||
data += "&coid=" + complateDbProdExistLst[0].skc_id;
|
||||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||||
data += "&wx_edit_prod_json=" + GetHtml.UrlEncodeUtf8(JsonConvert.SerializeObject(wxProdInfoLite, jsonSetting));
|
||||
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;
|
||||
return "查询回采商品错误:" + errMsg;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "商品回采保存成功!";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "商品采集失败!" + ex.Message;
|
||||
}
|
||||
return "商品采集失败!";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -445,7 +445,8 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
List<string> shopIdList = GetCheckedShopIdList();
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
foreach(DataGridViewRow row in dgvShop.Rows.Cast<DataGridViewRow>())
|
||||
var rows = dgvShop.Rows.Cast<DataGridViewRow>().ToList();
|
||||
foreach (DataGridViewRow row in rows)
|
||||
{
|
||||
if (!shopList.Any(s => s.ShopId == row.Cells["colShopId"].Value.ParseToString()))
|
||||
this.dgvShop.Rows.Remove(row);
|
||||
|
||||
@@ -446,7 +446,7 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
sb.Append("(function(){");
|
||||
sb.Append("CefSharp.BindObjectAsync('shopObj');");
|
||||
sb.Append("})();");
|
||||
//cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sb.ToString());
|
||||
cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sb.ToString());
|
||||
}
|
||||
|
||||
//public Func<object, string, string, request, bool> BeforeResourceLoadEvent; // sender, requestUrl, postData, request, true(表示取消执行)
|
||||
@@ -538,6 +538,58 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
this.lstShopCompany.Add(sc);
|
||||
});
|
||||
}
|
||||
|
||||
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采") && currentUrl.StartsWith("https://store.weixin.qq.com/shop/goods/list"))
|
||||
{
|
||||
//Task.Run(() => {
|
||||
string sAddInputJs = @"
|
||||
document.addEventListener('wheel', function(event) {
|
||||
// 检查滚动方向
|
||||
//if (event.deltaY < 0) {
|
||||
// console.log('向上滚动');
|
||||
//} else {
|
||||
// console.log('向下滚动');
|
||||
//}
|
||||
// 或者使用 event.deltaX 来检查水平滚动
|
||||
//if (event.deltaX < 0) {
|
||||
// console.log('向左滚动');
|
||||
//} else if (event.deltaX > 0) {
|
||||
// console.log('向右滚动');
|
||||
//}
|
||||
|
||||
// 阻止默认的滚动行为(如果有需要)
|
||||
//event.preventDefault();
|
||||
|
||||
addGetProdButton();
|
||||
});
|
||||
addGetProdButton();
|
||||
|
||||
function addGetProdButton() {
|
||||
const element = document.getElementsByName('goods')[0];
|
||||
const shadowRoot = element.shadowRoot;
|
||||
var productLst = shadowRoot.querySelector('micro-app-body').getElementsByClassName('goods_info')
|
||||
for ( i= 0; i < productLst.length; i++) {
|
||||
var addBtnItem = productLst[i]; //.parentElement.parentElement.parentElement;
|
||||
var pos = addBtnItem.innerHTML.indexOf('ID:')
|
||||
if (addBtnItem.innerHTML.indexOf('回采') < 0 && pos >= 0) {
|
||||
var sSpuId = addBtnItem.innerHTML.substring(pos + 3);
|
||||
sSpuId = sSpuId.substring(0, sSpuId.indexOf('<span')).trim();
|
||||
//addBtnItem.innerHTML += ""<input type=\""button\"" style=\""display:inline; width:60px; margin-left:10px; margin-top:0px; cursor:pointer; border:1px solid\"" value =\""回采商品\"" onclick=\""shopObj.getProduct('"" + sSpuId + ""','" + this.shop.ShopId + @"')\"">""
|
||||
//addBtnItem.innerHTML += ""<input type=\""button\"" style=\""display:inline; width:60px; margin-left:10px; margin-top:0px; cursor:pointer; border:1px solid\"" value =\""回采商品\"" onclick=\""alert('"" + sSpuId + ""')\"">""
|
||||
//addBtnItem.innerHTML = addBtnItem.innerHTML.replace(""分享 </a></div>"", ""分享 </a></div><input type=\""button\"" style=\""display:inline; width:60px; margin-left:10px; margin-top:0px; cursor:pointer; border:1px solid\"" value =\""回采商品\"" onclick=\""shopObj.getProduct('"" + sSpuId + ""','" + this.shop.ShopId + @"')\"">"");
|
||||
var newDiv = document.createElement(""div"");
|
||||
newDiv.innerHTML = ""<a style=\""display:inline; padding:2px 5px; cursor:pointer; border:1px solid\"" onclick=\""shopObj.getProduct('"" + sSpuId + ""','" + this.shop.ShopId + @"')\"">回采<\a>"";
|
||||
addBtnItem.lastChild.appendChild(newDiv);
|
||||
}
|
||||
}
|
||||
}";
|
||||
cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sAddInputJs);
|
||||
//});
|
||||
|
||||
//const element = document.getElementsByName('goods')[0]
|
||||
//const shadowRoot = element.shadowRoot;
|
||||
//shadowRoot.querySelector('micro-app-body').getElementsByClassName('goods_info')
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user