|
|
@ -678,27 +678,30 @@ namespace BBWYB.Server.Business |
|
|
|
var skuIdList = purchaseSchemeList.Select(ps => ps.SkuId).Distinct().ToList(); |
|
|
|
var recentDate = DateTime.Now.Date.AddDays(-30); |
|
|
|
|
|
|
|
var purchaseSchemeProductList = fsql.Select<PurchaseSchemeProduct, Purchaser>() |
|
|
|
.InnerJoin((psp, p) => psp.PurchaserId == p.Id) |
|
|
|
.Where((psp, p) => purchaseSchemeIdList.Contains(psp.SkuPurchaseSchemeId)) |
|
|
|
.ToList((psp, p) => new PurchaseSchemeProductResponse |
|
|
|
{ |
|
|
|
CreateTime = psp.CreateTime, |
|
|
|
Id = psp.Id, |
|
|
|
ProductId = psp.ProductId, |
|
|
|
PurchaseProductId = psp.PurchaseProductId, |
|
|
|
PurchaseUrl = psp.PurchaseUrl, |
|
|
|
SkuId = psp.SkuId, |
|
|
|
SkuPurchaseSchemeId = psp.SkuPurchaseSchemeId, |
|
|
|
PurchaserId = p.Id, |
|
|
|
PurchaserId2 = p.Id2, |
|
|
|
PurchaserLocation = p.Location, |
|
|
|
PurchaserName = p.Name, |
|
|
|
PurchasePlatform = p.Platform, |
|
|
|
PurchaserMemberId = p.MemberId, |
|
|
|
PurchaserPurchasedCount = p.PurchasedCount, |
|
|
|
PurchaserPurchasedSkuCount = p.PurchasedSkuCount, |
|
|
|
}); |
|
|
|
//var purchaseSchemeProductList = fsql.Select<PurchaseSchemeProduct, Purchaser>()
|
|
|
|
// .InnerJoin((psp, p) => psp.PurchaserId == p.Id)
|
|
|
|
// .Where((psp, p) => purchaseSchemeIdList.Contains(psp.SkuPurchaseSchemeId))
|
|
|
|
// .ToList((psp, p) => new PurchaseSchemeProductResponse
|
|
|
|
// {
|
|
|
|
// CreateTime = psp.CreateTime,
|
|
|
|
// Id = psp.Id,
|
|
|
|
// ProductId = psp.ProductId,
|
|
|
|
// PurchaseProductId = psp.PurchaseProductId,
|
|
|
|
// PurchaseUrl = psp.PurchaseUrl,
|
|
|
|
// SkuId = psp.SkuId,
|
|
|
|
// SkuPurchaseSchemeId = psp.SkuPurchaseSchemeId,
|
|
|
|
// PurchaserId = p.Id,
|
|
|
|
// PurchaserId2 = p.Id2,
|
|
|
|
// PurchaserLocation = p.Location,
|
|
|
|
// PurchaserName = p.Name,
|
|
|
|
// PurchasePlatform = p.Platform,
|
|
|
|
// PurchaserMemberId = p.MemberId
|
|
|
|
// //PurchaserPurchasedCount = p.PurchasedCount,
|
|
|
|
// //PurchaserPurchasedSkuCount = p.PurchasedSkuCount,
|
|
|
|
// });
|
|
|
|
var purchaseSchemeProductList = fsql.Select<PurchaseSchemeProduct>() |
|
|
|
.Where(psp => purchaseSchemeIdList.Contains(psp.SkuPurchaseSchemeId)) |
|
|
|
.ToList<PurchaseSchemeProductResponse>(); |
|
|
|
|
|
|
|
var purchaseSchemeProductSkuList = fsql.Select<PurchaseSchemeProductSku>().Where(p => purchaseSchemeIdList.Contains(p.SkuPurchaseSchemeId)) |
|
|
|
.ToList().Map<List<PurchaseSchemeProductSkuResponse>>(); |
|
|
@ -758,6 +761,48 @@ namespace BBWYB.Server.Business |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<string> purchaserIdList = purchaseSchemeProductList.Select(x => x.PurchaserId).Distinct().ToList(); |
|
|
|
var dbPurchaserList = fsql.Select<Purchaser>(purchaserIdList).ToList<PurchaserResponse>(); |
|
|
|
if (request.IncludePurchaserStatisticsInfo == 1) |
|
|
|
{ |
|
|
|
#region 查询SKU采购数
|
|
|
|
var purchasedSkuList = fsql.Select<SkuHistoryPurchaserRelation, ProductSku>() |
|
|
|
.InnerJoin((spr, ps) => spr.SkuId == ps.Id) |
|
|
|
.Where((spr, ps) => ps.ShopId == request.ShopId && purchaserIdList.Contains(spr.PurchaserId)) |
|
|
|
.GroupBy((spr, ps) => new { spr.PurchaserId, spr.SkuId }) |
|
|
|
.ToList(g => new |
|
|
|
{ |
|
|
|
g.Key.PurchaserId, |
|
|
|
g.Key.SkuId |
|
|
|
}); |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 查询订单数
|
|
|
|
var poList = fsql.Select<OrderPurchaseInfo, Order>() |
|
|
|
.InnerJoin((opi, o) => opi.OrderId == o.Id) |
|
|
|
.Where((opi, o) => opi.ShopId == request.ShopId && |
|
|
|
opi.IsEnabled == true && |
|
|
|
o.OrderState != Enums.OrderState.已取消 && |
|
|
|
purchaserIdList.Contains(opi.PurchaserId)) |
|
|
|
.GroupBy((opi, o) => opi.PurchaserId) |
|
|
|
.ToList(g => new |
|
|
|
{ |
|
|
|
PurchaserId = g.Key, |
|
|
|
Count = g.Count() |
|
|
|
}); |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
foreach (var purchaser in dbPurchaserList) |
|
|
|
{ |
|
|
|
purchaser.PurchasedSkuCount = purchasedSkuList.Where(x => x.PurchaserId == purchaser.Id) |
|
|
|
.Select(x => x.SkuId) |
|
|
|
.Distinct() |
|
|
|
.Count(); |
|
|
|
purchaser.PurchasedCount = poList.FirstOrDefault(x => x.PurchaserId == purchaser.Id)?.Count ?? 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var scheme in purchaseSchemeList) |
|
|
|
{ |
|
|
@ -771,6 +816,18 @@ namespace BBWYB.Server.Business |
|
|
|
psk.PurchaseProductId == schemeProduct.PurchaseProductId); |
|
|
|
if (schemeProductSkuList.Count() > 0) |
|
|
|
schemeProduct.PurchaseSchemeProductSkuList.AddRange(schemeProductSkuList); |
|
|
|
|
|
|
|
var purchaser = dbPurchaserList.FirstOrDefault(p => p.Id == schemeProduct.PurchaserId); |
|
|
|
if (purchaser != null) |
|
|
|
{ |
|
|
|
schemeProduct.PurchaserId = purchaser.Id; |
|
|
|
schemeProduct.PurchaserId2 = purchaser.Id2; |
|
|
|
schemeProduct.PurchaserLocation = purchaser.Location; |
|
|
|
schemeProduct.PurchaserMemberId = purchaser.MemberId; |
|
|
|
schemeProduct.PurchaserName = purchaser.Name; |
|
|
|
schemeProduct.PurchaserPurchasedCount = purchaser.PurchasedCount; |
|
|
|
schemeProduct.PurchaserPurchasedSkuCount = purchaser.PurchasedSkuCount; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -779,17 +836,9 @@ namespace BBWYB.Server.Business |
|
|
|
{ |
|
|
|
if (!scheme.PurchaserList.Any(p => p.Id == schemeProduct.PurchaserId)) |
|
|
|
{ |
|
|
|
scheme.PurchaserList.Add(new Purchaser() |
|
|
|
{ |
|
|
|
Id = schemeProduct.PurchaserId, |
|
|
|
Id2 = schemeProduct.PurchaserId2, |
|
|
|
Location = schemeProduct.PurchaserLocation, |
|
|
|
Name = schemeProduct.PurchaserName, |
|
|
|
Platform = schemeProduct.PurchasePlatform, |
|
|
|
MemberId = schemeProduct.PurchaserMemberId, |
|
|
|
PurchasedCount = schemeProduct.PurchaserPurchasedCount, |
|
|
|
PurchasedSkuCount = schemeProduct.PurchaserPurchasedSkuCount |
|
|
|
}); |
|
|
|
var purchaser = dbPurchaserList.FirstOrDefault(p => p.Id == schemeProduct.PurchaserId); |
|
|
|
if (purchaser != null) |
|
|
|
scheme.PurchaserList.Add(purchaser); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|