예제 #1
0
        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);
                            }
                            //}
                        }
                    }
                }
            }
        }
예제 #2
0
        private int GetItemCount(BaseItemInfo item, Dictionary <string, BaseItemInfo> items, bool isTK)
        {
            try
            {
                int count = 0;
                do
                {
                    foreach (BaseItemInfo sItem in items.Values)
                    {
                        if (isTK)
                        {
                            if (CommonFun.IsSameFormat(item.Format, sItem.Format, item.Name, sItem.Name))
                            {
                                return(Convert.ToInt32(sItem.Inventory));
                            }
                        }
                        else
                        {
                            bool isSame = false;
                            if (count > 0)
                            {
                                isSame = CommonFun.IsSameFormat(item.Format, sItem.Format, item.Name, sItem.Name);
                            }
                            else
                            {
                                isSame = item.Type.Trim() == sItem.Type.Trim();
                            }
                            if (isSame)
                            {
                                return(Convert.ToInt32(sItem.Inventory));
                            }
                        }
                    }
                } while (++count < 2 && !isTK);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }


            return(int.MaxValue);
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        public override void Start()
        {
            try
            {
                ticks = DateTime.Now.Ticks;

                base.Start();

                //对比数据
                ReadPlatFormWebPageValue flatform = new ReadPlatFormWebPageValue();

                int totalCount = ShopAllItems.Count, curCount = 0;
                foreach (KeyValuePair <string, BaseItemInfo> info in ShopAllItems)
                {
                    try
                    {
                        Console.WriteLine("{0},totalCount:{1}, curCount:{2}", DateTime.Now.ToString(), totalCount, ++curCount);

                        if ((DateTime.Now - startTime).TotalMinutes > 30)
                        {
                            //Login();
                            flatform.Login();
                            startTime = DateTime.Now;
                        }


                        BaseItemInfo item = info.Value;

                        string key = item.Name + item.Format + item.Created;

                        string seachInfo = item.ID;

                        //查找该商品
                        if (!seachedItemID.ContainsKey(seachInfo))
                        {
                            seachedItemID.Add(seachInfo, item.Name);

                            List <BaseItemInfo> item_list = flatform.SeachInfoByID(seachInfo);

                            if (item_list.Count > 0)
                            {
                                //seachItemList[seachInfo] = item_list;
                                seachItemList.Add(seachInfo, item_list);
                            }
                            else
                            {
                                Console.WriteLine("not seach items id:{0}", seachInfo);
                            }
                        }

                        if (seachItemList.ContainsKey(seachInfo))
                        {
                            List <BaseItemInfo> compareItems = seachItemList[seachInfo];
                            bool isExist = false;
                            foreach (BaseItemInfo compareItem in compareItems)
                            {
                                if (CommonFun.IsSameFormat(item.Format, compareItem.Format, item.Name, compareItem.Name))
                                {
                                    ComparePrice(compareItem, item);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #5
0
        /// <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);
                }
            }
        }
예제 #6
0
        /// <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);
            }
        }