|
|
@ -207,9 +207,13 @@ namespace BBWY.Server.Business |
|
|
|
List<OrderCostDetail> insertOrderCostDetailList = new List<OrderCostDetail>(); |
|
|
|
List<OrderSku> insertOrderSkuList = new List<OrderSku>(); |
|
|
|
List<OrderCoupon> insertOrderCouponList = new List<OrderCoupon>(); |
|
|
|
List<SkuDailySalesDetail> insertSkuDailySaleDetailList = new List<SkuDailySalesDetail>(); |
|
|
|
|
|
|
|
IList<IUpdate<Order>> updateOrderList = new List<IUpdate<Order>>(); |
|
|
|
IList<IUpdate<PurchaseOrder>> updatePurchaseOrderList = new List<IUpdate<PurchaseOrder>>(); |
|
|
|
IList<IUpdate<SkuDailySalesDetail>> updateSkuDailySalesDetailList = new List<IUpdate<SkuDailySalesDetail>>(); |
|
|
|
|
|
|
|
IDictionary<DateTime, List<SkuDailySalesDetail>> skuDailySalesDetailDictionary = new Dictionary<DateTime, List<SkuDailySalesDetail>>(); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
foreach (var orderJToken in orderTokenList) |
|
|
@ -274,19 +278,46 @@ namespace BBWY.Server.Business |
|
|
|
insertOrderList.Add(dbOrder); |
|
|
|
|
|
|
|
#region OrderSku
|
|
|
|
var orderSkuList = orderJToken["itemInfoList"].Where(skuJToken => skuJToken.Value<decimal>("jdPrice") != 0M).Select(skuToken => new OrderSku() |
|
|
|
var itemInfoList = orderJToken["itemInfoList"].Where(skuJToken => skuJToken.Value<decimal>("jdPrice") != 0M); |
|
|
|
foreach (var orderSkuJToken in itemInfoList) |
|
|
|
{ |
|
|
|
var osku = new OrderSku() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
ItemTotal = skuToken.Value<int>("itemTotal"), |
|
|
|
Price = skuToken.Value<decimal>("jdPrice"), |
|
|
|
ProductId = skuToken.Value<string>("wareId"), |
|
|
|
Title = skuToken.Value<string>("skuName").SimplifySkuName(), |
|
|
|
ProductNo = skuToken.Value<string>("productNo"), |
|
|
|
ItemTotal = orderSkuJToken.Value<int>("itemTotal"), |
|
|
|
Price = orderSkuJToken.Value<decimal>("jdPrice"), |
|
|
|
ProductId = orderSkuJToken.Value<string>("wareId"), |
|
|
|
Title = orderSkuJToken.Value<string>("skuName").SimplifySkuName(), |
|
|
|
ProductNo = orderSkuJToken.Value<string>("productNo"), |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
OrderId = orderId, |
|
|
|
SkuId = skuToken.Value<string>("skuId") |
|
|
|
}).ToList(); |
|
|
|
insertOrderSkuList.AddRange(orderSkuList); |
|
|
|
SkuId = orderSkuJToken.Value<string>("skuId") |
|
|
|
}; |
|
|
|
insertOrderSkuList.Add(osku); |
|
|
|
|
|
|
|
if (!skuDailySalesDetailDictionary.TryGetValue(dbOrder.StartTime.Value, out List<SkuDailySalesDetail> skuDailySalesDetailList)) |
|
|
|
{ |
|
|
|
skuDailySalesDetailList = new List<SkuDailySalesDetail>(); |
|
|
|
skuDailySalesDetailDictionary.Add(dbOrder.StartTime.Value, skuDailySalesDetailList); |
|
|
|
} |
|
|
|
var skuDailySalesDetail = skuDailySalesDetailList.FirstOrDefault(s => s.Sku == osku.SkuId); |
|
|
|
if (skuDailySalesDetail == null) |
|
|
|
{ |
|
|
|
skuDailySalesDetail = new SkuDailySalesDetail() |
|
|
|
{ |
|
|
|
ShopId = shopId, |
|
|
|
Spu = osku.ProductId, |
|
|
|
Sku = osku.SkuId, |
|
|
|
Platform = Enums.Platform.京东, |
|
|
|
Price = osku.Price, |
|
|
|
Date = dbOrder.StartTime.Value |
|
|
|
}; |
|
|
|
skuDailySalesDetailList.Add(skuDailySalesDetail); |
|
|
|
} |
|
|
|
skuDailySalesDetail.Amount += osku.Price.Value * osku.ItemTotal.Value; |
|
|
|
skuDailySalesDetail.ItemTotal += osku.ItemTotal.Value; |
|
|
|
skuDailySalesDetail.OrderCount++; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
#endregion
|
|
|
@ -297,10 +328,6 @@ namespace BBWY.Server.Business |
|
|
|
var orderConsignee = new OrderConsignee() |
|
|
|
{ |
|
|
|
OrderId = orderId, |
|
|
|
//Address = orderJToken["consigneeInfo"].Value<string>("fullAddress"),
|
|
|
|
//ContactName = orderJToken["consigneeInfo"].Value<string>("fullname"),
|
|
|
|
//Mobile = orderJToken["consigneeInfo"].Value<string>("mobile"),
|
|
|
|
//TelePhone = orderJToken["consigneeInfo"].Value<string>("telephone"),
|
|
|
|
City = orderJToken["consigneeInfo"].Value<string>("city"), |
|
|
|
Province = orderJToken["consigneeInfo"].Value<string>("province"), |
|
|
|
County = orderJToken["consigneeInfo"].Value<string>("county"), |
|
|
@ -618,6 +645,46 @@ namespace BBWY.Server.Business |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region sku销量统计
|
|
|
|
if (skuDailySalesDetailDictionary.Keys.Count > 0) |
|
|
|
{ |
|
|
|
foreach (var date in skuDailySalesDetailDictionary.Keys) |
|
|
|
{ |
|
|
|
var skuDailySalesDetailList = skuDailySalesDetailDictionary[date]; |
|
|
|
var skuDailySalesDetailIds = skuDailySalesDetailList.Select(s => s.Sku).ToList(); |
|
|
|
var dbSkuDailySalesDetailIds = fsql.Select<SkuDailySalesDetail>().Where(s => s.ShopId == shopId && |
|
|
|
s.Date == date && |
|
|
|
skuDailySalesDetailIds.Contains(s.Sku)).ToList(s => s.Sku); |
|
|
|
var exceptIds = skuDailySalesDetailIds.Except(dbSkuDailySalesDetailIds).ToList(); |
|
|
|
if (exceptIds.Count() > 0) |
|
|
|
{ |
|
|
|
var insertList = skuDailySalesDetailList.Where(s => exceptIds.Contains(s.Sku)); |
|
|
|
foreach (var s in insertList) |
|
|
|
{ |
|
|
|
s.Id = idGenerator.NewLong(); |
|
|
|
s.CreateTime = DateTime.Now; |
|
|
|
insertSkuDailySaleDetailList.Add(s); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var intersectIds = skuDailySalesDetailIds.Intersect(dbSkuDailySalesDetailIds).ToList(); |
|
|
|
if (intersectIds.Count() > 0) |
|
|
|
{ |
|
|
|
var updateList = skuDailySalesDetailList.Where(s => intersectIds.Contains(s.Sku)); |
|
|
|
foreach (var s in updateList) |
|
|
|
{ |
|
|
|
var iupdate = fsql.Update<SkuDailySalesDetail>().Set(ds => ds.Amount + s.Amount) |
|
|
|
.Set(ds => ds.OrderCount + s.OrderCount) |
|
|
|
.Set(ds => ds.ItemTotal + s.ItemTotal) |
|
|
|
.Where(ds => ds.ShopId == shopId && ds.Date == s.Date && ds.Sku == s.Sku); |
|
|
|
updateSkuDailySalesDetailList.Add(iupdate); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
if (insertOrderList.Count() > 0) |
|
|
@ -632,6 +699,8 @@ namespace BBWY.Server.Business |
|
|
|
fsql.Insert(insertOrderCostDetailList).ExecuteAffrows(); |
|
|
|
if (insertOrderCouponList.Count() > 0) |
|
|
|
fsql.Insert(insertOrderCouponList).ExecuteAffrows(); |
|
|
|
if (insertSkuDailySaleDetailList.Count() > 0) |
|
|
|
fsql.Insert(insertSkuDailySaleDetailList).ExecuteAffrows(); |
|
|
|
|
|
|
|
if (updatePurchaseOrderList.Count() > 0) |
|
|
|
{ |
|
|
@ -644,6 +713,10 @@ namespace BBWY.Server.Business |
|
|
|
foreach (var update in updateOrderList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
} |
|
|
|
|
|
|
|
if (updateSkuDailySalesDetailList.Count > 0) |
|
|
|
foreach (var update in updateSkuDailySalesDetailList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|