/// <summary> /// 上架新物品 /// </summary> /// <param name="id"></param> /// <returns></returns> public bool UpNewItem(BaseItemInfo item, Http.HttpRequest http) { if (item.ShopPrice < 5) { return(false); } //find string findUrl = "https://admin.tkyfw.com/Goods/findExp"; string findPostData = "store_id=34"; http.HttpPost(findUrl, findPostData); //findApp string findAppUrl = "https://admin.tkyfw.com/Goods/findAppNum"; string findAppPostData = string.Format("appNum:{0}", item.ID); http.HttpPost(findAppUrl, findAppPostData); string url = string.Format("https://admin.tkyfw.com/Goods/complateInfo?cat_first=&cat_second=&cat_third=&approval_number={0}", item.ID); string upNewItemUrl = "https://admin.tkyfw.com/Goods/findRepeatCheck"; string checkUrl = "https://admin.tkyfw.com/Goods/checkGoods"; string content = http.HttpGet(url); MatchCollection ms = CommonFun.GetValues(content, "gxtj_ul", "</li>"); foreach (Match m in ms) { string fromat = CommonFun.GetValue(m.Value, "<span>", "<span>"); fromat = CommonFun.FormatStr(fromat, item.Name); if (fromat == item.Format) { string boxStr = CommonFun.GetValue(m.Value, "\"checkbox\"", "/>"); string value = CommonFun.GetValue(boxStr, "value=\"", "\""); string result = http.HttpPost(upNewItemUrl, string.Format("value_arr={0}{1}", value, HttpUtility.UrlEncode(","))); result = CommonFun.GetValue(result, ":", "}"); if (result == "2") { CommonFun.WriteCSV("TKAdmin/UpNew" + fileName + ".csv", item); http.HttpPost(checkUrl, "", url, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", null); Console.WriteLine("UpNewItem,name:{0}, id:{1}, fromat:{2}", item.Name, item.ID, item.Format); } Thread.Sleep(random.Next(3, 6) * 1000); // UpdatePrice(item, http); } } return(true); }
/// <summary> /// 比较新品并上架 /// </summary> /// <returns></returns> public bool CarepareAndUpItem() { BaseReadWebPage newItem = new BaseReadWebPage(); BaseReadWebPage downItem = new BaseReadWebPage(); BaseReadWebPage onlineItem = new BaseReadWebPage(); newItem.ReadBaseItemInfo("TK/低于20以上.csv", true); downItem.ReadBaseItemInfo("TKAdmin/down.csv", true); onlineItem.ReadBaseItemInfo("TKAdmin/TKAdmin.csv", true); Http.HttpRequest http = new Http.HttpRequest(); http.CookieContainer = Login(); foreach (string key in newItem.ShopAllItems.Keys) { if (onlineItem.ShopAllItems.ContainsKey(key)) { continue; } if (downItem.ShopAllItems.ContainsKey(key)) { downItem.ShopAllItems[key].ShopPrice = newItem.ShopAllItems[key].ShopPrice; ReUpItem(downItem.ShopAllItems[key], http); CommonFun.WriteCSV("TKAdmin/need_reUp.csv", downItem.ShopAllItems[key]); continue; } UpNewItem(newItem.ShopAllItems[key], http); CommonFun.WriteCSV("TKAdmin/new" + fileName + ".csv", newItem.ShopAllItems[key]); } return(true); }
public override bool ComparePrice(BaseItemInfo platformItem, BaseItemInfo info) { //15块钱以下的百分之40个点 15到30的百分之30 30到50百分之25 50以上百分之20 decimal compacePrice = platformItem.ShopSelaPrice; decimal infoPrice = info.ShopPrice; bool result = false; if (compacePrice > 50) { if (compacePrice * (decimal)0.8 >= infoPrice) { info.PlatformPrice = platformItem.ShopSelaPrice; info.Type = platformItem.Type; info.ViewCount = platformItem.ViewCount; CommonFun.WriteCSV("QLK/50以上" + ticks + ".csv", info); result = true; } } else if (compacePrice > 30) { if (compacePrice * (decimal)0.75 >= infoPrice) { info.PlatformPrice = platformItem.ShopSelaPrice; info.Type = platformItem.Type; info.ViewCount = platformItem.ViewCount; CommonFun.WriteCSV("QLK/30-50" + ticks + ".csv", info); result = true; } } else if (compacePrice > 15) { if (compacePrice * (decimal)0.7 >= infoPrice) { info.PlatformPrice = platformItem.ShopSelaPrice; info.Type = platformItem.Type; info.ViewCount = platformItem.ViewCount; CommonFun.WriteCSV("QLK/15-30" + ticks + ".csv", info); result = true; } } else if (compacePrice > 5) { if (compacePrice * (decimal)0.6 >= infoPrice) { info.PlatformPrice = platformItem.ShopSelaPrice; info.Type = platformItem.Type; info.ViewCount = platformItem.ViewCount; CommonFun.WriteCSV("QLK/15以下" + ticks + ".csv", info); result = true; } } return(result); }
/// <summary> /// 修改所有在售物品的价格 /// </summary> /// <returns></returns> public bool UpdateAllSellingItemPrice(string itemStr, GetWebPageDate.Http.HttpRequest http, decimal upParam = 1) { itemStr = itemStr.Replace('\n', ' '); itemStr = itemStr.Replace('\t', ' '); MatchCollection ms = CommonFun.GetValues(itemStr, "<div class=\"tkprolistbox\">", "修改"); foreach (Match m in ms) { ItemInfo item = GetOneItem(m.Value); string tag = CommonFun.GetValue(m.Value, "promotionEd=\"", "\""); decimal price = GetPlatformPrice(item.ID, item.Format, http); string info = ""; if (item.Type != "333" && price != decimal.MaxValue && item.PlatformPrice != price) { info = UpdatePrice(http, price * upParam, item.ViewCount, item.Type, item.Inventory); Thread.Sleep(random.Next(3, 6) * 1000); if (info != "1") { string priceStr = CommonFun.GetValue(info, ":\"", "\""); price = 0; try { price = Convert.ToDecimal(priceStr); if (price != 1) { price = (decimal)((double)price - 0.01); } else { price = GetItemPrice(item); } } catch (Exception ex) { Console.WriteLine(ex); } if (price != item.PlatformPrice) { UpdatePrice(http, price, item.ViewCount, tag, item.Inventory); } } } item.ShopPrice = price; CommonFun.WriteCSV("TKAdmin/TKAdmin" + fileName + ".csv", item); } return(true); }
public override void ReadAllItem() { try { foreach (string id in AllItemUrl) { try { string itemPriceUrl = "http://ad.dabai.7lk.com/custom/price/info"; string itemInfoUrl = "https://ad.dabai.7lk.com/medication/detail"; string itemInfoPostData = "pid={0}&doctorId=321967&token=9d571f1dc32cadf0ea38"; string itemPricePostData = "doctorId=321967&userId=321967&skuId={0}&token=9d571f1dc32cadf0ea38"; string content = request.HttpPost(itemInfoUrl, string.Format(itemInfoPostData, id)); BaseItemInfo item = GetItem(content); string skuId = CommonFun.GetValue(content, "\"skuId\":", ","); content = request.HttpPost(itemPriceUrl, string.Format(itemPricePostData, skuId)); string priceStr = CommonFun.GetValue(content, "\"priceMin\":", ","); item.ShopPrice = string.IsNullOrEmpty(priceStr) ? 0 : Convert.ToDecimal(priceStr) / 100; string key = item.ID + "{" + item.Format + "}"; if (ShopAllItems.ContainsKey(key)) { if (item.ShopPrice != 0 && ShopAllItems[key].ShopPrice > item.ShopPrice) { ShopAllItems[key] = item; } } else { ShopAllItems.Add(key, item); } CommonFun.WriteCSV("QLK/QL" + ticks + ".csv", item); } catch (Exception ex) { Console.WriteLine(ex); } } } catch (Exception ex) { Console.WriteLine(ex); } }
public void ComparePrice() { ReadPlatFormWebPageValue flatform = new ReadPlatFormWebPageValue(); BaseReadWebPage res = new BaseReadWebPage(); BaseReadWebPage target = new BaseReadWebPage(); target.ReadBaseItemInfo("YaoTu/YaoTu636500822100643979.csv", true); res.ReadBaseItemInfo("YaoTu/Plateform636500822100643979.csv", true); foreach (BaseItemInfo item in target.ShopAllItems.Values) { foreach (BaseItemInfo platformItem in res.ShopAllItems.Values) { if ((item.Name == platformItem.Name && item.Created == platformItem.Created)) { if (CommonFun.IsSameFormat(platformItem.Format, item.Format, platformItem.Name, item.Name)) { //浏览量对比 //if (!string.IsNullOrEmpty(platformItem.ViewCount) && Convert.ToInt32(platformItem.ViewCount) >= 500) //{ if (platformItem.ShopSelaPrice * (decimal)0.75 >= item.ShopPrice) { item.ID = platformItem.ID; item.ShopSelaPrice = platformItem.ShopSelaPrice; item.Type = platformItem.Type; item.ViewCount = platformItem.ViewCount; CommonFun.WriteCSV("YaoTu/25%_" + ticks + ".csv", item); } else if (platformItem.ShopSelaPrice * (decimal)0.8 >= item.ShopPrice) { item.ID = platformItem.ID; item.ShopSelaPrice = platformItem.ShopSelaPrice; item.Type = platformItem.Type; item.ViewCount = platformItem.ViewCount; CommonFun.WriteCSV("YaoTu/20%_" + ticks + ".csv", item); } else if (platformItem.ShopSelaPrice * (decimal)0.85 >= item.ShopPrice) { item.ID = platformItem.ID; item.ShopSelaPrice = platformItem.ShopSelaPrice; item.Type = platformItem.Type; item.ViewCount = platformItem.ViewCount; CommonFun.WriteCSV("YaoTu/15%_" + ticks + ".csv", item); } //} } } } } }
private bool ComparePrice(BaseItemInfo platformItem, BaseItemInfo info) { if (info.PlatformPrice > 0 && info.PlatformPrice * (decimal)0.8 >= platformItem.ShopSelaPrice) { info.ShopPrice = platformItem.ShopSelaPrice; info.Type = platformItem.Type; CommonFun.WriteCSV("TYaoFang/20以上" + 636493584245833259 + ".csv", info); return(true); } return(false); }
public override bool ComparePrice(BaseItemInfo platformItem, BaseItemInfo info) { if (info.PlatformPrice > 0 && info.PlatformPrice * (decimal)0.8 >= platformItem.ShopSelaPrice) { info.ShopPrice = platformItem.ShopSelaPrice; info.Type = platformItem.Type; info.ViewCount = platformItem.ViewCount; CommonFun.WriteCSV("HA/20以上" + ticks + ".csv", info); return(true); } return(false); }
/// <summary> /// 获取下架列表 /// </summary> /// <param name="cookie"></param> /// <returns></returns> public bool GetDownListItem(CookieCollection cookie) { GetWebPageDate.Http.HttpRequest http = new GetWebPageDate.Http.HttpRequest(); string url = "https://admin.tkyfw.com/Goods/throughAudit?/Goods/throughAudit=&status=1&state=2"; http.Cookie = "acw_tc=AQAAAMj+8lkEeQUA3eT4OlKCFpqJmk95; Qs_lvt_150743=1509785002%2C1510643909; PHPSESSID=0cv28td420q4ii7ult49qm4111; sellerCooke=think%3A%7B%22sellerName%22%3A%22hankang%22%2C%22sellerStoreName%22%3A%22%25E9%2595%25BF%25E6%25B2%2599%25E5%258E%25BF001%25E5%25BA%2597%22%7D; Qs_pv_150743=3457133030228596700%2C2642740307105821700%2C2882295116553261000%2C1172614365052146400%2C979891720064693100; Hm_lvt_ed70f863f631ecaac146592025767ed8=1509785002,1510643909; Hm_lpvt_ed70f863f631ecaac146592025767ed8=1510645265; nTalk_CACHE_DATA={uid:kf_9335_ISME9754_guestTEMP1758-0E75-6A,tid:1510643909116098}; NTKF_T2D_CLIENTID=guestTEMP1758-0E75-6A74-9EB9-8632DF7CEB19; Hm_lvt_3ad2c5e8712b25159b989a93a9927632=1510644101; Hm_lpvt_3ad2c5e8712b25159b989a93a9927632=1510645266; Hm_lvt_7203bc79de07054ef3770e27e8ca9068=1509780503,1509934350,1510060776,1510543588; Hm_lpvt_7203bc79de07054ef3770e27e8ca9068=1510647168"; string content = http.HttpGet(url); string itemStr = CommonFun.GetValue(content, "<form name=\"form\" method=\"post\">", "</form>"); MatchCollection ms = CommonFun.GetValues(itemStr, "<div class=\"white-box table-box\">", "<div class=\"span2 operationone\">"); foreach (Match m in ms) { CommonFun.WriteCSV("TKAdmin/down.csv", GetOneItem(m.Value)); } string pageStr = CommonFun.GetValue(content, "<div><li><span>", "\"><span>末页</span>"); pageStr = pageStr.Substring(pageStr.LastIndexOf("=") + 1); int totalPage = 0; if (!string.IsNullOrEmpty(pageStr)) { totalPage = Convert.ToInt32(pageStr); } for (int i = 2; i <= totalPage; i++) { content = http.HttpGet(url + "&p=" + i); itemStr = CommonFun.GetValue(content, "<form name=\"form\" method=\"post\">", "</form>"); ms = CommonFun.GetValues(itemStr, "<div class=\"white-box table-box\">", "<div class=\"span2 operationone\">"); foreach (Match m in ms) { CommonFun.WriteCSV("TKAdmin/down.csv", GetOneItem(m.Value)); } Console.WriteLine("{2}:totalPage:{0}, curPage:{1}", totalPage, i, DateTime.Now); } return(true); }
public void Start() { try { //1、读取固定 GetFixedItem(); tk.Login(); yy.Login(); tof.Login(); do { double ticks = DateTime.Now.Ticks; int curCount = 0; int totalCount = unUpdate.Count; try { foreach (KeyValuePair <string, BaseItemInfo> info in unUpdate) { try { BaseItemInfo item = info.Value; // 首次同步其他三个平台 bool isFirstUpdate = string.IsNullOrEmpty(item.SellType); //2、取平台库存 Dictionary <string, BaseItemInfo> tkItems = tk.GetSellingItem(info.Value.ID); Dictionary <string, BaseItemInfo> tofItems = tof.GetSellingItem(info.Value.ID, false, false); if (isFirstUpdate) { foreach (BaseItemInfo tkItem in tkItems.Values) { if (CommonFun.IsSameFormat(item.Format, tkItem.Format, item.Name, tkItem.Name)) { if (tkItem.Inventory != item.Inventory) { tkItem.Inventory = item.Inventory; tkItem.ShopPrice = tkItem.PlatformPrice; tkItem.Type = "201"; tk.UpdatePrice(tkItem, tkItem.Type); } break; } } int count = 0; bool isFind = false; do { foreach (BaseItemInfo tofItem in tofItems.Values) { bool isSame = false; if (count > 0) { isSame = CommonFun.IsSameFormat(tofItem.Format, item.Format, tofItem.Name, item.Name); } else { isSame = tofItem.Type.Trim() == item.Type.Trim(); } if (isSame) { if (tofItem.Inventory != item.Inventory) { tofItem.Inventory = item.Inventory; tof.UpdateItemInfo(tofItem.ItemName, tofItem.PlatformPrice, "0", item.Type, tofItem.Inventory, tofItem); } isFind = true; break; } } } while (++count < 2 && !isFind); yy.UpdateStock(item.Type, item.Inventory); ehf.SyncStock(item); CommonFun.WriteCSV("Stock/Init" + ticks + ".csv", item); } else { //item.SellType = "2018-06-16 12:00:00"; //以固定表为上次同步值 int baseCount = Convert.ToInt32(item.Inventory); int nextCount = baseCount; int tkCount = GetItemCount(item, tkItems, true); int tofCount = GetItemCount(item, tofItems, false); int ehfCount = ehf.GetStock(item.Type); int yyCount = int.MaxValue; Dictionary <string, BaseItemInfo> yyItems = yy.GetSellingItem(item.Type, DateTime.ParseExact(item.SellType, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture)); foreach (BaseItemInfo yyItem in yyItems.Values) { yyCount = Convert.ToInt32(yyItem.Inventory); } tkCount = tkCount == int.MaxValue ? tkCount : baseCount - tkCount; yyCount = yyCount == int.MaxValue ? yyCount : baseCount - yyCount; tofCount = tofCount == int.MaxValue ? tofCount : baseCount - tofCount; ehfCount = ehfCount == int.MaxValue ? ehfCount : baseCount - ehfCount; if (tkCount < 0 || yyCount < 0 || tofCount < 0 || ehfCount < 0) { if (tkCount < 0) { nextCount = baseCount - tkCount; } else if (yyCount < 0) { nextCount = baseCount - yyCount; } else if (tofCount < 0) { nextCount = baseCount - tofCount; } else if (ehfCount < 0) { nextCount = baseCount - nextCount; } } else { nextCount = tkCount == int.MaxValue ? nextCount : nextCount - tkCount; nextCount = yyCount == int.MaxValue ? nextCount : nextCount - yyCount; nextCount = tofCount == int.MaxValue ? nextCount : nextCount - tofCount; nextCount = ehfCount == int.MaxValue ? nextCount : nextCount - ehfCount; } Console.WriteLine("TotalCount:{0} CurCount:{1} baseCount:{2} nextCount:{6} tkCount:{3} tofCount:{4} yyCount:{5}", totalCount, ++curCount, baseCount, tkCount, tofCount, yyCount, nextCount); if (nextCount != int.MaxValue && nextCount >= 0) { if (nextCount != baseCount) { item.Inventory = nextCount.ToString(); foreach (BaseItemInfo tkItem in tkItems.Values) { if (CommonFun.IsSameFormat(item.Format, tkItem.Format, item.Name, tkItem.Name)) { if (tkItem.Inventory != item.Inventory) { tkItem.Inventory = item.Inventory; tkItem.ShopPrice = tkItem.PlatformPrice; tkItem.Type = "201"; tk.UpdatePrice(tkItem, tkItem.Type); } break; } } int count = 0; bool isFind = false; do { foreach (BaseItemInfo tofItem in tofItems.Values) { bool isSame = false; if (count > 0) { isSame = CommonFun.IsSameFormat(tofItem.Format, item.Format, tofItem.Name, item.Name); } else { isSame = tofItem.Type.Trim() == item.Type.Trim(); } if (isSame) { if (tofItem.Inventory != item.Inventory) { tofItem.Inventory = item.Inventory; tof.UpdateItemInfo(tofItem.ItemName, tofItem.PlatformPrice, tofItem.SellType, tofItem.Type, tofItem.Inventory, tofItem); } isFind = true; break; } } } while (++count < 2 && !isFind); yy.UpdateStock(item.Type, item.Inventory); ehf.SyncStock(item); } } else { Console.WriteLine("The stock is null id:{0}, name:{1}, format{2}, NO:{3}", item.ID, item.Name, item.Format, item.Type); CommonFun.WriteCSV("Stock/StockNull" + ticks + ".csv", item); continue; } } item.SellType = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); CommonFun.UpdateXLS("KTUnUpdate.xlsx", new string[] { "出售方式(零或整)", "库存" }, new string[] { item.SellType, item.Inventory }, "剂型", item.Type); } catch (Exception ex) { Console.WriteLine(ex); } } } catch (Exception ex) { Console.WriteLine(ex); } } while (true); } catch (Exception ex) { Console.WriteLine(ex); } }
/// <summary> /// 上架新品 /// </summary> public void UpNewItem() { Login(); BaseReadWebPage read = new BaseReadWebPage(); read.ReadBaseItemInfo("TYaoFang/20以上636493584245833259--------------.csv", true); int count = 0; foreach (BaseItemInfo item in read.ShopAllItems.Values) { try { if (count++ % 200 == 0) { Login(); } int startIndex = item.ID.IndexOf('字'); startIndex = (startIndex > 0 ? startIndex : item.ID.IndexOf('号')) + 1; string id = item.ID.Substring(startIndex, item.ID.Length - startIndex); // 查找商品模板 string seachUrl = "http://www.12yao.com/pharmacy/ajax_productinfo.php"; string postDataStr = "action=getProductSearch&keywords={0}&searchType=1"; string data = string.Format(postDataStr, id); string content = request.HttpPost(seachUrl, data, "http://www.12yao.com/pharmacy/productRelease.php?rootID=1", null, Encoding.GetEncoding("gb2312")); MatchCollection ms = CommonFun.GetValues(content, "<li>", "</li>"); foreach (Match m in ms) { //对比格式 string format = CommonFun.GetValue(m.Value, "<b>", "</b>"); if (format == item.Format) { string productID = CommonFun.GetValue(m.Value, "value='", "'"); string postDataStrInfo = "action=getProductInfo&ProductID={0}"; content = request.HttpPost(seachUrl, string.Format(postDataStrInfo, productID)); // 保存价格数据 string saveUrl = "http://www.12yao.com/pharmacy/SaveProduct.php"; string postDataSave = "PreferentialPrice={1}&RetailPrice={1}&ProductStock={2}&Weight=6&ProductCode={0}&standardCode=&REPID=&Base_ProductID={0}&action=addproductrelease&Submit=%CB%D1%CB%F7"; Random random = new Random((int)DateTime.Now.Ticks); content = request.HttpPost(saveUrl, string.Format(postDataSave, productID, item.PlatformPrice, random.Next(30, 40))); //获取待上架列表 string willUpUrl = string.Format("http://www.12yao.com/pharmacy/ProductUnderFrameList.php?ProductName=&ReasonShelves=0&ProductBatch={0}&CompanyTitle=&ProductCode=&ProductType=0&time1=&time2=", HttpUtility.UrlEncode(item.ID, Encoding.GetEncoding("gb2312")).ToUpper()); content = request.HttpGet(willUpUrl, null, Encoding.GetEncoding("gb2312")); bool isUp = false; if (!string.IsNullOrEmpty(content)) { MatchCollection upIdMs = CommonFun.GetValues(content, " <tr id=\"", " </tr>"); foreach (Match upIdM in upIdMs) { string willUpFormat = CommonFun.GetValue(upIdM.Value, "<td class=\"dgui\">", "</td>"); if (willUpFormat == item.Format) { string upId = CommonFun.GetValue(upIdM.Value, " value=\"", "\""); // 上架商品 string upUrl = "http://www.12yao.com/pharmacy/ProductsUnderFrame.php"; string postDataUp = "SelectPid={0}&action=setMultipleProductUpFrame"; string reuslt = request.HttpPost(upUrl, string.Format(postDataUp, upId)); isUp = true; } } } if (!isUp) { CommonFun.WriteCSV("TYaoFang/faild" + tick + ".csv", item); } } } } catch (Exception ex) { CommonFun.WriteCSV("TYaoFang/faild" + tick + ".csv", item); Console.WriteLine(ex); } } }
/// <summary> /// 数据对比 /// </summary> public void Compare() { ReadPlatFormWebPageValue flatform = new ReadPlatFormWebPageValue(); BaseReadWebPage platform = new BaseReadWebPage(); BaseReadWebPage shop = new BaseReadWebPage(); platform.ReadBaseItemInfo("Platform/Platform636488666326049889.csv", true); shop.ReadBaseItemInfo("TYaoFang/NotIsEixst636493584245833259.csv", true); foreach (BaseItemInfo item in shop.ShopAllItems.Values) { bool isEixst = false; string itemName = item.Name; if (item.Name.Contains("】")) { int itemNameIndex = item.Name.LastIndexOf("】") + 1; itemName = item.Name.Substring(itemNameIndex, item.Name.Length - itemNameIndex); } if (itemName.Contains("(")) { int itemNameIndex = itemName.IndexOf('('); itemName = itemName.Substring(0, itemNameIndex); } foreach (BaseItemInfo platformItem in platform.ShopAllItems.Values) { bool isSame = false; if (!string.IsNullOrEmpty(item.ID) && !string.IsNullOrEmpty(platformItem.ID)) { if (item.ID.Trim() == platformItem.ID.Trim()) { isSame = true; } } if (isSame || (itemName == platformItem.Name && item.Created == platformItem.Created)) { if (CommonFun.IsSameFormat(platformItem.Format, item.Format, platformItem.Name, item.Name)) { isEixst = true; if (ComparePrice(platformItem, item)) { break; } } } } //if (!isEixst) //{ // List<BaseItemInfo> seachItems = flatform.SeachInfoByID(item.ID); // Dictionary<string, BaseItemInfo> saveInfos = new Dictionary<string, BaseItemInfo>(); // foreach (BaseItemInfo info in seachItems) // { // string key = info.Name + info.Format + info.Created; // if (!platform.ShopAllItems.ContainsKey(key)) // { // if (item.ID == info.ID || (itemName == info.Name && item.Created == info.Created)) // { // if (CommonFun.IsSameFormat(info.Format, item.Format, info.Name, item.Name)) // { // isEixst = true; // ComparePrice(info, item); // } // } // platform.ShopAllItems.Add(key, info); // saveInfos.Add(key, info); // } // else if (platform.ShopAllItems[key].ShopSelaPrice > info.ShopSelaPrice) // { // if (item.ID == info.ID || (itemName == info.Name && item.Created == info.Created)) // { // if (CommonFun.IsSameFormat(info.Format, item.Format, info.Name, item.Name)) // { // isEixst = true; // ComparePrice(info, item); // } // } // platform.ShopAllItems[key] = info; // saveInfos[key] = info; // } // } // foreach (BaseItemInfo saveInfo in saveInfos.Values) // { // CommonFun.WriteCSV("Platform/Platform636488666326049889.csv", saveInfo); // } //} if (!isEixst) { CommonFun.WriteCSV("TYaoFang/NotIsEixst" + tick + ".csv", item); } } }
public override void ReadAllItem() { Dictionary <string, string> itemIDAndPrices = new Dictionary <string, string>(); string pageListUrl = "http://api.12yao.com/v1003/products/list?j={0}&p1=&r={1}&t=151306281"; string itemUrl = "http://api.12yao.com/v1003/products/pharmacy_list?g=0&id={0}&t=151306508"; int totalCount = menuList.Count; int curCount = 0; foreach (string j in menuList.Keys) { try { int r = 1; string url = string.Format(pageListUrl, j, r); string content = request.HttpGet(url); JObject jo = (JObject)JsonConvert.DeserializeObject(content); int totalPage = (int)Math.Ceiling(Convert.ToDouble(jo["d"]["k"]) / 20); GetItemIDs(content, itemIDAndPrices); for (r++; r <= totalPage; r++) { url = string.Format(pageListUrl, j, r); content = request.HttpGet(url); GetItemIDs(content, itemIDAndPrices); Console.WriteLine("TotalPage:{0}, curPage:{1}", totalPage, r); } Console.WriteLine("TotalCount:{0}, CurCount:{1}", totalCount, ++curCount); } catch (Exception ex) { Console.WriteLine("err:{0}, list:{1}", ex.ToString(), j); } } foreach (string id in itemIDAndPrices.Keys) { string url = string.Format(itemUrl, id); string content = request.HttpGet(url); BaseItemInfo item = GetItemInfo(content, itemIDAndPrices[id]); if (item != null) { string key = item.ID + item.Format + item.Created; if (!ShopAllItems.ContainsKey(key)) { ShopAllItems.Add(key, item); } else if (ShopAllItems[key].PlatformPrice > item.PlatformPrice) { ShopAllItems[key].PlatformPrice = item.PlatformPrice; } } else { Console.WriteLine("Item is null,id:{0}", id); } } foreach (BaseItemInfo item in ShopAllItems.Values) { CommonFun.WriteCSV(fileName, item); } }
/// <summary> /// 对比价格(在线数据) /// </summary> public void OnlineComparePrice() { ReadPlatFormWebPageValue flatform = new ReadPlatFormWebPageValue(); Dictionary <string, BaseItemInfo> platItems = new Dictionary <string, BaseItemInfo>(); Dictionary <string, List <BaseItemInfo> > seachItems = new Dictionary <string, List <BaseItemInfo> >(); Dictionary <string, string> seachedItemName = new Dictionary <string, string>(); foreach (BaseItemInfo item in ShopAllItems.Values) { string key = item.Name + item.Format + item.Created; //查找该商品 if (!seachedItemName.ContainsKey(item.Name)) { seachedItemName.Add(item.Name, item.Name); List <BaseItemInfo> item_list = flatform.SeachInfoByID(item.Name); Dictionary <string, BaseItemInfo> minPricItems = new Dictionary <string, BaseItemInfo>(); foreach (BaseItemInfo sItem in item_list) { string sItemKey = sItem.Name + sItem.Format + sItem.Created; if (!platItems.ContainsKey(sItemKey)) { platItems.Add(sItemKey, sItem); minPricItems.Add(sItemKey, sItem); } else if (platItems[sItemKey].ShopSelaPrice > sItem.ShopSelaPrice) { platItems[sItemKey] = sItem; minPricItems[sItemKey] = sItem; } } seachItems.Add(item.Name, minPricItems.Values.ToList()); } //对比价格 if (seachItems.ContainsKey(item.Name)) { List <BaseItemInfo> compareItems = seachItems[item.Name]; bool isExist = false; foreach (BaseItemInfo compareItem in compareItems) { if (item.Created == compareItem.Created) { if (CommonFun.IsSameFormat(item.Format, compareItem.Format, item.Name, compareItem.Name)) { isExist = true; //价格对比 if (item.ShopPrice > 0 && item.ShopPrice * (decimal)0.75 >= compareItem.ShopSelaPrice) { //浏览量对比 if (!string.IsNullOrEmpty(compareItem.ViewCount) && Convert.ToInt32(compareItem.ViewCount) >= 500) { item.ID = compareItem.ID; item.ShopSelaPrice = compareItem.ShopSelaPrice; item.Type = compareItem.Type; item.ViewCount = compareItem.ViewCount; CommonFun.WriteCSV("25%" + ticks + ".csv", item); } } break; } } } if (!isExist) { CommonFun.WriteCSV("YaoTu/NoFormat" + ticks + ".csv", item); } } else { CommonFun.WriteCSV("YaoTu/NotExist" + ticks + ".csv", item); } } foreach (BaseItemInfo item in platItems.Values) { CommonFun.WriteCSV("YaoTu/Plateform" + ticks + ".csv", item); } }