From 75a4f779cbea94737e9aef78593f7373fb5528bf Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Sun, 3 Dec 2023 03:01:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=B8=E5=8D=97=E8=81=9A=E5=90=88-=E5=88=9B?= =?UTF-8?q?=E6=84=8F/SKU=E6=8E=A8=E5=B9=BF=E7=BB=B4=E5=BA=A6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BA=A7=E5=93=81=E7=BB=B4=E5=BA=A6=E8=81=9A=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SiNan.Business/AggregationBusiness.cs | 9 ++- SiNan.Business/GOIBusiness.cs | 56 +++++++++++++++++++ .../AggregationJDPopularizeAdSkuDaily.cs | 12 ++++ 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/SiNan.Business/AggregationBusiness.cs b/SiNan.Business/AggregationBusiness.cs index 7b23877..3e5f1fb 100644 --- a/SiNan.Business/AggregationBusiness.cs +++ b/SiNan.Business/AggregationBusiness.cs @@ -798,6 +798,7 @@ namespace SiNan.Business List insertAggregationAdSkuDailyList = new List(); var aggregationDate_PopularizeLevelList = goiBusiness.CalculationAdSkuLevelGOI(adSkuIdList, startDate_aggregationDate, endDate_aggregationDate); + var aggregationDate_ProductLevelList = goiBusiness.CalculationAdSkuProductLevelGOI(adSkuIdList, startDate_aggregationDate, endDate_aggregationDate); var adSkuIndex = 0; foreach (var adSku in adSkuList) @@ -805,10 +806,11 @@ namespace SiNan.Business adSkuIndex++; Console.WriteLine($"{DateTime.Now} {shopName} SKU聚合 {adSkuIndex}/{adSkuIdList.Count()}"); - #region 处理计划每日聚合 + #region 处理SKU每日聚合 var adSkuGoi_AggregationDate_PopularizeLevel = aggregationDate_PopularizeLevelList.FirstOrDefault(x => x.Sku == adSku.Sku && x.BusinessType == adSku.BusinessType); + var adSkuGoi_AggregationDate_ProductLevel = aggregationDate_ProductLevelList.FirstOrDefault(x => x.Sku == adSku.Sku && x.BusinessType == adSku.BusinessType); - if (adSkuGoi_AggregationDate_PopularizeLevel != null) + if (adSkuGoi_AggregationDate_PopularizeLevel != null || adSkuGoi_AggregationDate_ProductLevel != null) { var adSkuDailyAggregation = new AggregationJDPopularizeAdSkuDaily() { @@ -819,6 +821,8 @@ namespace SiNan.Business Cost = adSkuGoi_AggregationDate_PopularizeLevel?.Cost ?? 0M, PopularizeLevelProfit = adSkuGoi_AggregationDate_PopularizeLevel?.Profit ?? 0M, PopularizeLevelGOI = adSkuGoi_AggregationDate_PopularizeLevel?.GOI ?? 0M, + ProductLevelProfit = adSkuGoi_AggregationDate_ProductLevel?.Profit ?? 0M, + ProductLevelGOI = adSkuGoi_AggregationDate_ProductLevel?.GOI ?? 0M, AdGroupId = adSku.AdGroupId, CampaignId = adSku.CampaignId, BusinessType = adSku.BusinessType, @@ -834,7 +838,6 @@ namespace SiNan.Business { fsql.Delete().Where(s => s.Date == aggregationDate && adSkuIdList.Contains(s.SkuId)).ExecuteAffrows(); fsql.Insert(insertAggregationAdSkuDailyList).ExecuteAffrows(); - }); } #endregion diff --git a/SiNan.Business/GOIBusiness.cs b/SiNan.Business/GOIBusiness.cs index 4620f20..094baf1 100644 --- a/SiNan.Business/GOIBusiness.cs +++ b/SiNan.Business/GOIBusiness.cs @@ -253,6 +253,62 @@ namespace SiNan.Business return list; } + public IList CalculationAdSkuProductLevelGOI(IList skuIdList, DateTime startDate, DateTime endDate) + { + var costs = fsql.Select() + .Where(jas => skuIdList.Contains(jas.Sku) && jas.Date >= startDate && jas.Date <= endDate) + .GroupBy(jas => new { jas.Sku, jas.BusinessType }) + .ToList(g => new + { + Cost = g.Sum(g.Value.Cost), + Sku = g.Key.Sku, + BusinessType = g.Key.BusinessType + }); + + var profits = fsql.Select() + .InnerJoin((ocd, o) => ocd.OrderId == o.Id) + .Where((ocd, o) => skuIdList.Contains(ocd.SkuId) && + ocd.IsEnabled && + o.StartTime >= startDate && + o.StartTime <= endDate && + o.OrderState != Enums.OrderState.已取消 && + o.IsGift == false) + .GroupBy((ocd, o) => ocd.SkuId) + .ToList(g => new + { + Profit = g.Sum(g.Value.Item1.SkuGrossProfit), + Sku = g.Key + }); + + IList list = new List(); + foreach (var skuId in skuIdList) + { + { + var cost = costs.FirstOrDefault(x => x.Sku == skuId && x.BusinessType == 2)?.Cost ?? 0M; + var profit = profits.FirstOrDefault(x => x.Sku == skuId)?.Profit ?? 0M; + + if (cost != 0 || profit != 0) + { + var adskuGoi = new GOIByAdSku() { Sku = skuId, Cost = cost, Profit = profit, BusinessType = 2 }; + list.Add(adskuGoi); + } + + } + + { + var cost = costs.FirstOrDefault(x => x.Sku == skuId && x.BusinessType == 134217728)?.Cost ?? 0M; + var profit = profits.FirstOrDefault(x => x.Sku == skuId)?.Profit ?? 0M; + if (cost != 0 || profit != 0) + { + var adskuGoi = new GOIByAdSku() { Sku = skuId, Cost = cost, Profit = profit, BusinessType = 134217728 }; + list.Add(adskuGoi); + } + } + + } + return list; + } + //public ListResponse QueryProductGOI(QueryProductGOIRequest request) //{ // if (request.ShopId == 0) diff --git a/SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdSkuDaily.cs b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdSkuDaily.cs index 6de9f3f..d575883 100644 --- a/SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdSkuDaily.cs +++ b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdSkuDaily.cs @@ -61,6 +61,18 @@ namespace SiNan.Model.Db [Column(DbType = "decimal(18,2)")] public decimal? PopularizeLevelProfit { get; set; } + /// + /// 产品维度GOI + /// + [Column(DbType = "decimal(18,2)")] + public decimal? ProductLevelGOI { get; set; } + + /// + /// 产品维度毛利 + /// + [Column(DbType = "decimal(18,2)")] + public decimal? ProductLevelProfit { get; set; } + [Column(DbType = "bigint")] public long? ShopId { get; set; }