public JsonResult ProductList(ShopBranchProductQuery query, int rows, int page) { query.ShopBranchProductStatus = 0; //查询商品 var pageModel = ShopBranchApplication.GetShopBranchProducts(query); //查询门店SKU库存 var allSKU = ProductManagerApplication.GetSKUByProducts(pageModel.Models.Select(p => p.Id)); List <string> skuids = allSKU.Select(p => p.Id).ToList(); var shopBranchSkus = ShopBranchApplication.GetSkusByIds(query.ShopBranchId.Value, skuids); var dataGrid = new DataGridModel <ProductModel>(); dataGrid.total = pageModel.Total; dataGrid.rows = pageModel.Models.Select(item => { var cate = ShopCategoryApplication.GetCategoryByProductId(item.Id); return(new ProductModel() { name = item.ProductName, id = item.Id, imgUrl = item.GetImage(ImageSize.Size_50), categoryName = cate == null ? "" : cate.Name, saleCounts = item.SaleCounts, stock = shopBranchSkus.Where(e => e.ProductId == item.Id).Sum(s => s.Stock), price = item.MinSalePrice, MinPrice = allSKU.Where(s => s.ProductId == item.Id).Min(s => s.SalePrice), MaxPrice = allSKU.Where(s => s.ProductId == item.Id).Max(s => s.SalePrice), ProductType = item.ProductType, shopBranchId = query.ShopBranchId.Value }); }).ToList(); return(Json(dataGrid)); }
public JsonResult ProductList(ShopBranchProductQuery query) { query.ShopBranchProductStatus = 0; query.OrderKey = 2; //查询商品 var pageModel = ShopBranchApplication.GetShopBranchProducts(query); //查询门店SKU库存 var allSKU = ProductManagerApplication.GetSKUByProducts(pageModel.Models.Select(p => p.Id)); List <string> skuids = allSKU.Select(p => p.Id).ToList(); var shopBranchSkus = ShopBranchApplication.GetSkusByIds(query.ShopBranchId.Value, skuids); var dataGrid = new DataGridModel <ProductModel>(); dataGrid.total = pageModel.Total; dataGrid.rows = pageModel.Models.Select(item => { var cate = ShopCategoryApplication.GetCategoryByProductId(item.Id); return(new ProductModel() { Name = item.ProductName, Id = item.Id, Image = item.GetImage(ImageSize.Size_50), CategoryName = cate == null ? "" : cate.Name, SaleCount = item.SaleCounts, Stock = shopBranchSkus.Where(e => e.ProductId == item.Id).Sum(s => s.Stock), Price = item.MinSalePrice, MinPrice = allSKU.Where(s => s.ProductId == item.Id).Min(s => s.SalePrice), MaxPrice = allSKU.Where(s => s.ProductId == item.Id).Max(s => s.SalePrice), Url = "", PublishTime = item.AddedDate.ToString("yyyy-MM-dd HH:mm"), SaleState = (int)item.SaleStatus, CategoryId = item.CategoryId, ProductCode = item.ProductCode, ProductType = item.ProductType }); }).ToList(); return(Json(dataGrid)); }