From 8fa9b353a481256903db699cfc4f483702e07f81 Mon Sep 17 00:00:00 2001 From: sanji Date: Fri, 1 Dec 2023 16:49:41 +0800 Subject: [PATCH] =?UTF-8?q?SKU=E6=AF=8F=E6=97=A5=E8=81=9A=E5=90=88?= =?UTF-8?q?=E8=A1=A8=E5=A2=9E=E5=8A=A0=E8=90=A5=E4=B8=9A=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SiNan.Business/AggregationBusiness.cs | 30 +++++++++++++++---- SiNan.Model/Core/ActualAmountBySpu.cs | 6 ++++ .../AggregationJDPopularizeSkuDaily.cs | 6 ++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/SiNan.Business/AggregationBusiness.cs b/SiNan.Business/AggregationBusiness.cs index eff0fed..69a2837 100644 --- a/SiNan.Business/AggregationBusiness.cs +++ b/SiNan.Business/AggregationBusiness.cs @@ -77,7 +77,7 @@ namespace SiNan.Business .WhereIf(!string.IsNullOrEmpty(querySpu), p => p.Id == querySpu) .OrderBy(p => p.CreateTime) .ToList(p => p.Id); - var skuList = fsql.Select().Where(ps => ps.ShopId == shopId && ps.State == 1) + var skuList = fsql.Select().Where(ps => ps.ShopId == shopId && ps.State == 1 && ps.Price > 0) .WhereIf(!string.IsNullOrEmpty(querySpu), ps => ps.ProductId == querySpu) .OrderBy(ps => ps.CreateTime) .ToList(ps => new @@ -111,7 +111,7 @@ namespace SiNan.Business spuGroupIndex++; Console.WriteLine($"{DateTime.Now} {shopName} SPU聚合 {spuGroupIndex}/{spuGroupCount}"); var currentGroupSkuList = skuList.Where(s => spuGroup.Contains(s.ProductId)).ToList(); - var currentGroupSkuIdList = currentGroupSkuList.Select(ps => ps.Id).ToList(); + var currentGroupSkuIdList = currentGroupSkuList.Select(ps => ps.Id).Distinct().ToList(); List insertAggregationSpuDailyList = new List(); List insertAggregationSkuDailyList = new List(); @@ -122,7 +122,7 @@ namespace SiNan.Business var aggregationDate_ProductLevelList = goiBusiness.StatisticsProductLevelGOI(currentGroupSkuIdList, startDate_aggregationDate, endDate_aggregationDate); var aggregationDate_PopularizeLevelList = goiBusiness.StatisticsPopularizeLevelGOI(currentGroupSkuIdList, startDate_aggregationDate, endDate_aggregationDate); - var aggregationDate_SpuActualAmountList = StatisticsActualAmountBySpu(spuGroup, startDate_aggregationDate, endDate_aggregationDate); + var aggregationDate_SkuActualAmountList = StatisticsActualAmountBySku(currentGroupSkuIdList, startDate_aggregationDate, endDate_aggregationDate); IList recent7d_ProductLevelList = null; IList recent7d_PopularizeLevelList = null; IList recent30d_ProductLevelList = null; @@ -180,7 +180,7 @@ namespace SiNan.Business ProductLevelGOI = spugoi_AggregationDate_ProductLevel?.GOI ?? 0M, PopularizeLevelProfit = spugoi_AggregationDate_PopularizeLevel?.Profit ?? 0M, PopularizeLevelGOI = spugoi_AggregationDate_PopularizeLevel?.GOI ?? 0M, - ActualAmount = aggregationDate_SpuActualAmountList.FirstOrDefault(x => x.Spu == spuId)?.ActualAmount ?? 0M + ActualAmount = aggregationDate_SkuActualAmountList.Where(x => x.Spu == spuId).Sum(x => x.ActualAmount) }; insertAggregationSpuDailyList.Add(spuDailyAggregation); #endregion @@ -287,7 +287,8 @@ namespace SiNan.Business ProductLevelProfit = skugoi_AggregationDate_ProductLevel?.Profit ?? 0M, ProductLevelGOI = skugoi_AggregationDate_ProductLevel?.GOI ?? 0M, PopularizeLevelProfit = skugoi_AggregationDate_PopularizeLevel?.Profit ?? 0M, - PopularizeLevelGOI = skugoi_AggregationDate_PopularizeLevel?.GOI ?? 0M + PopularizeLevelGOI = skugoi_AggregationDate_PopularizeLevel?.GOI ?? 0M, + ActualAmount = aggregationDate_SkuActualAmountList.FirstOrDefault(x => x.Sku == skuId)?.ActualAmount ?? 0M }; insertAggregationSkuDailyList.Add(skuDailyAggregation); #endregion @@ -390,6 +391,25 @@ namespace SiNan.Business }); return list; } + + private IList StatisticsActualAmountBySku(IList skuList, DateTime startDate, DateTime endDate) + { + var list = fsql.Select().InnerJoin((osku, o) => osku.OrderId == o.Id) + .Where((osku, o) => o.OrderState != Enums.OrderState.已取消 && + o.IsGift == false && + o.StartTime >= startDate && + o.EndTime <= endDate && + osku.Price > 0 && + skuList.Contains(osku.SkuId)) + .GroupBy((osku, o) => new { osku.SkuId, osku.ProductId }) + .ToList(g => new ActualAmountBySku + { + ActualAmount = g.Sum(g.Value.Item1.ActualAmount), + Sku = g.Key.SkuId, + Spu = g.Key.ProductId + }); + return list; + } #endregion #region 计划聚合任务 diff --git a/SiNan.Model/Core/ActualAmountBySpu.cs b/SiNan.Model/Core/ActualAmountBySpu.cs index d789e99..bff8539 100644 --- a/SiNan.Model/Core/ActualAmountBySpu.cs +++ b/SiNan.Model/Core/ActualAmountBySpu.cs @@ -9,4 +9,10 @@ public string Spu { get; set; } } + + public class ActualAmountBySku: ActualAmountBySpu + { + + public string Sku { get; set; } + } } diff --git a/SiNan.Model/Db/Aggregation/AggregationJDPopularizeSkuDaily.cs b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeSkuDaily.cs index 1748564..a321cca 100644 --- a/SiNan.Model/Db/Aggregation/AggregationJDPopularizeSkuDaily.cs +++ b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeSkuDaily.cs @@ -61,6 +61,12 @@ namespace SiNan.Model.Db [Column(StringLength = 50)] public string SkuId { get; set; } + /// + /// 商品营业额(SKU实收) + /// + [Column(DbType = "decimal(18,2)")] + public decimal? ActualAmount { get; set; } = 0.00M; + } }