using Newtonsoft.Json.Linq; using QYMessageCenter.Client.Models; using QYMessageCenter.Common.Http; using QYMessageCenter.Common.Models; using System.Net.Http; namespace QYMessageCenter.Client.APIServices { public class MdsApiService : BaseApiService, IDenpendency { private string mdsApi = "http://mdsapi.qiyue666.com"; public MdsApiService(RestApiService restApiService, GlobalContext globalContext) : base(restApiService, globalContext) { } public ApiResponse GetUserInfo(string userToken) { return SendRequest(mdsApi, "/TaskList/User/GetUserInfo", null, new Dictionary() { { "Authorization", $"Bearer {userToken}" } }, HttpMethod.Get); } public ApiResponse> GetShopDetailList() { var response = new ApiResponse>(); var response2 = SendRequest(mdsApi, "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) { var shopId = jShop.Value("ShopId"); if (shopId == null || string.IsNullOrEmpty(jShop.Value("AppToken"))) continue; //排除未授权 try { var jayAccounts = jShop.Value("AccountList"); if ((jayAccounts == null || !jayAccounts.HasValues) && d.ShopList.Count(s => s.ShopId == shopId) > 0) { continue; } var shop = new Shop() { ShopId = shopId.Value, 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); 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 = (Platform)jPurchaseAccount.Value("AppPlatformId") }); } } catch (Exception ex) { Console.WriteLine(jShop.ToString()); throw; } } } return response; } } }