/// <summary> /// 添加SKU,并过滤已添加的 /// </summary> /// <param name="pids"></param> /// <param name="shopBranchId"></param> /// <param name="shopId"></param> public static void AddProductSkus(List <long> pids, long shopBranchId, long shopId) { var products = ProductManagerApplication.GetProducts(pids, shopId); if (products.Count == 0) { throw new MessageException("未找到商品数据"); } if (products.Any(d => d.IsOpenLadder)) { throw new MessageException("不可添加阶梯价商品"); } //查询已添加的SKU,用于添加时过滤 var oldskus = Service.GetSkus(shopId, new List <long> { shopBranchId }, null).Select(e => e.SkuId); var allSkus = ProductManagerApplication.GetSKUByProducts(products.Select(p => p.Id)); var shopBranchSkus = new List <ShopBranchSkuInfo>(); var skus = allSkus.Where(s => !oldskus.Any(sku => sku == s.Id)).Select(e => new ShopBranchSkuInfo { ProductId = e.ProductId, SkuId = e.Id, ShopId = shopId, ShopBranchId = shopBranchId, Stock = 0, CreateDate = DateTime.Now }); shopBranchSkus.AddRange(skus); Service.AddSkus(shopBranchSkus); }
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 ActionResult Edit(long id) { var model = _iCollocationService.GetCollocation(id); if (model.ShopId != CurrentSellerManager.ShopId) { RedirectToAction("Management"); } CollocationDataModel m = new CollocationDataModel(); m.CreateTime = model.CreateTime.Value; m.EndTime = model.EndTime; m.ShopId = model.ShopId; m.ShortDesc = model.ShortDesc; m.Title = model.Title; m.StartTime = model.StartTime; m.Id = model.Id; var cProducts = _iCollocationService.GetProducts(new List <long> { model.Id }); var cAllSKUs = _iCollocationService.GetSKUs(cProducts.Select(p => p.Id).ToList()); var products = ProductManagerApplication.GetProductByIds(cProducts.Select(p => p.ProductId).ToList()); var allSKUs = ProductManagerApplication.GetSKUByProducts(products.Select(p => p.Id).ToList()); m.CollocationPoruducts = cProducts.Select(a => { var product = products.FirstOrDefault(p => p.Id == a.ProductId); var skus = allSKUs.Where(p => p.ProductId == a.ProductId); var cSKUs = cAllSKUs.Where(p => p.ColloProductId == a.Id); return(new CollocationPoruductModel() { Id = a.Id, ColloId = a.ColloId, DisplaySequence = a.DisplaySequence, IsMain = a.IsMain, ProductId = a.ProductId, ProductName = product ? .ProductName, ImagePath = product ? .ImagePath, CollocationSkus = cSKUs.Select(b => { var sku = skus.FirstOrDefault(t => t.Id == b.SkuID); return new CollocationSkus() { Id = b.Id, Price = b.Price, SkuID = b.SkuID, SKUName = sku == null ? "" : sku.Color + " " + sku.Size + " " + sku.Version, SkuPirce = b.SkuPirce, ColloProductId = b.ColloProductId, ProductId = b.ProductId }; }).ToList() }); }).OrderBy(a => a.DisplaySequence).ToList(); var market = _iMarketService.GetMarketService(CurrentSellerManager.ShopId, MarketType.Collocation); ViewBag.EndTime = MarketApplication.GetServiceEndTime(market.Id).ToString("yyyy-MM-dd"); return(View(m)); }
public static List <ProductCollocationModel> GetDisplayCollocation(long productID) { var result = new List <ProductCollocationModel>(); var collocations = Service.GetAvailableCollocationByProduct(productID); if (collocations.Count == 0) { return(result); } var collProducts = Service.GetProducts(collocations.Select(p => p.Id).ToList()); var collSKUs = Service.GetSKUs(collProducts.Select(p => p.Id).ToList()); var allProducts = ProductManagerApplication.GetOnSaleProducts(collProducts.Select(p => p.ProductId).ToList()); var allSKUs = ProductManagerApplication.GetSKUByProducts(allProducts.Select(p => p.Id).ToList()); //移除不在销售中的活动商品 collProducts = collProducts.Where(p => allProducts.Select(o => o.Id).Contains(p.ProductId)).ToList(); var index = 0; foreach (var collocation in collocations) { var cProducts = collProducts.Where(p => p.ColloId == collocation.Id); var mainProduct = cProducts.FirstOrDefault(p => p.IsMain); if (mainProduct == null) { continue; //主商品不在销售中 } index++; var item = new ProductCollocationModel(); item.Id = item.Id; item.Name = "组合购" + GetChineseNumber(index); item.ProductId = mainProduct.ProductId; item.ShopId = collocation.ShopId; item.Products = cProducts.Select(cp => { var product = allProducts.FirstOrDefault(p => p.Id == cp.ProductId); var skus = allSKUs.Where(p => p.ProductId == cp.ProductId); var cSKUs = collSKUs.Where(p => p.ColloProductId == cp.Id); return(new CollocationProducts() { DisplaySequence = cp.DisplaySequence, IsMain = cp.IsMain, Stock = skus.Sum(t => t.Stock), MaxCollPrice = cSKUs.Max(x => x.Price), MaxSalePrice = cSKUs.Max(x => x.SkuPirce), MinCollPrice = cSKUs.Min(x => x.Price), MinSalePrice = cSKUs.Min(x => x.SkuPirce), ProductName = product.ProductName, ProductId = cp.ProductId, ColloPid = cp.Id, Image = Core.MallIO.GetImagePath(product.RelativePath) }); }).ToList(); item.Cheap = item.Products.Sum(a => a.MaxSalePrice) - item.Products.Sum(a => a.MinCollPrice); result.Add(item); } return(result); }
public List <SKU> GetDisplaySKUsByProducts(List <long> products) { var skus = ProductManagerApplication.GetSKUByProducts(products); var types = TypeApplication.GetTypes(); return(new List <SKU>()); }
public object GetShopBranchProducts( string keywords = "", /* 搜索关键字 */ long cid = 0, /* 分类ID */ int pageNo = 1, /*页码*/ int pageSize = 10, /*每页显示数据量*/ int branchProductStatus = 0 ) { CheckUserLogin(); ShopBranchProductQuery query = new ShopBranchProductQuery { PageNo = pageNo, PageSize = pageSize, KeyWords = keywords, ShopId = CurrentShopBranch.ShopId, ShopBranchId = CurrentShopBranch.Id, ShopBranchProductStatus = (CommonModel.ShopBranchSkuStatus)branchProductStatus, HasLadderProduct = true }; if (cid > 0) { query.ShopCategoryId = cid; } //查询商品 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(CurrentShopBranch.Id, skuids); var product = pageModel.Models.Select(item => { return(new { id = item.Id, name = item.ProductName, price = item.MinSalePrice, salesCount = item.SaleCounts, img = Core.MallIO.GetRomoteProductSizeImage(item.RelativePath, 1, (int)Mall.CommonModel.ImageSize.Size_350), stock = shopBranchSkus.Where(e => e.ProductId == item.Id).Sum(s => s.Stock), productCode = item.ProductCode }); }); var result = new { success = true, products = product, skus = shopBranchSkus, total = pageModel.Total }; return(result); }
// GET: Mobile/PortfolioBuy public ActionResult ProductDetail(long productId) { var serivce = ServiceApplication.Create <ICollocationService>(); var collocation = serivce.GetCollocationByProductId(productId); if (collocation == null) { return(View()); } var cProducts = serivce.GetProducts(new List <long> { collocation.Id }); var allCollSKUs = serivce.GetSKUs(cProducts.Select(p => p.Id).ToList()); var products = ProductManagerApplication.GetOnSaleProducts(cProducts.Select(p => p.ProductId).ToList()); var allSKUs = ProductManagerApplication.GetSKUByProducts(products.Select(p => p.Id).ToList()); //移除下架商品 cProducts = cProducts.Where(p => products.Select(o => o.Id).Contains(p.ProductId)).ToList(); var result = cProducts.Select(item => { var product = products.FirstOrDefault(p => p.Id == item.ProductId); var cSKUs = allCollSKUs.Where(p => p.ProductId == item.ProductId); var skus = allSKUs.Where(p => p.ProductId == item.ProductId); var collocationProduct = new CollocationProducts() { DisplaySequence = item.DisplaySequence, IsMain = item.IsMain, Stock = skus.Sum(t => t.Stock), ProductName = product.ProductName, ProductId = item.ProductId, ColloPid = item.Id, Image = Core.MallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Mall.CommonModel.ImageSize.Size_100), IsShowSku = isShowSku(item.ProductId) }; if (cSKUs != null && cSKUs.Count() > 0) { collocationProduct.MaxCollPrice = cSKUs.Max(x => x.Price); collocationProduct.MaxSalePrice = cSKUs.Max(x => x.SkuPirce); collocationProduct.MinCollPrice = cSKUs.Min(x => x.Price); collocationProduct.MinSalePrice = cSKUs.Min(x => x.SkuPirce); } return(collocationProduct); }).Where(p => p.Stock > 0).OrderBy(a => a.DisplaySequence).ToList(); return(View(result)); }
public object GetProducts( string keywords = "", /* 搜索关键字 */ long cid = 0, /* 分类ID */ int pageNo = 1, /*页码*/ int pageSize = 10 /*每页显示数据量*/ ) { CheckUserLogin(); ProductSearch model = new ProductSearch() { shopId = CurrentShopBranch.ShopId, Keyword = keywords, PageNumber = pageNo, PageSize = pageSize, CategoryId = cid, shopBranchId = CurrentShopBranch.Id, HasLadderProduct = true }; model.AttrIds = new List <string>() { }; var products = ProductManagerApplication.GetProducts(model); var skus = ProductManagerApplication.GetSKUByProducts(products.Models.Select(p => p.Id)); var product = products.Models.Select(item => new { id = item.Id, name = item.ProductName, price = item.MinSalePrice, salesCount = item.SaleCounts + Mall.Core.Helper.TypeHelper.ObjectToInt(item.VirtualSaleCounts), img = Core.MallIO.GetRomoteProductSizeImage(item.RelativePath, 1, (int)ImageSize.Size_100), stock = skus.Where(sku => sku.ProductId == item.Id).Sum(sku => (long?)sku.Stock).GetValueOrDefault(0), productCode = item.ProductCode, isSaleCountOnOff = SiteSettingApplication.SiteSettings.ProductSaleCountOnOff == 1 }).ToList(); var result = new { success = true, products = product, total = products.Total }; return(result); }
public JsonResult GetLimitedProducts(List <long> ids) { var result = LimitTimeApplication.GetPriceByProducrIds(ids).ToList(); var productIds = result.Select(p => p.ProductId); var skuInfos = ProductManagerApplication.GetSKUByProducts(productIds); //商品规格 var flashSaleIds = result.Select(p => p.Id); var flashSaleDetails = LimitTimeApplication.GetFlashSaleDetailByFlashSaleIds(ids).ToList(); //限时购明细 var products = result.Select(item => new { ProductName = item.ProductName, MinPrice = item.MinPrice, ProductId = item.ProductId, Count = (skuInfos == null || flashSaleDetails == null) ? 0 : (Math.Min(skuInfos.Where(a => a.ProductId == item.ProductId).Sum(b => b.Stock) , flashSaleDetails.Where(t => t.ProductId == item.ProductId).Sum(t => t.TotalCount)))//取活动=限时购活动库存和规格库存最少的一个 }); return(Json(products, true)); }
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)); }
/// <summary> /// 修正商品sku /// <para>0库存添加新的sku</para> /// </summary> /// <param name="productId"></param> public static void CorrectBranchProductSkus(long productId, long shopId) { var productsInfo = ProductManagerApplication.GetProduct(productId); if (productsInfo == null || productsInfo.ShopId != shopId) { throw new MallException("未找到商品数据"); } var shopbrids = Service.GetAgentShopBranchIds(productId); List <long> pids = new List <long>(); pids.Add(productId); foreach (var shopBranchId in shopbrids) { //查询已添加的SKU,用于添加时过滤 var oldskus = Service.GetSkus(shopId, new List <long> { shopBranchId }, null).Select(e => e.SkuId); var allSkus = ProductManagerApplication.GetSKUByProducts(pids); var shopBranchSkus = new List <Entities.ShopBranchSkuInfo> { }; var skus = allSkus.Where(s => !oldskus.Any(sku => sku == s.Id)).Select(e => new Entities.ShopBranchSkuInfo { ProductId = e.ProductId, SkuId = e.Id, ShopId = shopId, ShopBranchId = shopBranchId, Stock = 0, CreateDate = DateTime.Now }); shopBranchSkus.AddRange(skus); Service.AddSkus(shopBranchSkus); } }
public object GetShopProducts( string status, /* 销售中0, 仓库中1, 待审核2,违规下架3 */ string keywords = "", /* 搜索关键字 */ long cid = 0, /* 分类ID */ int pageNo = 1, /*页码*/ int pageSize = 10 /*每页显示数据量*/ ) { CheckUserLogin(); ProductQuery query = new ProductQuery { PageNo = pageNo, PageSize = pageSize, KeyWords = keywords, ShopId = CurrentShop.Id }; if (!string.IsNullOrWhiteSpace(status)) { switch (status) { case "0": query.SaleStatus = Entities.ProductInfo.ProductSaleStatus.OnSale; query.AuditStatus = new Entities.ProductInfo.ProductAuditStatus[] { Entities.ProductInfo.ProductAuditStatus.Audited }; break; case "1": query.SaleStatus = Entities.ProductInfo.ProductSaleStatus.InStock; query.AuditStatus = new Entities.ProductInfo.ProductAuditStatus[] { Entities.ProductInfo.ProductAuditStatus.Audited, Entities.ProductInfo.ProductAuditStatus.UnAudit, Entities.ProductInfo.ProductAuditStatus.WaitForAuditing }; break; case "2": query.SaleStatus = Entities.ProductInfo.ProductSaleStatus.OnSale; query.AuditStatus = new Entities.ProductInfo.ProductAuditStatus[] { Entities.ProductInfo.ProductAuditStatus.WaitForAuditing }; break; case "3": query.AuditStatus = new Entities.ProductInfo.ProductAuditStatus[] { Entities.ProductInfo.ProductAuditStatus.InfractionSaleOff }; break; } } if (cid > 0) { query.ShopCategoryId = cid; } //查询商品 var products = ProductManagerApplication.GetProducts(query); var pids = products.Models.Select(e => e.Id); var skus = ProductManagerApplication.GetSKUByProducts(pids); //查询门店SKU库存 var list = products.Models.Select(item => { return(new { id = item.Id, name = item.ProductName, price = item.MinSalePrice, salesCount = item.SaleCounts, img = Core.MallIO.GetRomoteProductSizeImage(item.RelativePath, 1, (int)CommonModel.ImageSize.Size_350), stock = skus.Where(e => e.ProductId == item.Id).Sum(e => e.Stock), productCode = item.ProductCode }); }); var result = new { success = true, products = list, total = products.Total, }; return(result); }
public string DownloadProduct(HttpContext context) { string bizcontent = context.Request["bizcontent"]; JObject jo = (JObject)JsonConvert.DeserializeObject(bizcontent); int PageIndex = GetJObjectValue <int>(jo, "PageIndex"); if (PageIndex < 1) { PageIndex = 1; } int PageSize = GetJObjectValue <int>(jo, "PageSize"); if (PageSize < 1) { PageSize = 10; } ProductQuery query = new ProductQuery { PageSize = PageSize, PageNo = PageIndex, ShopId = CurShopId }; long ProductId = 0; if (jo["ProductId"] != null) { long.TryParse("", out ProductId); } if (ProductId > 0) { query.Ids = new long[] { ProductId }; } string ProductName = GetJObjectValue <string>(jo, "ProductName"); if (!string.IsNullOrWhiteSpace(ProductName)) { query.KeyWords = ProductName; } string QStatus = GetJObjectValue <string>(jo, "Status"); switch (QStatus) { case "JH_01": //已上架商品 query.SaleStatus = ProductInfo.ProductSaleStatus.OnSale; query.AuditStatus = new ProductInfo.ProductAuditStatus[] { ProductInfo.ProductAuditStatus.Audited }; break; case "JH_02": //已下架商品(违规下架) query.AuditStatus = new ProductInfo.ProductAuditStatus[] { ProductInfo.ProductAuditStatus.InfractionSaleOff }; break; case "JH_03": //已售罄商品(超过警界库存) query.OverSafeStock = true; break; case "JH_04": //未通过审核 query.AuditStatus = new ProductInfo.ProductAuditStatus[] { Entities.ProductInfo.ProductAuditStatus.AuditFailed }; break; case "JH_05": //审核中商品 query.AuditStatus = new ProductInfo.ProductAuditStatus[] { Entities.ProductInfo.ProductAuditStatus.WaitForAuditing }; break; case "JH_06": //即将上架商品(仓库) query.SaleStatus = ProductInfo.ProductSaleStatus.InStock; break; } var _iTypeService = ObjectContainer.Current.Resolve <Himall.IServices.ITypeService>(); var data = ProductManagerApplication.GetProducts(query); StringBuilder sb = new StringBuilder(); sb.Append("{"); sb.Append("\"code\":" + "\"" + "10000" + "\""); sb.Append(",\"message\":" + "\"" + "SUCCESS" + "\""); sb.Append(",\"totalcount\":" + "\"" + data.Total + "\""); sb.Append(",\"goodslist\":"); sb.Append("["); int curitemnum = 0; var allskus = ProductManagerApplication.GetSKUByProducts(data.Models.Select(d => d.Id)); foreach (var item in data.Models) { var skus = allskus.Where(p => p.ProductId == item.Id); if (curitemnum > 0) { sb.Append(","); } sb.Append("{"); sb.Append("\"PlatProductID\":" + "\"" + item.Id + "\""); sb.Append(",\"name\":" + "\"" + item.ProductName + "\""); sb.Append(",\"OuterID\":" + "\"" + item.Id + "\""); sb.Append(",\"price\":" + "\"" + item.MinSalePrice + "\""); sb.Append(",\"num\":" + "\"" + skus.Sum(d => d.Stock) + "\""); sb.Append(",\"pictureurl\":" + "\"" + HimallIO.GetProductSizeImage(item.ImagePath, 1, ImageSize.Size_400.GetHashCode()) + "\""); sb.Append(",\"whsecode\":" + "\"" + "" + "\""); sb.Append(",\"attrbutes\":"); sb.Append("["); #region 商品属性填充 var prodAttrs = ProductManagerApplication.GetProductAttributes(item.Id); var prodAttrids = prodAttrs.Select(d => d.AttributeId).Distinct().ToList(); if (prodAttrids.Count > 0) { List <string> propslst = new List <string>(); List <string> propsvallst = new List <string>(); int curattrnum = 0; foreach (var curattid in prodAttrids) { var attr = prodAttrs.FirstOrDefault(d => d.AttributeId == curattid); propsvallst.Clear(); var values = _iTypeService.GetAttributeValues(curattid); var attribute = _iTypeService.GetAttribute(curattid); foreach (var attrV in values) { if (prodAttrs.Any(p => p.ValueId == attrV.Id)) { if (curattrnum > 0) { sb.Append(","); } sb.Append("{"); sb.Append("\"name\":\"" + attribute.Name + "\""); sb.Append(",\"value\":\"" + attrV.Value + "\""); sb.Append(",\"attributeid\":\"" + attrV.Id + "\""); sb.Append(",\"iscustom\":\"1\""); sb.Append("}"); propsvallst.Add(attrV.Value); curattrnum++; } } } } #endregion sb.Append("]"); sb.Append(",\"skus\":"); sb.Append("["); #region SKUS var typeInfo = TypeApplication.GetProductType(item.TypeId); string colorAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias; string sizeAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias; string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias; if (item != null) { colorAlias = !string.IsNullOrWhiteSpace(item.ColorAlias) ? item.ColorAlias : colorAlias; sizeAlias = !string.IsNullOrWhiteSpace(item.SizeAlias) ? item.SizeAlias : sizeAlias; versionAlias = !string.IsNullOrWhiteSpace(item.VersionAlias) ? item.VersionAlias : versionAlias; } int curskunum = 0; foreach (var skuitem in skus) { if (curskunum > 0) { sb.Append(","); } string sku_properties_all_name = colorAlias + ":" + skuitem.Color + " " + sizeAlias + ":" + skuitem.Size + versionAlias + " " + ":" + skuitem.Version; string sku_properties_name = skuitem.Color + " " + skuitem.Size + " " + skuitem.Version; string skuOuterID = skuitem.Sku; if (string.IsNullOrWhiteSpace(skuOuterID)) { skuOuterID = item.ProductCode; } sb.Append("{"); sb.Append("\"SkuID\":" + "\"" + skuitem.Id + "\""); sb.Append(",\"skuOuterID\":" + "\"" + skuOuterID + "\""); sb.Append(",\"skuprice\":" + "\"" + skuitem.SalePrice + "\""); sb.Append(",\"skuQuantity\":" + "\"" + skuitem.Stock + "\""); sb.Append(",\"skuname\":" + "\"" + skuitem.Sku + "\""); sb.Append(",\"skuproperty\":" + "\"" + "" + "\""); sb.Append(",\"skupictureurl\":" + "\"" + "" + "\""); sb.Append("}"); curskunum++; } #endregion sb.Append("]"); sb.Append("}"); curitemnum++; } sb.Append("]"); sb.Append("}"); return(sb.ToString()); }
public JsonResult Browse(long?categoryId, int?auditStatus, string ids, int page, string keyWords, string shopName, int?saleStatus, bool?isShopCategory, int rows = 10, bool isLimitTimeBuy = false, bool showSku = false, long[] exceptProductIds = null) { var query = new ProductQuery() { PageSize = rows, PageNo = page, KeyWords = keyWords, ShopName = shopName, CategoryId = isShopCategory.GetValueOrDefault() ? null : categoryId, ShopCategoryId = isShopCategory.GetValueOrDefault() ? categoryId : null, Ids = string.IsNullOrWhiteSpace(ids) ? null : ids.Split(',').Select(item => long.Parse(item)), ShopId = CurrentSellerManager.ShopId, IsLimitTimeBuy = isLimitTimeBuy, ExceptIds = exceptProductIds, IsFilterStock = false, HasLadderProduct = false, AuditStatus = new[] { ProductInfo.ProductAuditStatus.Audited }, SaleStatus = ProductInfo.ProductSaleStatus.OnSale }; var data = ProductManagerApplication.GetProducts(query); var shops = ShopApplication.GetShops(data.Models.Select(p => p.ShopId)); var brands = BrandApplication.GetBrands(data.Models.Select(p => p.BrandId)); var skus = ProductManagerApplication.GetSKUByProducts(data.Models.Select(p => p.Id)); var products = data.Models.Select(item => { var brand = brands.FirstOrDefault(p => p.Id == item.BrandId); var shop = shops.FirstOrDefault(p => p.Id == item.ShopId); var cate = CategoryApplication.GetCategory(item.CategoryId); var sku = skus.Where(p => p.ProductId == item.Id); var limitAdd = LimitTimeApplication.IsAdd(item.Id); return(new { name = item.ProductName, brandName = brand?.Name ?? string.Empty, categoryName = brand == null ? "" : cate.Name, id = item.Id, imgUrl = item.GetImage(ImageSize.Size_50), price = item.MinSalePrice, skus = !showSku ? null : sku.Select(a => new SKUModel() { Id = a.Id, SalePrice = a.SalePrice, Size = a.Size, Stock = a.Stock, Version = a.Version, Color = a.Color, Sku = a.Sku, AutoId = a.AutoId, ProductId = a.ProductId }), shopName = shop.ShopName, isOpenLadder = item.IsOpenLadder, isLimit = limitAdd }); }); var dataGrid = new { rows = products, total = data.Total }; return(Json(dataGrid)); }
/// <summary> /// 加载门店编辑商品列表 /// </summary> /// <param name="ids"></param> /// <param name="shopbranchId"></param> /// <returns></returns> public JsonResult GetProductsByIds(string ids, long shopbranchId) { if (string.IsNullOrWhiteSpace(ids)) { return(Json(new { success = false, msg = "参数传递错误" })); } var pIds = ConvertToIEnumerable(ids); var products = ProductManagerApplication.GetAllProductByIds(pIds); //查询门店SKU库存 var allSKU = ProductManagerApplication.GetSKUByProducts(products.Select(p => p.Id)); List <string> skuids = allSKU.Select(p => p.Id).ToList(); var shopBranchSkus = ShopBranchApplication.GetSkusByIds(shopbranchId, skuids); List <ProductModel> productlist = new List <ProductModel>(); foreach (var item in products) { var skus = ProductManagerApplication.GetSKUs(item.Id); ProductModel product = new ProductModel() { Name = item.ProductName, Id = item.Id, Image = item.GetImage(ImageSize.Size_50), Price = item.MinSalePrice }; List <SKuModel> skulist = new List <SKuModel>(); foreach (var skuInfo in skus) { var shopbranckSku = shopBranchSkus.Where(s => s.SkuId == skuInfo.Id).FirstOrDefault(); var str = string.Empty; if (!string.IsNullOrWhiteSpace(skuInfo.Color)) { str += item.ColorAlias + ":" + skuInfo.Color; } else { str += " " + item.ColorAlias + ";"; } if (!string.IsNullOrWhiteSpace(skuInfo.Size)) { str += " " + item.SizeAlias + ":" + skuInfo.Size; } else { str += " " + item.SizeAlias + ";"; } if (!string.IsNullOrWhiteSpace(skuInfo.Version)) { str += " " + item.VersionAlias + ":" + skuInfo.Version; } else { str += " " + item.VersionAlias + ";"; } var model = new SKuModel() { ProductName = (item.HasSKU ? str.TrimEnd(';') : ""), Sku = item.HasSKU ? (skuInfo.Sku ?? string.Empty) : item.ProductCode, Id = skuInfo.Id, AutoId = shopbranckSku.Id, Stock = shopbranckSku.Stock, MarketPrice = item.MarketPrice, SalePrice = item.HasSKU ? skuInfo.SalePrice : item.MinSalePrice,//有规格则取规格商城价,否则取商品本身商城价 ProductId = item.Id, HasSKU = item.HasSKU ? 1 : 0 }; if (skus.IndexOf(skuInfo) == 0) { model.IsFirst = 1; } skulist.Add(model); } product.Skus = skulist; productlist.Add(product); } return(Json(new { success = true, model = productlist })); }