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

3825 lines
169 KiB
C#
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using AllBase;
using Work.CollectClass;
using Work.ManageClass;
using System.Data;
using System.Threading.Tasks;
namespace Work.Api
{
public class UploadPinduoduoMain
{
public string Name;
public ShopChatBase Shop;
public UploadPinduoduoMain(string name)
{
Name = name;
}
public static bool isUseCache = true;
public static Dictionary<long, DateTime> EditDayTemp = new Dictionary<long, DateTime>();
public static Dictionary<long, DateTime> CatDayTemp = new Dictionary<long, DateTime>();
public static Dictionary<long, string> CatHtmlTemp = new Dictionary<long, string>();
public static decimal MultiPrice = 0, MultiSavePrice = 0, MultiPricex = 0, Postage = 0, SinglePrice = 0, BeforePrice = 0, LowPricePercent = 1.0m, LowPriceStock = 0, LowPriceAdd = 0;
public static bool RandPrice = false, ImageBuild = false, PropImageToMain = false, DeleteMainImage = false, RandSku = false, ErrorDown = false,
RandDeleteSku = false, RandDeleteImage = false, RandMainImage = false, Running = false, RunningReplace = false, JustSaveContentImage = false, DeleteFirst = false,
PriceShield = false, RandDesc = false, UseApi = false, Relation = false, GotoEnd = false, NoSold = false, NoVisit = false, NoNeerReplace = false, OffProduct = false,
JustOnline = false, JustOffline = false, Waiting = false, ReplaceWaiting = false, JustFree = false, LimitReplace = false, PreFix = false, Irregularities = false, IrregularitiesWord = false,JinUp = false,
CutHand = false, RunningLoop = false, LowPriceSku = false, LowPriceQ = false, JustCollection = false, JustSales = false, limitCount = false, ResurHand = false, DesShop = false, WhiteBack = false, SelBrand = false, NoRepeat = false, MainImg = false, singleUP = false,upRunning=false;
public static int DeleteMainImageCut = 0, CutHandStock = 3, SubCoupon = 0,
ShopThreadCount = 0,
SingleThreadCount = 0,
RandPrice1 = 0,
RandPrice2 = 0,
MaxUpload = 1000,
JustSaveContentImageCount = 0, LimitBuy = 999, BuyLimit = 99, OrderLimit = 99, GroupCount = 2, VisitCount = 0, NoNeerDays = 0, Days = 0, OffProductCount = 0, ReplaceCount = 0, DelCount = 0;
public static long MinPrice = 0, MaxPrice = 0;
public static string PreFixTitle = "";
public static string CutHandName = "", CutHandImage = "", CutHandPath = "";
public static string onTime = "";
public static string offTime = "";
public static List<TaobaoProductBase> ProductStock = new List<TaobaoProductBase>();
public static List<TaobaoProductBase> ProductStockTemp = new List<TaobaoProductBase>();
public static List<TaobaoProductBase> ProductTemp = new List<TaobaoProductBase>();
public static List<long> DeleteIds = new List<long>();
public static List<ShopChatBase> ShopTemp = new List<ShopChatBase>();
public static List<TaobaoProductBase> ProductReplaceTemp = new List<TaobaoProductBase>();
public static List<TaobaoProductBase> ProductArrangeTemp = new List<TaobaoProductBase>();
public static List<TaobaoProductBase> ProductResurVioTemp = new List<TaobaoProductBase>();
public static List<ProductResurBase> ProductResurTemp = new List<ProductResurBase>();
public static List<TaobaoProductBase> PromotionPlanList = new List<TaobaoProductBase>();
public static List<TaobaoProductBase> PromotionPlanTempList = new List<TaobaoProductBase>();
public static List<PromPlan> PromPlanList = new List<PromPlan>();
public static List<ShopChatBase> ShopReplaceTemp = new List<ShopChatBase>();
//public static List<TaobaoProductBase> ProductOnOrOffTemp = new List<TaobaoProductBase>();
public static List<TaobaoProductBase> ProductDelTemp = new List<TaobaoProductBase>();
public static List<OnOrOffStatus> onOrOffStatusList = new List<OnOrOffStatus>();
public static List<OnOrOffStatus> onOrLoopOffStatusList = new List<OnOrOffStatus>();
public static List<DelGroupStatus> delGroupStatusList = new List<DelGroupStatus>();
public static int onSaleHour = 0;
public static int offSaleHour = 0;
public static List<OnOrOffProuduct> ProductOnOrOffTempDic = new List<OnOrOffProuduct>();
public static List<TaobaoProductBase> RestoreProduct = new List<TaobaoProductBase>();
public static bool onStartFlag = false;
public bool isOnline = false;
public string delTitle = "";
public static bool isAdvance = false, SaleSetFalseDown = false, NoRuleIds = false, defaultPid = false, isLowPriceApplied = false;
public static long endAdvanceTime = 0;
public long arrangePid = 0;
public static string arrangeGoodName = "";
public List<long> arrangePidList = new List<long>();
public string arrangeShopName = "";
public static List<string> brandNameList = new List<string>();
public List<TaobaoProductBase> ResurProList = new List<TaobaoProductBase>();
public List<string> goodIds = new List<string>();
public List<string> keywords = new List<string>();
public static Dictionary<long, int> dicPlan = new Dictionary<long, int>();
public static List<string> formIdlist = new List<string>();
public static int CustomThreadCount = 20;
public static Dictionary<string, List<string>> ShopTitles = new Dictionary<string, List<string>>();
public static List<string> RuleIds = new List<string>();
public static List<string> RuleTitles = new List<string>();
public static bool ckBrandName = false;
public static string BrandName = "";
public static int upGoodsCount = 0;
public static string fixName = "前缀";
public static bool isPreSale = false;
public static long endAdvanceTimex = 0;
public static bool isSevNoRea = false;
public static bool isDefaultQun = false;
public static bool isDefaultMoni = false;
public static bool isProxy = true;
public static bool isfolt = false;
public static bool isSecond = false;
public static bool isLogistics = false;
public static bool isFourLogistics = false;
public static bool isSpecCount = false;
public static bool ismaterial = false;
public static bool isfruit = false;
public static bool isExpressPrice = true;
public static bool isChkAutophy = false;
public static bool isUpSku = true;
public static string AntiContent = "";
public static long SingleCount = -1;
public static string AddCatString = "";
public static bool upfinish = false;
public static bool isCatType = false;
public static Dictionary<string, string> CountryList = new Dictionary<string, string>();
public static List<string> brandFilterNameList = new List<string>();
public static decimal minPrice = 0M;
public static decimal maxPrice = 0M;
public static string priceModel = "0";
public static bool isPriceModel = false;
public static bool isDraft = false;
public static bool isMaxPrice = false;
public static bool isUsePddCache = true;
public static bool isUseTaoBaoCache = true;
public static bool isUseDouYinCache = true;
public static List<PriceRangeModel> PriceModelList = new List<PriceRangeModel>();
public void Get()
{
upRunning = true;
GotoEnd = false;
bool first = true;
JingXiCollect.VerifyCodeUrl = "";//京喜采集全局变量初始化赋初值 by ttzhao 2020.6.29
new Thread(CutImage).Start();
if (singleUP)
{
ProductStockTemp.Clear();
for (int i = 0; i < ProductStock.Count; i++)
{
ProductStockTemp.Add(ProductStock[i]);
}
}
for (int i = 0; i < ProductStock.Count; i++)
{
if (ProductStock[i].MainCatId == 0)
{
CatTemp.Add(ProductStock[i]);
}
}
if (CatTemp.Count > 0)
{
new Thread(GetNewCat).Start();
}
//Again:
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count && upRunning; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.Select || !shop.Showed)
continue;
if (singleUP)
Threadx.ThreadListWait(ref ts, new Thread(new UploadShopControl(Name, shop).Getsingle), ShopThreadCount);
else
Threadx.ThreadListWait(ref ts, new Thread(new UploadShopControl(Name, shop).Get), ShopThreadCount);
Thread.Sleep(1000);
if (first && ShopThreadCount > 1)
{
first = false;
Thread.Sleep(20 * 1000);
}
}
Threadx.ThreadListWait(ref ts);
//if (ProductStock.Count==0)
//{
// Running = false;
// GotoEnd = true;
//}
//else
//{
// goto Again;
//}
MessageBox.Show("上传执行完成", "提示");
upfinish = true;
//if (UploadPinduoduoMain.isChkAutophy)
// GetInsPec();
}
public static List<string> imgList = new List<string>();
public static bool RunningImage = false;
public static int RelErrorCount = 0;
public static string RelErrorMessage = "";
public void CutImage()
{
if (RunningImage)
return;
RunningImage = true;
List<Thread> ts = new List<Thread>();
while (true)
{
if (imgList.Count <= 0)
{
Thread.Sleep(2000);
continue;
}
try
{
var p = imgList[0];
imgList.RemoveAt(0);
string[] info = p.Split('@');
var shop = GetShopLoginInfo.Shops.Find(s => s.ShopName == info[0]);
if (shop == null)
continue;
CutImage cutImage = new CutImage(Name, shop);
cutImage.goodsId = long.Parse(info[1]);
cutImage.url = info[2];
Threadx.ThreadListWait(ref ts, new Thread(cutImage.CutImageVaule), 8);
Thread.Sleep(1000);
}
catch
{
}
}
}
public void GetReplace()
{
RunningReplace = true;
GotoEnd = false;
List<Thread> ts = new List<Thread>();
bool first = true;
for (int i = 0; i < GetShopLoginInfo.Shops.Count && RunningReplace; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
Threadx.ThreadListWait(ref ts, new Thread(new UploadShopControl(Name, shop).GetReplacePrice), ShopThreadCount);
Thread.Sleep(1000 * ShopThreadCount);
if (first && ShopThreadCount > 1)
{
first = false;
Thread.Sleep(20 * 1000);
}
}
Threadx.ThreadListWait(ref ts);
Running = false;
GotoEnd = true;
MessageBox.Show("替换执行完成", "提示");
}
public void GetClearWord()
{
RunningReplace = true;
GotoEnd = false;
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count && RunningReplace; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
Threadx.ThreadListWait(ref ts, new Thread(new UploadShopControl(Name, shop).ClearTitle), ShopThreadCount);
Thread.Sleep(2000 * ShopThreadCount);
}
Threadx.ThreadListWait(ref ts);
Running = false;
GotoEnd = true;
MessageBox.Show("替换执行完成", "提示");
}
public void SetNewTitle()
{
RunningReplace = true;
GotoEnd = false;
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count && RunningReplace; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
Threadx.ThreadListWait(ref ts, new Thread(new UploadShopControl(Name, shop, true).ClearTitle), ShopThreadCount);
Thread.Sleep(2000 * ShopThreadCount);
}
Threadx.ThreadListWait(ref ts);
Running = false;
GotoEnd = true;
MessageBox.Show("替换执行完成", "提示");
}
public void GetInsPec()
{
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.Select || !shop.Showed)
continue;
string url = "https://mms.pinduoduo.com/gear/mall/inspect/new/goods/action/start";
string refer = "https://mms.pinduoduo.com/search/good_inspect_v2/inspect_start";
string data = "{}";
string html = GetPostTaobaoHtml.GetJsonPost(url, refer, true, data, shop.Cookies);
LogSave.Add(Name, "店铺" + shop.ShopName + "商品体验执行完成");
}
LogSave.Add(Name, "商品体验全部执行完成");
}
public void SetAdvanceSale()
{
RunningReplace = true;
//GotoEnd = false;
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count && RunningReplace; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
UploadShopControl.endAdvanceTime = endAdvanceTime;
Threadx.ThreadListWait(ref ts, new Thread(new UploadShopControl(Name, shop, isAdvance).SetAdvanceSale), ShopThreadCount);
Thread.Sleep(3000);
}
Threadx.ThreadListWait(ref ts);
Running = false;
//GotoEnd = true;
//MessageBox.Show("预售执行完成", "提示");
}
public void GetOnline()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
if (JustOnline)
{
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
Threadx.ThreadListWait(ref ts, new Thread(p.GetOnline), ShopThreadCount);
}
if (JustOffline)
{
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = false;
p.OffOroduct = OffProduct;
p.OffProductCount = OffProductCount;
Threadx.ThreadListWait(ref ts, new Thread(p.GetOnline), ShopThreadCount);
}
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetArrangeOnline()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
if (JustOnline && JustOffline)
{
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
//p.isOnline = false;
p.JustCollection = JustCollection;
p.JustSales = JustSales;
p.minPrice = MinPrice;
p.maxPrice = MaxPrice;
p.arrangeGoodName = arrangeGoodName;
//p.OffOroduct = OffProduct;
//p.OffProductCount = OffProductCount;
Threadx.ThreadListWait(ref ts, new Thread(p.GetAllArrangeOnline), ShopThreadCount);
}
else if (JustOnline)
{
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
p.JustCollection = JustCollection;
p.JustSales = JustSales;
p.minPrice = MinPrice;
p.maxPrice = MaxPrice;
p.arrangeGoodName = arrangeGoodName;
Threadx.ThreadListWait(ref ts, new Thread(p.GetArrangeOnline), ShopThreadCount);
}
else if (JustOffline)
{
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = false;
p.JustCollection = JustCollection;
p.JustSales = JustSales;
p.minPrice = MinPrice;
p.maxPrice = MaxPrice;
p.arrangeGoodName = arrangeGoodName;
//p.OffOroduct = OffProduct;
//p.OffProductCount = OffProductCount;
Threadx.ThreadListWait(ref ts, new Thread(p.GetArrangeOnline), ShopThreadCount);
}
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public static void GetCateTempHtml(int catId)
{
if (!Directory.Exists("temp/cattemp/"))
FileBase.DirectoryCreate("temp/cattemp/");
string s = FileBase.ReadAllText("temp/cattemp/" + catId + "cathtml.tjm");
if (string.IsNullOrEmpty(s) || !s.Contains("@"))
return;
string[] li = s.Split('@');
if (li.Length > 2)
li[2] = s.Substring(li[0].Length + li[1].Length + 2);
long id = 0;
if (li.Length <= 2 || !long.TryParse(li[0], out id))
return;
DateTime dt = DateTime.Parse(li[1]);
if (CatDayTemp.ContainsKey(id))
{
CatDayTemp[id] = dt;
CatHtmlTemp[id] = li[2];
}
else
{
try
{
CatDayTemp.Add(id, dt);
CatHtmlTemp.Add(id, li[2]);
}
catch
{
}
}
}
public static void GetCateTempHtml()
{
if (!Directory.Exists("temp/cattemp/"))
FileBase.DirectoryCreate("temp/cattemp/");
string[] files = Directory.GetFiles("temp/cattemp/", "*.tjm");
for (int i = 0; i < files.Length; i++)
{
string[] fl = FileBase.ReadAllLines(files[i]);
if (fl != null)
{
foreach (string s in fl)
{
if (string.IsNullOrEmpty(s) || !s.Contains("@"))
continue;
string[] li = s.Split('@');
if (li.Length > 2)
li[2] = s.Substring(li[0].Length + li[1].Length + 2);
long id = 0;
if (li.Length <= 2 || !long.TryParse(li[0], out id))
continue;
DateTime dt = DateTime.Parse(li[1]);
if (CatDayTemp.ContainsKey(id))
{
CatDayTemp[id] = dt;
CatHtmlTemp[id] = li[2];
}
else
{
CatDayTemp.Add(id, dt);
CatHtmlTemp.Add(id, li[2]);
}
}
}
}
}
public void GetResurReplace()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < ResurProList.Count; i++)
{
var shop = GetShopLoginInfo.Shops.Find(s => s.ShopName == ResurProList[i].ShopName);
if (shop == null)
continue;
if (shop.ExpressId == 0)
{
shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(shop.Cookies, shop.MallId, shop);
if (shop.ExpressId == 0)
{
Thread.Sleep(10000);
shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
}
if (shop.ExpressId == 0)
{
LogSave.Add(Name, "运费模板未找到");
shop.Message = "请设置运费模板";
UploadPinduoduoMain.ShopTemp.Add(Shop);
continue;
}
}
if (!Directory.Exists("temp/resursame/"))
FileBase.DirectoryCreate("temp/resursame/");
string[] fl = FileBase.ReadAllLines("temp/resursame/" + shop.ShopName + "edit.tjm");
if (fl != null)
{
foreach (string s in fl)
{
if (string.IsNullOrEmpty(s) || !s.Contains(","))
continue;
string[] li = s.Split(',');
long id = 0;
if (li.Length != 2 || !long.TryParse(li[0], out id))
continue;
DateTime dt = DateTime.Parse(li[1]);
if (UpPinduoduoProduct.EditDayTemp.ContainsKey(id))
UpPinduoduoProduct.EditDayTemp[id] = dt;
else
UpPinduoduoProduct.EditDayTemp.Add(id, dt);
}
}
var list = UpPinduoduoProduct.EditDayTemp.ToList();
bool ishad = false;
for (int j = 0; j < list.Count; j++)
{
if (list[j].Value < DateTime.Now.AddDays(-UploadPinduoduoMain.NoNeerDays))
continue;
var pp = ResurProList.Find(tt => tt != null && tt.GoodsId == list[j].Key);
if (pp != null)
{
//ResurProList.Remove(pp);
ishad = true;
LogSave.Add(Name, "商品最近替换过,跳过:" + list[j].Key);
Thread.Sleep(100);
break;
}
}
if (ishad)
continue;
var uc = new UploadShopControl(Name, shop, null);
uc.product = ResurProList[i];
uc.GetReplaceRes();
Thread.Sleep(3000);
}
}
public void GetResurAddOnline()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectResure || !shop.Showed)
continue;
var uc = new UploadShopControl(Name, shop);
uc.productList = ResurProList;
Threadx.ThreadListWait(ref ts, new Thread(uc.GetResureAdd), ShopThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetResurOnline()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectResurVio || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
//p.ReplaceModel = true;
//p.isOnline = false;
//p.JustCollection = JustCollection;
//p.JustSales = JustSales;
////p.OffOroduct = OffProduct;
////p.OffProductCount = OffProductCount;
Threadx.ThreadListWait(ref ts, new Thread(p.GetResurOnline), ShopThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetPromotionPlan()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectPlan || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.goodIds = goodIds;
p.keywordxs = keywords;
Threadx.ThreadListWait(ref ts, new Thread(p.GetPromotionPlan), ShopThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetNonAdvanceOnline()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
Threadx.ThreadListWait(ref ts, new Thread(p.GetNonAdvanceOnline), ShopThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetAllShopOnline()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
GetProductOnlineClass.endAdvanceTime = endAdvanceTime;
Threadx.ThreadListWait(ref ts, new Thread(p.GetAllShopOnline), 50);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetOnSaleProductline()
{
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
new Thread(p.GetOnline).Start();
}
}
public void GetVisit()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetVisitProductNew(Name, shop);
p.ReplaceModel = true;
Threadx.ThreadListWait(ref ts, new Thread(p.Get), ShopThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public bool SetOnline = false;
public void SetStatus()
{
bool setOnLine = SetOnline;
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.isOnline = !setOnLine;
p.OffOroduct = OffProduct;
p.OffProductCount = OffProductCount;
Threadx.ThreadListWait(ref ts, new Thread(p.UploadMethod), ShopThreadCount);
}
Threadx.ThreadListWait(ref ts);
}
public void SetShopGoodsStatus()
{
bool setOnLine = SetOnline;
var shop = GetShopLoginInfo.Shops.Find(s => s.ShopName == arrangeShopName);
if (!shop.SelectReplace || !shop.Showed)
return;
var p = new GetProductOnlineClass(Name, shop);
p.isOnline = !setOnLine;
p.arrangePid = arrangePid;
new Thread(p.UploadArrangeMethod).Start();
}
public void SetShopGoodsListStatus()
{
bool setOnLine = SetOnline;
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.isOnline = !setOnLine;
Threadx.ThreadListWait(ref ts, new Thread(p.GetDownGood), ShopThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public static Dictionary<string, int> TypeName = new Dictionary<string, int>();
public static Dictionary<string, int> TypeValues = new Dictionary<string, int>();
private static int firstKeyId = 0, firstValueId = 0;
/// <summary>
/// 特殊属性独立添加
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public static string AddType(ref ProductCollectBase p, int mainCatId, string cookies, int mallId)
{
return "";
if (mainCatId == 5)
{
if (TypeName.Count == 0)
{
string url = "https://mms.pinduoduo.com/malls/" + mallId + "/transport/glide/query/clothes_fabric/list";
string refere = "https://mms.pinduoduo.com/Pdd.html";
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, "{}", cookies);
var m = BaseRegex.GetMatchRegex(ref html, @"""code"":([\d]+),""desc"":""(.*?)""");
for (int i = 0; m != null && i < m.Count; i++)
{
string name = m[i].Groups[2].Value;
int value = int.Parse(m[i].Groups[1].Value);
if (firstKeyId == 0)
firstKeyId = value;
if (!TypeName.ContainsKey(name))
TypeName.Add(name, value);
}
}
if (TypeValues.Count == 0)
{
string url = "https://mms.pinduoduo.com/malls/" + mallId + "/transport/glide/query/clothes_fabric_content/list";
string refere = "https://mms.pinduoduo.com/Pdd.html";
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, "{}", cookies);
var m = BaseRegex.GetMatchRegex(ref html, @"""code"":([\d]+),""desc"":""(.*?)""");
for (int i = 0; m != null && i < m.Count; i++)
{
string name = m[i].Groups[2].Value;
int value = int.Parse(m[i].Groups[1].Value);
if (firstValueId == 0)
firstValueId = value;
if (!TypeValues.ContainsKey(name))
TypeValues.Add(name, value);
}
}
}
if (mainCatId == 5)
{
string name = "材质成分";
string value = "";
for (int i = 0; i < p.Prop.Count; i++)
{
if (p.Prop[i].Key == name)
{
value = p.Prop[i].Value;
break;
}
}
int keyId = 0, valueId = 0;
if (!string.IsNullOrEmpty(value) && value.Contains("%"))
{
string v = BaseRegex.GetMatchRegexString(ref value, @"([\d]+)%");
string namex = value.Substring(0, value.IndexOf(v + "%"));
if (string.IsNullOrEmpty(v) || string.IsNullOrEmpty(namex))
{
goto NoValue;
}
int pe = int.Parse(v);
foreach (KeyValuePair<string, int> k in TypeName)
{
if (k.Key.Contains(namex) || namex.Contains(k.Key))
{
keyId = k.Value;
foreach (KeyValuePair<string, int> vv in TypeValues)
{
var mm = BaseRegex.GetMatchRegex(vv.Key, @"([\d]+)%");
if (mm.Count == 2)
{
int min = int.Parse(mm[0].Groups[1].Value);
int max = int.Parse(mm[1].Groups[1].Value);
if (pe >= min && pe <= max)
{
valueId = vv.Value;
goto NoValue;
}
}
}
break;
}
}
}
NoValue:
if (keyId == 0)
keyId = firstKeyId;
if (valueId == 0)
valueId = firstValueId;
string addContent = ",\"fabric\":" + keyId + ",\"fabric_content\":" + valueId;
return addContent;
}
return "";
}
public List<TaobaoProductBase> CatTemp = new List<TaobaoProductBase>();
public List<TaobaoProductBase> DataBaseTemp = new List<TaobaoProductBase>();
public List<TaobaoProductBase> batchDataBaseTemp = new List<TaobaoProductBase>();
public async Task InputData(string file, string shopName)
{
await Task.Run(() =>
{
InputData(file, shopName, null);
});
GetMainCat();
}
public async Task InputData(string file, string shopName, string[] fc)
{
bool message = false;
string[] f;
if (fc != null)
f = fc;
else
f = FileBase.ReadAllLines(file, GetFileEncoding(file));
if (f == null || f.Length == 0)
return;
for (int i = 0; i < f.Length; i++)
{
if (i > 10000)
{
}
if (string.IsNullOrEmpty(f[i]))
continue;
string l = f[i];
if (!(l.Contains("detail.tmall") || l.Contains("taobao.com") || l.Contains("1688.com") || l.Contains("weidian.com") || l.Contains("jd.com")))
{
try
{
l = Md5Base.EncryptDecode(l);
}
catch
{
continue;
}
}
if ((f[i].Contains("淘宝") || f[i].Contains("阿里巴巴")) && f[i].Split(',').Length <= 7)
l = f[i];
if (string.IsNullOrEmpty(l))
continue;
//l = l.Replace("\t", "-----").Replace("----------", "-----").Replace("----------", "-----").Replace(",", "").Replace("\"", "");
string lb = l;
string sp = "-----";
string url = l, title = "", shop = "", catid = "", from = "", fid = "";
string viname = "", viId = "", viPrice = "", viMPrice = "";
if (l.Contains("\",\""))
{
var mm = BaseRegex.GetMatchRegex(l, @"(.*?),""([\d]+)"",""([^""]+?)"",""([\d]+)"",""([\d]+)"",""([\d]+)"",""([\d]+)"",""([\d]+)"",""([-.\d]+%\+[-.\d]+)"",""([^""]+?)""");
if (mm != null && mm.Count > 0)
{
from = mm[0].Groups[1].Value.Replace("\"", "").Replace("\"", "");
fid = mm[0].Groups[2].Value;
title = mm[0].Groups[3].Value;
catid = mm[0].Groups[6].Value;
viname = mm[0].Groups[7].Value;
viId = mm[0].Groups[8].Value;
viPrice = mm[0].Groups[9].Value;
viMPrice = mm[0].Groups[10].Value;
goto End;
}
var m = BaseRegex.GetMatchRegex(l, @"""([^""]+?)"",""([\d]+?)"",""([^""]+?)"",""([\d]+?)"",""([\d]+?)"",""([\d]+?)"",""([^""]+?)"",""([\d]+?)"",""([^""]+?)""");
if (m.Count == 0)
m = BaseRegex.GetMatchRegex(l, @"""([^""]+?)"",""([\d]+?)"",""([^""]+?)"",""([\d]+?)"",""([\d]+?)"",""([\d]+?)""");
//var m = BaseRegex.GetMatchRegex(f[i], @"""([^""]+?)"",""([\d]+?)"",""([^""]+?)"",""([\d]+?)"",""([\d]+?)"",""([\d]+?)""");
if (m != null && m.Count > 0)
{
from = m[0].Groups[1].Value;
fid = m[0].Groups[2].Value;
title = m[0].Groups[3].Value;
catid = m[0].Groups[6].Value;
viname = m[0].Groups[7].Value;
viId = m[0].Groups[8].Value;
viPrice = m[0].Groups[9].Value;
//if (from== "搜款网") //这里不要还原
//{
// //from = "拼多多";
// int p1 = 0;
// int p2 = fid.Length - 1;
// string ret = "";
// ret = fid.Substring(0, p1) + fid[p2];
// ret += fid.Substring(p1 + 1, p2 - p1 - 1) + fid[p1];
// ret += fid.Substring(p2 + 1, fid.Length - p2 - 1);
// fid = ret;
//}
goto End;
}
}
if (l.Contains(sp))
{
url = l.Substring(0, l.IndexOf(sp));
l = l.Substring(l.IndexOf(sp) + sp.Length);
title = l;
}
if (title.Contains(sp))
{
title = l.Substring(0, l.IndexOf(sp));
l = l.Substring(l.IndexOf(sp) + sp.Length);
shop = l;
}
if (shop.Contains(sp))
{
shop = l.Substring(0, l.IndexOf(sp));
l = l.Substring(l.IndexOf(sp) + sp.Length);
catid = BaseRegex.GetMatchRegexString(l, @"([\d]+)");
}
if (string.IsNullOrEmpty(shop))
shop = shopName;
shop = "";
fid = BaseRegex.GetMatchRegexString(url, @"/([\d]+)\.html");
if (string.IsNullOrEmpty(fid))
fid = BaseRegex.GetMatchRegexString(url, @"goods_id=([\d]+)");
if (string.IsNullOrEmpty(fid))
fid = BaseRegex.GetMatchRegexString(url, @"id=([\d]+)");
if (url.Contains("yangkeduo.com"))
{
from = "拼多多";
continue;
}
if (url.Contains(".taobao.com") || url.Contains(".tmall.com"))
from = "淘宝";
if (url.Contains(".1688.com"))
from = "阿里巴巴";
if (url.Contains("weidian.com"))
from = "微店";
if (url.Contains("jd.com"))
from = "京喜";
if (!lb.Contains("-----") && lb.Contains(@""","""))
{
var m = BaseRegex.GetMatchRegex(ref lb, @"""(.*?)"",""([\d]+)"",""(.*?)""");
if (m == null || m.Count <= 0) continue;
if (m.Count > 0)
{
from = m[0].Groups[1].Value;
fid = m[0].Groups[2].Value;
title = m[0].Groups[3].Value;
catid = "";
}
}
End:
//if (!string.IsNullOrEmpty(viname) && viname != "6") 临时开放转换淘宝
if (!string.IsNullOrEmpty(viname) && viname != "6" && viname != "1")
continue;
if (string.IsNullOrEmpty(fid) || string.IsNullOrEmpty(from))
continue;
if (!string.IsNullOrEmpty(viPrice) && string.IsNullOrEmpty(viMPrice))
{
if (!message)
{
MessageBox.Show("老格式数据已经不支持\r\n请升级采集程序,重新转化数据后导入新格式,重新转化速度会很快", "提示:老格式已经不支持");
message = true;
}
continue;
}
if (BaseClass.UpIds.Count > 0)
{
bool ishas = false;
for (int j = 0; j < BaseClass.UpIds.Count; j++)
{
string rid = BaseRegex.GetMatchRegexString(BaseClass.UpIds[j], @"([\d]+)");
if (string.IsNullOrEmpty(rid))
continue;
if (fid == rid)
{
ishas = true;
break;
}
}
if (ishas)
continue;
}
TaobaoProductBase t = new TaobaoProductBase();
long idx;
if (!long.TryParse(fid, out idx))
continue;
t.TolerantFormId = fid;
t.FromId = idx;
if (ProductStock.FindAll(p => p != null && p.FromId == t.FromId).Count + CatTemp.FindAll(p => p != null && p.FromId == t.FromId).Count >= 500)
continue;
t.ViGoodsName = viname;
long.TryParse(viId, out t.ViGoodsId);
t.ViPrice = viPrice;
t.FromType = from;
if (!string.IsNullOrEmpty(viMPrice))
{
t.ViPriceMaxMin = viMPrice;
string[] strPrice = viMPrice.Split(':');
if (strPrice.Length == 3)
{
t.ViPriceMin = (int)(decimal.Parse(strPrice[0]) * 100);
t.ViPriceMax = (int)(decimal.Parse(strPrice[1]) * 100);
t.ViExpressPrice = (int)(decimal.Parse(strPrice[2]));
}
}
if (!string.IsNullOrEmpty(catid))
{
if (catid.Length > 8)
continue;
int cid = int.Parse(catid);
cid = PinduoduoCatList.GetNewCat3(cid);
if (PinduoduoCatList.CatIds.ContainsKey(cid))
{
var ci = PinduoduoCatList.CatIds[cid];
t.CatId = ci.id;
t.Cat1 = ci.cat1;
t.Cat2 = ci.cat2;
t.Cat3 = ci.cat3;
t.Cat4 = ci.cat4;
FromTitleToCat ff = new FromTitleToCat();
int mainCatId = ff.GetMainCatId(t.Cat1);
t.MainCatName = ff.MainCatName;
t.MainCatId = ci.main_cat_id;
if (ci.main_cat_id != mainCatId && mainCatId != 0)
t.MainCatId = mainCatId;
}
else if (PinduoduoCatList.CatBaks.ContainsKey(cid))
{
var ci = PinduoduoCatList.CatBaks[cid];
t.CatId = ci.id;
t.Cat1 = ci.cat1;
t.Cat2 = ci.cat2;
t.Cat3 = ci.cat3;
t.Cat4 = ci.cat4;
FromTitleToCat ff = new FromTitleToCat();
int mainCatId = ff.GetMainCatId(t.Cat1);
t.MainCatName = ff.MainCatName;
t.MainCatId = ci.main_cat_id;
if (ci.main_cat_id != mainCatId && mainCatId != 0)
t.MainCatId = mainCatId;
}
else
{
if (t.FromType == "搜款网")
t.CatId = cid;
}
}
t.Titlte = title.Replace("\",\"", "");
var sh = GetShopLoginInfo.Shops.Find(s => s.ShopName == shop);
if (sh != null)
{
if (t.MainCatId > 0)
{
if (t.MainCatId == sh.MainCatId)
t.ShopName = sh.ShopName;
}
else
t.ShopName = sh.ShopName;
}
//if (t.MainCatId > 0)
//{
if (!ProductStock.Exists(p => p != null && p.FromId == t.FromId && p.Titlte == t.Titlte))
{
ProductStock.Add(t);
//if (t.MainCatId > 0)
DataBaseTemp.Add(t);
batchDataBaseTemp.Add(t);
if (batchDataBaseTemp.Count == 500)
{
AddListToDataBaseSingle(batchDataBaseTemp);
batchDataBaseTemp.Clear();
}
if (string.IsNullOrEmpty(t.ShopName))
continue;
var s = GetShopLoginInfo.Shops.Find(ss => ss.ShopName == t.ShopName);
if (s != null)
{
s.ProductCount++;
ShopReplaceTemp.Add(s);
ShopTemp.Add(s);
}
}
continue;
//}
//if (ProductStock.Exists(p => p != null && p.FromId == t.FromId && p.Titlte == t.Titlte) || CatTemp.Exists(p => p != null && p.FromId == t.FromId && p.Titlte == t.Titlte))
// continue;
//CatTemp.Add(t);
}
if (batchDataBaseTemp.Count > 0)
{
AddListToDataBaseSingle(batchDataBaseTemp);
batchDataBaseTemp.Clear();
}
string s1s = "";
foreach (var v1 in ProductStock)
{
s1s += v1.FromId + "\r\n";
}
//new Thread(AddListToDataBase).Start();
//new Thread(GetCat).Start();
//if (CatTemp.Count > 0)
//{
// MessageBox.Show("正在努力识别分类,请稍等", "提示");
//}
}
public static List<string> batchString = new List<string>();
public void AddListToDataBaseSingle(List<TaobaoProductBase> temp)
{
for (int i = 0; i < temp.Count; i++)
{
AddbatchToDataBase(temp[i]);
}
SqliteHelper.BatchExecuteNonQuery(batchString);
batchString.Clear();
}
public void AddListToDataBase()
{
for (int i = 0; i < DataBaseTemp.Count; i++)
{
AddbatchToDataBase(DataBaseTemp[i]);
if ((i + 1) % 500 == 0)
{
SqliteHelper.BatchExecuteNonQuery(batchString);
batchString.Clear();
}
}
if (batchString.Count > 0)
{
SqliteHelper.BatchExecuteNonQuery(batchString);
batchString.Clear();
}
}
public static void AddbatchToDataBase(TaobaoProductBase p)
{
string content = p.FromId + "," + p.FromType + "," + p.Titlte + "," + p.Cat1 + "," + p.Cat2 + "," +
p.Cat3 + "," + p.Cat4 + "," + p.CatId + "," + p.MainCatId + "," + p.MainCatName + "," + p.MainImage + "," +
p.Price + "," + p.SaleCount + "," + p.ShopName + "," + p.AddPrice;
if (!string.IsNullOrEmpty(p.ViGoodsName))
content += "," + p.ViGoodsId + "," + p.ViGoodsName + "," + p.ViPrice + "," + p.ViPriceMaxMin;
string sql = "insert into Product(content,fromid) values('" + SqliteHelper.ReplaceSqlx(content) + "','" + p.guid + "')";
batchString.Add(sql);
}
public static System.Text.Encoding GetFileEncoding(string filename)
{
using (var fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read))
using (var br = new System.IO.BinaryReader(fs))
{
var buffer = br.ReadBytes(2);
if (buffer[0] >= 0xEF)
{
if (buffer[0] == 0xEF && buffer[1] == 0xBB)
{
return System.Text.Encoding.UTF8;
}
if (buffer[0] == 0xFE && buffer[1] == 0xFF)
{
return System.Text.Encoding.BigEndianUnicode;
}
if (buffer[0] == 0xFF && buffer[1] == 0xFE)
{
return System.Text.Encoding.Unicode;
}
}
return GetEncodingWithBomUtf8(fs, System.Text.Encoding.Default);
}
}
private static System.Text.Encoding GetEncodingWithBomUtf8(Stream fs, Encoding defaultEncoding)
{
byte[] unicode = new byte[] { 0xFF, 0xFE, 0x41 };
byte[] unicodeBig = new byte[] { 0xFE, 0xFF, 0x00 };
//带BOM
byte[] utf8 = new byte[] { 0xEF, 0xBB, 0xBF };
var reVal = defaultEncoding;
using (var r = new System.IO.BinaryReader(fs))
{
byte[] ss = r.ReadBytes(4);
if (ss[0] == 0xFE && ss[1] == 0xFF && ss[2] == 0x00)
{
reVal = Encoding.BigEndianUnicode;
}
else if (ss[0] == 0xFF && ss[1] == 0xFE && ss[2] == 0x41)
{
reVal = Encoding.Unicode;
}
else
{
if (ss[0] == 0xEF && ss[1] == 0xBB && ss[2] == 0xBF)
{
reVal = Encoding.UTF8;
}
else
{
int i;
int.TryParse(fs.Length.ToString(), out i);
ss = r.ReadBytes(i);
if (IsUtf8Bytes(ss))
{
reVal = Encoding.UTF8;
}
}
}
return reVal;
}
}
/// <summary>
/// 判断是否是不带 BOM 的 UTF8 格式
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
private static bool IsUtf8Bytes(byte[] data)
{
int charByteCounter = 1;  //计算当前正分析的字符应还有的字节数
for (int i = 0; i < data.Length; i++)
{
var curByte = data[i]; //当前分析的字节.
if (charByteCounter == 1)
{
if (curByte >= 0x80)
{
//判断当前
while (((curByte <<= 1) & 0x80) != 0)
{
charByteCounter++;
}
//标记位首位若为非0 则至少以2个1开始 如:110XXXXX...........1111110X 
if (charByteCounter == 1 || charByteCounter > 6)
{
return false;
}
}
}
else
{
//若是UTF-8 此时第一位必须为1
if ((curByte & 0xC0) != 0x80)
{
return false;
}
charByteCounter--;
}
}
if (charByteCounter > 1)
{
throw new Exception("非预期的byte格式!");
}
return true;
}
public void GetCat()
{
int CatThreadCount = 20;
if (FromTitleToCat.UserApi)
CatThreadCount = 2;
List<Thread> ts = new List<Thread>();
for (int i = 0; i < CatTemp.Count; i++)
{
try
{
if (CatTemp[i] == null)
continue;
if (CatTemp[i].FromType == "拼多多")
{
PinduoduoProductCollect pp = new PinduoduoProductCollect(Name, CatTemp[i], false);
if (!string.IsNullOrEmpty(CatTemp[i].Titlte))
{
KeyValuesBase k;
FromTitleToCat ftt = new FromTitleToCat();
if (FromTitleToCat.TempCat.ContainsKey(CatTemp[i].FromId))
{
k = FromTitleToCat.TempCat[CatTemp[i].FromId];
ftt.Cat1 = k.Value1;
ftt.Cat2 = k.Value2;
ftt.Cat3 = k.Value3;
ftt.Cat4 = k.Value4;
if (ftt.Cat3 != "0" || ftt.Cat4 != "0")
{
ftt.MainCatId = k.Key;
ftt.GetMainCatId(int.Parse(ftt.Cat1));
}
}
else
{
k = ftt.GetServerTempCat(CatTemp[i].FromId, 2);
}
if (k != null)
{
pp.pb.cat1 = int.Parse(ftt.Cat1);
pp.pb.cat2 = int.Parse(ftt.Cat2);
pp.pb.cat3 = int.Parse(ftt.Cat3);
pp.pb.cat4 = int.Parse(ftt.Cat4);
pp.pb.cat_id = pp.pb.cat4 > 0 ? pp.pb.cat4 : pp.pb.cat3;
pp.pb.main_cid = int.Parse(ftt.MainCatId);
ftt.GetMainCatId(pp.pb.cat1);
pp.pb.main_cat_name = ftt.MainCatName;
}
else
{
pp.Get();
}
}
else
{
Thread.Sleep(500);
pp.Get();
if (!TaobaoMobileCollect.ProductTemp.ContainsKey(CatTemp[i].FromId))
{
if (!pp.OnSale)
CatTemp[i].Message = pp.message;// "商品或已下架";
else
CatTemp[i].Message = pp.message;// "IP或买手号被限制,请更换IP或检查买手号是否能正常浏览商品";
LogSave.Add(Name, CatTemp[i].FromId + ":" + CatTemp[i].Message);
continue;
}
}
if (pp.pb.cat1 == 0)
{
Thread.Sleep(5000);
LogSave.Add(Name, "拼多多ID已下架:" + CatTemp[i].FromId);
continue;
}
CatTemp[i].Cat1 = pp.pb.cat1;
CatTemp[i].Cat2 = pp.pb.cat2;
CatTemp[i].Cat3 = pp.pb.cat3;
CatTemp[i].Cat4 = pp.pb.cat4;
CatTemp[i].CatId = pp.pb.cat_id;
if (pp.pb.price > 0)
CatTemp[i].Price = pp.pb.price;
CatTemp[i].SaleCount = pp.pb.saleCount;
CatTemp[i].MainCatId = pp.pb.main_cid;
CatTemp[i].MainCatName = pp.pb.main_cat_name;
CatTemp[i].country = pp.pb.country;
if (string.IsNullOrEmpty(CatTemp[i].Titlte))
{
CatTemp[i].Titlte = pp.pb.name;
}
var s = GetShopLoginInfo.Shops.Find(ss => ss.ShopName == CatTemp[i].ShopName);
if (s != null)
{
if (CatTemp[i].MainCatId == s.MainCatId)
{
s.ProductCount++;
ShopReplaceTemp.Add(s);
ShopTemp.Add(s);
}
else
{
CatTemp[i].ShopName = "";
}
}
ProductStock.Add(CatTemp[i]);
AddToDataBase(CatTemp[i]);
continue;
}
if (string.IsNullOrEmpty(CatTemp[i].Titlte))
{
ProductCollectBase pb = new ProductCollectBase();
pb.from_id = CatTemp[i].FromId;
pb.from = CatTemp[i].FromType;
if (CatTemp[i].FromType == "淘宝")
{
pb.from_url = "https://item.taobao.com/item.htm?id=" + CatTemp[i].FromId;
TaobaoMobileCollect tm = new TaobaoMobileCollect(pb);
tm.Pinduoduo = true;
tm.NoContent = true;
tm.Get();
pb = tm.Product;
CatTemp[i].Titlte = pb.name;
CatTemp[i].Cat1 = pb.cat1;
CatTemp[i].Cat2 = pb.cat2;
CatTemp[i].Cat3 = pb.cat3;
CatTemp[i].Cat4 = pb.cat4;
CatTemp[i].CatId = pb.cat4 > 0 ? pb.cat4 : pb.cat3;
CatTemp[i].MainCatId = pb.main_cid;
CatTemp[i].MainCatName = pb.main_cat_name;
CatTemp[i].country = pb.country;
}
if (CatTemp[i].FromType == "阿里巴巴")
{
pb.from_url = "https://detail.1688.com/offer/" + CatTemp[i].FromId + ".html";
AlibabaProductGet ali = new AlibabaProductGet(pb);
ali.IsPinduoduo = true;
ali.Get();
pb = ali.Product;
CatTemp[i].Titlte = pb.name;
}
Thread.Sleep(100);
}
if (CatTemp[i].CatId > 0)
{
ProductStock.Add(CatTemp[i]);
AddToDataBase(CatTemp[i]);
continue;
}
if (string.IsNullOrEmpty(CatTemp[i].Titlte))
continue;
FromTitleToCat ft = new FromTitleToCat();
ft.TaobaoProduct = CatTemp[i];
ft.Title = CatTemp[i].Titlte;
ft.AddToStock = true;
Threadx.ThreadListWait(ref ts, new Thread(ft.Get), CatThreadCount);
Thread.Sleep(100);
}
catch
{
}
}
}
public void GetMainCat(int sleepTime = 1000)
{
string temp = "";
Dictionary<string, int> cat = new Dictionary<string, int>();
for (int i = 0; i < UploadPinduoduoMain.ProductStock.Count; i++)
{
var p = UploadPinduoduoMain.ProductStock[i];
if (p == null)
continue;
if (cat.ContainsKey(p.MainCatName))
cat[p.MainCatName]++;
else
cat.Add(p.MainCatName, 1);
}
cat = cat.OrderByDescending(d => d.Key).ToDictionary(p => p.Key, o => o.Value);
var c = cat.ToList();
for (int i = 0; i < c.Count; i++)
{
temp += " " + (c[i].Key == "" ? "待分类" : c[i].Key) + ":" + c[i].Value;
}
AddCatString = temp;
Thread.Sleep(sleepTime);
}
public void GetNewCat()
{
int CatThreadCount = 20;
if (FromTitleToCat.UserApi)
CatThreadCount = 2;
List<Thread> ts = new List<Thread>();
for (int i = 0; i < CatTemp.Count; i++)
{
try
{
if (CatTemp[i] == null)
continue;
if (CatTemp[i].FromType == "拼多多")
{
PinduoduoProductCollect pp = new PinduoduoProductCollect(Name, CatTemp[i], UploadPinduoduoSet.IsUseProxyCollectUp);
if (!string.IsNullOrEmpty(CatTemp[i].Titlte))
{
KeyValuesBase k;
FromTitleToCat ftt = new FromTitleToCat();
if (FromTitleToCat.TempCat.ContainsKey(CatTemp[i].FromId))
{
k = FromTitleToCat.TempCat[CatTemp[i].FromId];
ftt.Cat1 = k.Value1;
ftt.Cat2 = k.Value2;
ftt.Cat3 = k.Value3;
ftt.Cat4 = k.Value4;
if (ftt.Cat3 != "0" || ftt.Cat4 != "0")
{
ftt.MainCatId = k.Key;
ftt.GetMainCatId(int.Parse(ftt.Cat1));
}
}
else
{
k = ftt.GetServerTempCat(CatTemp[i].FromId, 2);
}
if (k != null)
{
pp.pb.cat1 = int.Parse(ftt.Cat1);
pp.pb.cat2 = int.Parse(ftt.Cat2);
pp.pb.cat3 = int.Parse(ftt.Cat3);
pp.pb.cat4 = int.Parse(ftt.Cat4);
pp.pb.cat_id = pp.pb.cat4 > 0 ? pp.pb.cat4 : pp.pb.cat3;
pp.pb.main_cid = int.Parse(ftt.MainCatId);
ftt.GetMainCatId(pp.pb.cat1);
pp.pb.main_cat_name = ftt.MainCatName;
}
else
{
pp.Get();
}
}
else
{
Thread.Sleep(500);
pp.Get();
if (!TaobaoMobileCollect.ProductTemp.ContainsKey(CatTemp[i].FromId))
{
if (!pp.OnSale)
CatTemp[i].Message = pp.message;// "商品或已下架";
else
CatTemp[i].Message = pp.message;// "IP或买手号被限制,请更换IP或检查买手号是否能正常浏览商品";
LogSave.Add(Name, CatTemp[i].FromId + ":" + CatTemp[i].Message);
continue;
}
}
if (pp.pb.cat1 == 0)
{
Thread.Sleep(5000);
LogSave.Add(Name, "拼多多ID已下架:" + CatTemp[i].FromId);
continue;
}
CatTemp[i].Cat1 = pp.pb.cat1;
CatTemp[i].Cat2 = pp.pb.cat2;
CatTemp[i].Cat3 = pp.pb.cat3;
CatTemp[i].Cat4 = pp.pb.cat4;
CatTemp[i].CatId = pp.pb.cat_id;
if (pp.pb.price > 0)
CatTemp[i].Price = pp.pb.price;
CatTemp[i].SaleCount = pp.pb.saleCount;
CatTemp[i].MainCatId = pp.pb.main_cid;
CatTemp[i].MainCatName = pp.pb.main_cat_name;
CatTemp[i].country = pp.pb.country;
if (string.IsNullOrEmpty(CatTemp[i].Titlte))
{
CatTemp[i].Titlte = pp.pb.name;
}
var s = GetShopLoginInfo.Shops.Find(ss => ss.ShopName == CatTemp[i].ShopName);
if (s != null)
{
if (CatTemp[i].MainCatId == s.MainCatId)
{
s.ProductCount++;
ShopReplaceTemp.Add(s);
ShopTemp.Add(s);
}
else
{
CatTemp[i].ShopName = "";
}
}
var ps = ProductStock.Find(p => p.FromId == CatTemp[i].FromId && p.Titlte == CatTemp[i].Titlte);
ps = CatTemp[i];
continue;
}
if (string.IsNullOrEmpty(CatTemp[i].Titlte))
{
ProductCollectBase pb = new ProductCollectBase();
pb.from_id = CatTemp[i].FromId;
pb.from = CatTemp[i].FromType;
if (CatTemp[i].FromType == "淘宝")
{
pb.from_url = "https://item.taobao.com/item.htm?id=" + CatTemp[i].FromId;
TaobaoMobileCollect tm = new TaobaoMobileCollect(pb);
tm.Pinduoduo = true;
tm.NoContent = true;
tm.Get();
pb = tm.Product;
CatTemp[i].Titlte = pb.name;
CatTemp[i].Cat1 = pb.cat1;
CatTemp[i].Cat2 = pb.cat2;
CatTemp[i].Cat3 = pb.cat3;
CatTemp[i].Cat4 = pb.cat4;
CatTemp[i].CatId = pb.cat4 > 0 ? pb.cat4 : pb.cat3;
CatTemp[i].MainCatId = pb.main_cid;
CatTemp[i].MainCatName = pb.main_cat_name;
CatTemp[i].country = pb.country;
CatTemp[i].logisticsTime = pb.logisticsTime;
}
if (CatTemp[i].FromType == "阿里巴巴")
{
pb.from_url = "https://detail.1688.com/offer/" + CatTemp[i].FromId + ".html";
AlibabaProductGet ali = new AlibabaProductGet(pb);
ali.IsPinduoduo = true;
ali.Get();
pb = ali.Product;
CatTemp[i].Titlte = pb.name;
}
if (CatTemp[i].FromType == "微店")
{
WeiDianProductCollect wd = new WeiDianProductCollect(CatTemp[i]);
wd.Get();
pb = wd.pb;
CatTemp[i].Titlte = pb.name;
}
if (CatTemp[i].FromType == "京喜")
{
pb.from_url = "https://item.m.jd.com/product/" + CatTemp[i].FromId + ".html";
JingXiCollect jx = new JingXiCollect(pb);
jx.Get();
pb = jx.Product;
CatTemp[i].Titlte = pb.name;
}
Thread.Sleep(100);
}
if (CatTemp[i].CatId > 0)
{
UpdateToDataBase(CatTemp[i]);
var ps = ProductStock.Find(p => p.FromId == CatTemp[i].FromId && p.Titlte == CatTemp[i].Titlte);
ps = CatTemp[i];
continue;
}
if (string.IsNullOrEmpty(CatTemp[i].Titlte))
continue;
FromTitleToCat ft = new FromTitleToCat();
ft.TaobaoProduct = CatTemp[i];
ft.Title = CatTemp[i].Titlte;
ft.AddToStock = true;
Threadx.ThreadListWait(ref ts, new Thread(ft.GetLoad), CatThreadCount);
Thread.Sleep(100);
}
catch
{
}
}
}
/// <summary>
/// 添加数据到数据库缓存
/// </summary>
/// <param name="p"></param>
public static void AddToDataBase(TaobaoProductBase p)
{
string content = p.FromId + "," + p.FromType + "," + p.Titlte + "," + p.Cat1 + "," + p.Cat2 + "," +
p.Cat3 + "," + p.Cat4 + "," + p.CatId + "," + p.MainCatId + "," + p.MainCatName + "," + p.MainImage + "," +
p.Price + "," + p.SaleCount + "," + p.ShopName + "," + p.AddPrice;
if (!string.IsNullOrEmpty(p.ViGoodsName))
content += "," + p.ViGoodsId + "," + p.ViGoodsName + "," + p.ViPrice + "," + p.ViPriceMaxMin;
string sql = "insert into Product(content,fromid) values('" + SqliteHelper.ReplaceSqlx(content) + "','" + p.guid + "')";
try
{
SqliteHelper.ExecuteNonQuery(sql);
}
catch
{
}
}
public static void UpdateToDataBase(TaobaoProductBase p)
{
string content = p.FromId + "," + p.FromType + "," + p.Titlte + "," + p.Cat1 + "," + p.Cat2 + "," +
p.Cat3 + "," + p.Cat4 + "," + p.CatId + "," + p.MainCatId + "," + p.MainCatName + "," + p.MainImage + "," +
p.Price + "," + p.SaleCount + "," + p.ShopName + "," + p.AddPrice;
if (!string.IsNullOrEmpty(p.ViGoodsName))
content += "," + p.ViGoodsId + "," + p.ViGoodsName + "," + p.ViPrice + "," + p.ViPriceMaxMin;
string sql = "update Product set content= '" + SqliteHelper.ReplaceSqlx(content) + "' where fromid='" + p.guid + "'";
try
{
SqliteHelper.ExecuteNonQuery(sql);
}
catch
{
}
}
/// <summary>
/// 删除数据 ID为空则删除全部数据
/// </summary>
/// <param name="id"></param>
public static void Delete(string id)
{
string sql = "DELETE FROM Product WHERE fromid = '" + id + "' ";
if (string.IsNullOrEmpty(id))
sql = "DELETE FROM Product ";
try
{
SqliteHelper.ExecuteNonQuery(sql);
}
catch
{
}
}
/// <summary>
/// 加载缓存
/// </summary>
public void LoadStock()
{
SqliteHelper.CreateProductTable();
formIdlist.Clear();
new Thread(LoadPbbStock).Start();
DataTable dt = SqliteHelper.ExecuteTable("select fromid,content from Product");
for (int i = 0; dt != null && i < dt.Rows.Count; i++)
{
string s = dt.Rows[i]["content"].ToString();
formIdlist.Add(dt.Rows[i]["fromid"].ToString());
if (string.IsNullOrEmpty(s) || !s.Contains(","))
continue;
string[] ll = s.Split(',');
if (ll.Length != 13 && ll.Length != 15 && ll.Length != 19)
continue;
try
{
TaobaoProductBase t = new TaobaoProductBase();
if (string.IsNullOrEmpty(ll[0]))
continue;
t.FromId = long.Parse(ll[0]);
t.FromType = ll[1];
t.Titlte = ll[2].Replace("\",\"", "");
t.Cat1 = int.Parse(ll[3]);
t.Cat2 = int.Parse(ll[4]);
t.Cat3 = int.Parse(ll[5]);
t.Cat4 = int.Parse(ll[6]);
t.CatId = int.Parse(ll[7]);
t.MainCatId = int.Parse(ll[8]);
t.MainCatName = ll[9];
if (t.MainCatId == 0)
{
FromTitleToCat f = new FromTitleToCat();
t.MainCatId = f.GetMainCatId(t.Cat1);
t.MainCatName = f.MainCatName;
}
t.MainImage = int.Parse(ll[10]);
t.Price = decimal.Parse(ll[11]);
t.SaleCount = int.Parse(ll[12]);
t.guid = dt.Rows[i]["fromid"].ToString();
if (ll.Length == 15 || ll.Length == 19)
{
t.ShopName = ll[13];
t.AddPrice = int.Parse(ll[14]);
}
if (ll.Length > 15)
{
long.TryParse(ll[15], out t.ViGoodsId);
t.ViGoodsName = ll[16];
t.ViPrice = ll[17];
t.ViPriceMaxMin = ll[18];
string[] strPrice = t.ViPriceMaxMin.Split(':');
if (strPrice.Length == 3)
{
t.ViPriceMin = (int)(decimal.Parse(strPrice[0]) * 100);
t.ViPriceMax = (int)(decimal.Parse(strPrice[1]) * 100);
t.ViExpressPrice = (int)(decimal.Parse(strPrice[2]));
}
}
//if (t.ViGoodsName != "6")
// 临时开放转换淘宝
//if (t.ViGoodsName != "6" && !((t.FromType == "淘宝" || t.FromType == "阿里巴巴") && string.IsNullOrEmpty(t.ViGoodsName)))
if (t.ViGoodsName != "6" && t.ViGoodsName != "1" && !((t.FromType == "淘宝" || t.FromType == "阿里巴巴" || t.FromType == "微店" || t.FromType == "京喜") && string.IsNullOrEmpty(t.ViGoodsName)))
continue;
ProductStock.Add(t);
//ProductTempStock.Add(t);
}
catch
{
}
}
GetMainCat();
}
public void LoadPbbStock()
{
string tempFile = "temp/PinBaoBao.pbb";
string[] l = FileBase.ReadAllLines(tempFile, Encoding.Default);
if (l == null || l.Length == 0)
return;
foreach (string s in l)
{
if (string.IsNullOrEmpty(s) || !s.Contains(","))
continue;
string[] ll = s.Split(',');
if (ll.Length != 13 && ll.Length != 15)
continue;
try
{
TaobaoProductBase t = new TaobaoProductBase();
if (string.IsNullOrEmpty(ll[0]))
continue;
t.FromId = long.Parse(ll[0]);
t.FromType = ll[1];
t.Titlte = ll[2].Replace("\",\"", "");
t.Cat1 = int.Parse(ll[3]);
t.Cat2 = int.Parse(ll[4]);
t.Cat3 = int.Parse(ll[5]);
t.Cat4 = int.Parse(ll[6]);
t.CatId = int.Parse(ll[7]);
t.MainCatId = int.Parse(ll[8]);
t.MainCatName = ll[9];
t.MainImage = int.Parse(ll[10]);
t.Price = decimal.Parse(ll[11]);
t.SaleCount = int.Parse(ll[12]);
if (ll.Length == 15)
t.ShopName = ll[13];
if (ll.Length == 15)
t.AddPrice = int.Parse(ll[14]);
ProductStock.Add(t);
AddToDataBase(t);
//ProductTempStock.Add(t);
}
catch
{
}
}
try
{
FileBase.Delete(tempFile);
}
catch
{
}
}
/// <summary>
/// 下架无流量
/// </summary>
public void GetOffSalesNoPV()
{
bool setOnLine = SetOnline;
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.isOnline = !setOnLine;
p.NoSold = NoSold;
p.NoVisit = NoVisit;
p.NoNeerReplace = NoNeerReplace;
p.NoNeerDays = NoNeerDays;
p.VisitCount = VisitCount;
p.OffOroduct = OffProduct;
p.OffProductCount = OffProductCount;
Threadx.ThreadListWait(ref ts, new Thread(p.GetOffSalesNoPV), ShopThreadCount);
}
Threadx.ThreadListWait(ref ts);
}
/// <summary>
/// 删除商品
/// </summary>
public void GetDelProduct()
{
bool setOnLine = SetOnline;
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.isOnline = !setOnLine;
p.OffOroduct = OffProduct;
p.OffProductCount = OffProductCount;
Threadx.ThreadListWait(ref ts, new Thread(p.GetDelProduct), ShopThreadCount);
}
Threadx.ThreadListWait(ref ts);
}
public void GetAllOnline()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
Threadx.ThreadListWait(ref ts, new Thread(p.GetAllOnline), ShopThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetDelKeyWordOnline()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
p.delTitle = delTitle;
Threadx.ThreadListWait(ref ts, new Thread(p.GetDelTitleProduct), CustomThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetDelGoodOnline()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
p.delTitle = delTitle;
Threadx.ThreadListWait(ref ts, new Thread(p.GetDelKeyWordOnline), CustomThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetDelKeyWordGoodOnline()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectClearDown || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
p.delTitle = delTitle;
Threadx.ThreadListWait(ref ts, new Thread(p.GetDelKeyWordOnline), CustomThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void DelKeyGoodOnline()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
Threadx.ThreadListWait(ref ts, new Thread(p.GetDelKeyGood), CustomThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetDelArrangeOnline()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
//p.delTitle = delTitle;
Threadx.ThreadListWait(ref ts, new Thread(p.GetDelArrangeProduct), ShopThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetAllOnlineIds(bool statusFlag)
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = statusFlag;
Threadx.ThreadListWait(ref ts, new Thread(p.GetAllOnlineIds), ShopThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetAllLoopOnlineIds(bool statusFlag)
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = statusFlag;
Threadx.ThreadListWait(ref ts, new Thread(p.GetAllOnlineIds), ShopThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetAutoVisit()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetVisitProductNew(Name, shop);
p.ReplaceModel = true;
Threadx.ThreadListWait(ref ts, new Thread(p.GetOnOrOff), ShopThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetGroupVisit()
{
List<Thread> ts = new List<Thread>();
var p = new GetVisitProductNew(Name, Shop);
p.ReplaceModel = true;
Threadx.ThreadListWait(ref ts, new Thread(p.GetOnOrOff), ShopThreadCount);
Thread.Sleep(100);
Threadx.ThreadListWait(ref ts);
}
public void GetGroupVisitIds()
{
List<Thread> ts = new List<Thread>();
var p = new GetVisitProductNew(Name, Shop);
p.ReplaceModel = true;
p.isOnline = isOnline;
Threadx.ThreadListWait(ref ts, new Thread(p.GetOnOrOffIds), ShopThreadCount);
Thread.Sleep(100);
Threadx.ThreadListWait(ref ts);
}
public void SetAutoOnGoodsStatus()
{
GetAllOnlineIds(false);
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
if (GetPun(shop.Cookies) != "无惩罚")
continue;
var p = new GetProductOnlineClass(Name, shop);
OnOrOffStatus onOrOffStatus = new OnOrOffStatus();
onOrOffStatus.shopName = shop.ShopName;
onOrOffStatus.onStatus = "上架开始执行";
onOrOffStatusList.Add(onOrOffStatus);
Threadx.ThreadListWait(ref ts, new Thread(p.UploadAutoOnMethod), 20);
}
Threadx.ThreadListWait(ref ts);
}
public void SetAutoOffGoodsStatus()
{
GetAllOnlineIds(true);
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
if (GetPun(shop.Cookies) != "无惩罚")
continue;
var p = new GetProductOnlineClass(Name, shop);
OnOrOffStatus onOrOffStatus = new OnOrOffStatus();
onOrOffStatus.shopName = shop.ShopName;
onOrOffStatus.offStatus = "下架开始执行";
onOrOffStatusList.Add(onOrOffStatus);
Threadx.ThreadListWait(ref ts, new Thread(p.UploadAutoOffMethod), 20);
}
}
public void SetLoopOffGoodsStatus()
{
RunningLoop = true;
//GetAllLoopOnlineIds(true);
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count && RunningLoop; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
if (GetPun(shop.Cookies) != "无惩罚")
continue;
var p = new GetProductOnlineClass(Name, shop);
OnOrOffStatus onOrOffStatus = new OnOrOffStatus();
onOrOffStatus.shopName = shop.ShopName;
onOrOffStatus.offStatus = "循环下架开始执行";
onOrOffStatusList.Add(onOrOffStatus);
Threadx.ThreadListWait(ref ts, new Thread(p.UploadLoopOffMethod), GetShopLoginInfo.Shops.Count);
}
}
public void SetLoopOnGoodsStatus()
{
RunningLoop = true;
if (RunningLoop)
{
new Thread(GetProductOnlineClass.UploadLoopOnMethod).Start();
}
}
public string GetPun(string cookies)
{
string url = "https://mms.pinduoduo.com/earth/api/mallPunishment";
string refere = "https://mms.pinduoduo.com/Pdd.html";
string data = "{\"size\":\"5\" }";
//第一页匹配结果
string html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data, CpsSetAllGoods.getAnti0aon());
//惩罚店铺
int level = BaseRegex.GetIntJson(ref html, "punishmentLevel");
string punishment = string.Empty;
if (level == 1)
{
punishment = "一级惩罚";
}
else if (level == 2)
{
punishment = "二级惩罚";
}
else if (level == 3)
{
punishment = "三级惩罚";
}
else
{
punishment = "无惩罚";
}
return punishment;
}
/// <summary>
/// 群控删除
/// </summary>
public void GetDelGroupProduct()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
p.minPrice = MinPrice;
p.maxPrice = MaxPrice;
Threadx.ThreadListWait(ref ts, new Thread(p.GetDelGroupProduct), CustomThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetRestoreProduct()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
Threadx.ThreadListWait(ref ts, new Thread(p.GetRestoreProduct), CustomThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetRestoreGoodProduct()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectClearDown || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
Threadx.ThreadListWait(ref ts, new Thread(p.GetRestoreProduct), CustomThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public void GetDelGroupOffProduct()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectReplace || !shop.Showed)
continue;
var p = new GetProductOnlineClass(Name, shop);
p.ReplaceModel = true;
p.isOnline = true;
p.minPrice = MinPrice;
p.maxPrice = MaxPrice;
Threadx.ThreadListWait(ref ts, new Thread(p.GetDelGroupOffProduct), CustomThreadCount);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
}
public class UploadShopControl
{
public string Name;
public ShopChatBase Shop;
public ShopChatBase OldShop;
public bool SetNewTitle = false;
public static long endAdvanceTime = 0;
public TaobaoProductBase product;
public List<TaobaoProductBase> productList = new List<TaobaoProductBase>();
public UploadShopControl(string name, ShopChatBase shop)
{
Name = name;
Shop = shop;
}
public UploadShopControl(string name, ShopChatBase shop, ShopChatBase oldShop)
{
Name = name;
Shop = shop;
OldShop = oldShop;
}
public UploadShopControl(string name, ShopChatBase shop, bool setNewTitle)
{
Name = name;
Shop = shop;
SetNewTitle = setNewTitle;
}
public void ClearTitle()
{
if (Shop.ExpressId == 0)
{
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
if (Shop.ExpressId == 0)
{
Thread.Sleep(10000);
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
}
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
if (Shop.ExpressId == 0)
{
LogSave.Add(Name, "运费模板未找到");
Shop.Message = "请设置运费模板";
UploadPinduoduoMain.ShopReplaceTemp.Add(Shop);
return;
}
}
for (int i = 0; i < Shop.OnlineProduct.Count; i++)
{
if (!SetNewTitle && (string.IsNullOrEmpty(Shop.OnlineProduct[i].Titlte) || !Shop.OnlineProduct[i].Titlte.Contains("✅")))
continue;
new BuildNewTitle(Shop, Shop.OnlineProduct[i].GoodsId, "", Name, SetNewTitle).Set();
Thread.Sleep(200);
}
LogSave.Add(Name, "店铺执行完成:" + Shop.ShopName);
}
public void SetAdvanceSale()
{
if (Shop.ExpressId == 0)
{
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
if (Shop.ExpressId == 0)
{
Thread.Sleep(10000);
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
}
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
if (Shop.ExpressId == 0)
{
LogSave.Add(Name, "运费模板未找到");
Shop.Message = "请设置运费模板";
UploadPinduoduoMain.ShopReplaceTemp.Add(Shop);
return;
}
}
for (int i = 0; i < Shop.OnlineProduct.Count; i++)
{
BuildNewTitle.endAdvanceTime = endAdvanceTime;
if (Shop.OnlineProduct[i] == null || string.IsNullOrEmpty(Shop.OnlineProduct[i].Titlte) || Shop.OnlineProduct[i].Titlte.Contains("预售"))
continue;
new BuildNewTitle(Shop, Shop.OnlineProduct[i].GoodsId, "", Name, SetNewTitle).SetAdvanceSale();
Thread.Sleep(200);
}
LogSave.Add(Name, "店铺执行完成:" + Shop.ShopName);
}
public void GetReplacePrice()
{
bool first = true;
Shop.CanUpload = true;
Shop.UpCount = 0;
DateTime begen = DateTime.Now;
List<Thread> ts = new List<Thread>();
new Thread(new DeleteRejectProduct(Shop).Get).Start();
UpPinduoduoProduct up = new UpPinduoduoProduct(Shop, Name);
up.IniProp(Shop.MainCatId, Shop.Cookies);
if (Shop.ExpressId == 0)
{
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
if (Shop.ExpressId == 0)
{
Thread.Sleep(10000);
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
}
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
if (Shop.ExpressId == 0)
{
LogSave.Add(Name, "运费模板未找到");
Shop.Message = "请设置运费模板";
UploadPinduoduoMain.ShopReplaceTemp.Add(Shop);
return;
}
}
string[] fl = FileBase.ReadAllLines("temp/upsame/" + Shop.Name + "edit.tjm");
if (fl != null)
{
foreach (string s in fl)
{
if (string.IsNullOrEmpty(s) || !s.Contains(","))
continue;
string[] li = s.Split(',');
long id = 0;
if (li.Length != 2 || !long.TryParse(li[0], out id))
continue;
DateTime dt = DateTime.Parse(li[1]);
if (UpPinduoduoProduct.EditDayTemp.ContainsKey(id))
UpPinduoduoProduct.EditDayTemp[id] = dt;
else
UpPinduoduoProduct.EditDayTemp.Add(id, dt);
if (UploadPinduoduoMain.NoNeerReplace && dt > DateTime.Now.AddDays(-UploadPinduoduoMain.NoNeerDays))
{
var p = Shop.OnlineProduct.Find(t => t != null && t.GoodsId == id);
if (p == null)
continue;
Shop.OnlineProduct.Remove(p);
}
}
}
if (Shop.OnlineProduct.Count < 200)
{
LogSave.Add("商品数少于200的店铺不替换:" + Shop.ShopName);
Shop.Message = "商品数小于200不替换";
UploadPinduoduoMain.ShopReplaceTemp.Add(Shop);
return;
}
Shop.OnlineProduct.Sort((x, y) => x.GoodsId.CompareTo(y.GoodsId));
int repalceCount = 0, maxCount = Int32.MaxValue;
if (UploadPinduoduoMain.LimitReplace)
maxCount = UploadPinduoduoMain.ReplaceCount;
while (repalceCount < maxCount)
{
if (UploadPinduoduoMain.NoNeerReplace)
{
var list = UpPinduoduoProduct.EditDayTemp.ToList();
for (int i = 0; i < list.Count; i++)
{
if (list[i].Value < DateTime.Now.AddDays(-UploadPinduoduoMain.NoNeerDays))
continue;
var pp = Shop.OnlineProduct.Find(tt => tt != null && tt.GoodsId == list[i].Key);
if (pp != null)
{
Shop.OnlineProduct.Remove(pp);
LogSave.Add(Name, "商品最近替换过,跳过:" + list[i].Key);
Thread.Sleep(100);
}
}
}
repalceCount++;
TaobaoProductBase t = null;
if (UploadPinduoduoMain.DesShop)
t = UploadPinduoduoMain.ProductStock.Find(
tb =>
tb != null && !tb.Uped && tb.UseShopName != Shop.ShopName && tb.ShopName != "" && tb.ShopName == Shop.ShopName &&
(tb.MainCatId == Shop.MainCatId ||
"5,4,11,3,6,12,10".Contains(Shop.MainCatId.ToString()) &&
"5,4,11,3,6,12,10".Contains(tb.MainCatId.ToString())));
else
t = UploadPinduoduoMain.ProductStock.Find(
tb =>
tb != null && !tb.Uped && tb.UseShopName != Shop.ShopName &&
(tb.MainCatId == Shop.MainCatId ||
"5,4,11,3,6,12,10".Contains(Shop.MainCatId.ToString()) &&
"5,4,11,3,6,12,10".Contains(tb.MainCatId.ToString())));
if (t == null)
{
LogSave.Add("无匹配数据,结束替换:" + Shop.ShopName);
Shop.Message = "无匹配数据,请增加备用数据";
UploadPinduoduoMain.ShopReplaceTemp.Add(Shop);
return;
}
UploadPinduoduoMain.ProductStock.Remove(t);
if (Shop.UpFromIds.ContainsKey(t.FromId) && Shop.UpFromIds[t.FromId] > 3)
{
t.FindTimes++;
if (t.FindTimes < 20)
{
UploadPinduoduoMain.ProductStock.Add(t);
}
else
{
UploadPinduoduoMain.Delete(t.guid);
}
LogSave.Add(Name, Shop.Name + " 遇到裂变数据,跳过 " + t.FromId + " 等待数据中...");
Thread.Sleep(1000);
continue;
}
if (!Shop.UpFromIds.ContainsKey(t.FromId))
Shop.UpFromIds.Add(t.FromId, 1);
else
Shop.UpFromIds[t.FromId]++;
t.Uped = true;
t.UserTimes++;
t.UseShopName = Shop.ShopName;
UploadPinduoduoMain.Delete(t.guid);
//========================采集商品===========================
ProductCollectBase pb = new ProductCollectBase();
if (TaobaoMobileCollect.ProductTemp.ContainsKey(t.FromId))
{
pb = TaobaoMobileCollect.ProductTemp[t.FromId].Clone();
}
else
{
if (t.FromType == "拼多多")
{
PinduoduoProductCollect pp = new PinduoduoProductCollect(Name, t);
pp.Get();
if (!TaobaoMobileCollect.ProductTemp.ContainsKey(t.FromId))
{
LogSave.Add("未找到商品数据:" + t.FromId);
continue;
}
}
else if (t.FromType == "阿里巴巴")
{
pb.from_url = "https://detail.1688.com/offer/" + t.FromId + ".html";
AlibabaProductGet ali = new AlibabaProductGet(pb);
ali.IsPinduoduo = true;
ali.Get();
if (!ali.OnSale)
{
LogSave.Add(Name, "未找到商品数据:" + t.FromId);
continue;
}
}
else
{
pb.from_url = "https://item.taobao.com/item.htm?id=" + t.FromId;
pb.from_id = t.FromId;
TaobaoMobileCollect tm = new TaobaoMobileCollect(pb);
tm.Pinduoduo = true;
tm.Name = Name;
tm.Get();
if (!tm.GetSuccess)
{
LogSave.Add(Name, "未找到商品数据:" + t.FromId);
continue;
}
}
if (TaobaoMobileCollect.ProductTemp.ContainsKey(t.FromId))
pb = TaobaoMobileCollect.ProductTemp[t.FromId].Clone();
else
{
LogSave.Add(Name, "未找到商品数据:" + t.FromId);
continue;
}
}
//======================采集商品信息结束=======================
decimal price = pb.price;
for (int i = 0; i < pb.SkuMaps.Count; i++)
{
if (price < pb.SkuMaps[i].price)
price = pb.SkuMaps[i].price;
}
decimal newPrice = new UploadPinduoduoSet(Shop, null, null).WhitePriceBuild(price, UploadPinduoduoMain.MultiPrice, pb.express_price) / 100m;
var p = Shop.OnlineProduct.Find(pd => pd != null && pd.Price > newPrice * 0.4m && pd.Price < newPrice * 2.5m);
if (p == null)
{
if (t.UserTimes < 2)
{
UploadPinduoduoMain.ProductStock.Add(t);
UploadPinduoduoMain.AddToDataBase(t);
LogSave.Add("未匹配到数据,再次进入队列:" + t.FromId);
continue;
}
UploadPinduoduoMain.ProductStock.Add(t);
UploadPinduoduoMain.AddToDataBase(t);
LogSave.Add("未匹配到数据,丢弃:" + t.FromId);
continue;
}
Shop.OnlineProduct.Remove(p);
if (UploadPinduoduoMain.NoNeerReplace && UpPinduoduoProduct.EditDayTemp.ContainsKey(p.GoodsId) &&
DateTime.Now.AddDays(-UpPinduoduoProduct.NoReplaceDay) > UpPinduoduoProduct.EditDayTemp[p.GoodsId])
{
Thread.Sleep(100);
t.Message = "最近更新不需替换";
UploadPinduoduoMain.ProductReplaceTemp.Add(p);
continue;
}
if (UploadPinduoduoMain.Irregularities && IrregularitiesWordFun(t.Titlte))
{
LogSave.Add(Name, Shop.Name + " 遇到品牌数据,跳过 " + t.FromId + " 该产品...");
Thread.Sleep(1000);
continue;
}
LogSave.Add("数据匹配成功,开始替换:" + t.FromId);
var u = new UploadPinduoduoSet(Shop, Name, t);
u.us = p;
Threadx.ThreadListWait(ref ts, new Thread(u.Get), UploadPinduoduoMain.SingleThreadCount);
Thread.Sleep(5000 * UploadPinduoduoMain.SingleThreadCount);
if (first && UploadPinduoduoMain.SingleThreadCount > 1)
{
first = false;
Thread.Sleep(20 * 1000);
}
}
Threadx.ThreadListWait(ref ts);
}
public void GetReplaceRes()
{
if (Shop.ResurVioSalesProduct.Count == 0)
{
LogSave.Add(Name, "店铺商品都是有销量的,没有可以替换的商品。");
TaobaoProductBase productx = new TaobaoProductBase();
productx.GoodsId = product.GoodsId;
productx.Message = "店铺商品都是有销量的,没有可以替换的商品。";
UploadPinduoduoMain.ProductResurVioTemp.Add(productx);
return;
}
int randx = new Random(Guid.NewGuid().GetHashCode()).Next(0, Shop.ResurVioSalesProduct.Count - 1);
var p = Shop.ResurVioSalesProduct[randx];
GetResForm(product.GoodsId, p.GoodsId, true);
}
public void GetAddRes()
{
//if (Shop.ResurVioSalesProduct.Count == 0)
// return;
//int randx = new Random(Guid.NewGuid().GetHashCode()).Next(0, OldShop.ResurVioSalesProduct.Count - 1);
//var p = OldShop.ResurVioSalesProduct[randx];
GetResForm(product.GoodsId, 0, false);
}
public void GetResForm(long pid, long oldpid, bool upFlag)
{
GetProductDetail ge = new GetProductDetail(upFlag == true ? Shop : OldShop, "复活违规");
var r = ge.Get(pid);
if (r == null)
{
if (OldShop.APIMessage == "请先购买API再上传" || Shop.APIMessage == "请先购买API再上传")
{
LogSave.Add(Name, "店铺没有购买Api服务,获取违规商品详情失败。");
TaobaoProductBase productx = new TaobaoProductBase();
productx.GoodsId = pid;
productx.Message = "店铺没有购买Api服务,获取违规商品详情失败。";
UploadPinduoduoMain.ProductResurVioTemp.Add(productx);
}
return;
}
string skuApiStringNew = "", skuString = "";
int maxPriceNewx = 0, minPriceNewx = 1000000;
for (int i = 0; i < r.sku_list.Count; i++)
{
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);
string specStr = "";
for (int j = 0; j < r.sku_list[i].spec.Count; j++)
{
specStr += ",{\"parent_name\":\"" + r.sku_list[i].spec[j].parent_name + "\",\"parent_id\":" +
r.sku_list[i].spec[j].parent_id + ",\"spec_name\":\"" + r.sku_list[i].spec[j].spec_name + "\",\"spec_id\":" +
r.sku_list[i].spec[j].spec_id + "}";
}
specStr = "[" + specStr.Substring(1) + "]";
skuString = ",{\"is_onsale\":" + r.sku_list[i].is_onsale + ",\"limit_quantity\":" + r.sku_list[i].limit_quantity +
",\"quantity_delta\":" + r.sku_list[i].limit_quantity + ",\"thumb_url\":\"\"," +
"\"multi_price\":" + r.sku_list[i].multi_price + ",\"price\":" +
r.sku_list[i].price + ",\"out_sku_sn\":\"" + r.sku_list[i].out_sku_sn + "\",\"id\":0,\"spec\":" +
specStr + ",\"weight\":1000}";
skuApiStringNew += ",{\"is_onsale\":" + r.sku_list[i].is_onsale + ",\"limit_quantity\":" + r.sku_list[i].limit_quantity +
",\"quantity_delta\":" + 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\":1,\"spec_id_list\":\"[" + spec + "]\"}";
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;
}
string addContent = ",\"fabric\":" + r.fabricx + ",\"fabric_content\":" + r.fabric_contentx;
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
r.cat_id = PinduoduoCatList.GetNewCat3(r.cat_id);
if (r.market_price >= maxPriceNewx * 5.0)
r.market_price = 2 * maxPriceNewx;
if (upFlag)
api.Data.Add("goods_id", oldpid.ToString());
api.Data.Add("goods_name", BaseClass.SubCharLength(r.goods_name.Replace("✅", "").Replace("◆", ""), 60));
api.Data.Add("goods_type", "1");
api.Data.Add("goods_desc", r.goods_desc);
api.Data.Add("cat_id", r.cat_id.ToString());
api.Data.Add("tiny_name", "");
api.Data.Add("country_id", "0");
api.Data.Add("market_price", r.market_price.ToString());
api.Data.Add("is_pre_sale", "false");
api.Data.Add("shipment_limit_second", "172800");
api.Data.Add("cost_template_id", upFlag == true ? r.cost_template_id.ToString() : Shop.ExpressId.ToString());
api.Data.Add("customer_num", UploadPinduoduoMain.GroupCount.ToString());//团购人数
if (!UploadPinduoduoMain.limitCount)
{
api.Data.Add("buy_limit", UploadPinduoduoMain.LimitBuy.ToString());
api.Data.Add("order_limit", UploadPinduoduoMain.LimitBuy.ToString());
}
api.Data.Add("is_refundable", "true");
api.Data.Add("second_hand", "false");
api.Data.Add("is_folt", "true");
if (!string.IsNullOrEmpty(addContent))
{
int fabric = BaseRegex.GetIntJson(ref addContent, "fabric");
int fabric_content = BaseRegex.GetIntJson(ref addContent, "fabric_content");
api.Data.Add("fabric", fabric.ToString());
api.Data.Add("fabric_content", fabric_content.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["goods_desc"] = r.goods_desc;
string goods_properties = "";
for (int i = 0; i < r.goods_property_list.Count; i++)
{
var p = r.goods_property_list[i];
goods_properties += ",{\"template_pid\":" + p.template_pid + ",\"vid\":" + p.vid + ",\"value\":\"" + p.vvalue + "\",\"value_unit\":\"" + p.punit + "\"}";
}
if (!string.IsNullOrEmpty(goods_properties))
api.Data.Add("goods_properties", "[" + goods_properties.Substring(1) + "]");
api.FromWeiDian = true;
string imageString = "";
//构造carousel_gallery 轮播图
string carousel_gallery = string.Empty;
if (r.carousel_gallery_list != null & r.carousel_gallery_list.Count > 0)
{
for (int i = 0; i < r.carousel_gallery_list.Count; i++)
{
carousel_gallery += ",\"" + r.carousel_gallery_list[i] + "\"";
imageString += ",{\"url\":\"" + r.carousel_gallery_list[i] + "\",\"width\":640,\"height\":640,\"type\":\"1\"}";
}
}
if (!string.IsNullOrEmpty(carousel_gallery))
carousel_gallery = carousel_gallery.Substring(1);
api.Data.Add("carousel_gallery", "[" + carousel_gallery + "]");
//构造detail_gallery商品详情图片
string detail_gallery = "";
for (int j = 0; j < r.detail_gallery_list.Count; j++)
{
if (r.detail_gallery_list.Count > 5 && j == 0 || r.detail_gallery_list.Count > 8 && j == r.detail_gallery_list.Count - 1)//不要第一张图和最后一张
{
continue;
}
string urlImg = r.detail_gallery_list[j];
if (!urlImg.StartsWith("http"))
urlImg = "http:" + urlImg;
string exe = Path.GetExtension(urlImg).ToLower();
if (exe != ".jpeg" && exe != ".jpg" && exe != ".png")
continue;
detail_gallery += ",\"" + urlImg + "\"";
imageString += ",{\"url\":\"" + urlImg + "\",\"width\":640,\"height\":640,\"type\":\"2\"}";
}
if (!string.IsNullOrEmpty(detail_gallery))
{
detail_gallery = detail_gallery.Substring(1);
}
api.Data.Add("detail_gallery", "[" + detail_gallery + "]");
api.Data.Add("gallery", imageString.Substring(1));
if (",2,6586,6785,6883,6758,6536,6630,6398,".Contains("," + r.cat_id + ","))//食品
{
api.Data.Add("shelf_life", "300");
api.Data.Add("start_production_date", BaseClass.GetTime(DateTime.Now.AddDays(-5)).ToString());
api.Data.Add("end_production_date", BaseClass.GetTime(DateTime.Now).ToString());
}
ProductResurBase resur = new ProductResurBase();
resur.FromId = pid;
resur.FormShopName = OldShop == null ? Shop.ShopName : OldShop.ShopName;
resur.GoodId = oldpid == 0 ? pid : oldpid;
resur.ShopName = Shop.ShopName;
resur.Title = r.goods_name;
TaobaoProductBase product = new TaobaoProductBase();
product.GoodsId = pid;
product.Message = "商品开始处理";
string html = "";
PinduoduoApiGetProduct apix = new PinduoduoApiGetProduct(Shop);
html = apix.GetRelation(r.goods_id.ToString());
long upid = 0;
// 有获取到对应的上家id
if (html.Contains("out_goods_id") && html.Contains("out_goods_platform"))
upid = BaseRegex.GetLongJson(ref html, "out_goods_id");
else
upid = Randomx.GetId(100000, 9999999) * (long)Randomx.GetId(10, 99999);
string mustCode = "";
var pb = new ProductCollectBase();
string properties = UploadPinduoduoProperties.GetNew(r.cat_id, 0, ref pb, ref Shop, out mustCode);
if (upFlag)
{
TaobaoProductBase us = new TaobaoProductBase();
us.FromId = oldpid;
us.GoodsId = oldpid;
UploadPinduoduoDeleteSku upx = new UploadPinduoduoDeleteSku(Name, Shop, us, "", "");
upx.pb = new ProductCollectBase();
upx.pb.name = r.goods_name;
upx.pb.cat_id = r.cat_id;
upx.Cat1 = 0;
upx.MaxPrice = maxPriceNewx;
upx.MinPrice = minPriceNewx;
upx.NewUpId = upid;
upx.skus = "[" + skuString.Substring(1) + "]";
foreach (KeyValuePair<string, string> key in api.Data)
{
upx.Data.Add(key.Key, key.Value);
}
bool success = upx.GetNew();
//if (api.Data.ContainsKey("skus"))
// api.Data.Remove("skus");
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
return;
html = api.UpdataNew();
if (html.Contains("调用过于频繁"))
{
Thread.Sleep(5000);
html = api.UpdataNew();
Thread.Sleep(2000);
}
if (html.Contains("该类目商品不允许设置限购,请设置单次限量为999999"))
{
api.Data["buy_limit"] = "999999";
api.Data["order_limit"] = "999999";
html = api.UpdataNew();
if (html.Contains("调用过于频繁"))
{
Thread.Sleep(5000);
html = api.UpdataNew();
Thread.Sleep(2000);
}
}
if (!string.IsNullOrEmpty(html) && html.Contains("\"error_msg\""))
{
string error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
LogSave.Add("复活违规", "替换商品失败,原因:" + error_msg);
resur.Status = "替换商品失败:" + error_msg;
}
else
{
string goodsidx = BaseRegex.GetStringJson(ref html, "goods_id");
LogSave.Add("复活违规", "替换商品成功:" + goodsidx);
resur.Status = "替换商品成功";
string tempFile = "temp/resursame/" + Shop.ShopName + "edit.tjm";
string temp = pid + "," + DateTime.Now.ToString("yyyy-MM-dd") + "\r\n";
html = api.Relation(oldpid, upid, (int)(minPriceNewx * 0.96m), (int)(maxPriceNewx * 0.96m), 0, 0);
FileBase.AppendAllText(tempFile, temp);
}
}
else
{
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
return;
html = api.AddNew();
if (html.Contains("调用过于频繁"))
{
Thread.Sleep(5000);
html = api.Add();
Thread.Sleep(2000);
}
if (html.Contains("该类目商品不允许设置限购,请设置单次限量为999999"))
{
api.Data["buy_limit"] = "999999";
api.Data["order_limit"] = "999999";
html = api.UpdataNew();
if (html.Contains("调用过于频繁"))
{
Thread.Sleep(5000);
html = api.UpdataNew();
Thread.Sleep(2000);
}
}
if (html.Contains("存在多余或重复输入") && !string.IsNullOrEmpty(mustCode))
{
api.Data["goods_properties"] = "[" + mustCode.Substring(1) + "]";
html = api.Add();
}
if (!string.IsNullOrEmpty(html) && html.Contains("\"error_msg\""))
{
string error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
LogSave.Add("复活违规", "新增商品失败,原因:" + error_msg);
resur.Status = "新增商品失败:" + error_msg;
}
else
{
resur.GoodId = BaseRegex.GetLongJson(ref html, "goods_id");
html = api.Relation(resur.GoodId, upid, (int)(minPriceNewx * 0.96m), (int)(maxPriceNewx * 0.96m), 0, 0);
LogSave.Add("复活违规", "新增商品成功:" + resur.GoodId);
resur.Status = "新增商品成功";
}
}
UploadPinduoduoMain.ProductResurTemp.Add(resur);
UploadPinduoduoMain.ProductResurVioTemp.Add(product);
}
public void GetSysRes(long pid)
{
GetProductDetail ge = new GetProductDetail(Shop, "");
var r = ge.Get(pid);
if (r == null)
return;
string skuApiStringNew = "", skuString = "";
int maxPriceNewx = 0, minPriceNewx = 1000000;
for (int i = 0; i < r.sku_list.Count; i++)
{
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);
string specStr = "";
for (int j = 0; j < r.sku_list[i].spec.Count; j++)
{
specStr += ",{\"parent_name\":\"" + r.sku_list[i].spec[j].parent_name + "\",\"parent_id\":" +
r.sku_list[i].spec[j].parent_id + ",\"spec_name\":\"" + r.sku_list[i].spec[j].spec_name + "\",\"spec_id\":" +
r.sku_list[i].spec[j].spec_id + "}";
}
specStr = "[" + specStr.Substring(1) + "]";
skuString = ",{\"is_onsale\":" + r.sku_list[i].is_onsale + ",\"limit_quantity\":" + r.sku_list[i].limit_quantity +
",\"quantity_delta\":" + r.sku_list[i].limit_quantity + ",\"thumb_url\":\"\"," +
"\"multi_price\":" + r.sku_list[i].multi_price + ",\"price\":" +
r.sku_list[i].price + ",\"out_sku_sn\":\"" + r.sku_list[i].out_sku_sn + "\",\"id\":0,\"spec\":" +
specStr + ",\"weight\":1000}";
skuApiStringNew += ",{\"is_onsale\":" + r.sku_list[i].is_onsale + ",\"limit_quantity\":" + r.sku_list[i].limit_quantity +
",\"quantity_delta\":" + 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\":1,\"spec_id_list\":\"[" + spec + "]\"}";
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;
}
string addContent = ",\"fabric\":" + r.fabricx + ",\"fabric_content\":" + r.fabric_contentx;
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
r.cat_id = PinduoduoCatList.GetNewCat3(r.cat_id);
if (r.market_price >= maxPriceNewx * 5.0)
r.market_price = 2 * maxPriceNewx;
api.Data.Add("goods_id", pid.ToString());
api.Data.Add("goods_name", BaseClass.SubCharLength(r.goods_name.Replace("✅", "").Replace("◆", ""), 60));
api.Data.Add("goods_type", "1");
api.Data.Add("goods_desc", r.goods_desc);
api.Data.Add("cat_id", r.cat_id.ToString());
api.Data.Add("tiny_name", "");
api.Data.Add("country_id", "0");
api.Data.Add("market_price", r.market_price.ToString());
api.Data.Add("is_pre_sale", "false");
api.Data.Add("shipment_limit_second", "172800");
api.Data.Add("cost_template_id", r.cost_template_id.ToString());
api.Data.Add("customer_num", UploadPinduoduoMain.GroupCount.ToString());//团购人数
if (!UploadPinduoduoMain.limitCount)
{
api.Data.Add("buy_limit", UploadPinduoduoMain.LimitBuy.ToString());
api.Data.Add("order_limit", UploadPinduoduoMain.LimitBuy.ToString());
}
api.Data.Add("is_refundable", "true");
api.Data.Add("second_hand", "false");
api.Data.Add("is_folt", "true");
if (!string.IsNullOrEmpty(addContent))
{
int fabric = BaseRegex.GetIntJson(ref addContent, "fabric");
int fabric_content = BaseRegex.GetIntJson(ref addContent, "fabric_content");
api.Data.Add("fabric", fabric.ToString());
api.Data.Add("fabric_content", fabric_content.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["goods_desc"] = r.goods_desc;
string goods_properties = "";
for (int i = 0; i < r.goods_property_list.Count; i++)
{
var p = r.goods_property_list[i];
goods_properties += ",{\"template_pid\":" + p.template_pid + ",\"vid\":" + p.vid + ",\"value\":\"" + p.vvalue + "\",\"value_unit\":\"" + p.punit + "\"}";
}
if (!string.IsNullOrEmpty(goods_properties))
api.Data.Add("goods_properties", "[" + goods_properties.Substring(1) + "]");
string imageString = "";
//构造carousel_gallery 轮播图
string carousel_gallery = string.Empty;
if (r.carousel_gallery_list != null & r.carousel_gallery_list.Count > 0)
{
for (int i = 0; i < r.carousel_gallery_list.Count; i++)
{
carousel_gallery += ",\"" + r.carousel_gallery_list[i] + "\"";
imageString += ",{\"url\":\"" + r.carousel_gallery_list[i] + "\",\"width\":640,\"height\":640,\"type\":\"1\"}";
}
}
if (!string.IsNullOrEmpty(carousel_gallery))
carousel_gallery = carousel_gallery.Substring(1);
api.Data.Add("carousel_gallery", "[" + carousel_gallery + "]");
//构造detail_gallery商品详情图片
string detail_gallery = "";
for (int j = 0; j < r.detail_gallery_list.Count; j++)
{
if (r.detail_gallery_list.Count > 5 && j == 0 || r.detail_gallery_list.Count > 8 && j == r.detail_gallery_list.Count - 1)//不要第一张图和最后一张
{
continue;
}
string urlImg = r.detail_gallery_list[j];
if (!urlImg.StartsWith("http"))
urlImg = "http:" + urlImg;
string exe = Path.GetExtension(urlImg).ToLower();
if (exe != ".jpeg" && exe != ".jpg" && exe != ".png")
continue;
detail_gallery += ",\"" + urlImg + "\"";
imageString += ",{\"url\":\"" + urlImg + "\",\"width\":640,\"height\":640,\"type\":\"2\"}";
}
if (!string.IsNullOrEmpty(detail_gallery))
{
detail_gallery = detail_gallery.Substring(1);
}
api.Data.Add("detail_gallery", "[" + detail_gallery + "]");
api.Data.Add("gallery", imageString.Substring(1));
if (",2,6586,6785,6883,6758,6536,6630,6398,".Contains("," + r.cat_id + ","))//食品
{
api.Data.Add("shelf_life", "300");
api.Data.Add("start_production_date", BaseClass.GetTime(DateTime.Now.AddDays(-5)).ToString());
api.Data.Add("end_production_date", BaseClass.GetTime(DateTime.Now).ToString());
}
//string properties = UploadPinduoduoProperties.GetNew(r.cat_id, 0, ref pb, ref Shop, out mustCode);
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
return;
string html = api.UpdataNew();
if (html.Contains("调用过于频繁"))
{
Thread.Sleep(5000);
html = api.UpdataNew();
Thread.Sleep(2000);
}
if (html.Contains("该类目商品不允许设置限购,请设置单次限量为999999"))
{
api.Data["buy_limit"] = "999999";
api.Data["order_limit"] = "999999";
html = api.UpdataNew();
if (html.Contains("调用过于频繁"))
{
Thread.Sleep(5000);
html = api.UpdataNew();
Thread.Sleep(2000);
}
}
if (!string.IsNullOrEmpty(html) && html.Contains("\"error_msg\""))
{
string error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
LogSave.Add("同步库存", "更新商品失败,原因:" + error_msg);
//resur.Status = "替换商品失败:" + error_msg;
}
else
{
string goodsidx = BaseRegex.GetStringJson(ref html, "goods_id");
LogSave.Add("同步库存", "更新商品成功:" + goodsidx);
//resur.Status = "更新商品成功";
string tempFile = "temp/resursame/" + Shop.ShopName + "edit.tjm";
string temp = pid + "," + DateTime.Now.ToString("yyyy-MM-dd") + "\r\n";
api = new PinduoduoApiGetProduct(Shop);
long upid = 0;
int fromSite = 0;
if (upid == 0)
upid = Randomx.GetId(100000, 9999999) * (long)Randomx.GetId(10, 99999);
if (maxPriceNewx < 100000)
{
var minUpPrice = r.sku_list.Min(s => s.price);
var maxUpPrice = r.sku_list.Max(s => s.price);
var express_price = 0;
html = api.Relationx(pid, upid, (int)(minUpPrice * 100), (int)(maxUpPrice * 100), (int)(express_price * 100), fromSite);
if (!html.Contains("{\"is_success\":true"))
html = api.Relationx(pid, upid, (int)(minUpPrice * 100), (int)(maxUpPrice * 100), (int)(express_price * 100), fromSite);
if (!html.Contains("{\"is_success\":true"))
product.Message = "同步商品关联失败!";
}
}
//UploadPinduoduoMain.ProductResurTemp.Add(resur);
UploadPinduoduoMain.ProductResurVioTemp.Add(product);
}
//public void GetReplace()
//{
// Shop.CanUpload = true;
// Shop.UpCount = 0;
// DateTime begen = DateTime.Now;
// List<Thread> ts = new List<Thread>();
// new Thread(new DeleteRejectProduct(Shop).Get).Start();
// UpPinduoduoProduct up = new UpPinduoduoProduct(Shop, Name);
// up.IniProp(Shop.MainCatId, Shop.Cookies);
// string[] fl = FileBase.ReadAllLines("temp/upsame/" + Shop.Name + "edit.tjm");
// if (fl != null)
// {
// foreach (string s in fl)
// {
// if (string.IsNullOrEmpty(s) || !s.Contains(","))
// continue;
// string[] li = s.Split(',');
// long id;
// if (li.Length != 2 || !long.TryParse(li[0], out id))
// continue;
// DateTime dt = DateTime.Parse(li[1]);
// if (UpPinduoduoProduct.EditDayTemp.ContainsKey(id))
// UpPinduoduoProduct.EditDayTemp[id] = dt;
// else
// UpPinduoduoProduct.EditDayTemp.Add(id, dt);
// }
// }
// Shop.OnlineProduct.Sort((x,y)=>x.GoodsId.CompareTo(y.GoodsId));
// while(UploadPinduoduoMain.LimitReplace && Shop.OnlineProduct.Count > UploadPinduoduoMain.ReplaceCount)
// {
// UploadPinduoduoMain.DeleteIds.Add(Shop.OnlineProduct[UploadPinduoduoMain.ReplaceCount].GoodsId);
// Shop.OnlineProduct.RemoveAt(UploadPinduoduoMain.ReplaceCount);
// }
// while (UploadPinduoduoMain.RunningReplace && Shop.CanUpload && Shop.OnlineProduct.Count>0 )
// {
// var us = Shop.OnlineProduct[0];
// Shop.OnlineProduct.RemoveAt(0);
// if(us==null)
// continue;
// if(UploadPinduoduoMain.NoNeerReplace && UpPinduoduoProduct.EditDayTemp.ContainsKey(us.GoodsId) &&
// DateTime.Now.AddDays(-UpPinduoduoProduct.NoReplaceDay) > UpPinduoduoProduct.EditDayTemp[us.GoodsId])
// {
// Thread.Sleep(100);
// us.Message = "最近更新不需替换";
// UploadPinduoduoMain.ProductReplaceTemp.Add(us);
// }
// TaobaoProductBase t =
// UploadPinduoduoMain.ProductStock.Find(tb => tb != null && !tb.Uped && (tb.MainCatId == us.MainCatId || "5,4,11,3,6,12,10".Contains(us.MainCatId.ToString())&& "5,4,11,3,6,12,10".Contains(tb.MainCatId.ToString())));
// if (t == null)
// {
// if(begen.AddMinutes(3)>DateTime.Now)
// Thread.Sleep(100);
// us.Message = "无匹配数据";
// LogSave.Add(Name, Shop.Name + " 等待数据中...");
// UploadPinduoduoMain.ProductReplaceTemp.Add(us);
// continue;
// }
// t.Uped = true;
// UploadPinduoduoMain.ProductStock.Remove(t);
// if (Shop.ExpressId == 0)
// {
// Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId,Shop);
// if (Shop.ExpressId == 0)
// {
// Thread.Sleep(10000);
// Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
// }
// if (Shop.ExpressId == 0)
// {
// LogSave.Add(Name, "运费模板未找到");
// Shop.Message = "请设置运费模板";
// UploadPinduoduoMain.ShopReplaceTemp.Add(Shop);
// return;
// }
// }
// var u = new UploadPinduoduoSet(Shop, Name, t);
// u.us = us;
// Threadx.ThreadListWait(ref ts, new Thread(u.Get), UploadPinduoduoMain.SingleThreadCount);
// Thread.Sleep(5000* UploadPinduoduoMain.SingleThreadCount);
// }
// Threadx.ThreadListWait(ref ts);
//}
/// <summary>
/// 在违规店铺中替换
/// </summary>
public void Get()
{
int top = FileBase.Exists("maxtop.ini") ? 50 : 30;
bool ok = CanUser(Shop);
if (BaseClass.UserVersion == 110)
{
ok = true;
}
if (!ok)
{
Shop.Message = "请先续费";
UploadPinduoduoMain.ShopTemp.Add(Shop);
return;
}
if (!UploadPinduoduoMain.ShopTitles.ContainsKey(Shop.ShopName) && UploadPinduoduoMain.NoRepeat)
{
var p = new GetProductOnlineClass(Name, Shop);
p.ReplaceModel = true;
p.isOnline = true;
p.GetRepeatOnline();
}
Shop.CanUpload = true;
Shop.UpCount = 0;
List<Thread> ts = new List<Thread>();
int waitTimes = 0;
int maxCount = 0;
int loopPrexCount = 0;
UpPinduoduoProduct up = new UpPinduoduoProduct(Shop, Name);
up.IniProp(Shop.MainCatId, Shop.Cookies);
GetAllShopGoodsCount();
bool first = true;
while (UploadPinduoduoMain.upRunning && Shop.CanUpload)
{
TaobaoProductBase t = null;
try
{
if (Shop.Name.Contains("专营店"))
{
if (UploadPinduoduoMain.DesShop)
t = UploadPinduoduoMain.ProductStock.Find(tb => tb != null && !tb.Uped && tb.MainCatId != 0 && tb.ShopName != "" && tb.ShopName == Shop.ShopName && tb.MainCatId == Shop.MainCatId);
else
t = UploadPinduoduoMain.ProductStock.Find(tb => tb != null && !tb.Uped && tb.MainCatId != 0 && tb.MainCatId == Shop.MainCatId);
if (t == null && Shop.MainCatName.Split(',').Length > 1)
{
string[] catnames = Shop.MainCatName.Split(',');
for (int i = 0; i < catnames.Length; i++)
{
for (int j = 0; j < FromTitleToCat.MainCat.Count; j++)
{
if (FromTitleToCat.MainCat[j].Value2 == catnames[i].Replace("\"", ""))
{
int MainCatId = int.Parse(FromTitleToCat.MainCat[j].Key);
if (UploadPinduoduoMain.DesShop)
t = UploadPinduoduoMain.ProductStock.Find(tb => tb != null && !tb.Uped && tb.MainCatId != 0 && tb.ShopName != "" && tb.ShopName == Shop.ShopName && tb.MainCatId == MainCatId);
else
t = UploadPinduoduoMain.ProductStock.Find(tb => tb != null && !tb.Uped && tb.MainCatId != 0 && tb.MainCatId == MainCatId);
if (t != null)
break;
}
}
if (t != null)
break;
}
}
}
// 医药健康
else if (Shop.MainCatId == 13)
{
t = UploadPinduoduoMain.ProductStock.Find(tb => tb != null && !tb.Uped && tb.MainCatId != 0 &&
(tb.MainCatId == Shop.MainCatId && tb.MainCatId == 13));
}
else
{
if (UploadPinduoduoMain.isCatType)
t = UploadPinduoduoMain.ProductStock.Find(tb => tb != null && !tb.Uped && tb.MainCatId != 0 && tb.MainCatId == Shop.MainCatId);
else if (UploadPinduoduoMain.DesShop)
t = UploadPinduoduoMain.ProductStock.Find(tb => tb != null && !tb.Uped && tb.ShopName != "" && tb.ShopName == Shop.ShopName && tb.MainCatId != 0 &&
(tb.MainCatId == Shop.MainCatId || tb.MainCatId == 7 && Shop.SelectFood || tb.MainCatId == 13 && Shop.SelectMedicinal || !Shop.SelectFood && !Shop.SelectMedicinal && "2,5,4,11,3,6,12,10,14".Contains(tb.MainCatId.ToString())));
//t = UploadPinduoduoMain.ProductStock.Find(tb => tb != null && !tb.Uped &&
//(tb.MainCatId == Shop.MainCatId || tb.MainCatId == 7 && Shop.SelectFood || tb.MainCatId == 13 && Shop.SelectMedicinal || !Shop.SelectFood && !Shop.SelectMedicinal && "5,4,11,3,6,12,10".Contains(tb.MainCatId.ToString())) && (tb.ShopName == "" || tb.ShopName == Shop.ShopName));
else
t = UploadPinduoduoMain.ProductStock.Find(tb => tb != null && !tb.Uped && tb.MainCatId != 0 &&
(tb.MainCatId == Shop.MainCatId || tb.MainCatId == 7 && Shop.SelectFood || tb.MainCatId == 13
&& Shop.SelectMedicinal || !Shop.SelectFood && !Shop.SelectMedicinal
&& "2,5,4,11,3,6,12,10,14".Contains(tb.MainCatId.ToString()) || ((Shop.MainCatId != 2 || Shop.MainCatId != 7 || Shop.MainCatId != 9 || Shop.MainCatId != 13) && "2,5,4,11,3,6,12,10,14".Contains(tb.MainCatId.ToString()))));
}
if (t == null)
{
waitTimes++;
if (waitTimes > 100)
return;
//if (Shop.APIMessage == "请先购买API再上传")
//{
// LogSave.Add(Name, Shop.Name + " 请先购买API再上传");
// if (waitTimes == 5)
// {
// Shop.Message = "请先购买API再上传";
// GetShopLoginInfo.ShopTemp.Add(Shop);
// }
// continue;
//}
Thread.Sleep(1000);
LogSave.Add(Name, Shop.Name + " 等待数据中...");
continue;
}
UploadPinduoduoMain.ProductStock.Remove(t);
if (UploadPinduoduoMain.ShopTitles.ContainsKey(Shop.ShopName) &&
UploadPinduoduoMain.ShopTitles[Shop.ShopName].Contains(t.Titlte))
{
continue;
}
if (!string.IsNullOrEmpty(t.ViPrice) && string.IsNullOrEmpty(t.ViPriceMaxMin))
{
LogSave.Add(Name, Shop.Name + " 版本升级不支持老数据格式,请重新制作新格式数据,跳过 " + t.FromId + " ");
continue;
}
}
catch
{
LogSave.Add(Name, Shop.Name + " 获取等待数据中...");
if (t == null)
continue;
}
try
{
if (Shop.UpFromIds.ContainsKey(t.FromId) && Shop.UpFromIds[t.FromId] > top)
{
t.FindTimes++;
if (t.FindTimes < 30)
{
UploadPinduoduoMain.ProductStock.Add(t);
}
LogSave.Add(Name, Shop.Name + " 遇到裂变数据,跳过 " + t.FromId + " 等待数据中...");
Thread.Sleep(1000);
continue;
}
UploadPinduoduoMain.Delete(t.guid);
if (!Shop.UpFromIds.ContainsKey(t.FromId))
Shop.UpFromIds.Add(t.FromId, 1);
else
Shop.UpFromIds[t.FromId]++;
}
catch
{
continue;
}
t.Uped = true;
if (Shop.ExpressId == 0)
{
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
if (Shop.ExpressId == 0)
{
Thread.Sleep(10000);
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
}
if (Shop.ExpressId == 0)
{
LogSave.Add(Name, "运费模板未找到");
Shop.Message = "请设置运费模板";
UploadPinduoduoMain.ShopTemp.Add(Shop);
return;
}
}
waitTimes = 0;
try
{
if (UploadPinduoduoMain.Irregularities && IrregularitiesWordFun(t.Titlte))
{
bool ishas = false;
for (int i = 0; i < UploadPinduoduoMain.brandNameList.Count; i++)
{
if (t.Titlte.Contains(brandNameList[i]))
{
ishas = true;
break;
}
}
if (ishas)
{
LogSave.Add(Name, Shop.Name + " 遇到品牌数据,跳过 " + t.FromId + " 该产品...");
Thread.Sleep(1000);
continue;
}
}
if (UploadPinduoduoMain.IrregularitiesWord)
{
foreach (string s in UploadPinduoduoMain.brandFilterNameList)
{
if (t.Titlte.Contains("【"))//移除【】和之间的数据
{
string delStr=BaseRegex.GetMatchRegexString(ref t.Titlte, @"(【[\w\W]+?】)");
t.Titlte = t.Titlte.Replace(delStr,"");
}
if (t.Titlte.Contains("["))//移除【】和之间的数据
{
string delStr = BaseRegex.GetMatchRegexString(ref t.Titlte, @"([[\w\W]+?])");
t.Titlte = t.Titlte.Replace(delStr, "");
}
if (t.Titlte.Contains(s))
t.Titlte = t.Titlte.Replace(s, "");
}
}
}
catch
{
continue;
}
t.Titlte = t.Titlte.Replace("//", "").Replace("\\", "");//Replace("/", "")
maxCount++;
if (maxCount > UploadPinduoduoMain.MaxUpload)
return;
if (t.Titlte.Contains("预售") && UploadPinduoduoMain.isLogistics)
{
LogSave.Add(Name, Shop.Name + " 跳过预售商品 " + t.FromId);
continue;
}
try
{
string[] l = UploadPinduoduoMain.PreFixTitle.Split('\n');
if (!string.IsNullOrEmpty(UploadPinduoduoMain.PreFixTitle))
{
if (loopPrexCount >= l.Length)
{
loopPrexCount = 0;
}
if (!t.Titlte.Contains(l[loopPrexCount]) && UploadPinduoduoMain.fixName == "前缀")
{
t.Titlte = l[loopPrexCount].Replace("\r", "").Trim() + t.Titlte;
if (BaseClass.GetCharLength(t.Titlte) > 60)
t.Titlte = BaseClass.SubCharLength(t.Titlte, 60);
}
if (!t.Titlte.Contains(l[loopPrexCount]) && UploadPinduoduoMain.fixName == "后缀")
{
t.Titlte = t.Titlte + l[loopPrexCount].Replace("\r", "").Trim();
if (BaseClass.GetCharLength(t.Titlte) > 60)
t.Titlte = BaseClass.SubCharLength(t.Titlte, 60);
}
}
loopPrexCount++;
}
catch
{
continue;
}
if (UploadPinduoduoMain.ShopTitles.ContainsKey(Shop.ShopName) &&
UploadPinduoduoMain.ShopTitles[Shop.ShopName].Contains(t.Titlte))
{
continue;
}
Threadx.ThreadListWait(ref ts, new Thread(new UploadPinduoduoSet(Shop, Name, t).Get), UploadPinduoduoMain.SingleThreadCount);
Thread.Sleep(3000);
if (first && UploadPinduoduoMain.SingleThreadCount > 1)
{
first = false;
Thread.Sleep(20 * 1000);
}
}
Threadx.ThreadListWait(ref ts);
}
/// <summary>
/// 在违规店铺中替换
/// </summary>
public void Getsingle()
{
int top = FileBase.Exists("maxtop.ini") ? 50 : 30;
bool ok = CanUser(Shop);
if (!ok)
{
Shop.Message = "请先续费";
UploadPinduoduoMain.ShopTemp.Add(Shop);
return;
}
List<TaobaoProductBase> ProductStockSingle = new List<TaobaoProductBase>();
for (int i = 0; i < UploadPinduoduoMain.ProductStockTemp.Count; i++)
{
ProductStockSingle.Add(UploadPinduoduoMain.ProductStockTemp[i].Clone());
}
if (!UploadPinduoduoMain.ShopTitles.ContainsKey(Shop.ShopName) && UploadPinduoduoMain.NoRepeat)
{
var p = new GetProductOnlineClass(Name, Shop);
p.ReplaceModel = true;
p.isOnline = true;
p.GetRepeatOnline();
}
Shop.CanUpload = true;
Shop.UpCount = 0;
List<Thread> ts = new List<Thread>();
int waitTimes = 0;
int maxCount = 0;
int loopPrexCount = 0;
UpPinduoduoProduct up = new UpPinduoduoProduct(Shop, Name);
up.IniProp(Shop.MainCatId, Shop.Cookies);
GetAllShopGoodsCount();
bool first = true;
while (UploadPinduoduoMain.upRunning && Shop.CanUpload)
{
TaobaoProductBase t = null;
try
{
if (Shop.Name.Contains("专营店"))
{
if (UploadPinduoduoMain.DesShop)
t = ProductStockSingle.Find(tb => tb != null && tb.ShopName != "" && tb.MainCatId != 0 && tb.ShopName == Shop.ShopName && tb.MainCatId == Shop.MainCatId);
else
t = ProductStockSingle.Find(tb => tb != null && tb.MainCatId != 0 && tb.MainCatId == Shop.MainCatId);
}
// 医药健康
else if (Shop.MainCatId == 13)
{
t = ProductStockSingle.Find(tb => tb != null && tb.MainCatId != 0 &&
(tb.MainCatId == Shop.MainCatId && tb.MainCatId == 13));
}
else
{
if (UploadPinduoduoMain.isCatType)
t = UploadPinduoduoMain.ProductStock.Find(tb => tb != null && !tb.Uped && tb.MainCatId != 0 && tb.MainCatId == Shop.MainCatId);
else if (UploadPinduoduoMain.DesShop)
t = ProductStockSingle.Find(tb => tb != null && tb.ShopName != "" && tb.ShopName == Shop.ShopName && tb.MainCatId != 0 &&
(tb.MainCatId == Shop.MainCatId || tb.MainCatId == 7 && Shop.SelectFood || tb.MainCatId == 13 && Shop.SelectMedicinal || !Shop.SelectFood && !Shop.SelectMedicinal && "2,5,4,11,3,6,12,10".Contains(tb.MainCatId.ToString())));
//t = UploadPinduoduoMain.ProductStock.Find(tb => tb != null && !tb.Uped &&
//(tb.MainCatId == Shop.MainCatId || tb.MainCatId == 7 && Shop.SelectFood || tb.MainCatId == 13 && Shop.SelectMedicinal || !Shop.SelectFood && !Shop.SelectMedicinal && "5,4,11,3,6,12,10".Contains(tb.MainCatId.ToString())) && (tb.ShopName == "" || tb.ShopName == Shop.ShopName));
else
t = ProductStockSingle.Find(tb => tb != null && tb.MainCatId != 0 &&
(tb.MainCatId == Shop.MainCatId || tb.MainCatId == 7 && Shop.SelectFood || tb.MainCatId == 13 && Shop.SelectMedicinal || !Shop.SelectFood && !Shop.SelectMedicinal && "2,5,4,11,3,6,12,10".Contains(tb.MainCatId.ToString()) || ((Shop.MainCatId != 2 || Shop.MainCatId != 7 || Shop.MainCatId != 9 || Shop.MainCatId != 13) && "2,5,4,11,3,6,12,10".Contains(tb.MainCatId.ToString()))));
}
if (t == null)
{
waitTimes++;
if (waitTimes > 100)
return;
Thread.Sleep(1000);
LogSave.Add(Name, Shop.Name + " 等待数据中...");
continue;
}
if (UploadPinduoduoMain.ProductStock.Contains(t))
UploadPinduoduoMain.ProductStock.Remove(t);
ProductStockSingle.Remove(t);
UploadPinduoduoMain.SingleCount = ProductStockSingle.Count;
if (UploadPinduoduoMain.ShopTitles.ContainsKey(Shop.ShopName) &&
UploadPinduoduoMain.ShopTitles[Shop.ShopName].Contains(t.Titlte))
{
continue;
}
if (!string.IsNullOrEmpty(t.ViPrice) && string.IsNullOrEmpty(t.ViPriceMaxMin))
{
LogSave.Add(Name, Shop.Name + " 版本升级不支持老数据格式,请重新制作新格式数据,跳过 " + t.FromId + " ");
continue;
}
}
catch
{
LogSave.Add(Name, Shop.Name + " 获取等待数据中...");
if (t == null)
continue;
}
try
{
if (Shop.UpFromIds.ContainsKey(t.FromId) && Shop.UpFromIds[t.FromId] > top)
{
t.FindTimes++;
if (t.FindTimes < 30)
{
UploadPinduoduoMain.ProductStock.Add(t);
}
LogSave.Add(Name, Shop.Name + " 遇到裂变数据,跳过 " + t.FromId + " 等待数据中...");
Thread.Sleep(1000);
continue;
}
UploadPinduoduoMain.Delete(t.guid);
if (!Shop.UpFromIds.ContainsKey(t.FromId))
Shop.UpFromIds.Add(t.FromId, 1);
else
Shop.UpFromIds[t.FromId]++;
}
catch
{
continue;
}
t.Uped = true;
if (Shop.ExpressId == 0)
{
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
if (Shop.ExpressId == 0)
{
Thread.Sleep(10000);
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
}
if (Shop.ExpressId == 0)
{
LogSave.Add(Name, "运费模板未找到");
Shop.Message = "请设置运费模板";
UploadPinduoduoMain.ShopTemp.Add(Shop);
return;
}
}
waitTimes = 0;
try
{
if (UploadPinduoduoMain.Irregularities && IrregularitiesWordFun(t.Titlte))
{
bool ishas = false;
for (int i = 0; i < UploadPinduoduoMain.brandNameList.Count; i++)
{
if (t.Titlte.Contains(brandNameList[i]))
{
ishas = true;
break;
}
}
if (ishas)//!(UploadPinduoduoMain.SelBrand && ishas)
{
LogSave.Add(Name, Shop.Name + " 遇到品牌数据,跳过 " + t.FromId + " 该产品...");
Thread.Sleep(1000);
continue;
}
}
if (UploadPinduoduoMain.IrregularitiesWord)
{
foreach (string s in UploadPinduoduoMain.brandFilterNameList)
{
if (t.Titlte.Contains("【"))//移除【】和之间的数据
{
string delStr = BaseRegex.GetMatchRegexString(ref t.Titlte, @"(【[\w\W]+?】)");
t.Titlte = t.Titlte.Replace(delStr, "");
}
if (t.Titlte.Contains("["))//移除【】和之间的数据
{
string delStr = BaseRegex.GetMatchRegexString(ref t.Titlte, @"([[\w\W]+?])");
t.Titlte = t.Titlte.Replace(delStr, "");
}
if (t.Titlte.Contains(s))
t.Titlte = t.Titlte.Replace(s, "");
}
}
}
catch
{
continue;
}
t.Titlte = t.Titlte.Replace("//", "").Replace("\\", "");//Replace("/", "")
maxCount++;
if (maxCount > UploadPinduoduoMain.MaxUpload)
return;
try
{
string[] l = UploadPinduoduoMain.PreFixTitle.Split('\n');
if (!string.IsNullOrEmpty(UploadPinduoduoMain.PreFixTitle))
{
if (loopPrexCount >= l.Length)
{
loopPrexCount = 0;
}
if (!t.Titlte.Contains(l[loopPrexCount]) && UploadPinduoduoMain.fixName == "前缀")
{
t.Titlte = l[loopPrexCount].Replace("\r", "").Trim() + t.Titlte;
if (BaseClass.GetCharLength(t.Titlte) > 60)
t.Titlte = BaseClass.SubCharLength(t.Titlte, 60);
}
if (!t.Titlte.Contains(l[loopPrexCount]) && UploadPinduoduoMain.fixName == "后缀")
{
t.Titlte = t.Titlte + l[loopPrexCount].Replace("\r", "").Trim();
if (BaseClass.GetCharLength(t.Titlte) > 60)
t.Titlte = BaseClass.SubCharLength(t.Titlte, 60);
}
}
loopPrexCount++;
}
catch
{
continue;
}
Threadx.ThreadListWait(ref ts, new Thread(new UploadPinduoduoSet(Shop, Name, t).Get), UploadPinduoduoMain.SingleThreadCount);
Thread.Sleep(3 * 1000);
if (first && UploadPinduoduoMain.SingleThreadCount > 1)
{
first = false;
Thread.Sleep(20 * 1000);
}
}
Threadx.ThreadListWait(ref ts);
}
/// <summary>
/// 新增违规到其他店铺
/// </summary>
public void GetResureAdd()
{
List<Thread> ts = new List<Thread>();
if (Shop.ExpressId == 0)
{
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
if (Shop.ExpressId == 0)
{
Thread.Sleep(10000);
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetFirst(Shop.Cookies, Shop.MallId, Shop);
}
if (Shop.ExpressId == 0)
{
LogSave.Add(Name, "运费模板未找到");
Shop.Message = "请设置运费模板";
UploadPinduoduoMain.ShopTemp.Add(Shop);
return;
}
}
for (int i = 0; i < productList.Count; i++)
{
var shop = GetShopLoginInfo.Shops.Find(s => s.ShopName == productList[i].ShopName);
if (shop == null)
continue;
if (shop == Shop)
continue;
var uc = new UploadShopControl(Name, Shop, shop);
uc.product = productList[i];
uc.GetAddRes();
Thread.Sleep(3000);
}
}
public void GetAllShopGoodsCount()
{
int mallId = Shop.MallId;
string cookies = Shop.Cookies, shopName = Shop.ShopName;
string url = "https://mms.pinduoduo.com/vodka/v2/mms/query/display/mall/goodsList";
string refere = "https://mms.pinduoduo.com/Pdd.html";
string data = "{\"order_by\":\"id:desc\",\"is_onsale\":1,\"size\":100,\"page\":#page#,\"mall_id\":" + mallId + "}";
string html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data.Replace("#page#", "1"), CpsSetAllGoods.getAnti0aon());
if (string.IsNullOrEmpty(html) || !html.Contains("total"))
{
Thread.Sleep(10 * 1000);
html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data.Replace("#page#", "1"), CpsSetAllGoods.getAnti0aon());
}
Shop.ProductCount = BaseRegex.GetIntJson(ref html, "total");
url = "https://mms.pinduoduo.com/earth/api/mallPunishment";
refere = "https://mms.pinduoduo.com/Pdd.html";
data = "{\"size\":\"5\" }";
//第一页匹配结果
html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data, CpsSetAllGoods.getAnti0aon());
//惩罚店铺
int level = BaseRegex.GetIntJson(ref html, "punishmentLevel");
string punishment = string.Empty;
if (level == 1)
{
punishment = "一级惩罚";
}
else if (level == 2)
{
punishment = "二级惩罚";
}
else if (level == 3)
{
punishment = "三级惩罚";
}
else
{
punishment = "无";
}
//罚款结束时间
string punEndtime = BaseRegex.GetStringJson(ref html, "endTime");
if (string.IsNullOrEmpty(punEndtime))
{
punishment = "无";
}
if (punishment != "无")
{
Shop.Message = punishment;
Shop.CanUpload = false;
}
UploadPinduoduoMain.ShopTemp.Add(Shop);
}
public static List<string> brandNameList = new List<string>();
public static bool IrregularitiesWordFun(string title)
{
if (string.IsNullOrEmpty(title) || brandNameList.Count == 0)
return false;
foreach (string s in brandNameList)
{
if (title.Contains(s))
return true;
}
return false;
}
public static bool CanUser(ShopChatBase shop)
{
string url = BaseClass.BuildObjString("pdd_shop_temp&act=goup");
string data = UserLogin.GetSignaturex(shop.ShopId, shop.ShopName);
string html = GetHtml.PostUtf8(url, data);
//string html = GetHtml.PostUtf8(url, data + "&act=goup");
if (html == "go")
return true;
return false;
}
}
public class ImageUrlBase
{
public ImageUrlBase(string url, int w, int h)
{
Url = url;
Width = w;
Height = h;
}
public string Url;
public int Width;
public int Height;
}
public class ProductInfo
{
public long productId = 0;
public string productName = "";
public bool offLine = false;
public DateTime updateTime;
}
public class OnOrOffStatus
{
public string shopName = "";
public string onStatus = "";
public string offStatus = "";
}
public class DelGroupStatus
{
public string shopName = "";
public string goodStatus = "";
public string goodOnStatus = "";
public string goodOffStatus = "";
public int count = 0;
public int goodsCount = 0;
public int goodsOnCount = 0;
public int goodsOffCount = 0;
public int offCount = 0;
public int onCount = 0;
public int delCount = 0;
public int resCount = 0;
public int vioCount = 0;
/// <summary>
/// 售罄商品数量
/// </summary>
public int soldOutCount = 0;
}
public class OnOrOffProuduct
{
public long id = 0;
public string message = "";
public string shopName = "";
public string name = "";
}
public class PriceRangeModel
{
public int MinPrice = 0;
public int MaxPrice = 0;
public int CoupPrice = 0;
}
}