コード例 #1
0
        public void HasOpenedBy()
        {
            var dayOpenTime = new DayOpenTime
            {
                Days = new List <DayOfWeek> {
                    DayOfWeek.Monday
                },
                Start = "9:00",
                End   = "17:00"
            };

            int      hours   = 0;
            int      minutes = 0;
            int      seconds = 0;
            TimeSpan time;

            while (hours < 24)
            {
                time = new TimeSpan(hours, minutes, seconds);
                if (hours >= 9)
                {
                    Assert.True(dayOpenTime.HasOpenedBy(time));
                }
                else
                {
                    Assert.False(dayOpenTime.HasOpenedBy(time));
                }
                minutes++;
                if (minutes >= 60)
                {
                    minutes = 0;
                    hours++;
                }
            }
        }
コード例 #2
0
        public StoreInfo GetStoreInfo(int erpStoreId, String token)
        {
            var shopid = getShopIdByErpStoreId(token, erpStoreId);
            var param  = new Dictionary <string, object>();

            param["shopId"] = shopid;
            var resultJson = Post(token, "eleme.shop.getShop", param);
            var info       = new StoreInfo()
            {
                Address    = resultJson.Value <string>("addressText"),
                Name       = resultJson.Value <string>("name"),
                NoticeInfo = resultJson.Value <string>("promotionInfo"),
                Status     = resultJson.Value <int>("isOpen") == 1 ? StoreStatus.Opened : StoreStatus.Closed
            };
            var phoneArr = (Newtonsoft.Json.Linq.JArray)resultJson["phones"];

            foreach (var phone in phoneArr)
            {
                var strPhone = phone.ToString();
                if (!string.IsNullOrEmpty(strPhone))
                {
                    info.Phones.Add(strPhone);
                }
            }
            var servingTimeArr = (Newtonsoft.Json.Linq.JArray)resultJson["servingTime"];
            var dayTime        = new DayOpenTime();

            info.DayOpenTimes.Add(dayTime);

            foreach (var timestr in servingTimeArr)
            {
                dayTime.Times.Add(timestr.ToString());
            }
            return(info);
        }
コード例 #3
0
        public void IsOpen24Hours()
        {
            var not24Hours = new DayOpenTime
            {
                Days = new List <DayOfWeek> {
                    DayOfWeek.Monday
                },
                Start = "0:00",
                End   = "17:00"
            };

            Assert.False(not24Hours.IsOpen24Hours());

            not24Hours = new DayOpenTime
            {
                Days = new List <DayOfWeek> {
                    DayOfWeek.Monday
                },
                Start = "17:00",
                End   = "00:00"
            };

            Assert.False(not24Hours.IsOpen24Hours());

            var is24Hours = new DayOpenTime
            {
                Days = new List <DayOfWeek> {
                    DayOfWeek.Monday
                },
                Start = "00:00",
                End   = "00:00"
            };

            Assert.True(is24Hours.IsOpen24Hours());
        }
コード例 #4
0
        public StoreInfo GetStoreInfo(int erpStoreId, String token)
        {
            var postDict = new SortedDictionary <string, string>();

            postDict["appAuthToken"] = token;
            postDict["ePoiIds"]      = erpStoreId.ToString();
            postDict["charset"]      = "utf-8";
            postDict["timestamp"]    = (Helper.ConvertDateTimeInt(DateTime.Now)).ToString();
            postDict["sign"]         = MeituanHelper.Sign(postDict, this.Config.SignKey);
            StringBuilder url = new StringBuilder("http://api.open.cater.meituan.com/waimai/poi/queryPoiInfo?");

            foreach (var item in postDict)
            {
                url.Append(item.Key);
                url.Append('=');
                url.Append(item.Value);
                url.Append('&');
            }

            var result = Helper.GetQueryString(url.ToString(), 8000);

            var jsonObj = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(result);

            Newtonsoft.Json.Linq.JToken errobj;
            if (jsonObj.TryGetValue("error", StringComparison.CurrentCultureIgnoreCase, out errobj))
            {
                throw new Exception(errobj.Value <string>("message"));
            }
            var data      = ((Newtonsoft.Json.Linq.JArray)jsonObj["data"])[0];
            var storeInfo = new StoreInfo();

            storeInfo.Address    = data.Value <string>("address");
            storeInfo.Name       = data.Value <string>("name");
            storeInfo.NoticeInfo = data.Value <string>("noticeInfo");
            var phone = data.Value <string>("phone");

            if (!string.IsNullOrEmpty(phone))
            {
                storeInfo.Phones.Add(phone);
            }
            storeInfo.Status = data.Value <int>("isOpen") == 1 ? StoreStatus.Opened : StoreStatus.Closed;
            string[] openTimes = data.Value <string>("openTime").Split(';');
            for (int i = 0; i < openTimes.Length; i++)
            {
                var daytime = new DayOpenTime();
                storeInfo.DayOpenTimes.Add(daytime);

                string[] times = openTimes[i].Split(',');
                if (times.Length == 1 && times[0] == "00:00-00:00")
                {
                    continue;
                }
                daytime.Times.AddRange(times);
            }
            return(storeInfo);
        }
コード例 #5
0
        public List <DishInfo> GetDishList(int erpStoreId, string token)
        {
            List <DishInfo> result = new List <DishInfo>();

            var data = (Newtonsoft.Json.Linq.JArray)Post("dish.menu.get", new Dictionary <string, object>()
            {
                { "shop_id", erpStoreId.ToString() }
            });

            // 循环所有分类
            foreach (var group in data)
            {
                var categoryName = group["category"].Value <string>("name");
                var products     = (Newtonsoft.Json.Linq.JArray)group["products"];

                // 循环分类下的菜品
                foreach (var dishJson in products)
                {
                    // 判断是否是菜品
                    if (dishJson.Value <int>("type") != 1)
                    {
                        continue;
                    }

                    DishInfo dish = new DishInfo();
                    result.Add(dish);
                    dish.CategoryName = categoryName;
                    dish.ErpDishId    = dishJson.Value <string>("dish_id");
                    dish.DishId       = dishJson.Value <string>("baidu_dish_id");
                    dish.DishName     = dishJson.Value <string>("name");
                    dish.Price        = dishJson.Value <double>("price") / 100;
                    dish.Picture      = dishJson.Value <string>("pic");
                    dish.BoxNumber    = dishJson.Value <int>("package_box_num");
                    dish.Description  = dishJson.Value <string>("description");
                    try
                    {
                        var available_times = (Newtonsoft.Json.Linq.JArray)dishJson["available_times"];
                        foreach (Newtonsoft.Json.Linq.JArray dayJson in available_times)
                        {
                            DayOpenTime dayTime = new DayOpenTime();
                            dish.AvailableTimes.Add(dayTime);

                            foreach (var timeJson in dayJson)
                            {
                                dayTime.Times.Add($"{timeJson["start_time"]}-{timeJson["end_time"]}");
                            }
                        }
                        if (dish.AvailableTimes.Count == 7)
                        {
                            //把第一个移到最后,因为第一个是周日
                            var sunday = dish.AvailableTimes[0];
                            dish.AvailableTimes.RemoveAt(0);
                            dish.AvailableTimes.Add(sunday);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            return(result);
        }