/// <summary> /// 是否可允许自提门店 /// </summary> /// <param name="shopId">商家ID</param> /// <returns></returns> public object GetIsSelfDelivery(long shopId, long productId, string fromLatLng = "") { if (shopId <= 0) { return(Json(new { Message = "请传入合法商家ID", IsSelfDelivery = 0 })); } if (!(fromLatLng.Split(',').Length == 2)) { return(Json(new { Message = "请传入合法经纬度", IsSelfDelivery = 0 })); } var query = new CommonModel.ShopBranchQuery() { ShopId = shopId, Status = CommonModel.ShopBranchStatus.Normal }; string address = "", province = "", city = "", district = "", street = ""; ShopbranchHelper.GetAddressByLatLng(fromLatLng, ref address, ref province, ref city, ref district, ref street); if (string.IsNullOrWhiteSpace(city)) { return(Json(new { Message = "无法获取当前城市", IsSelfDelivery = 0 })); } Region cityInfo = RegionApplication.GetRegionByName(city, Region.RegionLevel.City); if (cityInfo == null) { return(Json(new { Message = "获取当前城市异常", IsSelfDelivery = 0 })); } query.CityId = cityInfo.Id; query.ProductIds = new long[] { productId }; var shopBranch = ShopBranchApplication.GetShopBranchsAll(query).Models; //获取该商品所在商家下,且与用户同城内门店,且门店有该商品 var skuInfos = ProductManagerApplication.GetSKU(productId); //获取该商品的sku //门店SKU内会有默认的SKU if (!skuInfos.Exists(p => p.Id == string.Format("{0}_0_0_0", productId))) { skuInfos.Add(new DTO.SKU() { Id = string.Format("{0}_0_0_0", productId) }); } var shopBranchSkus = ShopBranchApplication.GetSkus(query.ShopId, shopBranch.Select(p => p.Id));//门店商品SKU //门店商品SKU,只要有一个sku有库存即可 shopBranch.ForEach(p => p.Enabled = skuInfos.Where(skuInfo => shopBranchSkus.Where(sbSku => sbSku.ShopBranchId == p.Id && sbSku.Stock > 0 && sbSku.SkuId == skuInfo.Id).Count() > 0).Count() > 0 ); return(Json(new { Message = "", IsSelfDelivery = shopBranch.Where(p => p.Enabled).Count() > 0 ? 1 : 0 }));//至少有一个能够自提的门店,才可显示图标 }
public JsonResult List(int pageSize, int pageNo, string fromLatLng, string shopId) { bool isOpenStore = SiteSettingApplication.GetSiteSettings() != null && SiteSettingApplication.GetSiteSettings().IsOpenStore; if (!isOpenStore) { throw new Core.HimallException("门店未授权!"); } ShopBranchQuery query = new ShopBranchQuery(); query.PageNo = pageNo; query.PageSize = pageSize; query.Status = ShopBranchStatus.Normal; query.CityId = -1; query.FromLatLng = fromLatLng; query.OrderKey = 2; query.OrderType = true; if (query.FromLatLng.Split(',').Length != 2) { return(Json(new { Success = false, Message = "无法获取您的当前位置,请确认是否开启定位服务!" }, JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrWhiteSpace(shopId))//如果传入了商家ID,则只取商家下门店 { query.ShopId = TypeHelper.ObjectToInt(shopId, 0); if (query.ShopId <= 0) { return(Json(new { Success = false, Message = "无法定位到商家!" }, JsonRequestBehavior.AllowGet)); } } else//否则取用户同城门店 { string address = "", province = "", city = "", district = "", street = ""; ShopbranchHelper.GetAddressByLatLng(query.FromLatLng, ref address, ref province, ref city, ref district, ref street); if (string.IsNullOrWhiteSpace(city)) { return(Json(new { Success = false, Message = "无法定位到城市!" }, JsonRequestBehavior.AllowGet)); } Region cityInfo = RegionApplication.GetRegionByName(city, Region.RegionLevel.City); if (cityInfo != null) { query.CityId = cityInfo.Id; } } var shopBranchs = ShopBranchApplication.GetNearShopBranchs(query); return(Json(new { Success = true, Models = shopBranchs.Models, Total = shopBranchs.Total }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 获取周边门店 /// </summary> /// <param name="fromLatLng"></param> /// <param name="shopId"></param> /// <param name="pageNo"></param> /// <param name="pageSize"></param> /// <returns></returns> public object GetStoreList( string fromLatLng = "", /* 用户当前位置经纬度 */ string shopId = "", /* 诊所ID */ int pageNo = 1, /*页码*/ int pageSize = 10 /*每页显示数据量*/ ) { ShopBranchQuery query = new ShopBranchQuery(); query.PageNo = pageNo; query.PageSize = pageSize; query.Status = ShopBranchStatus.Normal; query.CityId = -1; query.FromLatLng = fromLatLng; query.OrderKey = 2; query.OrderType = true; if (query.FromLatLng.Split(',').Length != 2) { return(Json(new { Success = false, Message = "无法获取您的当前位置,请确认是否开启定位服务!" })); } if (!string.IsNullOrWhiteSpace(shopId))//如果传入了诊所ID,则只取诊所下门店 { query.ShopId = TypeHelper.ObjectToInt(shopId, 0); if (query.ShopId <= 0) { return(Json(new { Success = false, Message = "无法定位到诊所!" })); } } else//否则取用户同城门店 { string address = "", province = "", city = "", district = "", street = ""; ShopbranchHelper.GetAddressByLatLng(query.FromLatLng, ref address, ref province, ref city, ref district, ref street); if (string.IsNullOrWhiteSpace(city)) { return(Json(new { Success = false, Message = "无法定位到城市!" })); } Region cityInfo = RegionApplication.GetRegionByName(city, Region.RegionLevel.City); if (cityInfo != null) { query.CityId = cityInfo.Id; } } var shopBranchs = ShopBranchApplication.GetNearShopBranchs(query); var storelist = shopBranchs.Models.ToList().Select(item => { return(new { Id = item.Id, Latitude = item.Latitude, Longitude = item.Longitude, DistanceUnit = item.DistanceUnit, ShopBranchName = item.ShopBranchName, ContactPhone = item.ContactPhone, AddressDetail = item.AddressDetail }); }); var result = new { Success = true, Storelist = storelist, total = shopBranchs.Total }; return(Json(result)); }
/// <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 })); }