public DishInfo GetDish(int erpStoreId, String token, string erpDishId) { var postDict = new SortedDictionary <string, string>(); postDict["appAuthToken"] = token; postDict["charset"] = "utf-8"; postDict["timestamp"] = (Helper.ConvertDateTimeInt(DateTime.Now)).ToString(); postDict["ePoiId"] = erpStoreId.ToString(); postDict["eDishCodes"] = erpDishId; postDict["sign"] = MeituanHelper.Sign(postDict, this.Config.SignKey); var result = Helper.PostQueryString("http://api.open.cater.meituan.com/waimai/dish/queryListByEdishCodes", postDict, 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 dishJson = ((Newtonsoft.Json.Linq.JArray)jsonObj["data"]["list"])[0]; var dish = new DishInfo(); dish.BoxNumber = dishJson.Value <int>("boxNum"); dish.BoxPrice = dishJson.Value <double>("boxPrice"); dish.CategoryName = dishJson.Value <string>("categoryName"); dish.Description = dishJson.Value <string>("description"); dish.DishName = dishJson.Value <string>("dishName"); dish.ErpDishId = dishJson.Value <string>("eDishCode"); dish.Price = dishJson.Value <double>("price"); dish.Picture = dishJson.Value <string>("picture"); dish.Sequence = dishJson.Value <int>("Sequence"); dish.Unit = dishJson.Value <string>("unit"); var waiMaiDishSkuBases = (Newtonsoft.Json.Linq.JArray)dishJson["skus"]; for (int j = 0; j < waiMaiDishSkuBases.Count; j++) { var skuJson = waiMaiDishSkuBases[j]; var subdish = new DishSkuInfo(); dish.Skus.Add(subdish); subdish.ErpSkuId = skuJson.Value <string>("skuId"); try { subdish.Stock = Convert.ToUInt32(skuJson.Value <string>("stock")); } catch { } subdish.Price = skuJson.Value <double>("price"); subdish.Spec = skuJson.Value <string>("spec"); } return(dish); }
public List <DishInfo> GetDishListByCategoryId(int erpStoreId, object categoryId, string catName, string token) { int index = 0; List <DishInfo> dishes = new List <DishInfo>(); var param = new Dictionary <string, object>(); param["categoryId"] = categoryId; var result = Post(token, "eleme.product.item.getItemsByCategoryId", param); var cur = result.First; while (cur != null && cur.First != null) { var json = cur.First; var dish = new DishInfo() { Sequence = index++, CategoryName = catName, DishId = json.Value <string>("id"), DishName = json.Value <string>("name"), }; dishes.Add(dish); var specs = (Newtonsoft.Json.Linq.JArray)json["specs"]; foreach (var specJson in specs) { DishSkuInfo sku = new DishSkuInfo(); dish.Skus.Add(sku); sku.Spec = specJson.Value <string>("name"); sku.Price = specJson.Value <double>("price"); sku.SkuId = specJson.Value <Int64>("specId"); sku.ErpSkuId = specJson.Value <string>("extendCode"); if (dish.Price == 0) { dish.Price = sku.Price; } } var attributes = (Newtonsoft.Json.Linq.JArray)json["attributes"]; foreach (var attJson in attributes) { DishAttribute att = new DishAttribute(); dish.Attributes.Add(att); att.Name = attJson.Value <string>("name"); var details = (Newtonsoft.Json.Linq.JArray)attJson["details"]; foreach (var item in details) { att.Values.Add(item.ToString()); } } try { var sellingTime = json["sellingTime"]; var weeks = (Newtonsoft.Json.Linq.JArray)sellingTime["weeks"]; var times = (Newtonsoft.Json.Linq.JArray)sellingTime["times"]; if (weeks.Count > 0) { for (int i = 0; i < 7; i++) { dish.AvailableTimes.Add(new DayOpenTime()); } var strArr = new List <string>(new string[] { "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY" }); for (int i = 0; i < weeks.Count; i++) { var day = weeks[i].ToString(); var dayIndex = strArr.IndexOf(day); if (dayIndex >= 0) { var targetTimes = dish.AvailableTimes[dayIndex].Times; if (times.Count > 0) { foreach (var timeJson in times) { targetTimes.Add(timeJson["beginTime"] + "-" + timeJson["endTime"]); } } else { //全时段 targetTimes.Add("00:00-23:59"); } } } } } catch { } cur = cur.Next; } return(dishes); }
public List <DishInfo> GetDishList(int erpStoreId, String token) { int offset = 0; List <DishInfo> dishes = new List <DishInfo>(); while (true) { var postDict = new SortedDictionary <string, object>(); postDict["appAuthToken"] = token; postDict["charset"] = "utf-8"; postDict["timestamp"] = (Helper.ConvertDateTimeInt(DateTime.Now)).ToString(); postDict["ePoiId"] = erpStoreId.ToString(); postDict["offset"] = offset.ToString(); postDict["limit"] = 199; postDict["sign"] = MeituanHelper.Sign(postDict, this.Config.SignKey); StringBuilder url = new StringBuilder("http://api.open.cater.meituan.com/waimai/dish/queryListByEPoiId?"); 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 datas = (Newtonsoft.Json.Linq.JArray)jsonObj["data"]; for (int i = 0; i < datas.Count; i++) { var dishJson = datas[i]; var dish = new DishInfo(); dishes.Add(dish); dish.CategoryName = dishJson.Value <string>("categoryName"); dish.DishName = dishJson.Value <string>("dishName"); dish.ErpDishId = dishJson.Value <string>("eDishCode"); dish.BoxNumber = dishJson.Value <int>("boxNum"); dish.BoxPrice = dishJson.Value <double>("boxPrice"); dish.Description = dishJson.Value <string>("description"); dish.Price = dishJson.Value <double>("price"); dish.Sequence = dishJson.Value <int>("sequence"); dish.Unit = dishJson.Value <string>("unit"); var skus = (Newtonsoft.Json.Linq.JArray)dishJson["skus"]; for (int j = 0; j < skus.Count; j++) { var skuJson = skus[j]; var subdish = new DishSkuInfo(); dish.Skus.Add(subdish); subdish.ErpSkuId = skuJson.Value <string>("skuId"); subdish.Price = skuJson.Value <double>("price"); subdish.Spec = skuJson.Value <string>("spec"); if (skuJson["stock"].HasValues) { subdish.Stock = skuJson.Value <uint>("stock"); } try { if (dish.AvailableTimes.Count == 0) { var availableTimes = skuJson["availableTimes"]; var weekToken = availableTimes.First as Newtonsoft.Json.Linq.JProperty; var strArr = new List <string>(new string[] { "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" }); while (weekToken != null) { if (dish.AvailableTimes.Count == 0) { for (int k = 0; k < 7; k++) { dish.AvailableTimes.Add(new DayOpenTime()); } } int dayindex = strArr.IndexOf(weekToken.Name); var targetTimes = dish.AvailableTimes[dayindex].Times; if (weekToken.Value.ToString().Length > 0) { targetTimes.AddRange(weekToken.Value.ToString().Split(',')); } weekToken = weekToken.Next as Newtonsoft.Json.Linq.JProperty; } } } catch { } } GetDishAttribute(dish.ErpDishId, dish.Attributes, token); } if (datas.Count < 199) { break; } else { // 继续下一页 offset += datas.Count; } } return(dishes); }