|
|
@ -3,6 +3,7 @@ using BBWYB.Common.Models; |
|
|
|
using BBWYB.Server.Model; |
|
|
|
using BBWYB.Server.Model.Db; |
|
|
|
using BBWYB.Server.Model.Dto; |
|
|
|
using FreeSql; |
|
|
|
using Yitter.IdGenerator; |
|
|
|
|
|
|
|
namespace BBWYB.Server.Business |
|
|
@ -32,9 +33,29 @@ namespace BBWYB.Server.Business |
|
|
|
|
|
|
|
public ListResponse<PurchaserResponse> QueryPurchaserList(QueryPurchaserRequest request) |
|
|
|
{ |
|
|
|
#region 数据验证
|
|
|
|
if (request.RecentDayCondition != null && request.RecentDayCondition.RecentDay > 0) |
|
|
|
{ |
|
|
|
if (request.RecentDayCondition.PurchasedCountComparisonOperator != null) |
|
|
|
{ |
|
|
|
if (request.RecentDayCondition.PurchasedCount == null || (request.RecentDayCondition.PurchasedCountComparisonOperator == Enums.ComparisonOperator.介于 && |
|
|
|
request.RecentDayCondition.PurchasedCount2 == null)) |
|
|
|
throw new BusinessException("采购量条件不完整"); |
|
|
|
} |
|
|
|
|
|
|
|
if (request.RecentDayCondition.PurchasedAmountComparisonOperator != null) |
|
|
|
{ |
|
|
|
if (request.RecentDayCondition.PurchasedAmount == null || (request.RecentDayCondition.PurchasedAmountComparisonOperator == Enums.ComparisonOperator.介于 && |
|
|
|
request.RecentDayCondition.PurchasedAmount2 == null)) |
|
|
|
throw new BusinessException("采购金额条件不完整"); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
if (request.PageSize > 20) |
|
|
|
request.PageSize = 20; |
|
|
|
var purchaserList = fsql.Select<Purchaser>() |
|
|
|
|
|
|
|
var select = fsql.Select<Purchaser>() |
|
|
|
.WhereIf(!string.IsNullOrEmpty(request.Spu), p => fsql.Select<PurchaseSchemeProduct>() |
|
|
|
.Where(psp1 => psp1.PurchaserId == p.Id && |
|
|
|
psp1.ProductId == request.Spu) |
|
|
@ -43,15 +64,62 @@ namespace BBWYB.Server.Business |
|
|
|
.Where(psp2 => psp2.PurchaserId == p.Id && |
|
|
|
psp2.SkuId == request.Sku) |
|
|
|
.Any()) |
|
|
|
.WhereIf(request.PurchaserNameList != null && request.PurchaserNameList.Count() > 0, p => request.PurchaserNameList.Contains(p.Name)) |
|
|
|
.WhereIf(request.CategoryIdList != null && request.CategoryIdList.Count() > 0, p => fsql.Select<Purchaser_ExtendedInfo_Relation>() |
|
|
|
.WhereIf(request.PurchaserNameList != null && |
|
|
|
request.PurchaserNameList.Count() > 0, p => request.PurchaserNameList.Contains(p.Name)) |
|
|
|
.WhereIf(request.CategoryIdList != null && |
|
|
|
request.CategoryIdList.Count() > 0, p => fsql.Select<Purchaser_ExtendedInfo_Relation>() |
|
|
|
.Where(per => per.PurchaserId == p.Id && |
|
|
|
request.CategoryIdList.Contains(per.ExtendedInfoId.Value)).Any()) |
|
|
|
.WhereIf(request.LocationList != null && request.LocationList.Count() > 0, p => request.LocationList.Contains(p.Location)) |
|
|
|
.Page(request.PageIndex, request.PageSize) |
|
|
|
.WhereIf(request.ManagmentMode != null, p => p.ManagmentMode == request.ManagmentMode); |
|
|
|
|
|
|
|
if (request.RecentDayCondition != null && request.RecentDayCondition.RecentDay > 0) |
|
|
|
{ |
|
|
|
var recentStartDay = DateTime.Now.Date.AddDays(request.RecentDayCondition.RecentDay.Value * -1); |
|
|
|
if (request.RecentDayCondition.PurchasedCountComparisonOperator != null) |
|
|
|
{ |
|
|
|
var childSelect = 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.已取消 && |
|
|
|
opi.CreateTime >= recentStartDay) |
|
|
|
.GroupBy((opi, o) => opi.PurchaserId) |
|
|
|
.HavingIf(request.RecentDayCondition.PurchasedCountComparisonOperator == Enums.ComparisonOperator.等于, g => g.Count() == request.RecentDayCondition.PurchasedCount) |
|
|
|
.HavingIf(request.RecentDayCondition.PurchasedCountComparisonOperator == Enums.ComparisonOperator.小于, g => g.Count() <= request.RecentDayCondition.PurchasedCount) |
|
|
|
.HavingIf(request.RecentDayCondition.PurchasedCountComparisonOperator == Enums.ComparisonOperator.大于, g => g.Count() >= request.RecentDayCondition.PurchasedCount) |
|
|
|
.HavingIf(request.RecentDayCondition.PurchasedCountComparisonOperator == Enums.ComparisonOperator.介于, g => g.Count() >= request.RecentDayCondition.PurchasedCount && g.Count() <= request.RecentDayCondition.PurchasedCount2) |
|
|
|
.WithTempQuery(g => new { g.Value.Item1.PurchaserId, Count = g.Count() }).As("pcc"); |
|
|
|
select = select.Where(p => childSelect.Where(pcc => pcc.PurchaserId == p.Id).Any()); |
|
|
|
} |
|
|
|
if (request.RecentDayCondition.PurchasedAmountComparisonOperator != null) |
|
|
|
{ |
|
|
|
var childSelect = fsql.Select<OrderCostDetail, Order, OrderPurchaseRelationInfo, OrderPurchaseInfo>() |
|
|
|
.InnerJoin((ocd, o, ori, opi) => ocd.OrderId == o.Id) |
|
|
|
.InnerJoin((ocd, o, ori, opi) => ocd.OrderId == ori.OrderId && ocd.SkuId == ori.BelongSkuId) |
|
|
|
.InnerJoin((ocd, o, ori, opi) => ori.OrderId == opi.OrderId) |
|
|
|
.Where((ocd, o, ori, opi) => o.ShopId == request.ShopId && |
|
|
|
o.OrderState != Enums.OrderState.已取消 && |
|
|
|
ocd.IsEnabled == true && |
|
|
|
opi.IsEnabled == true && |
|
|
|
opi.CreateTime >= recentStartDay) |
|
|
|
.GroupBy((ocd, o, ori, opi) => opi.PurchaserId) |
|
|
|
.HavingIf(request.RecentDayCondition.PurchasedAmountComparisonOperator == Enums.ComparisonOperator.等于, g => g.Sum(g.Value.Item1.SkuAmount + g.Value.Item1.PurchaseFreight) == request.RecentDayCondition.PurchasedAmount) |
|
|
|
.HavingIf(request.RecentDayCondition.PurchasedAmountComparisonOperator == Enums.ComparisonOperator.小于, g => g.Sum(g.Value.Item1.SkuAmount + g.Value.Item1.PurchaseFreight) <= request.RecentDayCondition.PurchasedAmount) |
|
|
|
.HavingIf(request.RecentDayCondition.PurchasedAmountComparisonOperator == Enums.ComparisonOperator.大于, g => g.Sum(g.Value.Item1.SkuAmount + g.Value.Item1.PurchaseFreight) >= request.RecentDayCondition.PurchasedAmount) |
|
|
|
.HavingIf(request.RecentDayCondition.PurchasedAmountComparisonOperator == Enums.ComparisonOperator.介于, g => g.Sum(g.Value.Item1.SkuAmount + g.Value.Item1.PurchaseFreight) >= request.RecentDayCondition.PurchasedAmount && g.Sum(g.Value.Item1.SkuAmount + g.Value.Item1.PurchaseFreight) <= request.RecentDayCondition.PurchasedAmount2) |
|
|
|
.WithTempQuery(g => new { g.Value.Item4.PurchaserId, PurchasedAmount = g.Sum(g.Value.Item1.SkuAmount + g.Value.Item1.PurchaseFreight) }).As("pca"); |
|
|
|
select = select.Where(p => childSelect.Where(pca => pca.PurchaserId == p.Id).Any()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var pageSelect = select.Page(request.PageIndex, request.PageSize); |
|
|
|
var sql = pageSelect.ToSql(); |
|
|
|
var purchaserList = select.Page(request.PageIndex, request.PageSize) |
|
|
|
.Count(out var count) |
|
|
|
.ToList<PurchaserResponse>(); |
|
|
|
|
|
|
|
if (purchaserList.Count() > 0) |
|
|
|
{ |
|
|
|
var purchaserIdList = purchaserList.Select(p => p.Id).ToList(); |
|
|
|
|
|
|
|
#region 查询SPU绑定数/SKU绑定数
|
|
|
@ -190,6 +258,7 @@ namespace BBWYB.Server.Business |
|
|
|
}).ToList(); |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new ListResponse<PurchaserResponse>() |
|
|
|
{ |
|
|
|