public string Tree() { //获取账户 var accounts = _serviceAccount.GetAccounts(Global.USER_ID); var nodes = new List <ZTreeNode>(); foreach (var account in accounts) { nodes.Add(new ZTreeNode { id = account.Id.ToString(), name = account.AccountName, pId = "", isParent = true }); var serviceUser = new EleUserApiService(); var res = serviceUser.GetUser(account.AccessToken); if (res.error != null) { continue; } var jObject = JObject.Parse(res.result.ToString()); var shops = JArray.Parse(jObject["authorizedShops"].ToString()); foreach (var shop in shops) { nodes.Add(new ZTreeNode { id = shop["id"].ToString(), name = shop["name"].ToString(), pId = account.Id.ToString(), token = account.AccessToken }); } } //将获取的节点集合转换为json格式字符串,并返回 var json = JsonConvert.SerializeObject(nodes); return(json); }
public List <ShopMap> GetList(string type = "") { var list = new List <ShopMap>(); //获取账户 var accounts = _serviceAccount.GetAccounts(Global.USER_ID); //已经映射过的门店 var listMapped = _serviceShop.GetByUserId(Global.USER_ID); //获取365门店 var listShop365 = Bak365Service.GetShopList(); //根据账户获取门店 foreach (var account in accounts) { EleUserApiService serviceUser = new EleUserApiService(); var res = serviceUser.GetUser(account.AccessToken); if (res.error != null) { continue; } JObject jObject = JObject.Parse(res.result.ToString()); JArray shops = JArray.Parse(jObject["authorizedShops"].ToString()); foreach (var shop in shops) { ShopMap shopMap = new ShopMap(); shopMap.AccountId = account.Id; shopMap.AccountNo = account.AccountNo; shopMap.AccountName = account.AccountName; shopMap.AccessToken = account.AccessToken; shopMap.ShopId = (long)shop["id"]; shopMap.ShopNameEle = shop["name"].ToString(); if (type.ToUpper() == "MATCH") { foreach (var shop365 in listShop365) { if (shop["name"].ToString().Contains(shop365.Value)) { shopMap.ShopNo = shop365.Key; shopMap.ShopName = shop365.Value; break; } } } else { var dd = listMapped.Find(a => a.ShopId.ToString() == shop["id"].ToString()); if (dd != null) { shopMap.ShopNo = dd.ShopNo; shopMap.ShopName = listShop365[dd.ShopNo]; } } list.Add(shopMap); } } return(list); }