using BBWYB.Common.Http; using BBWYB.Common.Models; using Newtonsoft.Json.Linq; using U.Models; using System; using System.Collections.Generic; using System.Net.Http; namespace U.APIServices { public class MdsApiService : BaseApiService, IDenpendency { public MdsApiService(RestApiService restApiService, GlobalContext globalContext) : base(restApiService, globalContext) { } public ApiResponse GetUserInfo(string userToken) { return SendRequest(globalContext.MDSApiHost, "/TaskList/User/GetUserInfo", null, new Dictionary() { { "Authorization", $"Bearer {userToken}" } }, HttpMethod.Get); } //public ApiResponse> GetShopsByUserTeam(long userId) //{ // return SendRequest>(globalContext.MDSApiHost, "TaskList/Shop/GetShopsByUserTeam", $"userId={userId}", null, System.Net.Http.HttpMethod.Get); //} public ApiResponse> GetShopDetailList() { var response = new ApiResponse>(); var response2 = SendRequest(globalContext.MDSApiHost, "TaskList/UserDepartment/GetShopDetailList", null, null, HttpMethod.Get); if (!response.Success) { response.Code = response2.Code; response.Msg = response2.Msg; return response; } response.Data = new List(); foreach (var jDepartment in response2.Data) { var jayShops = jDepartment.Value("ShopList"); if (jayShops == null || !jayShops.HasValues) continue; //排除空店部门 var d = new Department() { Id = jDepartment.Value("Id"), Name = jDepartment.Value("DepartmentName") }; response.Data.Add(d); foreach (var jShop in jayShops) { if (jShop.Value("ShopId") == null || string.IsNullOrEmpty(jShop.Value("AppToken"))) continue; //排除未授权 try { var shop = new Shop() { ShopId = jShop.Value("ShopId"), AppKey = jShop.Value("AppKey"), AppSecret = jShop.Value("AppSecret"), AppToken = jShop.Value("AppToken"), ManagePwd = jShop.Value("ManagePwd"), Platform = (Platform)jShop.Value("PlatformId"), PlatformCommissionRatio = jShop.Value("PlatformCommissionRatio") ?? 0.05M, ShopName = jShop.Value("ShopName"), VenderType = jShop.Value("ShopType"), TeamId = jShop.Value("TeamId") }; d.ShopList.Add(shop); //var jayAccounts = jShop.Value("AccountList"); //if (jayAccounts == null || !jayAccounts.HasValues) // continue; //shop.PurchaseAccountList = new List(); //foreach (var jPurchaseAccount in jayAccounts) //{ // shop.PurchaseAccountList.Add(new PurchaseAccount() // { // Id = jPurchaseAccount.Value("Id"), // AccountName = jPurchaseAccount.Value("AccountName"), // AppKey = jPurchaseAccount.Value("AppKey"), // AppSecret = jPurchaseAccount.Value("AppSecret"), // AppToken = jPurchaseAccount.Value("AppToken"), // ShopId = shop.ShopId // //PurchasePlatformId = jPurchaseAccount.Value() // }); //} } catch (Exception ex) { Console.WriteLine(jShop.ToString()); throw; } } } return response; } } }