public JsonResult GetSalePrice() { //会员折扣 decimal discount = 1M; long shopId = 0; if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; var shopInfo = ShopApplication.GetSelfShop(); shopId = shopInfo.Id; } var list = LimitTimeApplication.GetLimitProducts(); return(Json(new { success = true, SelfShopId = shopId, Discount = discount, LimitProducts = list }, JsonRequestBehavior.AllowGet)); }
public JsonResult GetSalePrice() { //会员折扣 decimal discount = 1M; long shopId = 0; if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; var shopInfo = ShopApplication.GetSelfShop(); shopId = shopInfo.Id; } var limit = LimitTimeApplication.GetLimitProducts(); var fight = FightGroupApplication.GetFightGroupPrice(); return(Json <dynamic>(success: true, data: new { SelfShopId = shopId, Discount = discount, LimitProducts = limit, FightProducts = fight })); }
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)); }
/// <summary> /// 门店首页获取诊疗项目列表 /// </summary> /// <param name="pageSize"></param> /// <param name="pageNo"></param> /// <param name="shopCategoryId">诊所一级分类</param> /// <param name="shopId">诊所ID</param> /// <param name="shopBranchId">门店ID</param> /// <returns></returns> public object GetProductList(int pageSize, int pageNo, string shopCategoryId, string shopId, string shopBranchId) { ShopBranchProductQuery query = new ShopBranchProductQuery(); query.PageSize = pageSize; query.PageNo = pageNo; //query.ShopCategoryId = TypeHelper.ObjectToInt(shopCategoryId, 0); query.ShopId = TypeHelper.ObjectToInt(shopId, 0); query.shopBranchId = TypeHelper.ObjectToInt(shopBranchId, 0); query.ShopBranchProductStatus = ShopBranchSkuStatus.Normal; if (query.ShopId <= 0) { return(Json(new { Success = false, Message = "无法定位到诊所!" })); } //if (query.ShopCategoryId <= 0) // return Json(new { Success = false, Message = "无法定位到诊所分类!" }); if (TypeHelper.ObjectToInt(shopCategoryId, 0) > 0) { query.ShopCategoryId = TypeHelper.ObjectToInt(shopCategoryId); } if (query.shopBranchId <= 0) { return(Json(new { Success = false, Message = "无法定位到门店!" })); } var pageModel = ShopBranchApplication.GetShopBranchProducts(query); if (pageModel.Models != null && pageModel.Models.Count > 0) { #region 处理诊疗项目 官方自营店会员折扣价,各活动价等。 var flashSalePriceList = LimitTimeApplication.GetPriceByProducrIds(pageModel.Models.Select(p => p.Id).ToList()); var fightGroupSalePriceList = FightGroupApplication.GetActiveByProductIds(pageModel.Models.Select(p => p.Id).ToArray()); if (CurrentUser != null) { var shopInfo = ShopApplication.GetShop(query.ShopId.Value); if (shopInfo != null && shopInfo.IsSelf)//当前诊所是否是官方自营店 { decimal discount = 1M; discount = CurrentUser.MemberDiscount; foreach (var item in pageModel.Models) { item.MinSalePrice = Math.Round(item.MinSalePrice * discount, 2); } } } foreach (var item in pageModel.Models) { var flashSale = flashSalePriceList.Any(p => p.ProductId == item.Id); var fightGroupSale = fightGroupSalePriceList.Any(p => p.ProductId == item.Id); if (flashSale && !fightGroupSale) { item.MinSalePrice = TypeHelper.ObjectToDecimal(flashSalePriceList.FirstOrDefault(p => p.ProductId == item.Id).MinPrice.ToString("f2")); } else if (!flashSale && fightGroupSale) { item.MinSalePrice = TypeHelper.ObjectToDecimal(fightGroupSalePriceList.FirstOrDefault(p => p.ProductId == item.Id).MiniGroupPrice.ToString("f2")); } } #endregion } var productlist = pageModel.Models.ToList().Select(item => { return(new { Id = item.Id, ProductName = item.ProductName, MeasureUnit = item.MeasureUnit, MinSalePrice = item.MinSalePrice.ToString("f2"), SaleCounts = item.SaleCounts, //销量统计没有考虑预约单支付完成。 RelativePath = Core.HimallIO.GetRomoteProductSizeImage(item.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_350), //150-350 }); }); var result = new { Success = true, ProductList = productlist, total = pageModel.Total }; return(Json(result)); }
public object GetIndexProductData(string openId = "", int pageIndex = 10, int pageSize = 1) { //CheckUserLogin(); var homeProducts = ServiceProvider.Instance <IWXSmallProgramService> .Create.GetWXSmallHomeProducts().OrderBy(item => item.Id).Skip((pageIndex - 1) * pageSize).Take(pageSize); decimal discount = 1M; long SelfShopId = 0; ShoppingCartInfo CartInfo = new ShoppingCartInfo(); var ids = homeProducts.Select(d => d.Id).ToArray(); List <object> productList = new List <object>(); List <ShoppingCartItem> cartitems = new List <ShoppingCartItem>(); if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; var shopInfo = ShopApplication.GetSelfShop(); SelfShopId = shopInfo.Id; CartInfo = ServiceProvider.Instance <ICartService> .Create.GetCart(CurrentUser.Id); cartitems = CartApplication.GetCartQuantityByIds(CurrentUser.Id, ids); } var limit = LimitTimeApplication.GetLimitProducts(); //var fight = FightGroupApplication.GetFightGroupPrice(); foreach (var item in homeProducts) { long activeId = 0; int activetype = 0; item.ImagePath = Core.HimallIO.GetRomoteProductSizeImage(Core.HimallIO.GetImagePath(item.ImagePath), 1, (int)Himall.CommonModel.ImageSize.Size_350); if (item.ShopId == SelfShopId) { item.MinSalePrice = item.MinSalePrice * discount; } var limitBuy = ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetLimitTimeMarketItemByProductId(item.Id); if (limitBuy != null) { item.MinSalePrice = limitBuy.MinPrice; activeId = limitBuy.Id; activetype = 1; } int quantity = 0; quantity = cartitems.Where(d => d.ProductId == item.Id).Sum(d => d.Quantity); //火拼 //if (activeInfo != null) //{ // item.MinSalePrice = activeInfo.MiniGroupPrice; // activeId = activeInfo.Id; // activetype = 2; //} var ChoiceProducts = new { ProductId = item.Id, ProductName = item.ProductName, SalePrice = item.MinSalePrice.ToString("0.##"), ThumbnailUrl160 = item.ImagePath, MarketPrice = item.MarketPrice.ToString("0.##"), CartQuantity = quantity, HasSKU = item.HasSKU, SkuId = GetSkuIdByProductId(item.Id), //d.Himall_Products d.Field<string>("SkuId"), ActiveId = activeId, ActiveType = activetype //获取该商品是否参与活动 }; productList.Add(ChoiceProducts); } var json = new { Status = "OK", Data = new { ChoiceProducts = productList } }; return(json); }
private List <CartProductModel> PackageCartProducts(Mall.Entities.ShoppingCartInfo cart, decimal prodPrice, decimal discount, IProductService productService, IShopService shopService, IShopBranchService shopBranchService, IVShopService vshopService, ITypeService typeservice, bool isBranch = false) { List <CartProductModel> products = new List <CartProductModel>(); var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList());//限时购价格 var groupCart = cart.Items.Where(item => item.ShopBranchId == 0).Select(c => { var cItem = new Mall.Entities.ShoppingCartItem(); var skuInfo = productService.GetSku(c.SkuId); if (skuInfo != null) { cItem = c; } return(cItem); }).GroupBy(i => i.ProductId).ToList(); foreach (var item in cart.Items) { var product = ProductManagerApplication.GetProduct(item.ProductId); var shop = shopService.GetShop(product.ShopId); DTO.ShopBranch shopbranch = null; Entities.ShopBranchSkuInfo shopbranchsku = null; if (item.ShopBranchId > 0) { shopbranch = ShopBranchApplication.GetShopBranchById(item.ShopBranchId); shopbranchsku = shopBranchService.GetSkusByIds(item.ShopBranchId, new List <string> { item.SkuId }).FirstOrDefault(); } if (null != shop) { var vshop = vshopService.GetVShopByShopId(shop.Id); var sku = ProductManagerApplication.GetSKU(item.SkuId); if (sku == null) { continue; } //处理限时购、会员折扣价格 var prod = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId); prodPrice = sku.SalePrice; if (prod != null && !isBranch) { prodPrice = prod.MinPrice; } else { if (shop.IsSelf) {//官方自营店才计算会员折扣 prodPrice = sku.SalePrice * discount; } } #region 阶梯价--张宇枫 //阶梯价 if (product.IsOpenLadder) { var quantity = groupCart.Where(i => i.Key == item.ProductId).ToList().Sum(cartitem => cartitem.Sum(i => i.Quantity)); prodPrice = ProductManagerApplication.GetProductLadderPrice(item.ProductId, quantity); if (shop.IsSelf) { prodPrice = prodPrice * discount; } } #endregion Entities.TypeInfo typeInfo = typeservice.GetType(product.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 (product != null) { colorAlias = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias; sizeAlias = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias; versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias; } if (sku != null) { #region 正在参加限时抢购商品在购物车失效 TDO:ZYF var isLimit = false; //门店商品,在参加限时购,也可以正常购买 var limit = LimitTimeApplication.GetLimitTimeMarketItemByProductId(item.ProductId); if (limit != null && !isBranch) { isLimit = limit.Status == Entities.FlashSaleInfo.FlashSaleStatus.Ongoing; } #endregion var _tmp = new CartProductModel { CartItemId = item.Id.ToString(), SkuId = item.SkuId, Id = product.Id.ToString(), ImgUrl = Core.MallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Mall.CommonModel.ImageSize.Size_150), Name = product.ProductName, Price = prodPrice.ToString("F2"), Count = item.Quantity.ToString(), ShopId = shop.Id.ToString(), Size = sku.Size, Color = sku.Color, Version = sku.Version, VShopId = vshop == null ? "0" : vshop.Id.ToString(), ShopName = shop.ShopName, ShopLogo = vshop == null ? "" : Core.MallIO.GetRomoteImagePath(vshop.StrLogo), Url = Core.MallIO.GetRomoteImagePath("/m-IOS/product/detail/") + item.ProductId, ProductStatus = isLimit ? 0 : (sku.Stock <= 0 ? ProductInfo.ProductSaleStatus.InStock.GetHashCode() : product.SaleStatus.GetHashCode()), Status = isLimit ? 1 : ProductManagerApplication.GetProductShowStatus(product, sku, shopbranch == null ? 1 : item.Quantity, shopbranch, shopbranchsku),// 0:正常;1:已失效;2:库存不足;3:已下架; ColorAlias = colorAlias, SizeAlias = sizeAlias, VersionAlias = versionAlias, AddTime = item.AddTime, ShopBranchId = item.ShopBranchId, ShopBranchName = null == shopbranch ? "" : shopbranch.ShopBranchName, ShopBranchLogo = null == shopbranch ? "" : Core.MallIO.GetRomoteImagePath(shopbranch.ShopImages) }; products.Add(_tmp); } } } return(products); }
public object GetCartProduct(string openId = "") { CheckUserLogin(); var cartHelper = ServiceProvider.Instance <ICartService> .Create; var cart = cartHelper.GetCart(CurrentUser.Id); var productService = ServiceProvider.Instance <IProductService> .Create; var shopService = ServiceProvider.Instance <IShopService> .Create; var vshopService = ServiceProvider.Instance <IVShopService> .Create; var siteSetting = ServiceProvider.Instance <ISiteSettingService> .Create.GetSiteSettings(); var typeservice = ServiceProvider.Instance <ITypeService> .Create; List <CartProductModel> products = new List <CartProductModel>(); //会员折扣 decimal discount = 1.0M;//默认折扣为1(没有折扣) if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; } decimal prodPrice = 0.0M; //优惠价格 var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList()); //限时购价格 foreach (var item in cart.Items) { var product = productService.GetProduct(item.ProductId); var shop = shopService.GetShop(product.ShopId); if (null != shop) { var vshop = vshopService.GetVShopByShopId(shop.Id); SKUInfo sku = productService.GetSku(item.SkuId); if (sku == null) { continue; } //处理限时购、会员折扣价格 var prod = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId); prodPrice = sku.SalePrice; if (prod != null) { prodPrice = prod.MinPrice; } else { if (shop.IsSelf) {//官方自营店才计算会员折扣 prodPrice = sku.SalePrice * discount; } } ProductTypeInfo typeInfo = typeservice.GetType(product.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 (sku != null) { var _tmp = new CartProductModel { CartItemId = item.Id.ToString(), SkuId = item.SkuId, Id = product.Id.ToString(), ImgUrl = Core.HimallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_150), Name = product.ProductName, Price = prodPrice.ToString("F2"), Count = item.Quantity.ToString(), ShopId = shop.Id.ToString(), Size = sku.Size, Color = sku.Color, Version = sku.Version, VShopId = vshop == null ? "0" : vshop.Id.ToString(), ShopName = shop.ShopName, ShopLogo = vshop == null ? "" : Core.HimallIO.GetRomoteImagePath(vshop.Logo), Url = Core.HimallIO.GetRomoteImagePath("/m-IOS/product/detail/") + item.ProductId, IsValid = (product.AuditStatus == ProductInfo.ProductAuditStatus.Audited && product.SaleStatus == ProductInfo.ProductSaleStatus.OnSale) ? 1 : 0, ColorAlias = colorAlias, SizeAlias = sizeAlias, VersionAlias = versionAlias, AddTime = item.AddTime }; products.Add(_tmp); } } } products = products.OrderBy(item => item.ShopId).ThenByDescending(o => o.AddTime).ToList(); var cartShop = products.GroupBy(item => item.ShopId); var cartModel = new { Status = "OK", Data = cartShop }; return(Json(cartModel));//原api返回 }
public static List <ProductBrowsedHistoryModel> GetBrowsingProducts(int num, long userId = 0) { List <ProductBrowsedHistoryModel> productIdList = new List <ProductBrowsedHistoryModel>(); string productIds = Core.Helper.WebHelper.GetCookie(CookieKeysCollection.Mall_PRODUCT_BROWSING_HISTORY); if (!string.IsNullOrEmpty(productIds)) { var arr = productIds.Split(','); foreach (var a in arr) { var item = a.Split('#'); if (item.Length > 1) { productIdList.Add(new ProductBrowsedHistoryModel() { ProductId = long.Parse(item[0]), BrowseTime = DateTime.Parse(item[1]) }); } else { productIdList.Add(new ProductBrowsedHistoryModel() { ProductId = long.Parse(item[0]), BrowseTime = DateTime.Now }); } } } var ids = productIdList.Select(p => p.ProductId).ToList(); List <FlashSalePrice> flashSaleList = LimitTimeApplication.GetPriceByProducrIds(ids); List <ProductBrowsedHistoryModel> model = new List <ProductBrowsedHistoryModel>(); if (userId == 0) { var products = ProductManagerApplication.GetProductByIds(productIdList.Select(a => a.ProductId)) .Where(d => d.SaleStatus == Entities.ProductInfo.ProductSaleStatus.OnSale && d.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited).ToArray() .Select(a => new ProductBrowsedHistoryModel() { ImagePath = Core.MallIO.GetProductSizeImage(a.RelativePath, 1, (int)ImageSize.Size_100), ProductId = a.Id, ProductName = a.ProductName, ProductPrice = GetRealPrice(flashSaleList, a.Id, a.MinSalePrice), ShopId = a.ShopId }).ToList(); return(products.OrderByDescending(a => a.BrowseTime).ToList()); } else { foreach (var m in productIdList) { AddBrowsingProduct(m.ProductId, userId); } var browsing = ProductManagerApplication.GetBrowsingProducts(userId); var products = ProductManagerApplication.GetOnSaleProducts(browsing.Select(p => p.ProductId).ToList()); browsing = browsing.Where(p => products.Select(o => o.Id).Contains(p.ProductId)).ToList(); model = browsing.OrderByDescending(a => a.BrowseTime).Take(num) .Select(a => { var product = products.FirstOrDefault(p => p.Id == a.ProductId); return(new ProductBrowsedHistoryModel() { ImagePath = Core.MallIO.GetProductSizeImage(product.RelativePath, 1, (int)ImageSize.Size_100), ProductId = a.ProductId, ProductName = product.ProductName, ProductPrice = GetRealPrice(flashSaleList, a.ProductId, product.MinSalePrice), BrowseTime = a.BrowseTime, ShopId = product.ShopId }); }).ToList(); } return(model); }
public JsonResult GetCartProducts() { var cartHelper = new CartHelper(); var cart = cartHelper.GetCart(CurrentUser.Id); var productService = _iProductService; var shopService = _iShopService; var vshopService = _iVShopService; //会员折扣 decimal discount = 1.0M;//默认折扣为1(没有折扣) if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; } List <long> pids = new List <long>(); decimal prodPrice = 0.0M; //优惠价格 var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList()); //限时购价格 var products = cart.Items.Select(item => { var product = productService.GetProduct(item.ProductId); var shop = shopService.GetShop(product.ShopId); SKUInfo sku = null; string colorAlias = ""; string sizeAlias = ""; string versionAlias = ""; string skuDetails = ""; if (null != shop) { var vshop = vshopService.GetVShopByShopId(shop.Id); sku = productService.GetSku(item.SkuId); if (sku == null) { return(null); } //处理限时购、会员折扣价格 var prod = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId); prodPrice = sku.SalePrice; if (prod != null) { prodPrice = prod.MinPrice; } else { if (shop.IsSelf) {//官方自营店才计算会员折扣 prodPrice = sku.SalePrice * discount; } } var typeInfo = TypeApplication.GetType(product.TypeId); colorAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias; sizeAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias; versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias; skuDetails = ""; if (!string.IsNullOrWhiteSpace(sku.Size)) { skuDetails += sizeAlias + ":" + sku.Size + " "; } if (!string.IsNullOrWhiteSpace(sku.Color)) { skuDetails += colorAlias + ":" + sku.Color + " "; } if (!string.IsNullOrWhiteSpace(sku.Version)) { skuDetails += versionAlias + ":" + sku.Version + " "; } return(new { cartItemId = item.Id, skuId = item.SkuId, id = product.Id, imgUrl = Himall.Core.HimallIO.GetProductSizeImage(product.RelativePath, 1, (int)ImageSize.Size_150), name = product.ProductName, price = prodPrice, count = item.Quantity, shopId = shop.Id, vshopId = vshop == null ? 0 : vshop.Id, shopName = shop.ShopName, shopLogo = vshop == null ? "" : vshop.Logo, status = (product.AuditStatus == ProductInfo.ProductAuditStatus.Audited && product.SaleStatus == ProductInfo.ProductSaleStatus.OnSale) ? 1 : 0, Size = sku.Size, Color = sku.Color, Version = sku.Version, ColorAlias = colorAlias, SizeAlias = sizeAlias, VersionAlias = versionAlias, skuDetails = skuDetails, AddTime = item.AddTime }); } else { return(null); } }).Where(d => d != null).OrderBy(s => s.vshopId).ThenByDescending(o => o.AddTime); var cartModel = new { products = products, amount = products.Sum(item => item.price * item.count), totalCount = products.Sum(item => item.count) }; return(Json(cartModel)); }
public object GetVShop(long id, bool sv = false) { //Json(ErrorResult<int>("取消失败,该订单已删除或者不属于当前用户!")); var vshopService = ServiceProvider.Instance <IVShopService> .Create; var vshop = vshopService.GetVShop(id); if (vshop == null) { return(ErrorResult <bool>("未开通微店!", code: -4)); } if (vshop.State == Entities.VShopInfo.VShopStates.Close) { return(ErrorResult <bool>("商家暂未开通微店!", code: -5)); } if (!vshop.IsOpen) { return(ErrorResult <bool>("此微店已关闭!", code: -3)); } var s = ShopApplication.GetShop(vshop.ShopId); if (null != s && s.ShopStatus == Entities.ShopInfo.ShopAuditStatus.HasExpired) { return(ErrorResult <bool>("此店铺已过期!", code: -1)); } //throw new MallApiException("此店铺已过期"); if (null != s && s.ShopStatus == Entities.ShopInfo.ShopAuditStatus.Freeze) { return(ErrorResult <bool>("此店铺已冻结!", code: -2)); } //throw new MallApiException("此店铺已冻结"); //轮播图配置只有商家微店首页配置页面可配置,现在移动端都读的这个数据 var slideImgs = ServiceProvider.Instance <ISlideAdsService> .Create.GetSlidAds(vshop.ShopId, Entities.SlideAdInfo.SlideAdType.VShopHome).ToList(); //首页商品现在只有商家配置微信首页,APP读的也是这个数据所以平台类型选的的微信端 var homeProducts = ServiceProvider.Instance <IMobileHomeProductsService> .Create.GetMobileHomeProducts(vshop.ShopId, PlatformType.WeiXin, 1, 8); #region 价格更新 //会员折扣 decimal discount = 1M; long SelfShopId = 0; if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; var shopInfo = ShopApplication.GetSelfShop(); SelfShopId = shopInfo.Id; } var limit = LimitTimeApplication.GetLimitProducts(); var fight = FightGroupApplication.GetFightGroupPrice(); var products = new List <ProductItem>(); var productData = ProductManagerApplication.GetProducts(homeProducts.Models.Select(p => p.ProductId)); foreach (var item in homeProducts.Models) { var product = productData.FirstOrDefault(p => p.Id == item.ProductId); var pitem = new ProductItem(); pitem.Id = item.ProductId; pitem.ImageUrl = Core.MallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Mall.CommonModel.ImageSize.Size_350); pitem.Name = product.ProductName; pitem.MarketPrice = product.MarketPrice; pitem.SalePrice = product.MinSalePrice; if (item.ShopId == SelfShopId) { pitem.SalePrice = product.MinSalePrice * discount; } var isLimit = limit.Where(r => r.ProductId == item.ProductId).FirstOrDefault(); var isFight = fight.Where(r => r.ProductId == item.ProductId).FirstOrDefault(); if (isLimit != null) { pitem.SalePrice = isLimit.MinPrice; } if (isFight != null) { pitem.SalePrice = isFight.ActivePrice; } products.Add(pitem); } #endregion var banner = ServiceProvider.Instance <INavigationService> .Create.GetSellerNavigations(vshop.ShopId, Core.PlatformType.WeiXin).ToList(); var couponInfo = GetCouponList(vshop.ShopId); var SlideAds = slideImgs.ToArray().Select(item => new HomeSlideAdsModel() { ImageUrl = Core.MallIO.GetRomoteImagePath(item.ImageUrl), Url = item.Url }); var Banner = banner; var Products = products; bool favoriteShop = false; if (CurrentUser != null) { favoriteShop = ServiceProvider.Instance <IShopService> .Create.IsFavoriteShop(CurrentUser.Id, vshop.ShopId); } string followUrl = ""; //快速关注 var vshopSetting = ServiceProvider.Instance <IVShopService> .Create.GetVShopSetting(vshop.ShopId); if (vshopSetting != null) { followUrl = vshopSetting.FollowUrl; } var model = new { Id = vshop.Id, //Logo = "http://" + Url.Request.RequestUri.Host + vshop.Logo, Logo = Core.MallIO.GetRomoteImagePath(vshop.StrLogo), Name = vshop.Name, ShopId = vshop.ShopId, Favorite = favoriteShop, State = vshop.State, FollowUrl = followUrl }; // 客服 var customerServices = CustomerServiceApplication.GetMobileCustomerServiceAndMQ(vshop.ShopId); //统计访问量 if (!sv) { vshopService.LogVisit(id); //统计店铺访问人数 StatisticApplication.StatisticShopVisitUserCount(vshop.ShopId); } dynamic result = new ExpandoObject(); result.VShop = model; result.SlideImgs = SlideAds; result.Products = products; result.Banner = banner; result.Coupon = couponInfo; result.CustomerServices = customerServices; return(Json(new { result })); }
public ActionResult Detail(string id) { if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Error404", "Error", new { area = "Web" })); } string price = ""; #region 定义Model和变量 LimitTimeProductDetailModel model = new LimitTimeProductDetailModel { MainId = long.Parse(id), HotAttentionProducts = new List <HotProductInfo>(), HotSaleProducts = new List <HotProductInfo>(), Product = new Entities.ProductInfo(), Shop = new ShopInfoModel(), ShopCategory = new List <CategoryJsonModel>(), Color = new CollectionSKU(), Size = new CollectionSKU(), Version = new CollectionSKU() }; FlashSaleModel market = null; Entities.ShopInfo shop = null; long gid = 0, mid = 0; #endregion #region 商品Id不合法 if (long.TryParse(id, out mid)) { } if (mid == 0) { //跳转到出错页面 return(RedirectToAction("Error404", "Error", new { area = "Web" })); } #endregion #region 初始化商品和店铺 market = _iLimitTimeBuyService.Get(mid); switch (market.Status) { case Entities.FlashSaleInfo.FlashSaleStatus.Ended: return(RedirectToAction("Detail", "Product", new { id = market.ProductId })); case Entities.FlashSaleInfo.FlashSaleStatus.Cancelled: return(RedirectToAction("Detail", "Product", new { id = market.ProductId })); } if (market.Status != Entities.FlashSaleInfo.FlashSaleStatus.Ongoing) { return(RedirectToAction("Home")); } model.FlashSale = market; if (market == null || market.Id == 0 || market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing) { //可能参数是商品ID market = market == null?_iLimitTimeBuyService.GetFlaseSaleByProductId(mid) : market; if (market == null) { //跳转到404页面 return(RedirectToAction("Error404", "Error", new { area = "Mobile" })); } if (market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing) { return(RedirectToAction("Detail", "Product", new { id = market.ProductId })); } } model.MaxSaleCount = market.LimitCountOfThePeople; model.Title = market.Title; shop = _iShopService.GetShop(market.ShopId); model.Shop.Name = shop.ShopName; #endregion #region 商品描述 var product = _iProductService.GetProduct(market.ProductId); gid = market.ProductId; var brandModel = ServiceApplication.Create <IBrandService>().GetBrand(product.BrandId); product.BrandName = brandModel == null ? "" : brandModel.Name; if (CurrentUser != null && CurrentUser.Id > 0) { product.IsFavorite = ProductManagerApplication.IsFavorite(product.Id, CurrentUser.Id); } model.Product = product; model.Skus = ProductManagerApplication.GetSKUsByProduct(new List <long> { product.Id }); var description = ProductManagerApplication.GetProductDescription(product.Id); model.ProductDescription = description.Description; if (description.DescriptionPrefixId != 0) { var desc = _iProductDescriptionTemplateService .GetTemplate(description.DescriptionPrefixId, product.ShopId); model.DescriptionPrefix = desc == null ? "" : desc.Content; } if (description.DescriptiondSuffixId != 0) { var desc = _iProductDescriptionTemplateService .GetTemplate(description.DescriptiondSuffixId, product.ShopId); model.DescriptiondSuffix = desc == null ? "" : desc.Content; } #endregion #region 店铺 var categories = _iShopCategoryService.GetShopCategory(product.ShopId); List <Entities.ShopCategoryInfo> allcate = categories.ToList(); foreach (var main in allcate.Where(s => s.ParentCategoryId == 0)) { var topC = new CategoryJsonModel() { Name = main.Name, Id = main.Id.ToString(), SubCategory = new List <SecondLevelCategory>() }; foreach (var secondItem in allcate.Where(s => s.ParentCategoryId == main.Id)) { var secondC = new SecondLevelCategory() { Name = secondItem.Name, Id = secondItem.Id.ToString(), }; topC.SubCategory.Add(secondC); } model.ShopCategory.Add(topC); } model.CashDeposits = _iCashDepositsService.GetCashDepositsObligation(product.Id); #endregion #region 热门销售 //会员折扣 decimal discount = 1M; long SelfShopId = 0; if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; var shopInfo = ShopApplication.GetSelfShop(); SelfShopId = shopInfo.Id; } var sale = _iProductService.GetHotSaleProduct(shop.Id, 5); if (sale != null) { foreach (var item in sale.ToArray()) { var salePrice = item.MinSalePrice; if (item.ShopId == SelfShopId) { salePrice = item.MinSalePrice * discount; } var limitBuy = LimitTimeApplication.GetLimitTimeMarketItemByProductId(item.Id); if (limitBuy != null) { salePrice = limitBuy.MinPrice; } model.HotSaleProducts.Add(new HotProductInfo { ImgPath = item.ImagePath, Name = item.ProductName, Price = Math.Round(salePrice, 2), Id = item.Id, SaleCount = (int)item.SaleCounts + Mall.Core.Helper.TypeHelper.ObjectToInt(item.VirtualSaleCounts) }); } } #endregion #region 热门关注 var hot = _iProductService.GetHotConcernedProduct(shop.Id, 5); if (hot != null) { foreach (var item in hot.ToArray()) { model.HotAttentionProducts.Add(new HotProductInfo { ImgPath = item.ImagePath, Name = item.ProductName, Price = item.MinSalePrice, Id = item.Id, SaleCount = (int)item.ConcernedCount }); } } #endregion #region 商品规格 Entities.TypeInfo typeInfo = _iTypeService.GetType(product.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 (product != null) { colorAlias = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias; sizeAlias = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias; versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias; } model.ColorAlias = colorAlias; model.SizeAlias = sizeAlias; model.VersionAlias = versionAlias; var skus = _iProductService.GetSKUs(product.Id); if (skus.Count > 0) { long colorId = 0, sizeId = 0, versionId = 0; foreach (var sku in skus) { var specs = sku.Id.Split('_'); if (specs.Count() > 0 && !string.IsNullOrEmpty(sku.Color)) { if (long.TryParse(specs[1], out colorId)) { } if (colorId != 0) { if (!model.Color.Any(v => v.Value.Equals(sku.Color))) { var c = skus.Where(s => s.Color.Equals(sku.Color)).Sum(s => s.Stock); model.Color.Add(new ProductSKU { //Name = "选择颜色", Name = "选择" + colorAlias, EnabledClass = c != 0 ? "enabled" : "disabled", //SelectedClass = !model.Color.Any(c1 => c1.SelectedClass.Equals("selected")) && c != 0 ? "selected" : "", SelectedClass = "", SkuId = colorId, Value = sku.Color, Img = Mall.Core.MallIO.GetImagePath(sku.ShowPic) }); } } } if (specs.Count() > 1 && !string.IsNullOrEmpty(sku.Size)) { if (long.TryParse(specs[2], out sizeId)) { } if (sizeId != 0) { if (!model.Size.Any(v => v.Value.Equals(sku.Size))) { var ss = skus.Where(s => s.Size.Equals(sku.Size)).Sum(s1 => s1.Stock); model.Size.Add(new ProductSKU { //Name = "选择尺码", Name = "选择" + sizeAlias, EnabledClass = ss != 0 ? "enabled" : "disabled", //SelectedClass = !model.Size.Any(s1 => s1.SelectedClass.Equals("selected")) && ss != 0 ? "selected" : "", SelectedClass = "", SkuId = sizeId, Value = sku.Size }); } } } if (specs.Count() > 2 && !string.IsNullOrEmpty(sku.Version)) { if (long.TryParse(specs[3], out versionId)) { } if (versionId != 0) { if (!model.Version.Any(v => v.Value.Equals(sku.Version))) { var v = skus.Where(s => s.Version.Equals(sku.Version)).Sum(s => s.Stock); model.Version.Add(new ProductSKU { //Name = "选择版本", Name = "选择" + versionAlias, EnabledClass = v != 0 ? "enabled" : "disabled", //SelectedClass = !model.Version.Any(v1 => v1.SelectedClass.Equals("selected")) && v != 0 ? "selected" : "", SelectedClass = "", SkuId = versionId, Value = sku.Version }); } } } } price = ProductWebApplication.GetProductPriceStr(product, skus, discount);//最小价或区间价文本 } model.Price = string.IsNullOrWhiteSpace(price) ? product.MinSalePrice.ToString("f2") : price; #endregion #region 商品属性 List <TypeAttributesModel> ProductAttrs = new List <TypeAttributesModel>(); var prodAttrs = ProductManagerApplication.GetProductAttributes(product.Id); foreach (var attr in prodAttrs) { if (!ProductAttrs.Any(p => p.AttrId == attr.AttributeId)) { var attribute = _iTypeService.GetAttribute(attr.AttributeId); var values = _iTypeService.GetAttributeValues(attr.AttributeId); var attrModel = new TypeAttributesModel() { AttrId = attr.AttributeId, AttrValues = new List <TypeAttrValue>(), Name = attribute.Name }; foreach (var attrV in values) { if (prodAttrs.Any(p => p.ValueId == attrV.Id)) { attrModel.AttrValues.Add(new TypeAttrValue { Id = attrV.Id.ToString(), Name = attrV.Value }); } } ProductAttrs.Add(attrModel); } else { var attrTemp = ProductAttrs.FirstOrDefault(p => p.AttrId == attr.AttributeId); var values = _iTypeService.GetAttributeValues(attr.AttributeId); if (!attrTemp.AttrValues.Any(p => p.Id == attr.ValueId.ToString())) { attrTemp.AttrValues.Add(new TypeAttrValue { Id = attr.ValueId.ToString(), Name = values.FirstOrDefault(a => a.Id == attr.ValueId).Value }); } } } model.ProductAttrs = ProductAttrs; #endregion #region 获取评论、咨询数量 model.CommentCount = CommentApplication.GetCommentCountByProduct(product.Id); var consultations = _iConsultationService.GetConsultations(gid); model.Consultations = consultations.Count(); #endregion #region 累加浏览次数、 加入历史记录 if (CurrentUser != null) { BrowseHistrory.AddBrowsingProduct(product.Id, CurrentUser.Id); } else { BrowseHistrory.AddBrowsingProduct(product.Id); } //_iProductService.LogProductVisti(gid); //统计商品浏览量、店铺浏览人数 StatisticApplication.StatisticVisitCount(product.Id, product.ShopId); #endregion #region 红包 var bonus = ServiceApplication.Create <IShopBonusService>().GetByShopId(product.ShopId); if (bonus != null) { model.GrantPrice = bonus.GrantPrice; } else { model.GrantPrice = 0; } #endregion #region 获取店铺的评价统计 var shopStatisticOrderComments = _iShopService.GetShopStatisticOrderComments(shop.Id); var productAndDescription = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescription).FirstOrDefault(); var sellerServiceAttitude = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitude).FirstOrDefault(); var sellerDeliverySpeed = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeed).FirstOrDefault(); var productAndDescriptionPeer = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionPeer).FirstOrDefault(); var sellerServiceAttitudePeer = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudePeer).FirstOrDefault(); var sellerDeliverySpeedPeer = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedPeer).FirstOrDefault(); var productAndDescriptionMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionMax).FirstOrDefault(); var productAndDescriptionMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionMin).FirstOrDefault(); var sellerServiceAttitudeMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudeMax).FirstOrDefault(); var sellerServiceAttitudeMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudeMin).FirstOrDefault(); var sellerDeliverySpeedMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedMax).FirstOrDefault(); var sellerDeliverySpeedMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedMin).FirstOrDefault(); decimal defaultValue = 5; //宝贝与描述 if (productAndDescription != null && productAndDescriptionPeer != null) { ViewBag.ProductAndDescription = productAndDescription.CommentValue; ViewBag.ProductAndDescriptionPeer = productAndDescriptionPeer.CommentValue; ViewBag.ProductAndDescriptionMin = productAndDescriptionMin.CommentValue; ViewBag.ProductAndDescriptionMax = productAndDescriptionMax.CommentValue; } else { ViewBag.ProductAndDescription = defaultValue; ViewBag.ProductAndDescriptionPeer = defaultValue; ViewBag.ProductAndDescriptionMin = defaultValue; ViewBag.ProductAndDescriptionMax = defaultValue; } //卖家服务态度 if (sellerServiceAttitude != null && sellerServiceAttitudePeer != null) { ViewBag.SellerServiceAttitude = sellerServiceAttitude.CommentValue; ViewBag.SellerServiceAttitudePeer = sellerServiceAttitudePeer.CommentValue; ViewBag.SellerServiceAttitudeMax = sellerServiceAttitudeMax.CommentValue; ViewBag.SellerServiceAttitudeMin = sellerServiceAttitudeMin.CommentValue; } else { ViewBag.SellerServiceAttitude = defaultValue; ViewBag.SellerServiceAttitudePeer = defaultValue; ViewBag.SellerServiceAttitudeMax = defaultValue; ViewBag.SellerServiceAttitudeMin = defaultValue; } //卖家发货速度 if (sellerDeliverySpeedPeer != null && sellerDeliverySpeed != null) { ViewBag.SellerDeliverySpeed = sellerDeliverySpeed.CommentValue; ViewBag.SellerDeliverySpeedPeer = sellerDeliverySpeedPeer.CommentValue; ViewBag.SellerDeliverySpeedMax = sellerDeliverySpeedMax.CommentValue; ViewBag.sellerDeliverySpeedMin = sellerDeliverySpeedMin.CommentValue; } else { ViewBag.SellerDeliverySpeed = defaultValue; ViewBag.SellerDeliverySpeedPeer = defaultValue; ViewBag.SellerDeliverySpeedMax = defaultValue; ViewBag.sellerDeliverySpeedMin = defaultValue; } #endregion #region 客服 model.Service = ServiceApplication.Create <ICustomerService>().GetCustomerService(shop.Id).Where(c => c.Type == Entities.CustomerServiceInfo.ServiceType.PreSale && c.TerminalType == Entities.CustomerServiceInfo.ServiceTerminalType.PC).OrderBy(m => m.Tool); #endregion #region 开团提醒场景二维码 var siteSetting = SiteSettingApplication.SiteSettings; if (DateTime.Parse(model.FlashSale.BeginDate) > DateTime.Now && WXIsConfig(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret)) { try { var token = AccessTokenContainer.TryGetAccessToken(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret); SceneHelper helper = new SceneHelper(); SceneModel scene = new SceneModel(QR_SCENE_Type.FlashSaleRemind, model.FlashSale.Id); int sceneId = helper.SetModel(scene); var ticket = QrCodeApi.Create(token, 86400, sceneId, Senparc.Weixin.MP.QrCode_ActionName.QR_LIMIT_SCENE, null).ticket; ViewBag.ticket = ticket; } catch { } } #endregion model.Logined = (null != CurrentUser) ? 1 : 0; model.EnabledBuy = product.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited && DateTime.Parse(market.BeginDate) <= DateTime.Now && DateTime.Parse(market.EndDate) > DateTime.Now && product.SaleStatus == Entities.ProductInfo.ProductSaleStatus.OnSale; if (market.Status == FlashSaleInfo.FlashSaleStatus.Ongoing && DateTime.Parse(market.BeginDate) < DateTime.Now && DateTime.Parse(market.EndDate) > DateTime.Now) { TimeSpan end = new TimeSpan(DateTime.Parse(market.EndDate).Ticks); TimeSpan start = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts = end.Subtract(start); model.Second = ts.TotalSeconds < 0 ? 0 : ts.TotalSeconds; } else if (market.Status == FlashSaleInfo.FlashSaleStatus.Ongoing && DateTime.Parse(market.BeginDate) > DateTime.Now) { TimeSpan end = new TimeSpan(DateTime.Parse(market.BeginDate).Ticks); TimeSpan start = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts = end.Subtract(start); model.Second = ts.TotalSeconds < 0 ? 0 : ts.TotalSeconds; } //补充当前店铺红包功能 ViewBag.isShopPage = true; ViewBag.CurShopId = product.ShopId; TempData["isShopPage"] = true; TempData["CurShopId"] = product.ShopId; ViewBag.Keyword = SiteSettings.Keyword; ViewBag.Quantity = market.Quantity;//总活动库存 model.VirtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(product.Id); model.FreightTemplate = FreightTemplateApplication.GetFreightTemplate(product.FreightTemplateId); return(View(model)); }
public object GetSearchProducts( string keywords = "", /* 搜索关键字 */ long cid = 0, /* 分类ID */ long b_id = 0, /* 品牌ID */ string a_id = "", /* 属性ID, 表现形式:attrId_attrValueId */ int orderKey = 1, /* 排序项(1:默认,2:销量,3:价格,4:评论数,5:上架时间) */ int orderType = 1, /* 排序方式(1:升序,2:降序) */ int pageNo = 1, /*页码*/ int pageSize = 10, /*每页显示数据量*/ long vshopId = 0, long sid = 0 /*商家ID*/ ) { if (string.IsNullOrEmpty(keywords) && vshopId == 0 && cid <= 0 && b_id <= 0 && a_id == "") { keywords = Application.SiteSettingApplication.GetSiteSettings().Keyword; } #region 初始化查询Model SearchProductQuery model = new SearchProductQuery(); model.VShopId = vshopId; model.ShopId = sid; model.BrandId = b_id; if (vshopId == 0 && cid != 0) { var catelist = ServiceProvider.Instance <ICategoryService> .Create.GetCategories(); var cate = catelist.FirstOrDefault(r => r.Id == cid); if (cate.Depth == 1) { model.FirstCateId = cid; } else if (cate.Depth == 2) { model.SecondCateId = cid; } else if (cate.Depth == 3) { model.ThirdCateId = cid; } } else if (vshopId != 0 && cid != 0) { model.ShopCategoryId = cid; } model.AttrValIds = a_id.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); model.Keyword = keywords; model.OrderKey = orderKey; model.OrderType = orderType == 1; model.PageNumber = pageNo; model.PageSize = pageSize; #endregion SearchProductResult result = ServiceProvider.Instance <ISearchProductService> .Create.SearchProduct(model); int total = result.Total; //当查询的结果少于一页时用like进行补偿(与PC端同步) if (result.Total < pageSize) { model.IsLikeSearch = true; SearchProductResult result2 = ServiceProvider.Instance <ISearchProductService> .Create.SearchProduct(model); var idList1 = result.Data.Select(a => a.ProductId).ToList(); var nresult = result2.Data.Where(a => !idList1.Contains(a.ProductId)).ToList(); if (nresult.Count > 0) { result.Total += nresult.Count; result.Data.AddRange(nresult); } } total = result.Total; #region 价格更新 //会员折扣 decimal discount = 1M; long SelfShopId = 0; if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; var shopInfo = ShopApplication.GetSelfShop(); SelfShopId = shopInfo.Id; } var limit = LimitTimeApplication.GetLimitProducts(); var fight = FightGroupApplication.GetFightGroupPrice(); foreach (var item in result.Data) { item.ImagePath = Core.HimallIO.GetRomoteProductSizeImage(Core.HimallIO.GetImagePath(item.ImagePath), 1, (int)Himall.CommonModel.ImageSize.Size_350); if (item.ShopId == SelfShopId) { item.SalePrice = item.SalePrice * discount; } var isLimit = limit.Where(r => r.ProductId == item.ProductId).FirstOrDefault(); var isFight = fight.Where(r => r.ProductId == item.ProductId).FirstOrDefault(); if (isLimit != null) { item.SalePrice = isLimit.MinPrice; } if (isFight != null) { item.SalePrice = isFight.ActivePrice; } } #endregion return(Json(new { Success = "true", Product = result.Data, keywords = model.Keyword, Total = total, cid = cid, b_id = b_id, a_id = a_id, orderKey = orderKey, orderType = orderType })); }
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)); }
public JsonResult GetCartProducts() { ShoppingCartInfo cart = new CartHelper().GetCart(base.CurrentUser.Id); IProductService productService = this._iProductService; IShopService shopService = this._iShopService; IVShopService vshopService = this._iVShopService; decimal discount = 1.0M; if (base.CurrentUser != null) { discount = base.CurrentUser.MemberDiscount; } List <long> list = new List <long>(); decimal prodPrice = 0.0M; List <FlashSalePrice> limitProducts = LimitTimeApplication.GetPriceByProducrIds((from e in cart.Items select e.ProductId).ToList <long>()); var source = from s in cart.Items.Where <ShoppingCartItem>(delegate(ShoppingCartItem d) { long?nullable; return(!d.ShopBranchId.HasValue || (((nullable = d.ShopBranchId).GetValueOrDefault() == 0L) && nullable.HasValue)); }).Select(delegate(ShoppingCartItem item) { Func <FlashSalePrice, bool> predicate = null; ProductInfo product = productService.GetProduct(item.ProductId); ShopInfo shop = shopService.GetShop(product.ShopId, false); SKUInfo sku = null; string str = ""; string str2 = ""; string str3 = ""; string str4 = ""; if (null != shop) { string str5; VShopInfo vShopByShopId = vshopService.GetVShopByShopId(shop.Id); sku = productService.GetSku(item.SkuId); if (sku == null) { return(null); } if (predicate == null) { predicate = e => e.ProductId == item.ProductId; } FlashSalePrice price = limitProducts.FirstOrDefault <FlashSalePrice>(predicate); prodPrice = sku.SalePrice; if (price != null) { prodPrice = price.MinPrice; } else if (shop.IsSelf) { prodPrice = sku.SalePrice * discount; } ProductType type = TypeApplication.GetType(product.TypeId); str = ((type == null) || string.IsNullOrEmpty(type.ColorAlias)) ? SpecificationType.Color.ToDescription() : type.ColorAlias; str2 = ((type == null) || string.IsNullOrEmpty(type.SizeAlias)) ? SpecificationType.Size.ToDescription() : type.SizeAlias; str3 = ((type == null) || string.IsNullOrEmpty(type.VersionAlias)) ? SpecificationType.Version.ToDescription() : type.VersionAlias; str4 = ""; if (!string.IsNullOrWhiteSpace(sku.Size)) { str5 = str4; str4 = str5 + str2 + ":" + sku.Size + " "; } if (!string.IsNullOrWhiteSpace(sku.Color)) { str5 = str4; str4 = str5 + str + ":" + sku.Color + " "; } if (!string.IsNullOrWhiteSpace(sku.Version)) { str5 = str4; str4 = str5 + str3 + ":" + sku.Version + " "; } return(new { cartItemId = item.Id, skuId = item.SkuId, id = product.Id, imgUrl = HimallIO.GetProductSizeImage(product.RelativePath, 1, 150), name = product.ProductName, price = prodPrice, count = item.Quantity, shopId = shop.Id, vshopId = (vShopByShopId == null) ? 0L : vShopByShopId.Id, shopName = shop.ShopName, shopLogo = (vShopByShopId == null) ? "" : vShopByShopId.Logo, status = ((product.AuditStatus == ProductInfo.ProductAuditStatus.Audited) && (product.SaleStatus == ProductInfo.ProductSaleStatus.OnSale)) ? 1 : 0, Size = sku.Size, Color = sku.Color, Version = sku.Version, ColorAlias = str, SizeAlias = str2, VersionAlias = str3, skuDetails = str4, AddTime = item.AddTime }); } return(null); }) where s != null orderby s.vshopId, s.AddTime descending select s; BranchCartHelper helper2 = new BranchCartHelper(); long memberId = 0L; if (base.CurrentUser != null) { memberId = base.CurrentUser.Id; } ShoppingCartInfo cartNoCache = helper2.GetCartNoCache(memberId, 0L); List <long> list2 = (from x in (from x in cartNoCache.Items where x.ShopBranchId.HasValue select x.ShopBranchId.Value).ToList <long>() group x by x into x select x.First <long>()).ToList <long>(); Dictionary <long, int> buyedCounts = null; if (memberId > 0L) { cart = helper2.GetCart(memberId, 0L); buyedCounts = new Dictionary <long, int>(); buyedCounts = OrderApplication.GetProductBuyCount(memberId, from x in cart.Items select x.ProductId); } List <object> list3 = new List <object>(); using (List <long> .Enumerator enumerator = list2.GetEnumerator()) { while (enumerator.MoveNext()) { Func <ShoppingCartItem, bool> func = null; long shopBranchId = enumerator.Current; prodPrice = 0.0M; List <ShopBranchSkusInfo> shopBranchSkuList = this._iShopBranchService.GetSkusByIds(shopBranchId, from x in cartNoCache.Items select x.SkuId); if (func == null) { func = delegate(ShoppingCartItem x) { long?nullable1 = x.ShopBranchId; long num = shopBranchId; return((nullable1.GetValueOrDefault() == num) && nullable1.HasValue); }; } var enumerable2 = from s in cartNoCache.Items.Where <ShoppingCartItem>(func).Select(delegate(ShoppingCartItem item) { Func <ShopBranchSkusInfo, bool> predicate = null; if (shopBranchId == 0x63L) { } ShopBranchInfo shopBranchById = this._iShopBranchService.GetShopBranchById(shopBranchId); ProductInfo product = this._iProductService.GetProduct(item.ProductId); ShopInfo shop = this._iShopService.GetShop(product.ShopId, false); SKUInfo sku = null; if ((shop != null) && (shopBranchById != null)) { VShopInfo vShopByShopId = this._iVShopService.GetVShopByShopId(shop.Id); sku = this._iProductService.GetSku(item.SkuId); if (sku == null) { return(null); } prodPrice = sku.SalePrice; if (shop.IsSelf) { prodPrice = sku.SalePrice * discount; } if (predicate == null) { predicate = x => x.SkuId == item.SkuId; } ShopBranchSkusInfo info6 = shopBranchSkuList.FirstOrDefault <ShopBranchSkusInfo>(predicate); long maxBuyCount = (info6 == null) ? ((long)0) : ((long)info6.Stock); if ((maxBuyCount > product.MaxBuyCount) && (product.MaxBuyCount > 0)) { maxBuyCount = product.MaxBuyCount; } if (((product.MaxBuyCount > 0) && (buyedCounts != null)) && buyedCounts.ContainsKey(item.ProductId)) { int num3 = buyedCounts[item.ProductId]; maxBuyCount -= num3; } return(new { cartItemId = item.Id, skuId = item.SkuId, id = product.Id, imgUrl = HimallIO.GetProductSizeImage(product.RelativePath, 1, 150), name = product.ProductName, price = prodPrice, count = item.Quantity, status = (info6 == null) ? 1 : ((info6.Status == ShopBranchSkuStatus.Normal) ? ((item.Quantity > maxBuyCount) ? 2 : 0) : 1), AddTime = item.AddTime, shopBranchId = shopBranchById.Id, shopBranchName = shopBranchById.ShopBranchName }); } return(null); }) where s != null orderby s.AddTime descending select s; list3.Add(enumerable2); } } var data = new { products = source, amount = Enumerable.Sum(source, item => item.price * (Decimal)item.count), totalCount = Enumerable.Sum(source, item => item.count), shopBranchCart = list3 }; return(base.Json(data)); }