diff --git a/SiNan.API/Controllers/GOIController.cs b/SiNan.API/Controllers/GOIController.cs index 219bafe..1db72c8 100644 --- a/SiNan.API/Controllers/GOIController.cs +++ b/SiNan.API/Controllers/GOIController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using SiNan.Business; +using SiNan.Model.Core; using SiNan.Model.Dto; namespace SiNan.API.Controllers @@ -41,7 +42,7 @@ namespace SiNan.API.Controllers /// /// [HttpPost] - public JDXXHistogramResponse QueryProduct360HistogramStatistics([FromBody]JDXXHistogramRequest request) + public JDXXHistogramResponse QueryProduct360HistogramStatistics([FromBody] JDXXHistogramRequest request) { return goiBusiness.QueryProduct360HistogramStatistics(request); } @@ -52,9 +53,31 @@ namespace SiNan.API.Controllers /// /// [HttpPost] - public Product360TopStatisticsResponse QueryProduct360TopStatistics([FromBody]Product360TopStatisticsRequest request) + public Product360TopStatisticsResponse QueryProduct360TopStatistics([FromBody] Product360TopStatisticsRequest request) { return goiBusiness.QueryProduct360TopStatistics(request); } + + /// + /// 根据spu查询推广维度GOI + /// + /// + /// SPU GOI + [HttpPost] + public ListResponse QueryPopularizeLevelGOIBySpuId([FromBody] QueryPopularizeLevelGOIBySpuIdRequest request) + { + return goiBusiness.QueryPopularizeLevelGOIBySpuId(request); + } + + /// + /// 根据shopId查询推广维度GOI + /// + /// + /// 店铺GOI + [HttpPost] + public GOIByShop QueryPopularizeLevelGOIByShopId([FromBody] QueryPopularizeLevelGOIByShopIdRequest request) + { + return goiBusiness.QueryPopularizeLevelGOIByShopId(request); + } } } diff --git a/SiNan.Business/GOIBusiness.cs b/SiNan.Business/GOIBusiness.cs index fc69735..99882be 100644 --- a/SiNan.Business/GOIBusiness.cs +++ b/SiNan.Business/GOIBusiness.cs @@ -95,6 +95,31 @@ namespace SiNan.Business return list; } + private GOIByShop StatisticsPopularizeLevelGOI(long shopId, DateTime? startDate, DateTime? endDate) + { + var cost = fsql.Select() + .Where(jas => jas.ShopId == shopId) // &&jas.Date >= startDate && jas.Date <= endDate + .WhereIf(startDate != null, jas => jas.Date >= startDate) + .WhereIf(endDate != null, jas => jas.Date <= endDate) + .Sum(jas => jas.Cost); + + var profit = fsql.Select() + .InnerJoin((jr, ocd, o) => jr.OrderId == ocd.OrderId) + .InnerJoin((jr, ocd, o) => jr.OrderId == o.Id) + .Where((jr, ocd, o) => jr.ShopId == shopId) + .WhereIf(startDate != null, (jr, ocd, o) => jr.CookieTime >= startDate) + .WhereIf(endDate != null, (jr, ocd, o) => jr.CookieTime <= endDate) + .Where((jr, ocd, o) => ocd.IsEnabled == true && o.OrderState != Enums.OrderState.已取消) + .Sum((jr, ocd, o) => ocd.SkuGrossProfit); + + return new GOIByShop() + { + ShopId = shopId, + Cost = cost, + Profit = profit, + }; + } + public IList CalculationCampaignLevelGOI(IList campaignIdList, DateTime startDate, DateTime endDate) { var costs = fsql.Select().Where(x => campaignIdList.Contains(x.CampaignId.Value) && @@ -520,5 +545,36 @@ namespace SiNan.Business TotalDeficit = totalDeficit }; } + + public ListResponse QueryPopularizeLevelGOIBySpuId(QueryPopularizeLevelGOIBySpuIdRequest request) + { + var list = new List(); + request.EndTime = request.EndTime.Date.AddDays(1).AddSeconds(-1); + var productSkuList = fsql.Select().Where(ps => request.SpuIdList.Contains(ps.ProductId)).ToList(); + var skuIdList = productSkuList.Select(ps => ps.ProductId).Distinct().ToList(); + var goiList = StatisticsPopularizeLevelGOI(skuIdList, request.StartTime, request.EndTime); + foreach (var spu in request.SpuIdList) + { + var currentSpuSkuIdList = productSkuList.Where(ps => ps.ProductId == spu).Select(ps => ps.Id).ToList(); + var currentGoiList = goiList.Where(g => currentSpuSkuIdList.Contains(g.Sku)); + var goi = new GOIBySpu() + { + Spu = spu, + Cost = currentGoiList.Sum(g => g.Cost), + Profit = currentGoiList.Sum(g => g.Profit), + }; + } + return new ListResponse() + { + Count = list.Count, + ItemList = list + }; + } + + public GOIByShop QueryPopularizeLevelGOIByShopId(QueryPopularizeLevelGOIByShopIdRequest request) + { + request.EndTime = request.EndTime.Date.AddDays(1).AddSeconds(-1); + return StatisticsPopularizeLevelGOI(request.ShopId, request.StartTime, request.EndTime); + } } } diff --git a/SiNan.Model/Core/GOI/GOIByShop.cs b/SiNan.Model/Core/GOI/GOIByShop.cs new file mode 100644 index 0000000..0a9d455 --- /dev/null +++ b/SiNan.Model/Core/GOI/GOIByShop.cs @@ -0,0 +1,9 @@ +using SiNan.Model.Dto; + +namespace SiNan.Model.Core +{ + public class GOIByShop : GOIResponse + { + public long ShopId { get; set; } + } +} diff --git a/SiNan.Model/Core/GOI/GOIBySpu.cs b/SiNan.Model/Core/GOI/GOIBySpu.cs new file mode 100644 index 0000000..027d321 --- /dev/null +++ b/SiNan.Model/Core/GOI/GOIBySpu.cs @@ -0,0 +1,9 @@ +using SiNan.Model.Dto; + +namespace SiNan.Model.Core +{ + public class GOIBySpu : GOIResponse + { + public string Spu { get; set; } + } +} diff --git a/SiNan.Model/Dto/Request/GOI/QueryPopularizeLevelGOIByShopIdRequest.cs b/SiNan.Model/Dto/Request/GOI/QueryPopularizeLevelGOIByShopIdRequest.cs new file mode 100644 index 0000000..7b58f68 --- /dev/null +++ b/SiNan.Model/Dto/Request/GOI/QueryPopularizeLevelGOIByShopIdRequest.cs @@ -0,0 +1,11 @@ +namespace SiNan.Model.Dto +{ + public class QueryPopularizeLevelGOIByShopIdRequest + { + public long ShopId { get; set; } + + public DateTime StartTime { get; set; } + + public DateTime EndTime { get; set; } + } +} diff --git a/SiNan.Model/Dto/Request/GOI/QueryPopularizeLevelGOIBySpuIdRequest.cs b/SiNan.Model/Dto/Request/GOI/QueryPopularizeLevelGOIBySpuIdRequest.cs new file mode 100644 index 0000000..bf8b5bf --- /dev/null +++ b/SiNan.Model/Dto/Request/GOI/QueryPopularizeLevelGOIBySpuIdRequest.cs @@ -0,0 +1,11 @@ +namespace SiNan.Model.Dto +{ + public class QueryPopularizeLevelGOIBySpuIdRequest + { + public List SpuIdList { get; set; } + + public DateTime StartTime { get; set; } + + public DateTime EndTime { get; set; } + } +}