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 object GetVShop(long id, bool sv = false) { var vshopService = ServiceProvider.Instance<IVShopService>.Create; var vshop = vshopService.GetVShop(id); if (vshop == null) return new Result { success = false, msg = "未开通微店", code = -4 }; if (vshop.State == Entities.VShopInfo.VshopStates.Close) return new Result { success = false, msg = "商家暂未开通微店", code = -5 }; if (!vshop.IsOpen) return new Result { success = false, msg = "此微店已关闭", code = -3 }; var s = ShopApplication.GetShop(vshop.ShopId); if (null != s && s.ShopStatus == Entities.ShopInfo.ShopAuditStatus.HasExpired) return new Result { success = false, msg = "此店铺已过期", code = -1 }; //throw new HimallApiException("此店铺已过期"); if (null != s && s.ShopStatus == Entities.ShopInfo.ShopAuditStatus.Freeze) return new Result { success = false, msg = "此店铺已冻结", code = -2 }; //throw new HimallApiException("此店铺已冻结"); //轮播图配置只有商家微店首页配置页面可配置,现在移动端都读的这个数据 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.HimallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Himall.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.HimallIO.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.HimallIO.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 = SuccessResult(); result.VShop = model; result.SlideImgs = SlideAds; result.Products = products; result.Banner = banner; result.Coupon = couponInfo; result.CustomerServices = customerServices; return 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); }