Beispiel #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));
        }
Beispiel #2
0
        /// <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));
        }