|
@ -1,11 +1,14 @@ |
|
|
using System; |
|
|
using BBWY.Common.Models; |
|
|
|
|
|
using BBWY.Server.Model.Db; |
|
|
|
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Linq; |
|
|
using System.Text; |
|
|
using System.Text; |
|
|
using Yitter.IdGenerator; |
|
|
using Yitter.IdGenerator; |
|
|
|
|
|
|
|
|
namespace BBWY.Server.Business |
|
|
namespace BBWY.Server.Business |
|
|
{ |
|
|
{ |
|
|
public class OrderSkuSaleDetailSyncBusiness : BaseBusiness |
|
|
public class OrderSkuSaleDetailSyncBusiness : BaseBusiness, IDenpendency |
|
|
{ |
|
|
{ |
|
|
public OrderSkuSaleDetailSyncBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator) : base(fsql, nLogManager, idGenerator) |
|
|
public OrderSkuSaleDetailSyncBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator) : base(fsql, nLogManager, idGenerator) |
|
|
{ |
|
|
{ |
|
@ -13,17 +16,182 @@ namespace BBWY.Server.Business |
|
|
|
|
|
|
|
|
public void SyncOrderSkuSaleDetail(long shopId, DateTime startDate, DateTime endDate) |
|
|
public void SyncOrderSkuSaleDetail(long shopId, DateTime startDate, DateTime endDate) |
|
|
{ |
|
|
{ |
|
|
StatisticsOrderSkuSaleDaily(shopId, startDate, endDate); |
|
|
StatisticsOrderSkuSaleDetail(shopId, startDate, endDate); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void SyncAllShopOrderSkuSaleDetail(DateTime startDate, DateTime endDate) |
|
|
public void SyncAllShopOrderSkuSaleDetail(DateTime startDate, DateTime endDate) |
|
|
{ |
|
|
{ |
|
|
StatisticsOrderSkuSaleDaily(null, startDate, endDate); |
|
|
StatisticsOrderSkuSaleDetail(null, startDate, endDate); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void StatisticsOrderSkuSaleDaily(long? shopId, DateTime startDate, DateTime endDate) |
|
|
private void StatisticsOrderSkuSaleDetail(long? shopId, DateTime startDate, DateTime endDate) |
|
|
{ |
|
|
{ |
|
|
|
|
|
var endTime = endDate.Date.AddDays(1).AddSeconds(-1); |
|
|
|
|
|
fsql.Delete<SkuDailySalesDetail>().WhereIf(shopId != null, s => s.ShopId == shopId) |
|
|
|
|
|
.Where(s => s.Date >= startDate && s.Date <= endDate) |
|
|
|
|
|
.ExecuteAffrows(); |
|
|
|
|
|
|
|
|
|
|
|
List<SkuDailySalesDetail> insertSkuDailySalesDetailList = new List<SkuDailySalesDetail>(); |
|
|
|
|
|
|
|
|
|
|
|
var oskuGroups = fsql.Select<OrderSku, Order>() |
|
|
|
|
|
.InnerJoin((osku, o) => osku.OrderId == o.Id) |
|
|
|
|
|
.WhereIf(shopId != null, (osku, o) => o.ShopId == shopId) |
|
|
|
|
|
.Where((osku, o) => o.StartTime >= startDate && o.StartTime <= endTime) |
|
|
|
|
|
.Where((osku, o) => o.StorageType != Model.Enums.StorageType.SD) |
|
|
|
|
|
.Where((osku, o) => o.OrderState != Model.Enums.OrderState.已取消) |
|
|
|
|
|
.GroupBy((osku, o) => new |
|
|
|
|
|
{ |
|
|
|
|
|
o.Platform, |
|
|
|
|
|
o.ShopId, |
|
|
|
|
|
osku.ProductId, |
|
|
|
|
|
osku.SkuId, |
|
|
|
|
|
osku.Price, |
|
|
|
|
|
o.StartTime.Value.Date |
|
|
|
|
|
}) |
|
|
|
|
|
.ToList(g => new SkuDailySalesDetail |
|
|
|
|
|
{ |
|
|
|
|
|
Platform = g.Key.Platform, |
|
|
|
|
|
ShopId = g.Key.ShopId, |
|
|
|
|
|
Spu = g.Key.ProductId, |
|
|
|
|
|
Sku = g.Key.SkuId, |
|
|
|
|
|
Date = g.Key.Date, |
|
|
|
|
|
Price = g.Key.Price, |
|
|
|
|
|
Amount = g.Sum(g.Value.Item1.Price * g.Value.Item1.ItemTotal), |
|
|
|
|
|
ItemTotal = (int)g.Sum(g.Value.Item1.ItemTotal) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var cancelOskuGroups = fsql.Select<OrderSku, Order>() |
|
|
|
|
|
.InnerJoin((osku, o) => osku.OrderId == o.Id) |
|
|
|
|
|
.WhereIf(shopId != null, (osku, o) => o.ShopId == shopId) |
|
|
|
|
|
.Where((osku, o) => o.ModifyTime >= startDate && o.ModifyTime <= endTime) |
|
|
|
|
|
.Where((osku, o) => o.StorageType != Model.Enums.StorageType.SD) |
|
|
|
|
|
.Where((osku, o) => o.OrderState == Model.Enums.OrderState.已取消) |
|
|
|
|
|
.GroupBy((osku, o) => new |
|
|
|
|
|
{ |
|
|
|
|
|
o.Platform, |
|
|
|
|
|
o.ShopId, |
|
|
|
|
|
osku.ProductId, |
|
|
|
|
|
osku.SkuId, |
|
|
|
|
|
osku.Price, |
|
|
|
|
|
o.ModifyTime.Value.Date |
|
|
|
|
|
}) |
|
|
|
|
|
.ToList(g => new SkuDailySalesDetail |
|
|
|
|
|
{ |
|
|
|
|
|
Platform = g.Key.Platform, |
|
|
|
|
|
ShopId = g.Key.ShopId, |
|
|
|
|
|
Spu = g.Key.ProductId, |
|
|
|
|
|
Sku = g.Key.SkuId, |
|
|
|
|
|
Date = g.Key.Date, |
|
|
|
|
|
Price = g.Key.Price, |
|
|
|
|
|
Amount = 0, |
|
|
|
|
|
ItemTotal = 0, |
|
|
|
|
|
CancelItemTotal = (int)g.Sum(g.Value.Item1.ItemTotal) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var giftOskuGroups = fsql.Select<GiftOrderSku, GiftOrder>() |
|
|
|
|
|
.InnerJoin((gos, go) => gos.GiftOrderId == go.Id) |
|
|
|
|
|
.WhereIf(shopId != null, (gos, go) => go.ShopId == shopId) |
|
|
|
|
|
.Where((gos, go) => go.StartTime >= startDate && go.StartTime <= endTime) |
|
|
|
|
|
.Where((gos, go) => go.OrderState != Model.Enums.OrderState.已取消) |
|
|
|
|
|
.GroupBy((gos, go) => new |
|
|
|
|
|
{ |
|
|
|
|
|
go.Platform, |
|
|
|
|
|
go.ShopId, |
|
|
|
|
|
gos.ProductId, |
|
|
|
|
|
gos.SkuId, |
|
|
|
|
|
gos.Price, |
|
|
|
|
|
go.StartTime.Value.Date |
|
|
|
|
|
}) |
|
|
|
|
|
.ToList(g => new SkuDailySalesDetail |
|
|
|
|
|
{ |
|
|
|
|
|
Platform = g.Key.Platform, |
|
|
|
|
|
ShopId = g.Key.ShopId, |
|
|
|
|
|
Spu = g.Key.ProductId, |
|
|
|
|
|
Sku = g.Key.SkuId, |
|
|
|
|
|
Date = g.Key.Date, |
|
|
|
|
|
Price = g.Key.Price, |
|
|
|
|
|
Amount = g.Sum(g.Value.Item1.Price * g.Value.Item1.ItemTotal), |
|
|
|
|
|
ItemTotal = (int)g.Sum(g.Value.Item1.ItemTotal) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var cancelGiftOskuGroups = fsql.Select<GiftOrderSku, GiftOrder>() |
|
|
|
|
|
.InnerJoin((gos, go) => gos.GiftOrderId == go.Id) |
|
|
|
|
|
.WhereIf(shopId != null, (gos, go) => go.ShopId == shopId) |
|
|
|
|
|
.Where((gos, go) => go.ModifyTime >= startDate && go.ModifyTime <= endTime) |
|
|
|
|
|
.Where((gos, go) => go.OrderState == Model.Enums.OrderState.已取消) |
|
|
|
|
|
.GroupBy((gos, go) => new |
|
|
|
|
|
{ |
|
|
|
|
|
go.Platform, |
|
|
|
|
|
go.ShopId, |
|
|
|
|
|
gos.ProductId, |
|
|
|
|
|
gos.SkuId, |
|
|
|
|
|
gos.Price, |
|
|
|
|
|
go.ModifyTime.Value.Date |
|
|
|
|
|
}) |
|
|
|
|
|
.ToList(g => new SkuDailySalesDetail |
|
|
|
|
|
{ |
|
|
|
|
|
Platform = g.Key.Platform, |
|
|
|
|
|
ShopId = g.Key.ShopId, |
|
|
|
|
|
Spu = g.Key.ProductId, |
|
|
|
|
|
Sku = g.Key.SkuId, |
|
|
|
|
|
Date = g.Key.Date, |
|
|
|
|
|
Price = g.Key.Price, |
|
|
|
|
|
Amount = 0, |
|
|
|
|
|
ItemTotal = 0, |
|
|
|
|
|
CancelItemTotal = (int)g.Sum(g.Value.Item1.ItemTotal) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
insertSkuDailySalesDetailList.AddRange(oskuGroups); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var canceloSkuGroup in cancelOskuGroups) |
|
|
|
|
|
{ |
|
|
|
|
|
var skuDaily = insertSkuDailySalesDetailList.FirstOrDefault(s => s.ShopId == canceloSkuGroup.ShopId && |
|
|
|
|
|
s.Date == canceloSkuGroup.Date && |
|
|
|
|
|
s.Sku == canceloSkuGroup.Sku); |
|
|
|
|
|
if (skuDaily != null) |
|
|
|
|
|
skuDaily.CancelItemTotal = canceloSkuGroup.CancelItemTotal; |
|
|
|
|
|
else |
|
|
|
|
|
insertSkuDailySalesDetailList.Add(canceloSkuGroup); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var giftOskuGroup in giftOskuGroups) |
|
|
|
|
|
{ |
|
|
|
|
|
var skuDaily = insertSkuDailySalesDetailList.FirstOrDefault(s => s.ShopId == giftOskuGroup.ShopId && |
|
|
|
|
|
s.Date == giftOskuGroup.Date && |
|
|
|
|
|
s.Sku == giftOskuGroup.Sku); |
|
|
|
|
|
if (skuDaily != null) |
|
|
|
|
|
{ |
|
|
|
|
|
skuDaily.ItemTotal += giftOskuGroup.ItemTotal; |
|
|
|
|
|
skuDaily.Amount += giftOskuGroup.Amount; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
insertSkuDailySalesDetailList.Add(giftOskuGroup); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var cancelGiftOskuGroup in cancelGiftOskuGroups) |
|
|
|
|
|
{ |
|
|
|
|
|
var skuDaily = insertSkuDailySalesDetailList.FirstOrDefault(s => s.ShopId == cancelGiftOskuGroup.ShopId && |
|
|
|
|
|
s.Date == cancelGiftOskuGroup.Date && |
|
|
|
|
|
s.Sku == cancelGiftOskuGroup.Sku); |
|
|
|
|
|
if (skuDaily != null) |
|
|
|
|
|
skuDaily.CancelItemTotal = cancelGiftOskuGroup.CancelItemTotal; |
|
|
|
|
|
else |
|
|
|
|
|
insertSkuDailySalesDetailList.Add(cancelGiftOskuGroup); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (insertSkuDailySalesDetailList.Count() > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var skuDaily in insertSkuDailySalesDetailList) |
|
|
|
|
|
{ |
|
|
|
|
|
skuDaily.Id = idGenerator.NewLong(); |
|
|
|
|
|
skuDaily.IsGift = skuDaily.Price == 0M; |
|
|
|
|
|
skuDaily.CreateTime = DateTime.Now; |
|
|
|
|
|
} |
|
|
|
|
|
fsql.Insert(insertSkuDailySalesDetailList).ExecuteAffrows(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|