예제 #1
0
        /// <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
            }));
        }