diff --git a/BBWYB.Server.API/Controllers/PurchaserController.cs b/BBWYB.Server.API/Controllers/PurchaserController.cs
index e24c5dd..0bc88a4 100644
--- a/BBWYB.Server.API/Controllers/PurchaserController.cs
+++ b/BBWYB.Server.API/Controllers/PurchaserController.cs
@@ -14,6 +14,28 @@ namespace BBWYB.Server.API.Controllers
this.purchaserBusiness = purchaserBusiness;
}
+ ///
+ /// 根据关键词搜索采购商名称列表
+ ///
+ ///
+ ///
+ [HttpGet("{keywords}")]
+ public ListResponse QueryPurchaserNameList([FromRoute] string keywords)
+ {
+ return purchaserBusiness.QueryPurchaserNameList(keywords);
+ }
+
+ ///
+ /// 根据关键词搜索采购商产地列表
+ ///
+ ///
+ ///
+ [HttpGet("{keywords}")]
+ public ListResponse QueryPurchaserLocationList([FromRoute] string keywords)
+ {
+ return purchaserBusiness.QueryPurchaserLocationList(keywords);
+ }
+
///
/// 查询采购商列表
///
diff --git a/BBWYB.Server.Business/Purchaser/PurchaserBusiness.cs b/BBWYB.Server.Business/Purchaser/PurchaserBusiness.cs
index 568ea12..d8392a9 100644
--- a/BBWYB.Server.Business/Purchaser/PurchaserBusiness.cs
+++ b/BBWYB.Server.Business/Purchaser/PurchaserBusiness.cs
@@ -14,9 +14,191 @@ namespace BBWYB.Server.Business
}
+ public ListResponse QueryPurchaserNameList(string keywords)
+ {
+ if (string.IsNullOrEmpty(keywords))
+ throw new BusinessException("关键字不能为空");
+ var list = fsql.Select().Where(p => p.Name.Contains(keywords)).Distinct().ToList(x => x.Name);
+ return new ListResponse { Items = list, TotalCount = list.Count() };
+ }
+
+ public ListResponse QueryPurchaserLocationList(string keywords)
+ {
+ if (string.IsNullOrEmpty(keywords))
+ throw new BusinessException("关键字不能为空");
+ var list = fsql.Select().Where(p => p.Location.Contains(keywords)).Distinct().ToList(x => x.Location);
+ return new ListResponse { Items = list, TotalCount = list.Count() };
+ }
+
public ListResponse QueryPurchaserList(QueryPurchaserRequest request)
{
- return new ListResponse();
+ if (request.PageSize > 20)
+ request.PageSize = 20;
+ var purchaserList = fsql.Select()
+ .WhereIf(!string.IsNullOrEmpty(request.Spu), p => fsql.Select()
+ .Where(psp1 => psp1.PurchaserId == p.Id &&
+ psp1.ProductId == request.Spu)
+ .Any())
+ .WhereIf(!string.IsNullOrEmpty(request.Sku), p => fsql.Select()
+ .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()
+ .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)
+ .Count(out var count)
+ .ToList();
+
+ var purchaserIdList = purchaserList.Select(p => p.Id).ToList();
+
+ #region 查询SPU绑定数/SKU绑定数
+ var bindList = fsql.Select()
+ .InnerJoin((psp, psc) => psp.SkuPurchaseSchemeId == psc.Id)
+ .Where((psp, psc) => psc.ShopId == request.ShopId && purchaserIdList.Contains(psp.PurchaserId))
+ .GroupBy((psp, psc) => new { psp.PurchaserId, psp.ProductId, psp.SkuId })
+ .ToList(g => new
+ {
+ g.Key.PurchaserId,
+ g.Key.ProductId,
+ g.Key.SkuId
+ });
+ #endregion
+
+ #region 查询SPU采购数/SKU采购数
+ var purchasedList = fsql.Select()
+ .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, ps.ProductId })
+ .ToList(g => new
+ {
+ g.Key.PurchaserId,
+ g.Key.ProductId,
+ g.Key.SkuId
+ });
+
+ #endregion
+
+ #region 查询订单数
+ var poList = fsql.Select()
+ .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
+
+ #region 查询采购金额
+ var purchaseAmountList = fsql.Select()
+ .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 &&
+ purchaserIdList.Contains(opi.PurchaserId))
+ .GroupBy((ocd, o, ori, opi) => opi.PurchaserId)
+ .ToList(g => new
+ {
+ PurchaserId = g.Key,
+ PurchaseAmount = g.Sum(g.Value.Item1.SkuAmount) + g.Sum(g.Value.Item1.PurchaseFreight)
+ });
+ #endregion
+
+ #region 查询最近采购时间
+ var recentPurchaseTimeList = fsql.Select()
+ .InnerJoin((opi1, o) => o.OrderState != Enums.OrderState.已取消)
+ .Where((opi1, o) => opi1.ShopId == request.ShopId &&
+ purchaserIdList.Contains(opi1.PurchaserId) &&
+ opi1.IsEnabled == true)
+ .GroupBy((opi1, o) => opi1.PurchaserId)
+ .WithTempQuery(g => new { MaxId = g.Max(g.Value.Item1.Id) })
+ .From()
+ .InnerJoin((opi1, opi2) => opi1.MaxId == opi2.Id)
+ .ToList((opi1, opi2) => new
+ {
+ opi2.PurchaserId,
+ opi2.CreateTime
+ });
+ #endregion
+
+ #region 查询标签/主营类目
+ var purchaserExtendInfoList = fsql.Select()
+ .InnerJoin((pei, per) => pei.Id == per.ExtendedInfoId)
+ .Where((pei, per) => purchaserIdList.Contains(per.PurchaserId))
+ .ToList((pei, per) => new
+ {
+ pei.Id,
+ pei.Name,
+ pei.Type,
+ per.PurchaserId
+ });
+ #endregion
+
+ foreach (var purchaser in purchaserList)
+ {
+ #region SPU绑定数/SKU绑定数
+ var currentBindList = bindList.Where(x => x.PurchaserId == purchaser.Id).ToList();
+ purchaser.BindingSpuCount = currentBindList.Select(x => x.ProductId).Distinct().Count();
+ purchaser.BindingSkuCount = currentBindList.Select(x => x.SkuId).Count();
+ #endregion
+
+ #region SPU采购数/SKU采购数
+ var currentPurchasedList = purchasedList.Where(x => x.PurchaserId == purchaser.Id).ToList();
+ purchaser.PurchasedSpuCount = currentPurchasedList.Select(x => x.ProductId).Distinct().Count();
+ purchaser.PurchasedSkuCount = currentPurchasedList.Select(x => x.SkuId).Count();
+ #endregion
+
+ #region 订单数
+ var currentOpiList = poList.Where(x => x.PurchaserId == purchaser.Id).ToList();
+ purchaser.PurchaseOrderCount = currentOpiList.FirstOrDefault(x => x.PurchaserId == purchaser.Id)?.Count ?? 0;
+ #endregion
+
+ #region 采购金额
+ var currentOpiAmountList = purchaseAmountList.Where(x => x.PurchaserId == purchaser.Id).ToList();
+ purchaser.PurchaseAmount = currentOpiAmountList.FirstOrDefault(x => x.PurchaserId == purchaser.Id)?.PurchaseAmount ?? 0;
+ #endregion
+
+ #region 最近采购时间
+ var currentRecentPurchaseTimeList = recentPurchaseTimeList.Where(x => x.PurchaserId == purchaser.Id).ToList();
+ purchaser.LastPurchaseTime = currentRecentPurchaseTimeList.FirstOrDefault(x => x.PurchaserId == purchaser.Id)?.CreateTime;
+ #endregion
+
+ #region 主营类目/标签
+ var currentExtendInfoList = purchaserExtendInfoList.Where(x => x.PurchaserId == purchaser.Id).ToList();
+ purchaser.CategoryList = currentExtendInfoList.Where(x => x.Type == Enums.PurchaserBasicInfoType.主营类目)
+ .Select(x => new PurchaserExtendedInfoResponse()
+ {
+ Id = x.Id,
+ Name = x.Name,
+ Type = x.Type
+ }).ToList();
+
+ purchaser.TagList = currentExtendInfoList.Where(x => x.Type == Enums.PurchaserBasicInfoType.标签)
+ .Select(x => new PurchaserExtendedInfoResponse()
+ {
+ Id = x.Id,
+ Name = x.Name,
+ Type = x.Type
+ }).ToList();
+ #endregion
+ }
+
+ return new ListResponse()
+ {
+ Items = purchaserList,
+ TotalCount = count
+ };
}
public ListResponse QueryPurchaserCategoryList(QueryPurchaserExtendedRequest request)
diff --git a/BBWYB.Server.Model/Dto/Request/Purchaser/QueryPurchaserRequest.cs b/BBWYB.Server.Model/Dto/Request/Purchaser/QueryPurchaserRequest.cs
index b8f6361..7c17296 100644
--- a/BBWYB.Server.Model/Dto/Request/Purchaser/QueryPurchaserRequest.cs
+++ b/BBWYB.Server.Model/Dto/Request/Purchaser/QueryPurchaserRequest.cs
@@ -2,6 +2,8 @@
{
public class QueryPurchaserRequest
{
+ public long ShopId { get; set; }
+
public string Spu { get; set; }
public string Sku { get; set; }
@@ -9,7 +11,7 @@
///
/// 采购商Id集合
///
- public List PurchaserIdList { get; set; }
+ public List PurchaserNameList { get; set; }
///
/// 主营类目Id集合
@@ -17,15 +19,19 @@
public List CategoryIdList { get; set; }
///
- /// 供应商产地
+ /// 供应商产地集合
///
- public string Location { get; set; }
+ public List LocationList { get; set; }
+
///
/// 页码 从1开始
///
public int PageIndex { get; set; }
+ ///
+ /// 页记录数 最大20
+ ///
public int PageSize { get; set; }
}
}