|
|
@ -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<JDPopularizeCampaign> GetJDCampaignList(Shops shop, int businessType, DateTime startTime, DateTime endTime) |
|
|
|
{ |
|
|
|
var pageIndex = 1; |
|
|
|
var shopId = long.Parse(shop.ShopId); |
|
|
|
List<JDPopularizeCampaign> campaignList = new List<JDPopularizeCampaign>(); |
|
|
|
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<ApiResponse<JArray>>(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<long>("campaignId"), |
|
|
|
CampaignName = j.Value<string>("campaignName"), |
|
|
|
Date = DateTime.ParseExact(j.Value<string>("date"), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture), |
|
|
|
Cost = j.Value<decimal>("cost"), |
|
|
|
Clicks = j.Value<int?>("clicks") ?? 0, |
|
|
|
Impressions = j.Value<int?>("impressions") ?? 0, |
|
|
|
TotalCartCnt = j.Value<int?>("totalCartCnt") ?? 0, |
|
|
|
TotalOrderCnt = j.Value<int?>("totalOrderCnt") ?? 0 |
|
|
|
})); |
|
|
|
|
|
|
|
if (jArray.Count() < 100) |
|
|
|
break; |
|
|
|
pageIndex++; |
|
|
|
} |
|
|
|
|
|
|
|
return campaignList; |
|
|
|
} |
|
|
|
|
|
|
|
public IList<JDPopularizeAdGroup> GetJDAdGroupList(Shops shop, DateTime startTime, DateTime endTime) |
|
|
|
{ |
|
|
|
var pageIndex = 1; |
|
|
|
var shopId = long.Parse(shop.ShopId); |
|
|
|
List<JDPopularizeAdGroup> adGroupList = new List<JDPopularizeAdGroup>(); |
|
|
|
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<ApiResponse<JArray>>(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<long>("campaignId"), |
|
|
|
AdGroupId = j.Value<long>("adGroupId"), |
|
|
|
AdGroupName = j.Value<string>("adGroupName"), |
|
|
|
Date = DateTime.ParseExact(j.Value<string>("date"), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture), |
|
|
|
Cost = j["retrievalType0"].Value<decimal>("cost"), |
|
|
|
Clicks = j["retrievalType0"].Value<int?>("clicks") ?? 0, |
|
|
|
Impressions = j["retrievalType0"].Value<int?>("impressions") ?? 0, |
|
|
|
TotalCartCnt = j["retrievalType0"].Value<int?>("totalCartCnt") ?? 0, |
|
|
|
TotalOrderCnt = j["retrievalType0"].Value<int?>("totalOrderCnt") ?? 0 |
|
|
|
})); |
|
|
|
|
|
|
|
if (jArray.Count() < 100) |
|
|
|
break; |
|
|
|
pageIndex++; |
|
|
|
} |
|
|
|
|
|
|
|
return adGroupList; |
|
|
|
} |
|
|
|
|
|
|
|
public IList<> |
|
|
|
} |
|
|
|
} |
|
|
|