public void GetDishAttribute(string erpDishId, List <DishAttribute> erpAttributes, String token) { if (string.IsNullOrEmpty(erpDishId)) { return; } var postDict = new SortedDictionary <string, string>(); postDict["appAuthToken"] = token; postDict["charset"] = "utf-8"; postDict["timestamp"] = (Helper.ConvertDateTimeInt(DateTime.Now)).ToString(); postDict["eDishCode"] = erpDishId; postDict["sign"] = MeituanHelper.Sign(postDict, this.Config.SignKey); StringBuilder url = new StringBuilder("http://api.open.cater.meituan.com/waimai/dish/queryPropertyList?"); 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 attJson = datas[i]; var attribute = new DishAttribute(); erpAttributes.Add(attribute); attribute.Name = attJson.Value <string>("propertyName"); var details = (Newtonsoft.Json.Linq.JArray)attJson["values"]; foreach (var item in details) { attribute.Values.Add(item.ToString()); } } }
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); }