diff --git a/SiNan.Business/TodayGOIBusiness.cs b/SiNan.Business/TodayGOIBusiness.cs index 3281923..b94035c 100644 --- a/SiNan.Business/TodayGOIBusiness.cs +++ b/SiNan.Business/TodayGOIBusiness.cs @@ -1,6 +1,7 @@ -using SiNan.Common.Http; -using SiNan.Common.Log; +using SiNan.Common.Log; using SiNan.Common.Models; +using SiNan.Model.Db; +using SiNan.Model.Db.Mds; using Yitter.IdGenerator; namespace SiNan.Business @@ -8,12 +9,122 @@ namespace SiNan.Business public class TodayGOIBusiness : BaseBusiness, IDenpendency { private RestApiService restApiService; + private string apihost = "http://yuding.qiyue666.com"; public TodayGOIBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, RestApiService restApiService) : base(fsql, nLogManager, idGenerator) { this.restApiService = restApiService; } + public IList GetJDCampaignList(Shops shop, int businessType, DateTime startTime, DateTime endTime) + { + var pageIndex = 1; + var shopId = long.Parse(shop.ShopId); + List campaignList = new List(); + while (true) + { + var httpResult = restApiService.SendRequest(apihost, "Api/PlatformSDK/GetJDSopularizeReportFormByCampaignLevel", new + { + shop.AppKey, + shop.AppSecret, + shop.AppToken, + EndDate = endTime, + StartDate = startTime, + Platform = shop.PlatformId, + PageIndex = pageIndex, + Business = businessType + }, null, HttpMethod.Post); + + if (httpResult.StatusCode != System.Net.HttpStatusCode.OK) + throw new Exception($"获取JD推广报表-计划维度失败 {httpResult.Content}"); + + var res = JsonConvert.DeserializeObject>(httpResult.Content); + if (!res.Success) + throw new Exception($"获取JD推广报表-计划维度失败 {res.Msg}"); + + var jArray = res.Data; + if (jArray == null || jArray.Count == 0) + break; + + campaignList.AddRange(jArray.Select(j => new JDPopularizeCampaign() + { + Id = idGenerator.NewLong(), + BusinessType = businessType, + ShopId = shopId, + CreateTime = DateTime.Now, + CampaignId = j.Value("campaignId"), + CampaignName = j.Value("campaignName"), + Date = DateTime.ParseExact(j.Value("date"), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture), + Cost = j.Value("cost"), + Clicks = j.Value("clicks") ?? 0, + Impressions = j.Value("impressions") ?? 0, + TotalCartCnt = j.Value("totalCartCnt") ?? 0, + TotalOrderCnt = j.Value("totalOrderCnt") ?? 0 + })); + + if (jArray.Count() < 100) + break; + pageIndex++; + } + + return campaignList; + } + + public IList GetJDAdGroupList(Shops shop, DateTime startTime, DateTime endTime) + { + var pageIndex = 1; + var shopId = long.Parse(shop.ShopId); + List adGroupList = new List(); + while (true) + { + var httpResult = restApiService.SendRequest(apihost, "Api/PlatformSDK/GetJDSopularizeReportFormByAdGroupLevel", new + { + shop.AppKey, + shop.AppSecret, + shop.AppToken, + EndDate = endTime, + StartDate = startTime, + Platform = shop.PlatformId, + PageIndex = pageIndex, + Business = 2 + }, null, HttpMethod.Post); + + if (httpResult.StatusCode != System.Net.HttpStatusCode.OK) + throw new Exception($"获取JD推广报表-单元维度失败 {httpResult.Content}"); + + var res = JsonConvert.DeserializeObject>(httpResult.Content); + if (!res.Success) + throw new Exception($"获取JD推广报表-单元维度失败 {res.Msg}"); + + var jArray = res.Data; + if (jArray == null || jArray.Count == 0) + break; + + adGroupList.AddRange(jArray.Select(j => new JDPopularizeAdGroup() + { + Id = idGenerator.NewLong(), + BusinessType = 2, + ShopId = shopId, + CreateTime = DateTime.Now, + CampaignId = j.Value("campaignId"), + AdGroupId = j.Value("adGroupId"), + AdGroupName = j.Value("adGroupName"), + Date = DateTime.ParseExact(j.Value("date"), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture), + Cost = j["retrievalType0"].Value("cost"), + Clicks = j["retrievalType0"].Value("clicks") ?? 0, + Impressions = j["retrievalType0"].Value("impressions") ?? 0, + TotalCartCnt = j["retrievalType0"].Value("totalCartCnt") ?? 0, + TotalOrderCnt = j["retrievalType0"].Value("totalOrderCnt") ?? 0 + })); + + if (jArray.Count() < 100) + break; + pageIndex++; + } + + return adGroupList; + } + public IList<> } }