Browse Source

Merge branch 'master' of http://code.qiyue666.com/pengcong001/bbwy

AddValidOverTime
506583276@qq.com 2 years ago
parent
commit
baaa37441b
  1. 62
      BBWY.Server.Business/Statistics/StatisticsBusiness.cs
  2. 9
      BBWY.Server.Model/Dto/Response/ListResponse.cs
  3. 20
      BBWY.Server.Model/Dto/Response/Order/XingXinagSearchResponse.cs
  4. 7
      BBWY.Server.Model/Dto/Response/Statistics/JDReportForm/GOIByShop.cs
  5. 7
      BBWY.Server.Model/Dto/Response/Statistics/JDReportForm/GOIBySpu.cs

62
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<Enums.OrderState> 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., 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<OrderSku>().Where(osku => osku.Price != 0 && orderIdList.Contains(osku.OrderId)).ToList();
//查询成本明细
var orderCostDetailList = fsql.Select<OrderCostDetail>().Where(ocd => orderIdList.Contains(ocd.OrderId) && ocd.IsEnabled == true).ToList();
var spuIdList = orderSkuList.Select(osku => osku.ProductId).Distinct().ToList();
List<GOIBySpu> 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<ListResponse<GOIBySpu>>(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<GOIByShop>(httpResult.Content);
}
#endregion
detailList = new List<XingXiangItemResponse>();
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()

9
BBWY.Server.Model/Dto/Response/ListResponse.cs

@ -0,0 +1,9 @@
namespace BBWY.Server.Model.Dto
{
public class ListResponse<T> where T : class
{
public System.Collections.Generic.List<T> ItemList { get; set; }
public long Count { get; set; }
}
}

20
BBWY.Server.Model/Dto/Response/Order/XingXinagSearchResponse.cs

@ -37,6 +37,9 @@ namespace BBWY.Server.Model.Dto
//public decimal TotalCost { get; set; }
/// <summary>
/// SPU毛利
/// </summary>
public decimal Profit { get; set; }
/// <summary>
@ -45,7 +48,7 @@ namespace BBWY.Server.Model.Dto
public decimal ActualAmount { get; set; }
/// <summary>
/// 毛利率
/// SPU毛利率
/// </summary>
public decimal ProfitRatio
{
@ -69,5 +72,20 @@ namespace BBWY.Server.Model.Dto
/// 刷单成交额
/// </summary>
public decimal SDOrderAmount { get; set; }
/// <summary>
/// 店铺毛利率
/// </summary>
public decimal? ShopProfitRatio { get; set; }
/// <summary>
/// 店铺盈利率
/// </summary>
public decimal? ShopYingLiRatio { get; set; }
/// <summary>
/// SPU盈利率
/// </summary>
public decimal? SpuYingLiRatio { get; set; }
}
}

7
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; }
}
}

7
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; }
}
}
Loading…
Cancel
Save