Files
KJD_WebService/Work/Api/BuildNewTitle.cs
T
2025-06-29 19:38:31 +08:00

709 lines
34 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AllBase;
using System;
using System.Threading;
using Work.CollectClass;
using Work.ManageClass;
namespace Work.Api
{
public class BuildNewTitle
{
public ShopChatBase Shop;
public long Pid;
public string Title,Name;
public string[] NoWords = "✅,💯,★".Split(',');
public bool SetNewTitle = false;
public static bool BeforRand = false,KeepAll = false;
public static long endAdvanceTime=0;
public BuildNewTitle(ShopChatBase shop, long pid, string title, string name)
{
Shop = shop;
Pid = pid;
Title = title;
Name = name;
}
public BuildNewTitle(ShopChatBase shop, long pid, string title, string name,bool setNewTitle)
{
Shop = shop;
Pid = pid;
Title = title;
Name = name;
SetNewTitle = setNewTitle;
}
public void Set()
{
GetProductDetail ge = new GetProductDetail(Shop, Name);
var r = ge.Get(Pid);
if (r == null)
{
LogSave.Add(Name,"获取失败,店铺:"+Shop.ShopName +" ID:"+Pid);
return;
}
string imageString = "", apiContentString = "";
for (int i = 0; i < r.carousel_gallery_list.Count; i++)
{
imageString += ",\"" + r.carousel_gallery_list[i] + "\"";
}
for (int i = 0; i < r.detail_gallery_list.Count; i++)
{
apiContentString += ",\"" + r.detail_gallery_list[i] + "\"";
}
string skuApiStringNew = "";
int price = int.MaxValue;
for (int i = 0; i < r.sku_list.Count; i++)
{
if (price > r.sku_list[i].multi_price)
price = r.sku_list[i].multi_price;
string spec = "";
for (int j = 0; j < r.sku_list[i].spec.Count; j++)
spec += "," + r.sku_list[i].spec[j].spec_id;
if (!string.IsNullOrEmpty(spec))
spec = spec.Substring(1);
skuApiStringNew += ",{\"is_onsale\":" + r.sku_list[i].is_onsale + ",\"limit_quantity\":" + r.sku_list[i].limit_quantity +
",\"price\":\"" + r.sku_list[i].price + "\",\"weight\":1000,\"multi_price\":\"" + r.sku_list[i].multi_price
+ "\",\"thumb_url\":\"" + r.sku_list[i].thumb_url + "\",\"out_sku_sn\":\"" + r.sku_list[i].out_sku_sn +
"\",\"quantity\":" + r.sku_list[i].quantity + ",\"spec_id_list\":\"[" + spec + "]\"}";
}
if (SetNewTitle && !KeepAll)
{
string upTitle = BaseRegex.GetMatchRegexString(ref r.goods_desc, @"【【【([\w\W]{10,60})】】");
if (string.IsNullOrEmpty(upTitle))
{
upTitle = r.goods_name;
r.goods_desc += "【【【"+r.goods_name+"】】";
}
BigDataBuild bd = new BigDataBuild(Name);
if (BeforRand)
{
Title = bd.GetRandTitle(upTitle);
}
else
{
string mainKey = bd.GetMainKeywords(upTitle);
if (string.IsNullOrEmpty(mainKey))
{
LogSave.Add(Name, "没有找到主关键词");
return;
}
Title = bd.GetAllTitle(mainKey);
if (string.IsNullOrEmpty(Title)&& mainKey.Split(' ').Length>2)
{
string[] l = mainKey.Split(' ');
string keyword = "";
for (int i = 0; i < 3; i++)
{
keyword += l[i];
}
Title = bd.GetAllTitle(keyword);
}
if (string.IsNullOrEmpty(Title))
{
Title = bd.GetRandTitle(upTitle);
}
}
Title = BaseClass.SubCharLength(Title, 60);
}
if (KeepAll)
Title = r.goods_name;
r.goods_name = BaseClass.SubCharLength(r.goods_name, 60);
foreach (string noWord in NoWords)
{
if (r.goods_name.Contains(noWord))
r.goods_name = r.goods_name.Replace(noWord, "");
if (r.goods_desc.Contains(noWord))
r.goods_desc = r.goods_desc.Replace(noWord, "");
}
r.goods_desc = BaseRegex.Clear(r.goods_desc, "");
string title;
if (!string.IsNullOrEmpty(Title))
title = Title;
else
title = r.goods_name;
r.cat_id = PinduoduoCatList.GetNewCat3(r.cat_id);
var api = new PinduoduoApiGetProduct(Shop);
if (r.tiny_name.Length > 10)
r.tiny_name = r.tiny_name.Substring(0, 10);
api.Data.Add("goods_id", Pid.ToString());
api.Data.Add("goods_name", title);
api.Data.Add("goods_type", r.goods_type.ToString());
api.Data.Add("goods_desc", r.goods_desc);
api.Data.Add("cat_id", r.cat_id.ToString());
api.Data.Add("tiny_name", r.tiny_name);
api.Data.Add("country_id", r.country_id.ToString());
api.Data.Add("market_price", r.market_price.ToString());
api.Data.Add("is_pre_sale", "false");
api.Data.Add("shipment_limit_second", r.shipment_limit_second.ToString());
api.Data.Add("cost_template_id", Shop.ExpressId.ToString());
api.Data.Add("customer_num", r.customer_num.ToString());//团购人数
if (!UploadPinduoduoMain.limitCount)
{
api.Data.Add("buy_limit", r.buy_limit.ToString());
api.Data.Add("order_limit", r.order_limit.ToString());
}
api.Data.Add("is_refundable", r.is_refundable==1? "true": "false");
api.Data.Add("second_hand", r.second_hand == 1 ? "true" : "false");
api.Data.Add("is_folt", r.is_folt == 1 ? "true" : "false");
if (BaseRegex.GetIntJson(ref ge.Html, "fabric_content_id")>0)
{
api.Data.Add("fabric", BaseRegex.GetIntJson(ref ge.Html, "fabric_id").ToString());
api.Data.Add("fabric_content", BaseRegex.GetIntJson(ref ge.Html, "fabric_content_id").ToString());
}
api.Data.Add("sku_list","[" + skuApiStringNew.Substring(1) + "]");
api.Data.Add("out_goods_id", r.outer_goods_id);
api.Data.Add("hd_thumb_url", r.hd_thumb_url);
api.Data.Add("thumb_url", r.thumb_url);
api.Data.Add("image_url", r.image_url);
api.Data.Add("carousel_gallery", "[" + imageString.Substring(1) + "]");
api.Data.Add("detail_gallery", "[" + apiContentString.Substring(1) + "]");
if(r.shelf_life>0)
{
api.Data.Add("shelf_life", r.shelf_life.ToString());
api.Data.Add("start_production_date", r.start_production_date.ToString());
api.Data.Add("end_production_date", r.end_production_date.ToString());
}
if (BaseRegex.GetIntJson(ref ge.Html, "paper_width") > 0)
{
api.Data.Add("paper_net_weight", BaseRegex.GetIntJson(ref ge.Html, "paper_net_weight").ToString());
api.Data.Add("paper_length", BaseRegex.GetIntJson(ref ge.Html, "paper_length").ToString());
api.Data.Add("paper_width", BaseRegex.GetIntJson(ref ge.Html, "paper_width").ToString());
api.Data.Add("paper_plies_num", BaseRegex.GetIntJson(ref ge.Html, "paper_plies_num").ToString());
}
if (r.goods_property_list.Count > 0)
{
string code = "";
for (int i = 0; i < r.goods_property_list.Count; i++)
{
//var p =
// UploadPinduoduoProperties.Properties.Find(
// pp => pp.template_pid == r.goods_property_list[i].template_pid);
//if(p==null)
// continue;
code +=
",{\"template_pid\":" + r.goods_property_list[i].template_pid + ",\"template_module_id\":" + r.goods_property_list[i].vid
+ ",\"pid\":" + r.goods_property_list[i].ref_pid + ",\"vid\":" + r.goods_property_list[i].vid
+ ",\"value\":\"" + r.goods_property_list[i].vvalue + "\",\"value_unit\":\"" + r.goods_property_list[i].punit + "\"}";
}
api.Data.Add("goods_properties", "[" + code.Substring(1) + "]");
}
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
return;
string html = api.Updata();
string error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("频繁"))
{
Thread.Sleep(6000);
html = api.Updata();
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
}
TaobaoProductBase t = new TaobaoProductBase();
t.GoodsId = Pid;
t.Titlte = title;
t.Price = price/100m;
if (string.IsNullOrEmpty(error_msg))
{
t.Message = "修改成功";
SetRelation(Pid, ref r, ref Shop);
}
else
{
if (KeepAll)
{
html = new PinduoduoApiGetProduct(Shop).SetOnline(r.goods_id, true);
Thread.Sleep(5 * 1000);
}
t.Message = error_msg;
}
UploadPinduoduoMain.ProductReplaceTemp.Add(t);
}
public void SetAdvanceSale()
{
GetProductDetail ge = new GetProductDetail(Shop, Name);
var r = ge.Get(Pid);
if (r == null)
{
LogSave.Add(Name, "获取失败,店铺:" + Shop.ShopName + " ID:" + Pid);
return;
}
long pre_sale_time = BaseRegex.GetLongJson(ref ge.Html, "pre_sale_time");
//if (pre_sale_time > BaseClass.GetTime(DateTime.Now))
//{
// LogSave.Add(Name, "已经设置跳过:" + Shop.ShopName + " ID:" + Pid);
// TaobaoProductBase tt = new TaobaoProductBase();
// tt.GoodsId = Pid;
// tt.Titlte = Title;
// tt.Message = "已设置跳过";
// UploadPinduoduoMain.ProductReplaceTemp.Add(tt);
// return;
//}
string imageString = "", apiContentString = "";
for (int i = 0; i < r.carousel_gallery_list.Count; i++)
{
imageString += ",\"" + r.carousel_gallery_list[i] + "\"";
}
for (int i = 0; i < r.detail_gallery_list.Count; i++)
{
apiContentString += ",\"" + r.detail_gallery_list[i] + "\"";
}
int maxPriceNew = 0, maxPriceOnline = 0;
//生成新的价格
for (int i = 0; i < r.sku_list.Count; i++)
{
if (maxPriceNew < r.sku_list[i].multi_price)
maxPriceNew = r.sku_list[i].multi_price;
if (maxPriceOnline < r.sku_list[i].price)
maxPriceOnline = r.sku_list[i].price;
}
bool userShield = false;
decimal dd = PinduoduoCatList.GetPriceSpace(r.cat_id) * 10;
for (int i = 0; i < r.sku_list.Count; i++) // 二级护盾
{
if (r.sku_list[i].multi_price < maxPriceNew / dd * 10)
{
r.sku_list[i].multi_price = (int)(maxPriceNew / dd * 10);
}
if (r.sku_list[i].price < maxPriceOnline / dd * 10)
{
r.sku_list[i].price = (int)(maxPriceOnline / dd * 10 + 100);
}
}
string skuApiStringNew = "";
int price = int.MaxValue;
for (int i = 0; i < r.sku_list.Count; i++)
{
if (price > r.sku_list[i].multi_price)
price = r.sku_list[i].multi_price;
string spec = "";
for (int j = 0; j < r.sku_list[i].spec.Count; j++)
spec += "," + r.sku_list[i].spec[j].spec_id;
if (!string.IsNullOrEmpty(spec))
spec = spec.Substring(1);
skuApiStringNew += ",{\"is_onsale\":" + r.sku_list[i].is_onsale + ",\"limit_quantity\":" + r.sku_list[i].limit_quantity +
",\"price\":\"" + r.sku_list[i].price + "\",\"weight\":1000,\"multi_price\":\"" + r.sku_list[i].multi_price
+ "\",\"thumb_url\":\"" + r.sku_list[i].thumb_url + "\",\"out_sku_sn\":\"" + r.sku_list[i].out_sku_sn +
"\",\"quantity\":" + r.sku_list[i].quantity + ",\"spec_id_list\":\"[" + spec + "]\"}";
}
r.goods_name = BaseClass.SubCharLength(r.goods_name, 60);
foreach (string noWord in NoWords)
{
if (r.goods_name.Contains(noWord))
r.goods_name = r.goods_name.Replace(noWord, "");
if (r.goods_desc.Contains(noWord))
r.goods_desc = r.goods_desc.Replace(noWord, "");
}
r.goods_desc = BaseRegex.Clear(r.goods_desc, "");
string title;
if (!string.IsNullOrEmpty(Title))
title = Title;
else
title = r.goods_name.Replace("\",\"", "");
r.cat_id = PinduoduoCatList.GetNewCat3(r.cat_id);
var api = new PinduoduoApiGetProduct(Shop);
if (BaseRegex.GetIntJson(ref ge.Html, "fabric_content_id") > 0)
{
api.Data.Add("fabric", BaseRegex.GetIntJson(ref ge.Html, "fabric_id").ToString());
api.Data.Add("fabric_content", BaseRegex.GetIntJson(ref ge.Html, "fabric_content_id").ToString());
}
if (r.shelf_life > 0)
{
api.Data.Add("shelf_life", r.shelf_life.ToString());
api.Data.Add("start_production_date", r.start_production_date.ToString());
api.Data.Add("end_production_date", r.end_production_date.ToString());
}
if (BaseRegex.GetIntJson(ref ge.Html, "paper_width") > 0)
{
api.Data.Add("paper_net_weight", BaseRegex.GetIntJson(ref ge.Html, "paper_net_weight").ToString());
api.Data.Add("paper_length", BaseRegex.GetIntJson(ref ge.Html, "paper_length").ToString());
api.Data.Add("paper_width", BaseRegex.GetIntJson(ref ge.Html, "paper_width").ToString());
api.Data.Add("paper_plies_num", BaseRegex.GetIntJson(ref ge.Html, "paper_plies_num").ToString());
}
if (r.goods_property_list.Count > 0)
{
string code = "";
for (int i = 0; i < r.goods_property_list.Count; i++)
{
code +=
",{\"template_pid\":" + r.goods_property_list[i].template_pid + ",\"template_module_id\":" + r.goods_property_list[i].vid
+ ",\"pid\":" + r.goods_property_list[i].ref_pid + ",\"vid\":" + r.goods_property_list[i].vid
+ ",\"value\":\"" + r.goods_property_list[i].vvalue + "\",\"value_unit\":\"" + r.goods_property_list[i].punit + "\"}";
}
api.Data.Add("goods_properties", "[" + code.Substring(1) + "]");
}
ProductCollectBase pb = new ProductCollectBase();
int Cat1 = 0;
if(PinduoduoCatList.CatIds.ContainsKey(r.cat_id))
Cat1 = PinduoduoCatList.CatIds[r.cat_id].cat1;
string mustCode = "";
string properties = UploadPinduoduoProperties.GetNew(r.cat_id, Cat1, ref pb, ref Shop, out mustCode);
if (!string.IsNullOrEmpty(properties) && !api.Data.ContainsKey("goods_properties"))
{
api.Data.Add("goods_properties", "[" + properties.Substring(1) + "]");
}
r.tiny_name = r.tiny_name.Replace("【", "")
.Replace("】", "")
.Replace("!", "")
.Replace(" ", "")
.Replace("!", "");
if (r.tiny_name.Length > 10)
r.tiny_name = r.tiny_name.Substring(0, 10);
api.Data.Add("goods_id", Pid.ToString());
api.Data.Add("goods_name", title.Replace("\",\"",""));
api.Data.Add("goods_type", r.goods_type.ToString());
api.Data.Add("goods_desc", r.goods_desc);
api.Data.Add("cat_id", r.cat_id.ToString());
api.Data.Add("tiny_name", r.tiny_name);
api.Data.Add("country_id", r.country_id.ToString());
api.Data.Add("market_price", r.market_price.ToString());
api.Data.Add("is_pre_sale", SetNewTitle.ToString());
api.Data.Add("pre_sale_time", endAdvanceTime.ToString());
api.Data.Add("shipment_limit_second", r.shipment_limit_second.ToString());
api.Data.Add("cost_template_id", Shop.ExpressId.ToString());
api.Data.Add("customer_num", r.customer_num.ToString());//团购人数
if (!UploadPinduoduoMain.limitCount)
{
api.Data.Add("buy_limit", r.buy_limit.ToString());
api.Data.Add("order_limit", r.order_limit.ToString());
}
api.Data.Add("is_refundable", r.is_refundable == 1 ? "true" : "false");
api.Data.Add("second_hand", r.second_hand == 1 ? "true" : "false");
api.Data.Add("is_folt", r.is_folt == 1 ? "true" : "false");
api.Data.Add("sku_list", "[" + skuApiStringNew.Substring(1) + "]");
api.Data.Add("out_goods_id", r.outer_goods_id);
api.Data.Add("hd_thumb_url", r.hd_thumb_url);
api.Data.Add("thumb_url", r.thumb_url);
api.Data.Add("image_url", r.image_url);
api.Data.Add("carousel_gallery", "[" + imageString.Substring(1) + "]");
api.Data.Add("detail_gallery", "[" + apiContentString.Substring(1) + "]");
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
return;
string html = api.Updata();
Thread.Sleep(5*1000);
string error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("频繁"))
{
Thread.Sleep(10000);
html = api.Updata();
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
}
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("频繁"))
{
Thread.Sleep(30000);
html = api.Updata();
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
}
TaobaoProductBase t = new TaobaoProductBase();
t.GoodsId = Pid;
t.Titlte = title;
t.Price = price / 100m;
if (string.IsNullOrEmpty(error_msg))
{
t.Message = "设置成功";
SetRelation(Pid, ref r, ref Shop);
}
else
{
if (UploadPinduoduoMain.SaleSetFalseDown)
{
api = new PinduoduoApiGetProduct(Shop);
api.SetOnline(Pid, false);
error_msg = "设置预售失败自动下架";
}
if (KeepAll)
{
html = new PinduoduoApiGetProduct(Shop).SetOnline(r.goods_id, true);
Thread.Sleep(5 * 1000);
}
t.Message = error_msg;
}
LogSave.Add(Name,"ID:"+ Pid+":"+ t.Message);
UploadPinduoduoMain.ProductReplaceTemp.Add(t);
}
public bool SetAdvanceSaleNew()
{
GetProductDetail ge = new GetProductDetail(Shop, Name);
var r = ge.Get(Pid);
if (r == null)
{
Thread.Sleep(2000);
r = ge.Get(Pid);
}
if (r == null)
{
LogSave.Add(Name, "获取失败,店铺:" + Shop.ShopName + " ID:" + Pid);
return false;
}
long pre_sale_time = BaseRegex.GetLongJson(ref ge.Html, "pre_sale_time");
string imageString = "", apiContentString = "";
for (int i = 0; i < r.carousel_gallery_list.Count; i++)
{
imageString += ",\"" + r.carousel_gallery_list[i] + "\"";
}
for (int i = 0; i < r.detail_gallery_list.Count; i++)
{
apiContentString += ",\"" + r.detail_gallery_list[i] + "\"";
}
int maxPriceNew = 0, maxPriceOnline = 0;
//生成新的价格
for (int i = 0; i < r.sku_list.Count; i++)
{
if (maxPriceNew < r.sku_list[i].multi_price)
maxPriceNew = r.sku_list[i].multi_price;
if (maxPriceOnline < r.sku_list[i].price)
maxPriceOnline = r.sku_list[i].price;
}
string skuApiStringNew = "";
int price = int.MaxValue;
for (int i = 0; i < r.sku_list.Count; i++)
{
if (price > r.sku_list[i].multi_price)
price = r.sku_list[i].multi_price;
string spec = "";
for (int j = 0; j < r.sku_list[i].spec.Count; j++)
spec += "," + r.sku_list[i].spec[j].spec_id;
if (!string.IsNullOrEmpty(spec))
spec = spec.Substring(1);
skuApiStringNew += ",{\"is_onsale\":" + r.sku_list[i].is_onsale + ",\"limit_quantity\":" + r.sku_list[i].limit_quantity +
",\"price\":\"" + r.sku_list[i].price + "\",\"weight\":1000,\"multi_price\":\"" + r.sku_list[i].multi_price
+ "\",\"thumb_url\":\"" + r.sku_list[i].thumb_url + "\",\"out_sku_sn\":\"" + r.sku_list[i].out_sku_sn +
"\",\"quantity\":" + r.sku_list[i].quantity + ",\"spec_id_list\":\"[" + spec + "]\"}";
}
r.goods_name = BaseClass.SubCharLength(r.goods_name, 60);
foreach (string noWord in NoWords)
{
if (r.goods_name.Contains(noWord))
r.goods_name = r.goods_name.Replace(noWord, "");
if (r.goods_desc.Contains(noWord))
r.goods_desc = r.goods_desc.Replace(noWord, "");
}
r.goods_desc = BaseRegex.Clear(r.goods_desc, "");
string title;
if (!string.IsNullOrEmpty(Title))
title = Title;
else
title = r.goods_name.Replace("\",\"", "");
r.cat_id = PinduoduoCatList.GetNewCat3(r.cat_id);
var api = new PinduoduoApiGetProduct(Shop);
if (BaseRegex.GetIntJson(ref ge.Html, "fabric_content_id") > 0)
{
api.Data.Add("fabric", BaseRegex.GetIntJson(ref ge.Html, "fabric_id").ToString());
api.Data.Add("fabric_content", BaseRegex.GetIntJson(ref ge.Html, "fabric_content_id").ToString());
}
if (r.shelf_life > 0)
{
api.Data.Add("shelf_life", r.shelf_life.ToString());
api.Data.Add("start_production_date", r.start_production_date.ToString());
api.Data.Add("end_production_date", r.end_production_date.ToString());
}
if (BaseRegex.GetIntJson(ref ge.Html, "paper_width") > 0)
{
api.Data.Add("paper_net_weight", BaseRegex.GetIntJson(ref ge.Html, "paper_net_weight").ToString());
api.Data.Add("paper_length", BaseRegex.GetIntJson(ref ge.Html, "paper_length").ToString());
api.Data.Add("paper_width", BaseRegex.GetIntJson(ref ge.Html, "paper_width").ToString());
api.Data.Add("paper_plies_num", BaseRegex.GetIntJson(ref ge.Html, "paper_plies_num").ToString());
}
if (r.goods_property_list.Count > 0)
{
string code = "";
for (int i = 0; i < r.goods_property_list.Count; i++)
{
code +=
",{\"template_pid\":" + r.goods_property_list[i].template_pid + ",\"template_module_id\":" + r.goods_property_list[i].vid
+ ",\"pid\":" + r.goods_property_list[i].ref_pid + ",\"vid\":" + r.goods_property_list[i].vid
+ ",\"value\":\"" + r.goods_property_list[i].vvalue + "\",\"value_unit\":\"" + r.goods_property_list[i].punit + "\"}";
}
api.Data.Add("goods_properties", "[" + code.Substring(1) + "]");
}
ProductCollectBase pb = new ProductCollectBase();
int Cat1 = 0;
if (PinduoduoCatList.CatIds.ContainsKey(r.cat_id))
Cat1 = PinduoduoCatList.CatIds[r.cat_id].cat1;
string mustCode = "";
string properties = UploadPinduoduoProperties.GetNew(r.cat_id, Cat1, ref pb, ref Shop, out mustCode);
if (!string.IsNullOrEmpty(properties) && !api.Data.ContainsKey("goods_properties"))
{
api.Data.Add("goods_properties", "[" + properties.Substring(1) + "]");
}
r.tiny_name = r.tiny_name.Replace("【", "")
.Replace("】", "")
.Replace("!", "")
.Replace(" ", "")
.Replace("!", "");
if (r.tiny_name.Length > 10)
r.tiny_name = r.tiny_name.Substring(0, 10);
api.Data.Add("goods_id", Pid.ToString());
api.Data.Add("goods_name", title.Replace("\",\"", ""));
api.Data.Add("goods_type", r.goods_type.ToString());
api.Data.Add("goods_desc", r.goods_desc);
api.Data.Add("cat_id", r.cat_id.ToString());
api.Data.Add("tiny_name", r.tiny_name);
api.Data.Add("country_id", r.country_id.ToString());
api.Data.Add("market_price", r.market_price.ToString());
api.Data.Add("is_pre_sale", SetNewTitle.ToString());
api.Data.Add("pre_sale_time", endAdvanceTime.ToString());
api.Data.Add("shipment_limit_second", r.shipment_limit_second.ToString());
api.Data.Add("cost_template_id", Shop.ExpressId.ToString());
api.Data.Add("customer_num", r.customer_num.ToString());//团购人数
if (!UploadPinduoduoMain.limitCount)
{
api.Data.Add("buy_limit", r.buy_limit.ToString());
api.Data.Add("order_limit", r.order_limit.ToString());
}
api.Data.Add("is_refundable", r.is_refundable == 1 ? "true" : "false");
api.Data.Add("second_hand", r.second_hand == 1 ? "true" : "false");
api.Data.Add("is_folt", r.is_folt == 1 ? "true" : "false");
api.Data.Add("sku_list", "[" + skuApiStringNew.Substring(1) + "]");
api.Data.Add("out_goods_id", r.outer_goods_id);
api.Data.Add("hd_thumb_url", r.hd_thumb_url);
api.Data.Add("thumb_url", r.thumb_url);
api.Data.Add("image_url", r.image_url);
api.Data.Add("carousel_gallery", "[" + imageString.Substring(1) + "]");
api.Data.Add("detail_gallery", "[" + apiContentString.Substring(1) + "]");
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
return false;
api.FromWeiDian = true;
string html = api.UpdataNew();
if (!string.IsNullOrEmpty(html) && (html.Contains("当前运费模板已绑定商品数超过限制,请更换运费模板") || html.Contains("请选择配送地区")))
{
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetRandx(Shop.Cookies, Shop.MallId, Shop);
if (Shop.ExpressId == 0)
{
Thread.Sleep(10000);
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetRandx(Shop.Cookies, Shop.MallId, Shop);
}
if (Shop.ExpressId == 0)
{
LogSave.Add(Name, "未找到新运费模板");
Shop.Message = "运费模板超过商品数限制,请设置新的运费模板";
UploadPinduoduoMain.ShopTemp.Add(Shop);
return false;
}
api.Data.Remove("cost_template_id");
api.Data["cost_template_id"] = Shop.ExpressId.ToString();
html = api.AddNew();
}
Thread.Sleep(5 * 1000);
string error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("频繁"))
{
Thread.Sleep(10000);
html = api.UpdataNew();
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
}
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("频繁"))
{
Thread.Sleep(30000);
html = api.UpdataNew();
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
}
TaobaoProductBase t = new TaobaoProductBase();
t.GoodsId = Pid;
t.Titlte = title;
t.Price = price / 100m;
if (string.IsNullOrEmpty(error_msg))
{
t.Message = "设置成功";
//SetRelation(Pid, ref r, ref Shop);
var ad = AdvanceSale.dic[Shop.ShopName];
ad.SetSuccess = ++ad.SetSuccess;
if (SetNewTitle)
{
ad.PreCount = ++ad.PreCount;
}
else
{
ad.PreCount = --ad.PreCount;
if (ad.PreCount < 0)
{
ad.PreCount = 0;
}
}
AdvanceSale.AdvanceList.Add(ad);
}
else
{
if (AdvanceSale.SaleSetFalseDown && !error_msg.Contains("签名验证失败"))
{
api = new PinduoduoApiGetProduct(Shop);
string htmlx = api.SetOnline(Pid, false);
error_msg = "设置预售失败自动下架:" + error_msg;
if (htmlx.Contains("false"))
htmlx = api.SetOnline(Pid, false);
var ad = AdvanceSale.dic[Shop.ShopName];
ad.DownSuccess = ++ad.DownSuccess;
ad.DownCount = ++ad.DownCount;
AdvanceSale.AdvanceList.Add(ad);
}
else
{
var ad = AdvanceSale.dic[Shop.ShopName];
ad.status = error_msg;
AdvanceSale.AdvanceList.Add(ad);
}
if (KeepAll)
{
html = new PinduoduoApiGetProduct(Shop).SetOnline(r.goods_id, true);
Thread.Sleep(5 * 1000);
}
t.Message = error_msg;
}
LogSave.Add(Name, "ID:" + Pid + ":" + t.Message);
if (error_msg.Contains("签名验证失败"))
{
var ad = AdvanceSale.dic[Shop.ShopName];
ad.status = "签名验证失败,请检查授权";
AdvanceSale.AdvanceList.Add(ad);
return false;
}
return true;
}
public static void SetRelation(long id,ref ProductDetailBase r,ref ShopChatBase shop)
{
decimal maxPriceNewx = 0, minPriceNewx = Decimal.MaxValue;
//生成新的价格
for (int i = 0; i < r.sku_list.Count; i++)
{
if (maxPriceNewx < r.sku_list[i].multi_price)
maxPriceNewx = r.sku_list[i].multi_price;
if (minPriceNewx > r.sku_list[i].multi_price)
minPriceNewx = r.sku_list[i].multi_price;
}
var api = new PinduoduoApiGetProduct(shop);
long upid = 0;
string html = api.GetRelation(r.goods_id.ToString());
// 有获取到对应的上家id
if (html.Contains("out_goods_id") && html.Contains("out_goods_platform"))
{
upid = BaseRegex.GetLongJson(ref html, "out_goods_id");
html = api.Relation(r.goods_id, upid, (int)(minPriceNewx * 0.94m), (int)(maxPriceNewx * 0.94m), 0, 0);
}
else
{
int fromSite = 0;
if (upid == 0)
upid = Randomx.GetId(100000, 9999999) * (long)Randomx.GetId(10, 99999);
html = api.Relation(id, upid, (int)(minPriceNewx * 0.95m), (int)(maxPriceNewx * 0.95m), 0, fromSite);
}
}
}
}