From e7904547b188e3ce0f9f19c43f30051972412c5e Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Sat, 4 Nov 2023 00:20:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E5=93=81360=E5=88=86=E6=9E=90GOI?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=E6=94=AF=E6=8C=81SPU?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6GOI=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SiNan.Business/GOIBusiness.cs | 23 +++++++++++++++---- .../Product360PopularizeAnalysisRequest.cs | 10 +++++++- .../Dto/Request/GOI/QueryProductGOIRequest.cs | 6 +++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/SiNan.Business/GOIBusiness.cs b/SiNan.Business/GOIBusiness.cs index 5d36446..5660887 100644 --- a/SiNan.Business/GOIBusiness.cs +++ b/SiNan.Business/GOIBusiness.cs @@ -173,12 +173,16 @@ namespace SiNan.Business if (request.ShopId == 0) throw new BusinessException("缺少店铺Id"); + if (request.PageSize > 5) + request.PageSize = 5; + ISelect? skuChildSelect = string.IsNullOrEmpty(request.Sku) ? null : fsql.Select().As("ps").Where(ps => ps.ShopId == request.ShopId && ps.Id == request.Sku); var productList = fsql.Select().Where(p => p.ShopId == request.ShopId) .WhereIf(!string.IsNullOrEmpty(request.Spu), p => p.Id == request.Spu) .WhereIf(skuChildSelect != null, p => skuChildSelect.Where(ps => ps.ProductId == p.Id).Any()) + .OrderByDescending(p => p.CreateTime) .Page(request.PageIndex, request.PageSize) .Count(out var productCount) .ToList(); @@ -278,6 +282,7 @@ namespace SiNan.Business Cost = productGoi.ProductSkuGOIList.Sum(x => x.PromotionGOI_Recent30Day?.Cost ?? 0M), Profit = productGoi.ProductSkuGOIList.Sum(x => x.PromotionGOI_Recent30Day?.Profit ?? 0M) }; + productGoi.TotalCost = productGoi.ProductSkuGOIList.Sum(x => x.TotalCost); productGoi.TotalDeficit = productGoi.ProductSkuGOIList.Sum(x => x.TotalDeficit); } @@ -291,8 +296,18 @@ namespace SiNan.Business public ListResponse QueryProduct360PopularizeGOI(Product360PopularizeAnalysisRequest request) { - if (request.SkuIdList == null || request.SkuIdList.Count() == 0) - throw new BusinessException("缺少sku"); + if (string.IsNullOrEmpty(request.Spu) && string.IsNullOrEmpty(request.Sku)) + throw new BusinessException("不能同时缺少spu和sku条件"); + + var skuIdList = new List(); + if (!string.IsNullOrEmpty(request.Sku)) + { + request.Spu = string.Empty; + skuIdList.Add(request.Sku); + } + if (!string.IsNullOrEmpty(request.Spu)) + skuIdList = fsql.Select().Where(ps => ps.ProductId == request.Spu).ToList(ps => ps.Id); + List list = new List(); var startDate_Recent7day = DateTime.Now.Date.AddDays(-7); @@ -304,8 +319,8 @@ namespace SiNan.Business var popularizeAdSkuSourceList = fsql.Select() .Where(x => x.ShopId == request.ShopId) .Where(x => x.Date >= request.StartDate && x.Date <= request.EndDate) - .WhereIf(request.SkuIdList.Count() == 1, x => x.Sku == request.SkuIdList[0]) - .WhereIf(request.SkuIdList.Count() > 1, x => request.SkuIdList.Contains(x.Sku)) + .WhereIf(skuIdList.Count() == 1, x => x.Sku == skuIdList[0]) + .WhereIf(skuIdList.Count() > 1, x => skuIdList.Contains(x.Sku)) .ToList(); var kuaicheCampaignSourceList = popularizeAdSkuSourceList.Where(x => x.BusinessType == 2).ToList(); diff --git a/SiNan.Model/Dto/Request/GOI/Product360PopularizeAnalysisRequest.cs b/SiNan.Model/Dto/Request/GOI/Product360PopularizeAnalysisRequest.cs index 526938a..02c10e1 100644 --- a/SiNan.Model/Dto/Request/GOI/Product360PopularizeAnalysisRequest.cs +++ b/SiNan.Model/Dto/Request/GOI/Product360PopularizeAnalysisRequest.cs @@ -4,7 +4,15 @@ { public long ShopId { get; set; } - public IList SkuIdList { get; set; } + /// + /// 按SPU条件查询时传值该字段 + /// + public string Spu { get; set; } + + /// + /// 按SKU条件查询时传值该字段,SPU和SKU同时有值会忽略SPU条件 + /// + public string Sku { get; set; } public DateTime StartDate { get; set; } diff --git a/SiNan.Model/Dto/Request/GOI/QueryProductGOIRequest.cs b/SiNan.Model/Dto/Request/GOI/QueryProductGOIRequest.cs index 7427194..2cdea58 100644 --- a/SiNan.Model/Dto/Request/GOI/QueryProductGOIRequest.cs +++ b/SiNan.Model/Dto/Request/GOI/QueryProductGOIRequest.cs @@ -2,8 +2,14 @@ { public class QueryProductGOIRequest { + /// + /// Spu搜索条件 + /// public string Spu { get; set; } + /// + /// Sku搜索条件(含有此sku的商品会被查出) + /// public string Sku { get; set; } public string SpuTitle { get; set; }