Files
KJD_WebService/TEMUKJD/PDDForms/ShopForms/PDDShopBrowserObject.cs
T

997 lines
53 KiB
C#

using AllBase;
using AllBase.Helper;
using AllBase.Model.Param.PDDProdParam;
using AllBase.Model.Result;
using AllBase.Model.Result.PDDResult;
using NaiBa.Util.Extension;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
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.PDDForms.AdminForms;
using TemuKJD.PDDForms.ProductThirdSelectForms;
using Work;
namespace TemuKJD.PDDForms.ShopForms
{
public class PDDShopBrowserObject
{
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)
{
BaseMsgForm.ShowError("商品Id不存在!");
return "failed";
}
//var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == supplierId.ParseToString());
var shop = PDDAdminShopListForm.lstAdminShopInfo.FirstOrDefault(s => s.ShopId == supplierId.ParseToString());
if (string.IsNullOrEmpty(supplierId) || shop == null)
{
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, string commitId = "", string catId = "", bool isChance = false, bool notSaveDb = false)
{
try
{
var sourceShop = shop;
var sourceProdId = prodId;
string success_err_msg = "";
//string errorMsg = "";
if (string.IsNullOrEmpty(commitId))
{
var commit_id_rst = GetPddProdCommitId(sourceShop, sourceProdId.ToString());
if (!commit_id_rst.Contains("\"success\":true") || !commit_id_rst.Contains("\"result\""))
{
var errMsg = BaseRegex.GetStringJson(ref commit_id_rst, "error_msg");
if (string.IsNullOrEmpty(errMsg))
errMsg = commit_id_rst;
//OnInfoReceived("商品获取失败!" + errMsg);
return "商品获取失败!" + errMsg;
}
commitId = BaseRegex.GetStringJson(ref commit_id_rst, "goods_commit_id");
if (string.IsNullOrEmpty(commitId))
{
//OnInfoReceived("商品获取失败!商品提交编号获取失败!");
return "商品获取失败!商品提交编号获取失败!";
}
}
Thread.Sleep(Randomx.GetId(10, 50));
var detail_json = "{}";
PDDProductDetailInfo product = null;
try
{
var prod_detail_rst = GetPddProdDetail(sourceShop, sourceProdId.ToString(), commitId);
JObject prod_detail_obj = JObject.Parse(prod_detail_rst);
detail_json = JsonHelper.SerializeObject(prod_detail_obj["result"]);
product = JsonHelper.DeserializeJsonToObject<PDDProductDetailInfo>(detail_json);
if (product == null || detail_json.Length < 10)
{
//OnInfoReceived("商品获取失败!商品数据格式获取失败!");
return "商品获取失败!商品数据格式获取失败!";
}
}
catch (Exception ex)
{
//OnInfoReceived("商品获取失败!商品数据格式获取失败!" + ex.Message);
return "商品获取失败!商品数据格式获取失败!" + ex.Message;
}
Thread.Sleep(Randomx.GetId(10, 50));
var size_json = "{}";
if (product.size_spec_id.ParseToLong() != 0)
{
try
{
var prod_size_rst = GetPddProdSizeSpec(sourceShop, sourceProdId.ToString(), commitId, product.size_spec_id.ParseToString());
prod_size_rst = GetHtml.Unicode2String(prod_size_rst);
JObject prod_size_obj = JObject.Parse(prod_size_rst);
size_json = JsonHelper.SerializeObject(prod_size_obj["result"]);
var size = JsonHelper.DeserializeJsonToObject<PDDSizeSpecInfo>(size_json);
if (size == null)
{
//OnInfoReceived("尺码表获取失败!尺码数据格式获取失败!");
return "尺码表获取失败!尺码数据格式获取失败!";
}
}
catch (Exception ex)
{
//OnInfoReceived("尺码表获取失败!尺码数据格式获取失败!" + ex.Message);
return "尺码表获取失败!尺码数据格式获取失败!" + ex.Message;
}
}
Thread.Sleep(Randomx.GetId(10, 50));
var property_template_json = "{}";
PDDProductPropertyInfo property = null;
if (!isChance) // 非机会商品编辑可以直接获取属性
{
try
{
var prod_property_rst = GetPddProdProperty(sourceShop, sourceProdId.ToString(), commitId);
prod_property_rst = GetHtml.Unicode2String(prod_property_rst);
JObject prod_property_obj = JObject.Parse(prod_property_rst);
property_template_json = JsonHelper.SerializeObject(prod_property_obj["result"]);
property = JsonHelper.DeserializeJsonToObject<PDDProductPropertyInfo>(property_template_json);
}
catch (Exception ex) { }
if (property == null)
{
//OnInfoReceived("商品获取失败!商品属性获取失败!");
return "商品获取失败!商品属性获取失败!";
}
}
else // 机会商品通过类目id获取属性
{
try
{
var prod_property_template_rst = get_chance_cat_prop_template(sourceShop, catId, sourceProdId.ToString(), commitId);
prod_property_template_rst = GetHtml.Unicode2String(prod_property_template_rst);
JObject prod_property_template_obj = JObject.Parse(prod_property_template_rst);
var prod_property_template_json = JsonHelper.SerializeObject(prod_property_template_obj["result"]["modules"][0]);
var temp_module_info = JsonHelper.DeserializeJsonToObject<pdd_module_item>(prod_property_template_json);
property = new PDDProductPropertyInfo() { goods_properties = new List<goods_propertie_item>(), sku_properties = new object() };
foreach (var propInfo in temp_module_info.propertys)
{
if (propInfo.goods_properties != null)
{
goods_propertie_item propParam = new goods_propertie_item() { values = new List<value_item>() };
property.goods_properties.Add(propParam);
propParam.name = propInfo.name_alias;
propParam.ref_pid = propInfo.ref_pid;
foreach (var goodsPropInfo in propInfo.goods_properties)
{
propParam.values.Add(new value_item()
{
raw_value = goodsPropInfo.v_value,
unit = goodsPropInfo.p_unit,
value = goodsPropInfo.v_value,
vid = goodsPropInfo.vid,
});
}
}
}
}
catch (Exception ex)
{
return "商品获取失败!商品属性获取失败!" + ex.Message;
}
if (property == null || property.goods_properties == null || property.goods_properties.Count == 0)
{
//OnInfoReceived("商品获取失败!商品属性获取失败!");
return "商品获取失败!商品属性获取失败!";
}
property_template_json = JsonHelper.SerializeObject(property);
}
// 属性模板暂时注释
//var prop_template_json = "{}";
//PDDProductTemplateInfo templateInfo = null;
//try
//{
// var prop_template_rst = GetPddCatPropTemplate(sourceShop, product.cat_id.ParseToString(), sourceProdId.ToString(), commitId);
// JObject prop_template_obj = JObject.Parse(prop_template_rst);
// prop_template_json = JsonHelper.SerializeObject(prop_template_obj["result"]);
// templateInfo = JsonHelper.DeserializeJsonToObject<PDDProductTemplateInfo>(prop_template_json);
//}
//catch (Exception ex) { }
//if (templateInfo == null)
//{
// OnInfoReceived("商品获取失败!商品属性模板获取失败!");
// return;
//}
Thread.Sleep(Randomx.GetId(10, 50));
var decoration_json = "{}";
PDDProductDecorationInfo decoration = null;
try
{
var prod_decoration_rst = GetPddProdDecoration(sourceShop, sourceProdId.ToString(), commitId);
if (!prod_decoration_rst.Contains("\"success\":true"))
{
var errMsg = BaseRegex.GetStringJson(ref prod_decoration_rst, "error_msg");
if (string.IsNullOrEmpty(errMsg))
errMsg = prod_decoration_rst;
//OnInfoReceived("商品获取失败!商品详情图获取失败!" + errMsg);
return "商品获取失败!商品详情图获取失败!" + errMsg;
}
JObject prod_decoration_obj = JObject.Parse(prod_decoration_rst);
if (!prod_decoration_obj["result"].IsNullOrEmpty())
decoration_json = JsonHelper.SerializeObject(prod_decoration_obj["result"]);
decoration = JsonHelper.DeserializeJsonToObject<PDDProductDecorationInfo>(decoration_json);
}
catch (Exception ex)
{
//OnInfoReceived("商品获取失败!商品详情图获取失败!" + ex.Message);
return "商品获取失败!商品详情图获取失败!" + ex.Message;
}
if (decoration != null && decoration_json.ParseToString().Length < 20)
{
//try
//{ // 获取另一组详情数据,结构和主详情不一样无法通用
// var prod_detail_decoration_rst = GetPddProdOnShopDetail(sourceShop, sourceProdId.ToString(), commitId);
// JObject prod_detail_decoration_obj = JObject.Parse(prod_detail_decoration_rst);
// foreach (JObject ob in prod_detail_decoration_obj["result"]["carousel_gallery"])
// {
// }
//}
//catch (Exception ex)
//{
// OnInfoReceived("商品获取失败!商品详情图获取失败!" + ex.Message);
// return;
//}
PDDProdDecorationCommitParam decorationParam = new PDDProdDecorationCommitParam();
decorationParam.goods_id = product.goods_id;
decorationParam.goods_commit_id = commitId.ParseToLong();
decorationParam.preview_key = "";
decorationParam.decoration_floor_list = new List<decoration_floor_param>();
foreach (var gallary in product.galleries)
{
if (gallary.type != 2)
continue;
var floor_param = new decoration_floor_param();
//floor_param.floor_id = 0; // floorItem.floor_id;
floor_param.type = "image"; // floorItem.type;
floor_param.content_list = new List<decoration_content_param>();
//foreach (var c in floorItem.content_list)
{
var decorationContentParam = new decoration_content_param()
{
//file_id = c.file_id,
img_url = gallary.url, //c.img_url,
//height = c.height,
//text = c.text,
//text_module_details = null,
//width = c.width,
};
//try { decorationContentParam.text_module_details = JsonHelper.DeserializeJsonToObject<text_module_detail_param>(JsonHelper.SerializeObject(c.text_module_details)); }
//catch (Exception ex) { }
floor_param.content_list.Add(decorationContentParam);
}
decorationParam.decoration_floor_list.Add(floor_param);
}
var addDecorationRst = save_decoration(shop, decorationParam, product.goods_id.ParseToString(), commitId);
Thread.Sleep(Randomx.GetId(10, 50));
// 第二次获取详情图
try
{
var prod_decoration_rst = GetPddProdDecoration(sourceShop, sourceProdId.ToString(), commitId);
if (!prod_decoration_rst.Contains("\"success\":true"))
{
var errMsg = BaseRegex.GetStringJson(ref prod_decoration_rst, "error_msg");
if (string.IsNullOrEmpty(errMsg))
errMsg = prod_decoration_rst;
//OnInfoReceived("商品获取失败!商品详情图获取失败!" + errMsg);
return "商品获取失败!商品详情图获取失败!" + errMsg;
}
JObject prod_decoration_obj = JObject.Parse(prod_decoration_rst);
if (!prod_decoration_obj["result"].IsNullOrEmpty())
decoration_json = JsonHelper.SerializeObject(prod_decoration_obj["result"]);
decoration = JsonHelper.DeserializeJsonToObject<PDDProductDecorationInfo>(decoration_json);
}
catch (Exception ex)
{
//OnInfoReceived("商品获取失败!商品详情图获取失败!" + ex.Message);
return "商品获取失败!商品详情图获取失败!" + ex.Message;
}
}
if (decoration == null || decoration_json.ParseToString().Length < 20)
{
//OnInfoReceived("商品获取失败!商品详情图获取失败!");
return "商品获取失败!商品详情图获取失败!";
}
Thread.Sleep(Randomx.GetId(10, 50));
var material3_json = "{}";
PDDMaterialInfo material3 = null;
try
{
var material3_rst = GetPddGoodsMaterial(sourceShop, sourceProdId.ToString(), commitId, 3);
if (!material3_rst.Contains("\"success\":true"))
{
var errMsg = BaseRegex.GetStringJson(ref material3_rst, "error_msg");
if (string.IsNullOrEmpty(errMsg))
errMsg = material3_rst;
//OnInfoReceived("商品获取失败!商品长图获取失败!" + errMsg);
return "商品获取失败!商品长图获取失败!" + errMsg;
}
JObject material3_obj = JObject.Parse(material3_rst);
if (!material3_obj["result"].IsNullOrEmpty())
material3_json = JsonHelper.SerializeObject(material3_obj["result"]);
material3 = JsonHelper.DeserializeJsonToObject<PDDMaterialInfo>(material3_json);
}
catch (Exception ex)
{
//OnInfoReceived("商品获取失败!商品长图获取失败!" + ex.Message);
return "商品获取失败!商品长图获取失败!" + ex.Message;
}
if (material3 == null)
{
//OnInfoReceived("商品获取失败!商品长图获取失败!");
return "商品获取失败!商品长图获取失败!";
}
Thread.Sleep(Randomx.GetId(10, 50));
var material1_json = "{}";
PDDMaterialInfo material1 = null;
try
{
var material1_rst = GetPddGoodsMaterial(sourceShop, sourceProdId.ToString(), commitId, 1);
if (!material1_rst.Contains("\"success\":true"))
{
var errMsg = BaseRegex.GetStringJson(ref material1_rst, "error_msg");
if (string.IsNullOrEmpty(errMsg))
errMsg = material1_rst;
//OnInfoReceived("商品获取失败!商品白底图获取失败!" + errMsg);
return "商品获取失败!商品白底图获取失败!" + errMsg;
}
JObject material1_obj = JObject.Parse(material1_rst);
if (!material1_obj["result"].IsNullOrEmpty())
material1_json = JsonHelper.SerializeObject(material1_obj["result"]);
material1 = JsonHelper.DeserializeJsonToObject<PDDMaterialInfo>(material1_json);
}
catch (Exception ex)
{
//OnInfoReceived("商品获取失败!商品白底图获取失败!" + ex.Message);
return "商品获取失败!商品白底图获取失败!" + ex.Message;
}
if (material1 == null)
{
//OnInfoReceived("商品获取失败!商品白底图获取失败!");
return "商品获取失败!商品白底图获取失败!";
}
bool isExist = false;
var existUrl = BaseClass.BuildObjString("product/get_product_list");
string existData = UserLogin.GetSignaturex() + "&search_spu=" + product.goods_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"))
html = GetHtml.PostUtf8(existUrl, existData);
if (!string.IsNullOrEmpty(html) && html.Contains("\"code\":200"))
{
if (html.Contains("\"data\":[") && !html.Contains("\"data\":[]"))
isExist = true;
}
string product_json = "{\"detail\":" + detail_json + ",\"size\":" + size_json + ",\"decoration\":" + decoration_json +
",\"material3\":" + material3_json + ",\"material1\":" + material1_json + ",\"property\":" + property_template_json + "}";
if (notSaveDb)
{
//prodInfo = JsonHelper.DeserializeJsonToObject<PDDProductInfo>(product_json);
string main_img = "";
//if (string.IsNullOrEmpty(main_img))
// main_img = product.image_url;
//if (string.IsNullOrEmpty(main_img))
// main_img = product.hd_thumb_url;
//if (string.IsNullOrEmpty(main_img))
// main_img = product.thumb_url;
if (string.IsNullOrEmpty(main_img))
main_img = (product.galleries?.FirstOrDefault(img => img.type == 1)?.url).ParseToString();
if (string.IsNullOrEmpty(main_img))
main_img = (product.galleries?.FirstOrDefault()?.url).ParseToString();
KJDDBProduct dbProd = new KJDDBProduct();
dbProd.from_shop_id = shop.ShopId;
dbProd.spu_id = product.goods_id.ParseToString();
dbProd.skc_id = product.goods_id.ParseToString();
dbProd.price_text = product.sku.Min(s => s.multi_price).ParseToInt() * 0.01m + "-" + product.sku.Max(s => s.multi_price).ParseToInt() * 0.01m;
dbProd.main_cat_id = (product.cat_ids?.FirstOrDefault(c => c != null)).ParseToString();
dbProd.main_cat_name = (product.cats?.FirstOrDefault(c => !string.IsNullOrEmpty(c))).ParseToString();
dbProd.cat_id = (product.cat_id).ParseToString();
dbProd.cat_name = (product.cats?.LastOrDefault(c => !string.IsNullOrEmpty(c))).ParseToString();
dbProd.ext_code = product.out_goods_sn;
dbProd.product_name = product.goods_name;
dbProd.product_json = product_json;
dbProd.size_json = size_json;
dbProd.main_img = main_img;
return "success" + JsonHelper.SerializeObject(dbProd);
}
else
{
string main_img = "";
//if (string.IsNullOrEmpty(main_img))
// main_img = product.image_url;
//if (string.IsNullOrEmpty(main_img))
// main_img = product.hd_thumb_url;
//if (string.IsNullOrEmpty(main_img))
// main_img = product.thumb_url;
if (string.IsNullOrEmpty(main_img))
main_img = (product.galleries?.FirstOrDefault(img => img.type == 1)?.url).ParseToString();
if (string.IsNullOrEmpty(main_img))
main_img = (product.galleries?.FirstOrDefault()?.url).ParseToString();
var url = BaseClass.BuildObjString("product/add_product");
if (isExist)
{
bool isOverride = false;
MainForm.instance.Invoke(new Action(() =>
{
var ok = BaseMsgForm.ShowConfirm("产品库内已存在相同id商品,是否更新?").DialogResult;
if (ok == DialogResult.OK)
isOverride = true;
}));
if (isOverride)
url = BaseClass.BuildObjString("product/mdy_product");
else
return "";
}
var data = Work.UserLogin.GetSignaturex() +
"&from_shop_id=" + shop.ShopId +
"&spu_id=" + product.goods_id.ParseToString() +
"&skc_id=" + product.goods_id.ParseToString() +
"&price_text=" + product.sku.Min(s => s.multi_price).ParseToInt() * 0.01m + "-" + product.sku.Max(s => s.multi_price).ParseToInt() * 0.01m +
"&main_cat_id=" + (product.cat_ids?.FirstOrDefault(c => c != null)).ParseToString() +
"&main_cat_name=" + HttpUtility.UrlEncode((product.cats?.FirstOrDefault(c => !string.IsNullOrEmpty(c))).ParseToString(), Encoding.UTF8) +
"&cat_id=" + (product.cat_id).ParseToString() +
"&cat_name=" + HttpUtility.UrlEncode((product.cats?.LastOrDefault(c => !string.IsNullOrEmpty(c))).ParseToString(), Encoding.UTF8) +
"&ext_code=" + HttpUtility.UrlEncode(product.out_goods_sn, Encoding.UTF8) +
"&product_name=" + HttpUtility.UrlEncode(product.goods_name, Encoding.UTF8) +
"&product_json=" + HttpUtility.UrlEncode(product_json, Encoding.UTF8) +
"&size_json=" + HttpUtility.UrlEncode(size_json, Encoding.UTF8) +
"&main_img=" + HttpUtility.UrlEncode(main_img, 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"))
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
{
string msg = "商品采集保存失败!请检查网络连接:" + BaseRegex.GetStringJson(ref html, "msg");
//OnInfoReceived(msg);
return msg;
}
else
{
string msg = "商品采集保存成功!" + success_err_msg;
return msg;
}
}
}
catch (Exception ex)
{
return "商品采集失败!" + ex.Message;
}
}
/// <summary>
/// 第三方获取商品并直接提交到第三方待上传列表
/// </summary>
/// <param name="sProdId"></param>
/// <param name="supplierId"></param>
/// <returns></returns>
public string getThirdProduct(string sProdId, string supplierId)
{
var prodId = sProdId.ParseToLong();
if (prodId <= 0)
{
BaseMsgForm.ShowError("商品Id不存在!");
return "failed";
}
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == supplierId.ParseToString());
if (string.IsNullOrEmpty(supplierId) || shop == null)
{
BaseMsgForm.ShowError("店铺不存在!");
return "failed";
}
Task.Run(() =>
{
try
{
var sourceShop = shop;
var sourceProdId = prodId;
string success_err_msg = "";
string errorMsg = "";
var html = GetPddProdCommitId(sourceShop, sourceProdId.ToString());
if (!html.Contains("\"success\":true") || !html.Contains("\"result\""))
{
var errMsg = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(errMsg))
errMsg = html;
OnInfoReceived("商品获取失败!" + errMsg);
return;
}
var commitId = BaseRegex.GetStringJson(ref html, "goods_commit_id");
if (string.IsNullOrEmpty(commitId))
{
OnInfoReceived("商品获取失败!商品提交编号获取失败!");
return;
}
html = GetPddProdDetail(sourceShop, sourceProdId.ToString(), commitId);
JObject obj = JObject.Parse(html);
var result = JsonHelper.SerializeObject(obj["result"]);
var sizeRst = "";
PDDProductDetailInfo product = JsonHelper.DeserializeJsonToObject<PDDProductDetailInfo>(result);
if (product == null)
{
OnInfoReceived("商品获取失败!商品数据格式获取失败!");
return;
}
//拼多多暂时注释尺码
//if (product.sizeTemplateId > 0)
//{
// html = SizeSpecQuery(sourceShop, sourceProdId.ToString(), product.sizeTemplateId.ToString());
// if (!html.Contains("\"success\":true"))
// {
// success_err_msg += " 尺码表获取失败!" + BaseRegex.GetStringJson(ref html, "errorMsg");
// }
// else
// {
// obj = JObject.Parse(html);
// sizeRst = JsonHelper.SerializeObject(obj["result"]);
// }
//}
List<ShopLoginInfo> shopLst = new List<ShopLoginInfo>();
PDDShopListForm.Instance.Invoke(new Action(() =>
{
PDDThirdProdSelectAddShopForm shopForm = new PDDThirdProdSelectAddShopForm();
shopForm.ShowDialog();
shopLst.AddRange(shopForm.lstSelectShop);
}));
if (shopLst.Count == 0)
{
OnInfoReceived("库存上传操作取消或未选择上传店铺!");
return;
}
string main_img = "";
//if (string.IsNullOrEmpty(main_img))
// main_img = product.image_url;
//if (string.IsNullOrEmpty(main_img))
// main_img = product.hd_thumb_url;
//if (string.IsNullOrEmpty(main_img))
// main_img = product.thumb_url;
if (string.IsNullOrEmpty(main_img))
main_img = (product.galleries?.FirstOrDefault(img => img.type == 1)?.url).ParseToString();
if (string.IsNullOrEmpty(main_img))
main_img = (product.galleries?.FirstOrDefault()?.url).ParseToString();
var url = BaseClass.BuildObjString("product_third/add_product");
var data = UserLogin.GetSignaturex() +
"&from_shop_id=" + shop.ShopId +
"&spu_id=" + product.goods_id.ParseToString() +
"&skc_id=" + product.goods_id.ParseToString() +
"&cat_id=" + (product.cat_id).ParseToString() +
"&cat_name=" + HttpUtility.UrlEncode((product.cats?.LastOrDefault(c => !string.IsNullOrEmpty(c))).ParseToString(), Encoding.UTF8) +
"&ext_code=" + HttpUtility.UrlEncode(product.out_goods_sn, Encoding.UTF8) +
"&product_name=" + HttpUtility.UrlEncode(product.goods_name, Encoding.UTF8) +
"&product_json=" + HttpUtility.UrlEncode(result, Encoding.UTF8) +
"&size_json=" + HttpUtility.UrlEncode(sizeRst, Encoding.UTF8) +
"&main_img=" + HttpUtility.UrlEncode(main_img, 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"))
// html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
{
errorMsg = "库存商品保存失败!请检查网络连接:" +
BaseRegex.GetStringJson(ref html, "msg").ParseToString().Replace("'", "\\'").Replace("\"", "\\\"");
}
var id = BaseRegex.GetLongJson(ref html, "id");
if (id == 0)
goto end;
foreach (var addProdShop in shopLst)
{
url = BaseClass.BuildObjString("product_third/add_user_select_product");
data = UserLogin.GetSignaturex() +
"&out_product_id=" + id +
"&shop_id=" + addProdShop.ShopId +
"&shop_account=" + addProdShop.ShopAccount +
"&main_user_name=" + addProdShop.UserName +
"&sub_user_name=" + addProdShop.SubUserName +
"&add_product_remaining=" + addProdShop.AddProductRemaining +
"&status=待上传";
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"))
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
{
errorMsg += product?.goods_id + " " + BaseRegex.GetStringJson(ref html, "msg") + "; ";
}
else
{
addProdShop.AddProductRemaining = addProdShop.AddProductRemaining - 1;
}
}
end:;
if (!string.IsNullOrEmpty(errorMsg))
{
OnInfoReceived(errorMsg);
}
else
{
OnInfoReceived("库存上传保存成功!" + success_err_msg);
}
}
catch (Exception ex)
{
OnInfoReceived("发生错误:" + ex.Message);
}
});
return "success";
}
TemuCat GetCat(TemuDetailProductInfo product)
{
if (product == null)
return new TemuCat();
var cat = product.categories.cat10;
if (string.IsNullOrWhiteSpace(cat.catName))
cat = product.categories.cat9;
if (string.IsNullOrWhiteSpace(cat.catName))
cat = product.categories.cat8;
if (string.IsNullOrWhiteSpace(cat.catName))
cat = product.categories.cat7;
if (string.IsNullOrWhiteSpace(cat.catName))
cat = product.categories.cat6;
if (string.IsNullOrWhiteSpace(cat.catName))
cat = product.categories.cat5;
if (string.IsNullOrWhiteSpace(cat.catName))
cat = product.categories.cat4;
if (string.IsNullOrWhiteSpace(cat.catName))
cat = product.categories.cat3;
if (string.IsNullOrWhiteSpace(cat.catName))
cat = product.categories.cat2;
if (string.IsNullOrWhiteSpace(cat.catName))
cat = product.categories.cat1;
return cat;
}
private string GetPddProdCommitId(ShopLoginInfo shop, string prodId)
{
var anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
string url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/create_by_sn";
string body = @"{""goods_id"":" + prodId + "}";
string refere = "https://mms.pinduoduo.com/goods/goods_list?msfrom=mms_sidenav";
var result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
for (int i = 0; i < 5 && result.Contains("网络繁忙,请不要频繁操作"); i++)
{
shop.AntiContents.Remove(anti);
anti = shop.AntiContents.FirstOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
{
Thread.Sleep(Randomx.GetId(300, 500));
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
}
}
return result;
}
public static string GetPddProdDetail(ShopLoginInfo shop, string prodId, string commitId)
{
var anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
//string url = "https://mms.pinduoduo.com/glide/v2/mms/query/commit/on_shop/detail"; //on_shop获取到的结构不对
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/commit/detail";
//string body = @"{""goods_id"":" + prodId + "}";
string body = @"{""goods_commit_id"":""" + commitId + @""",""goods_id"":""" + prodId + @"""}";
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=" + commitId + "&goods_id=" + prodId + "&type=edit";
var result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
for (int i = 0; i < 5 && result.Contains("网络繁忙,请不要频繁操作"); i++)
{
shop.AntiContents.Remove(anti);
anti = shop.AntiContents.FirstOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
{
Thread.Sleep(Randomx.GetId(300, 500));
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
}
}
return result;
}
public static string GetPddProdDetailOnShop(ShopLoginInfo shop, string prodId, string commitId)
{
var anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/commit/on_shop/detail"; //on_shop
string body = @"{""goods_commit_id"":""" + commitId + @""",""goods_id"":""" + prodId + @"""}";
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=" + commitId + "&goods_id=" + prodId + "&type=edit";
var result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
for (int i = 0; i < 5 && result.Contains("网络繁忙,请不要频繁操作"); i++)
{
shop.AntiContents.Remove(anti);
anti = shop.AntiContents.FirstOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
{
Thread.Sleep(Randomx.GetId(300, 500));
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
}
}
return result;
}
private string GetPddProdOnShopDetail(ShopLoginInfo shop, string prodId, string commitId)
{
var anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/commit/on_shop/detail"; //获取详情图
//string url = "https://mms.pinduoduo.com/glide/v2/mms/query/commit/detail";
//string body = @"{""goods_id"":" + prodId + "}";
string body = @"{""goods_commit_id"":""" + commitId + @""",""goods_id"":""" + prodId + @"""}";
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=" + commitId + "&goods_id=" + prodId + "&type=edit";
var result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
for (int i = 0; i < 5 && result.Contains("网络繁忙,请不要频繁操作"); i++)
{
shop.AntiContents.Remove(anti);
anti = shop.AntiContents.FirstOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
{
Thread.Sleep(Randomx.GetId(300, 500));
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
}
}
return result;
}
/// <summary>
/// 保存商品详情图装修列表
/// gorse/mms/goods/decoration/commit/save
/// </summary>
/// <param name="shop"></param>
/// <param name="decoration"></param>
/// <param name="goodsId"></param>
/// <param name="commitId"></param>
/// <returns></returns>
private string save_decoration(ShopLoginInfo shop, PDDProdDecorationCommitParam decoration, string goodsId, string commitId)
{
var anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
string url = "https://mms.pinduoduo.com/gorse/mms/goods/decoration/commit/save";
string body = @"{""goods_id"":" + goodsId + "}";
body = JsonHelper.SerializeObject(decoration);
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=" + commitId + "&goods_id=" + goodsId + "&type=edit";
var result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
for (int i = 0; i < 5 && result.Contains("网络繁忙,请不要频繁操作"); i++)
{
shop.AntiContents.Remove(anti);
anti = shop.AntiContents.FirstOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
{
Thread.Sleep(Randomx.GetId(300, 500));
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
}
}
return result;
}
private string GetPddProdSizeSpec(ShopLoginInfo shop, string prodId, string commitId, string sizeSpecId)
{
var anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
string url = "https://mms.pinduoduo.com/cabernet/mms/sizespec/query/draft";
//string body = @"{""goods_id"":" + prodId + "}";
string body = @"{""id"":" + sizeSpecId + @"}";
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=" + commitId + "&goods_id=" + prodId + "&type=edit";
var result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
for (int i = 0; i < 5 && result.Contains("网络繁忙,请不要频繁操作"); i++)
{
shop.AntiContents.Remove(anti);
anti = shop.AntiContents.FirstOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
{
Thread.Sleep(Randomx.GetId(300, 500));
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
}
}
return result;
}
private string GetPddProdProperty(ShopLoginInfo shop, string prodId, string commitId)
{
var anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
string url = "https://mms.pinduoduo.com/draco-ms/mms/query-goods-property";
string body = @"{""goods_id"":" + prodId + "}";
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=" + commitId + "&goods_id=" + prodId + "&type=edit";
var result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
for (int i = 0; i < 5 && result.Contains("网络繁忙,请不要频繁操作"); i++)
{
shop.AntiContents.Remove(anti);
anti = shop.AntiContents.FirstOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
{
Thread.Sleep(Randomx.GetId(300, 500));
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
}
}
return result;
}
private string get_chance_cat_prop_template(ShopLoginInfo shop, string catId, string goodsId, string commitId, string chanceTab = "")
{
var anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
string url = "https://mms.pinduoduo.com/draco-ms/mms/template/mall?catId=" + catId +
"&goodsCommitId=" + commitId + "&goodsId=" + goodsId;
string body = @"";
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?type=add&from=chance&id=" + commitId +
"&goods_id=" + goodsId + "&chance_tab=hot_theme&sourcePage=goodsListTopButton_CHANCE"; // chance_tab=search
if (!string.IsNullOrEmpty(chanceTab))
refere = refere.Replace("chance_tab=hot_theme", "chance_tab=" + chanceTab);
var result = HttpResponseBLL.PDDGetResponse(shop, url, body, refere, anti);
for (int i = 0; i < 5 && (result.Contains("操作太过频繁") || result.Contains("网络繁忙,请不要频繁操作")); i++)
{
shop.AntiContents.Remove(anti);
anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
{
Thread.Sleep(Randomx.GetId(300, 500));
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
result = HttpResponseBLL.PDDGetResponse(shop, url, body, refere, anti);
}
}
return result;
}
private string GetPddProdDecoration(ShopLoginInfo shop, string prodId, string commitId)
{
var anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
string url = "https://mms.pinduoduo.com/gorse/mms/goods/decoration/commit/query/V2";
url = "https://mms.pinduoduo.com/gorse/mms/goods/decoration/commit/query/V2";
string body = @"{""goods_commit_id"":" + commitId + @",""goods_id"":" + prodId + @"}";
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=" + commitId + "&goods_id=" + prodId + "&type=edit";
var result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
for (int i = 0; i < 5 && result.Contains("网络繁忙,请不要频繁操作"); i++)
{
shop.AntiContents.Remove(anti);
anti = shop.AntiContents.FirstOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
{
Thread.Sleep(Randomx.GetId(300, 500));
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
}
}
return result;
}
/// <summary>
/// 获取物料详情 type = 1 或者 3 1是白底图,3是长图
/// </summary>
/// <param name="shop"></param>
/// <param name="catId"></param>
/// <param name="prodId"></param>
/// <param name="commitId"></param>
/// <param name="type"></param>
/// <returns></returns>
private string GetPddGoodsMaterial(ShopLoginInfo shop, string prodId, string commitId, int type)
{
var anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
string url = "https://mms.pinduoduo.com/giraffe/mms/material/goodsMaterialInfo";
string body = @"{""goods_id"":" + prodId + @",""type"":" + type + "}";
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=" + commitId + "&goods_id=" + prodId + "&type=edit";
var result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
for (int i = 0; i < 5 && (result.Contains("操作太过频繁") || result.Contains("网络繁忙,请不要频繁操作")); i++)
{
shop.AntiContents.Remove(anti);
anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
{
Thread.Sleep(Randomx.GetId(300, 500));
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
}
}
return result;
}
private string GetPddCatPropTemplate(ShopLoginInfo shop, string catId, string prodId, string commitId)
{
var anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
string url = "https://mms.pinduoduo.com/draco-ms/mms/template/mall?catId=" + catId +
"&goodsCommitId=" + commitId + "&goodsId=" + prodId;
string body = @"";
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=" + commitId + "&goods_id=" + prodId + "&type=edit";
var result = HttpResponseBLL.PDDGetResponse(shop, url, body, refere, anti);
for (int i = 0; i < 5 && (result.Contains("操作太过频繁") || result.Contains("网络繁忙,请不要频繁操作")); i++)
{
shop.AntiContents.Remove(anti);
anti = shop.AntiContents.LastOrDefault().ParseToString();
if (shop.AntiContents.Count > 0)
{
Thread.Sleep(Randomx.GetId(300, 500));
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
result = HttpResponseBLL.PDDGetResponse(shop, url, body, refere, anti);
}
}
return result;
}
private string SizeSpecQuery(ShopLoginInfo shop, string prodId, string sizeSpecId)
{
//string url = "https://seller.kuajingmaihuo.com/bg-anniston-mms/sizespec/query";
//string body = @"{""businessId"":" + sizeSpecId + @",""reusable"":false}";
//string refere = "https://seller.kuajingmaihuo.com/goods/product-create/product-edit?from=productList&productId=" + prodId;
//return HttpResponseBLL.PostResponse(shop, url, body, refere);
return "";
}
}
}