/// <summary> /// 获取门店信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public JsonResult <Result <dynamic> > GetStoreInfo(long id, string fromLatLng = "") { CheckOpenStore(); var shopBranch = ShopBranchApplication.GetShopBranchById(id); if (shopBranch == null) { throw new HimallApiException(ApiErrorCode.Parameter_Error, "id"); } var shop = ShopApplication.GetShop(shopBranch.ShopId); if (null != shop && shop.ShopStatus == Entities.ShopInfo.ShopAuditStatus.HasExpired) { return(Json(ErrorResult <dynamic>("此店铺已过期"))); } if (null != shop && shop.ShopStatus == Entities.ShopInfo.ShopAuditStatus.Freeze) { return(Json(ErrorResult <dynamic>("此店铺已冻结"))); } if (!string.IsNullOrWhiteSpace(fromLatLng)) { shopBranch.Distance = ShopBranchApplication.GetLatLngDistances(fromLatLng, string.Format("{0},{1}", shopBranch.Latitude, shopBranch.Longitude)); } shopBranch.AddressDetail = ShopBranchApplication.RenderAddress(shopBranch.AddressPath, shopBranch.AddressDetail, 2); shopBranch.ShopImages = HimallIO.GetRomoteImagePath(shopBranch.ShopImages); Mapper.CreateMap <ShopBranch, HomeGetShopBranchInfoModel>(); var store = Mapper.Map <ShopBranch, HomeGetShopBranchInfoModel>(shopBranch); var homepageBranch = ProcessBranchHomePageData(new List <ShopBranch>() { shopBranch }, true).FirstOrDefault(); //过滤不能领取的优惠券 homepageBranch.ShopAllActives.ShopCoupons = homepageBranch.ShopAllActives.ShopCoupons.ToList(); //统计门店访问人数 StatisticApplication.StatisticShopBranchVisitUserCount(shopBranch.ShopId, shopBranch.Id); return(JsonResult <dynamic>(new { Store = store, homepageBranch.ShopAllActives, CommentScore = ShopBranchApplication.GetServiceMark(store.Id).ComprehensiveMark, //评分 })); }
/// <summary> /// 根据商品查找门店 /// </summary> /// <param name="fromLatLng"></param> /// <param name="productId"></param> /// <param name="shopId"></param> /// <param name="pageNo"></param> /// <param name="pageSize"></param> /// <returns></returns> public JsonResult <Result <dynamic> > GetStoresByProduct(string fromLatLng, long productId, long?shopId = null, int pageNo = 1, int pageSize = 10) { CheckOpenStore(); ShopBranchQuery query = new ShopBranchQuery(); query.PageNo = pageNo; query.PageSize = pageSize; query.Status = ShopBranchStatus.Normal; query.ShopBranchProductStatus = ShopBranchSkuStatus.Normal; query.ProductIds = new long[] { productId }; query.CityId = -1; query.FromLatLng = fromLatLng; query.OrderKey = 2; query.OrderType = true; //query.FilterVirtualProduct = true; if (query.FromLatLng.Split(',').Length != 2) { throw new HimallException("无法获取您的当前位置,请确认是否开启定位服务!"); } string address = "", province = "", city = "", district = "", street = ""; string currentPosition = string.Empty;//当前详情地址,优先顺序:建筑、社区、街道 Region cityInfo = new Region(); if (shopId.HasValue)//如果传入了商家ID,则只取商家下门店 { query.ShopId = shopId.Value; if (query.ShopId <= 0) { throw new HimallException("无法定位到商家!"); } } else//否则取用户同城门店 { var addressObj = ShopbranchHelper.GetAddressByLatLng(query.FromLatLng, ref address, ref province, ref city, ref district, ref street); if (string.IsNullOrWhiteSpace(city)) { throw new HimallException("无法定位到城市!"); } cityInfo = RegionApplication.GetRegionByName(city, Region.RegionLevel.City); if (cityInfo != null) { query.CityId = cityInfo.Id; } //处理当前地址 currentPosition = street; } var shopBranchs = ShopBranchApplication.StoreByProductNearShopBranchs(query); //组装首页数据 //补充门店活动数据 var homepageBranchs = ProcessBranchHomePageData(shopBranchs.Models); AutoMapper.Mapper.CreateMap <HomePageShopBranch, HomeGetStoreListModel>(); var homeStores = AutoMapper.Mapper.Map <List <HomePageShopBranch>, List <HomeGetStoreListModel> >(homepageBranchs); long userId = 0; if (CurrentUser != null) { //如果已登陆取购物车数据 //memberCartInfo = CartApplication.GetShopBranchCart(CurrentUser.Id); userId = CurrentUser.Id; } var cartItemCount = ShopBranchApplication.GetShopBranchCartItemCount(userId, homeStores.Select(e => e.ShopBranch.Id).ToList()); foreach (var item in homeStores) { //商品 ShopBranchProductQuery proquery = new ShopBranchProductQuery(); proquery.PageSize = 4; proquery.PageNo = 1; proquery.OrderKey = 3; proquery.ShopBranchId = item.ShopBranch.Id; proquery.ShopBranchProductStatus = ShopBranchSkuStatus.Normal; //proquery.FilterVirtualProduct = true; var pageModel = ShopBranchApplication.GetShopBranchProducts(proquery); if (productId > 0) { var product = pageModel.Models.FirstOrDefault(n => n.Id == productId); pageModel.Models.Remove(product); var models = pageModel.Models.OrderByDescending(p => p.SaleCounts).ThenByDescending(p => p.Id).Take(3).ToList(); if (null != product) { models.Insert(0, product); } pageModel.Models = models; } var dtNow = DateTime.Now; //var saleCountByMonth = OrderApplication.GetSaleCount(dtNow.AddDays(-30).Date, dtNow, shopBranchId: proquery.ShopBranchId.Value); item.SaleCount = OrderApplication.GetSaleCount(shopBranchId: proquery.ShopBranchId.Value); item.SaleCountByMonth = ShopBranchApplication.GetShopBranchSaleCount(item.ShopBranch.Id, dtNow.AddDays(-30).Date, dtNow); item.ShowProducts = pageModel.Models.Select(p => new HomeGetStoreListProductModel { Id = p.Id, DefaultImage = HimallIO.GetRomoteProductSizeImage(p.ImagePath, 1, ImageSize.Size_150.GetHashCode()), MinSalePrice = p.MinSalePrice, ProductName = p.ProductName, HasSKU = p.HasSKU, MarketPrice = p.MarketPrice }).ToList(); item.ProductCount = pageModel.Total; if (cartItemCount != null) { item.CartQuantity = cartItemCount.ContainsKey(item.ShopBranch.Id) ? cartItemCount[item.ShopBranch.Id] : 0; } //评分 item.CommentScore = ShopBranchApplication.GetServiceMark(item.ShopBranch.Id).ComprehensiveMark; } return(JsonResult <dynamic>(new { Total = shopBranchs.Total, CityInfo = new { Id = cityInfo.Id, Name = cityInfo.Name }, CurrentAddress = currentPosition, Stores = homeStores, ProductSaleCountOnOff = SiteSettingApplication.SiteSettings.ProductSaleCountOnOff == 1 })); }
/// <summary> /// 门店列表 /// </summary> /// <returns></returns> public JsonResult <Result <dynamic> > GetStoreList(string fromLatLng, string keyWords = "", long?tagsId = null, long?shopId = null, int pageNo = 1, int pageSize = 10) { //TODO:FG 异常查询 MysqlExecuted:226,耗时:1567.4137毫秒 CheckOpenStore(); ShopBranchQuery query = new ShopBranchQuery(); query.PageNo = pageNo; query.PageSize = pageSize; query.Status = ShopBranchStatus.Normal; query.ShopBranchName = keyWords.Trim(); query.ShopBranchTagId = tagsId; query.CityId = -1; query.FromLatLng = fromLatLng; query.OrderKey = 2; query.OrderType = true; query.ShopBranchProductStatus = ShopBranchSkuStatus.Normal; if (query.FromLatLng.Split(',').Length != 2) { throw new HimallException("无法获取您的当前位置,请确认是否开启定位服务!"); } if (shopId.HasValue) { //var shop = ShopApplication.GetShopInfo(shopId.Value); var isFreeze = ShopApplication.IsFreezeShop(shopId.Value); if (isFreeze) { return(Json(ErrorResult <dynamic>(msg: "此店铺已冻结"))); } else { var isExpired = ShopApplication.IsExpiredShop(shopId.Value); if (isExpired) { return(Json(ErrorResult <dynamic>(msg: "此店铺已过期"))); } } } string address = "", province = "", city = "", district = "", street = ""; string currentPosition = string.Empty;//当前详情地址,优先顺序:建筑、社区、街道 Region cityInfo = new Region(); if (shopId.HasValue)//如果传入了商家ID,则只取商家下门店 { query.ShopId = shopId.Value; if (query.ShopId <= 0) { throw new HimallException("无法定位到商家!"); } } else//否则取用户同城门店 { var addressObj = ShopbranchHelper.GetAddressByLatLng(query.FromLatLng, ref address, ref province, ref city, ref district, ref street); if (string.IsNullOrWhiteSpace(city)) { city = province; } if (string.IsNullOrWhiteSpace(city)) { throw new HimallException("无法定位到城市!"); } cityInfo = RegionApplication.GetRegionByName(city, Region.RegionLevel.City); if (cityInfo == null) { throw new HimallException("无法定位到城市!"); } if (cityInfo != null) { query.CityId = cityInfo.Id; } //处理当前地址 currentPosition = street; } var shopBranchs = ShopBranchApplication.SearchNearShopBranchs(query); //组装首页数据 //补充门店活动数据 var homepageBranchs = ProcessBranchHomePageData(shopBranchs.Models); AutoMapper.Mapper.CreateMap <HomePageShopBranch, HomeGetStoreListModel>(); var homeStores = AutoMapper.Mapper.Map <List <HomePageShopBranch>, List <HomeGetStoreListModel> >(homepageBranchs); long userId = 0; if (CurrentUser != null) {//如果已登陆取购物车数据 //memberCartInfo = CartApplication.GetShopBranchCart(CurrentUser.Id); userId = CurrentUser.Id; } //统一处理门店购物车数量 var cartItemCount = ShopBranchApplication.GetShopBranchCartItemCount(userId, homeStores.Select(e => e.ShopBranch.Id).ToList()); foreach (var item in homeStores) { //商品 ShopBranchProductQuery proquery = new ShopBranchProductQuery(); proquery.PageSize = 4; proquery.PageNo = 1; proquery.OrderKey = 3; if (!string.IsNullOrWhiteSpace(keyWords)) { proquery.KeyWords = keyWords; } proquery.ShopBranchId = item.ShopBranch.Id; proquery.ShopBranchProductStatus = ShopBranchSkuStatus.Normal; //proquery.FilterVirtualProduct = true; var pageModel = ShopBranchApplication.GetShopBranchProducts(proquery); var dtNow = DateTime.Now; //var saleCountByMonth = OrderApplication.GetSaleCount(dtNow.AddDays(-30).Date, dtNow, shopBranchId: proquery.ShopBranchId.Value); item.SaleCount = OrderApplication.GetSaleCount(shopBranchId: proquery.ShopBranchId.Value); item.SaleCountByMonth = ShopBranchApplication.GetShopBranchSaleCount(item.ShopBranch.Id, dtNow.AddDays(-30).Date, dtNow); item.ShowProducts = pageModel.Models.Select(p => { var comcount = CommentApplication.GetProductHighCommentCount(productId: p.Id, shopBranchId: proquery.ShopBranchId.Value); return(new HomeGetStoreListProductModel { Id = p.Id, DefaultImage = HimallIO.GetRomoteProductSizeImage(p.ImagePath, 1, ImageSize.Size_150.GetHashCode()), MinSalePrice = p.MinSalePrice, ProductName = p.ProductName, HasSKU = p.HasSKU, MarketPrice = p.MarketPrice, SaleCount = Himall.Core.Helper.TypeHelper.ObjectToInt(p.VirtualSaleCounts) + OrderApplication.GetSaleCount(dtNow.AddDays(-30).Date, dtNow, shopBranchId: proquery.ShopBranchId.Value, productId: p.Id), HighCommentCount = comcount, }); }).ToList(); item.ProductCount = pageModel.Total; if (cartItemCount != null) { item.CartQuantity = cartItemCount.ContainsKey(item.ShopBranch.Id) ? cartItemCount[item.ShopBranch.Id] : 0; } //评分 item.CommentScore = ShopBranchApplication.GetServiceMark(item.ShopBranch.Id).ComprehensiveMark; } return(JsonResult <dynamic>(new { Total = shopBranchs.Total, CityInfo = new { Id = cityInfo.Id, Name = cityInfo.Name }, CurrentAddress = currentPosition, Stores = homeStores, ProductSaleCountOnOff = SiteSettingApplication.SiteSettings.ProductSaleCountOnOff == 1 })); }