|
|
@ -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() |
|
|
|