Browse Source

统计销量

qianyi
shanji 3 years ago
parent
commit
b106cd8c76
  1. 99
      BBWY.Server.Business/Sync/OrderSyncBusiness.cs
  2. 10
      BBWY.Server.Model/Db/Statistics/SkuDailySalesDetails.cs

99
BBWY.Server.Business/Sync/OrderSyncBusiness.cs

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

10
BBWY.Server.Model/Db/Statistics/SkuDailySalesDetails.cs

@ -7,8 +7,8 @@ namespace BBWY.Server.Model.Db
/// <summary>
/// sku每日销量详情
/// </summary>
[Table(Name = "skudailysalesdetails", DisableSyncStructure = true)]
public partial class Skudailysalesdetails
[Table(Name = "skudailysalesdetail", DisableSyncStructure = true)]
public partial class SkuDailySalesDetail
{
[Column(IsPrimary = true)]
@ -18,7 +18,7 @@ namespace BBWY.Server.Model.Db
/// 销售额
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? Amount { get; set; }
public decimal Amount { get; set; } = 0.0M;
[Column(DbType = "datetime")]
public DateTime? CreateTime { get; set; }
@ -30,13 +30,13 @@ namespace BBWY.Server.Model.Db
/// 销售件数
/// </summary>
public int? ItemTotal { get; set; }
public int ItemTotal { get; set; } = 0;
/// <summary>
/// 订单数
/// </summary>
public int? OrderCount { get; set; }
public int OrderCount { get; set; } = 0;
[Column(MapType = typeof(int?))]
public Enums.Platform? Platform { get; set; }

Loading…
Cancel
Save