1微信店铺切换登录 20% 2过滤筛选备注改为全等于 3数据库数据拉回逻辑优化

This commit is contained in:
wule committed 2026-03-13 16:21:15 +08:00
1 parent dc83334c59
commit 860b4408ef
37 files changed
+2520 -274

No files matched your search

+133 -15
View File
@@ -28,7 +28,7 @@ namespace TemuKJD.WXForms.ShopForms
public delegate void InfoReceivedHandler(string information);
public event InfoReceivedHandler OnInfoReceived;
public string getProduct(string sProdId, string supplierId, bool notSaveDb = false)
public string getProduct(string sProdId, string supplierId, bool isReGet = true, bool notSaveDb = false)
{
var prodId = sProdId.ParseToLong();
if (prodId <= 0)
@@ -54,10 +54,10 @@ namespace TemuKJD.WXForms.ShopForms
Task.Run(() =>
{
var msg = getPDDProductWidthEdit(shop, sProdId);
var msg = reGetProductWidthWXFormat(shop, sProdId, isReGet);
if (!string.IsNullOrEmpty(msg))
{
if (!msg.StartsWith("success") && !msg.StartsWith("商品回采保存成功"))
if (!msg.StartsWith("success") && !msg.StartsWith("商品回采保存成功") && !msg.Contains("微信商品采集入库成功"))
{
MainForm.instance.Invoke(new Action(() =>
{
@@ -77,8 +77,9 @@ namespace TemuKJD.WXForms.ShopForms
return "success";
}
public string getPDDProductWidthEdit(ShopLoginInfo shop, string prodId)
public string reGetProductWidthWXFormat(ShopLoginInfo shop, string prodId, bool isReGet = true)
{
string getString = isReGet ? "商品回采" : "商品采集";
try
{
Thread.Sleep(Randomx.GetId(10, 50));
@@ -99,28 +100,55 @@ namespace TemuKJD.WXForms.ShopForms
if (shop.LoginStatus != "登录成功")
errmsg = "店铺掉线";
return "商品回采失败!" + errmsg;
return getString + "失败!" + errmsg;
}
}
catch (Exception ex)
{
//OnInfoReceived("商品获取失败!商品数据格式获取失败!" + ex.Message);
return "商品回采失败!商品数据格式获取失败!" + ex.Message;
return getString + "失败!商品数据格式获取失败!" + ex.Message;
}
WXGetEditProductInfoLite wxProdInfoLite = null;
try
{
wxProdInfoLite = JsonHelper.DeserializeJsonToObject<WXGetEditProductInfoLite>(getEditProdRst);
var addressRst = WXUpload.getAddressById(shop, wxProdInfoLite.product.info.afterSaleInfo.afterSaleAddressId);
if (addressRst.Contains("biz magic invalid"))
{
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
}
if (!addressRst.Contains("\"success\":true"))
{
var errmsg = BaseRegex.GetStringJson(ref addressRst, "msg");
if (string.IsNullOrWhiteSpace(errmsg))
errmsg = addressRst;
if (shop.LoginStatus != "登录成功")
errmsg = "店铺掉线";
return getString + "失败!" + errmsg;
}
var addressStr = JsonHelper.JObjectParse(addressRst)["addressList"].FirstOrDefault().ParseToString();
wxProdInfoLite.address = JsonHelper.DeserializeJsonToObject<WXAfterSaleAddressInfo>(addressStr);
if (isReGet && wxProdInfoLite.address == null)
return getString + "失败!商品详情获取失败";
// 查看下json结构
var wxProdInfoLiteStr = JsonHelper.SerializeObject(wxProdInfoLite);
if (string.IsNullOrWhiteSpace(wxProdInfoLite.product.info.spuCode))
{
return "商品回采失败:外部编码采集失败,跳过";
if (isReGet)
{
return getString + "失败:外部编码采集失败,跳过";
}
else
{
return SaveWxProd(shop, prodId, wxProdInfoLite);
}
}
}
catch (Exception ex)
{
return "商品回采失败:格式转换失败 " + ex.Message;
return getString + "失败:格式转换失败 " + ex.Message;
}
@@ -138,15 +166,14 @@ namespace TemuKJD.WXForms.ShopForms
var errMsg = BaseRegex.GetStringJson(ref result, "msg");
if (string.IsNullOrEmpty(errMsg))
errMsg = result;
return "查询回采商品错误:" + errMsg;
return getString + "查询商品错误:" + errMsg;
}
List<KJDDBProduct> complateDbProdExistLst = JsonHelper.DeserializeJsonToList<KJDDBProduct>(JsonHelper.JObjectParse(result)["data"].ParseToString());
if (complateDbProdExistLst.Count == 0)
{
return "回采商品不存在";
return getString + "商品不存在";
}
url = BaseClass.BuildPDDObjString("product/add_prod_wx_complate");
Thread.Sleep(200);
data = UserLogin.GetSignaturex();
@@ -163,18 +190,109 @@ namespace TemuKJD.WXForms.ShopForms
var errMsg = BaseRegex.GetStringJson(ref result, "msg");
if (string.IsNullOrEmpty(errMsg))
errMsg = result;
return "查询回采商品错误:" + errMsg;
return getString + "查询商品错误:" + errMsg;
}
else
{
return "商品回采保存成功!";
return getString + "保存成功!";
}
}
catch (Exception ex)
{
return "商品采集失败!" + ex.Message;
return getString + "失败!" + ex.Message;
}
}
string SaveWxProd(ShopLoginInfo shop, string prodId, WXGetEditProductInfoLite wxEditProdInfoLite)
{
bool isExist = false;
var existUrl = BaseClass.BuildPDDObjString("product/get_product_spu_id_list");
string existData = UserLogin.GetSignaturex() + "&search_spu_ids=" + prodId;
//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"))
{
return "采集入库失败,产品数据库连接失败";
}
else
{
if (html.Contains("\"data\":[") && !html.Contains("\"data\":[]"))
isExist = true;
}
var url = BaseClass.BuildPDDObjString("product/add_product");
if (isExist)
url = BaseClass.BuildPDDObjString("product/mdy_product");
var skus = wxEditProdInfoLite.product.productSkus;
var data = Work.UserLogin.GetSignaturex() +
"&from_shop_id=" + shop.ShopId +
"&from_shop_name=" + shop.ShopAccount +
"&spu_id=" + prodId +
"&skc_id=" + prodId +
"&price_text=" + skus.Min(s => s.productSkuInfo.salePrice * 0.01m) + " - " + skus.Max(s => s.productSkuInfo.salePrice * 0.01m) +
"&ext_code=" + "" +
"&product_name=" + HttpUtility.UrlEncode(wxEditProdInfoLite.product.info.title, Encoding.UTF8) +
"&product_json=" + HttpUtility.UrlEncode(JsonHelper.SerializeObject(wxEditProdInfoLite), Encoding.UTF8) +
"&size_json=" + HttpUtility.UrlEncode("{}", Encoding.UTF8) +
"&sale_count=" +
"&sale_count_text=" +
"&main_img=" + HttpUtility.UrlEncode(wxEditProdInfoLite.product.info.headImg.FirstOrDefault(), Encoding.UTF8) +
"&wx_safe_status=" + HttpUtility.UrlEncode("安全商品", Encoding.UTF8) +
"&product_get_type=" + HttpUtility.UrlEncode("微信店采", Encoding.UTF8);
if (wxEditProdInfoLite.product.info.category.Count > 0)
{
data += "&wx_cat_1=" + wxEditProdInfoLite.product.info.category[0].catId;
data += "&main_cat_id=" + wxEditProdInfoLite.product.info.category[0].catId;
data += "&main_cat_name=" + wxEditProdInfoLite.product.info.category[0].name;
data += "&wx_cat_leaf=" + wxEditProdInfoLite.product.info.category.LastOrDefault()?.catId;
data += "&cat_id=" + wxEditProdInfoLite.product.info.category.LastOrDefault()?.catId;
data += "&cat_name=" + HttpUtility.UrlEncode((wxEditProdInfoLite.product.info.category.LastOrDefault()?.name).ParseToString(), Encoding.UTF8);
}
if (wxEditProdInfoLite.product.info.category.FirstOrDefault().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;
//}));
return msg;
}
else
{
//prod.getProductMsg = "商品入库成功!";
//Invoke(new Action(() =>
//{
// row.Cells["colMsg"].Value = prod.getProductMsg;
//}));
if (!isExist)
{
url = BaseClass.BuildPDDObjString("product/mdy_product");
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");
return msg;
}
}
return "微信商品采集入库成功!";
}
return "商品采集失败!";
}
}
}