From 27d55c942aa838d6142fe9833b790084d97f8805 Mon Sep 17 00:00:00 2001 From: sanji Date: Mon, 6 Nov 2023 18:38:43 +0800 Subject: [PATCH] =?UTF-8?q?xx=E6=8E=A5=E5=8F=A3=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Statistics/StatisticsBusiness.cs | 62 ++++++++++++++++++- .../Dto/Response/ListResponse.cs | 9 +++ .../Response/Order/XingXinagSearchResponse.cs | 20 +++++- .../Statistics/JDReportForm/GOIByShop.cs | 7 +++ .../Statistics/JDReportForm/GOIBySpu.cs | 7 +++ 5 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 BBWY.Server.Model/Dto/Response/ListResponse.cs create mode 100644 BBWY.Server.Model/Dto/Response/Statistics/JDReportForm/GOIByShop.cs create mode 100644 BBWY.Server.Model/Dto/Response/Statistics/JDReportForm/GOIBySpu.cs diff --git a/BBWY.Server.Business/Statistics/StatisticsBusiness.cs b/BBWY.Server.Business/Statistics/StatisticsBusiness.cs index 2e51173b..0fd2515e 100644 --- a/BBWY.Server.Business/Statistics/StatisticsBusiness.cs +++ b/BBWY.Server.Business/Statistics/StatisticsBusiness.cs @@ -1,12 +1,16 @@  +using BBWY.Common.Http; using BBWY.Common.Models; using BBWY.Server.Model; using BBWY.Server.Model.Db; using BBWY.Server.Model.Db.Mds; using BBWY.Server.Model.Dto; +using Newtonsoft.Json; +using Org.BouncyCastle.Ocsp; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices.ComTypes; using Yitter.IdGenerator; namespace BBWY.Server.Business @@ -15,11 +19,13 @@ namespace BBWY.Server.Business { private IList invalidOrderStateList; private FreeSqlMultiDBManager freeSqlMultiDBManager; + private RestApiService restApiService; - public StatisticsBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, FreeSqlMultiDBManager freeSqlMultiDBManager) : base(fsql, nLogManager, idGenerator) + public StatisticsBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, FreeSqlMultiDBManager freeSqlMultiDBManager, RestApiService restApiService) : base(fsql, nLogManager, idGenerator) { invalidOrderStateList = new List() { Enums.OrderState.待付款, Enums.OrderState.已取消 }; this.freeSqlMultiDBManager = freeSqlMultiDBManager; + this.restApiService = restApiService; } public OrderAchievementResponse GetOrderAchievementStatistics(OrderAchievementRequest request) @@ -192,11 +198,47 @@ namespace BBWY.Server.Business return null; var orderIdList = orderList.Select(o => o.Id).ToList(); - //查询orderSku + var orderSkuList = fsql.Select().Where(osku => osku.Price != 0 && orderIdList.Contains(osku.OrderId)).ToList(); + //查询成本明细 var orderCostDetailList = fsql.Select().Where(ocd => orderIdList.Contains(ocd.OrderId) && ocd.IsEnabled == true).ToList(); + var spuIdList = orderSkuList.Select(osku => osku.ProductId).Distinct().ToList(); + List spuGoiList = null; + GOIByShop shopGoi = null; + #region spu goi + { + var httpResult = restApiService.SendRequest("http://snapi.qiyue666.com/api/goi/QueryPopularizeLevelGOIBySpuId", string.Empty, new + { + SpuIdList = spuIdList, + StartTime = xingXiangSearchOrderRequest.SearchDate, + EndTime = xingXiangSearchOrderRequest.SearchDate + }, null, System.Net.Http.HttpMethod.Post); + + if (httpResult.StatusCode != System.Net.HttpStatusCode.OK) + throw new BusinessException("查询spu goi失败"); + var listRes = JsonConvert.DeserializeObject>(httpResult.Content); + spuGoiList = listRes.ItemList; + } + #endregion + + #region shop goi + { + var httpResult = restApiService.SendRequest("http://snapi.qiyue666.com/api/goi/QueryPopularizeLevelGOIByShopId", string.Empty, new + { + xingXiangSearchOrderRequest.ShopId, + StartTime = xingXiangSearchOrderRequest.SearchDate, + EndTime = xingXiangSearchOrderRequest.SearchDate + }, null, System.Net.Http.HttpMethod.Post); + + if (httpResult.StatusCode != System.Net.HttpStatusCode.OK) + throw new BusinessException("查询店铺 goi失败"); + shopGoi = JsonConvert.DeserializeObject(httpResult.Content); + } + #endregion + + detailList = new List(); foreach (var order in orderList) { @@ -229,6 +271,22 @@ namespace BBWY.Server.Business } } + var shopProductAmount = orderSkuList.Sum(osku => osku.ItemTotal * osku.Price); + + foreach (var d in detailList) + { + var spuGoi = spuGoiList?.FirstOrDefault(x => x.Spu == d.Spu); + if (spuGoi != null) + { + var productAmount = orderSkuList.Where(osku => osku.ProductId == d.Spu).Sum(osku => osku.ItemTotal * osku.Price); + d.SpuYingLiRatio = Math.Round((spuGoi.Profit - spuGoi.Cost) / productAmount.Value, 2); + } + + d.ShopYingLiRatio = shopProductAmount == 0 ? 0 : Math.Round((shopGoi.Profit - shopGoi.Cost) / shopProductAmount.Value, 2); + d.ShopProfitRatio = shopProductAmount == 0 ? 0 : Math.Round(shopGoi.Profit / shopProductAmount.Value, 2); + } + + var sdOrderList = orderList.Where(o => o.StorageType == Enums.StorageType.SD); return new XingXinagSearchResponse() diff --git a/BBWY.Server.Model/Dto/Response/ListResponse.cs b/BBWY.Server.Model/Dto/Response/ListResponse.cs new file mode 100644 index 00000000..f533e0f2 --- /dev/null +++ b/BBWY.Server.Model/Dto/Response/ListResponse.cs @@ -0,0 +1,9 @@ +namespace BBWY.Server.Model.Dto +{ + public class ListResponse where T : class + { + public System.Collections.Generic.List ItemList { get; set; } + + public long Count { get; set; } + } +} diff --git a/BBWY.Server.Model/Dto/Response/Order/XingXinagSearchResponse.cs b/BBWY.Server.Model/Dto/Response/Order/XingXinagSearchResponse.cs index 2cb074f3..9a726b8b 100644 --- a/BBWY.Server.Model/Dto/Response/Order/XingXinagSearchResponse.cs +++ b/BBWY.Server.Model/Dto/Response/Order/XingXinagSearchResponse.cs @@ -37,6 +37,9 @@ namespace BBWY.Server.Model.Dto //public decimal TotalCost { get; set; } + /// + /// SPU毛利 + /// public decimal Profit { get; set; } /// @@ -45,7 +48,7 @@ namespace BBWY.Server.Model.Dto public decimal ActualAmount { get; set; } /// - /// 毛利率 + /// SPU毛利率 /// public decimal ProfitRatio { @@ -69,5 +72,20 @@ namespace BBWY.Server.Model.Dto /// 刷单成交额 /// public decimal SDOrderAmount { get; set; } + + /// + /// 店铺毛利率 + /// + public decimal? ShopProfitRatio { get; set; } + + /// + /// 店铺盈利率 + /// + public decimal? ShopYingLiRatio { get; set; } + + /// + /// SPU盈利率 + /// + public decimal? SpuYingLiRatio { get; set; } } } diff --git a/BBWY.Server.Model/Dto/Response/Statistics/JDReportForm/GOIByShop.cs b/BBWY.Server.Model/Dto/Response/Statistics/JDReportForm/GOIByShop.cs new file mode 100644 index 00000000..844e7f3d --- /dev/null +++ b/BBWY.Server.Model/Dto/Response/Statistics/JDReportForm/GOIByShop.cs @@ -0,0 +1,7 @@ +namespace BBWY.Server.Model.Dto +{ + public class GOIByShop : GOIResponse + { + public long ShopId { get; set; } + } +} diff --git a/BBWY.Server.Model/Dto/Response/Statistics/JDReportForm/GOIBySpu.cs b/BBWY.Server.Model/Dto/Response/Statistics/JDReportForm/GOIBySpu.cs new file mode 100644 index 00000000..acdfbf3b --- /dev/null +++ b/BBWY.Server.Model/Dto/Response/Statistics/JDReportForm/GOIBySpu.cs @@ -0,0 +1,7 @@ +namespace BBWY.Server.Model.Dto +{ + public class GOIBySpu : GOIResponse + { + public string Spu { get; set; } + } +}