From d5a67fe401245b9fcccb5cbc5ff646ec7770eeb7 Mon Sep 17 00:00:00 2001
From: shanj <18996038927@163.com>
Date: Mon, 6 Nov 2023 01:30:44 +0800
Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AEspu=E6=9F=A5=E8=AF=A2?=
=?UTF-8?q?=E6=8E=A8=E5=B9=BF=E7=BB=B4=E5=BA=A6GOI=20=E6=A0=B9=E6=8D=AEsho?=
=?UTF-8?q?pId=E6=9F=A5=E8=AF=A2=E6=8E=A8=E5=B9=BF=E7=BB=B4=E5=BA=A6GOI?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
SiNan.API/Controllers/GOIController.cs | 27 ++++++++-
SiNan.Business/GOIBusiness.cs | 56 +++++++++++++++++++
SiNan.Model/Core/GOI/GOIByShop.cs | 9 +++
SiNan.Model/Core/GOI/GOIBySpu.cs | 9 +++
.../QueryPopularizeLevelGOIByShopIdRequest.cs | 11 ++++
.../QueryPopularizeLevelGOIBySpuIdRequest.cs | 11 ++++
6 files changed, 121 insertions(+), 2 deletions(-)
create mode 100644 SiNan.Model/Core/GOI/GOIByShop.cs
create mode 100644 SiNan.Model/Core/GOI/GOIBySpu.cs
create mode 100644 SiNan.Model/Dto/Request/GOI/QueryPopularizeLevelGOIByShopIdRequest.cs
create mode 100644 SiNan.Model/Dto/Request/GOI/QueryPopularizeLevelGOIBySpuIdRequest.cs
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; }
+ }
+}