Ejemplo n.º 1
0
        private int GetSupproseShopCount(string provinceName, List <string> pids)
        {
            ShopSearchRequest request = new ShopSearchRequest()
            {
                ProvinceName = provinceName,
                Filters      = new List <ShopQueryFilterModel>()
                {
                    new ShopQueryFilterModel()
                    {
                        FilterValueType = ShopQueryFilterValueType.MrPid.ToString(),
                        Values          = pids,//传服务ID
                        JoinType        = JoinType.And.ToString()
                    }
                },
                PageSize  = 10, //页面大小
                PageIndex = 1   //第几页
            };
            int result = 0;

            try
            {
                using (var clinet = new ShopClient())
                {
                    var serviceResult = clinet.SearchShopIds(request);
                    serviceResult.ThrowIfException(true);
                    result = serviceResult.Result.Pager.Total;
                }
            }
            catch (Exception ex)
            {
                logger.Error($"SearchShopIds:{ex.Message}", ex);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> SearchShopModel(double?latBegin, double?lngBegin,
                                                         string city, string district, string province, string sort, string serviceType, string serviceId,
                                                         int pageIndex = 1, int pageSize = 10)
        {
            var dic = new Dictionary <string, object> {
                ["Code"] = "0"
            };

            Tuhu.Models.PagerModel page = null;

            #region 获取所有相关的ShopId所需的Request

            var filters = new List <ShopQueryFilterModel>();
            if (!string.IsNullOrWhiteSpace(serviceType))
            {
                if (string.Equals(serviceType, "MR"))
                {
                    filters.Add(new ShopQueryFilterModel()
                    {
                        FilterValueType = ShopQueryFilterValueType.BeautyCategoryId.ToString(),
                        Values          = null,
                        JoinType        = JoinType.And.ToString()
                    });
                }
                else
                {
                    filters.Add(new ShopQueryFilterModel()
                    {
                        FilterValueType = ShopQueryFilterValueType.ServiceType.ToString(),
                        Values          = new List <string>()
                        {
                            serviceType
                        },
                        JoinType = JoinType.And.ToString()
                    });
                }
            }
            if (!string.IsNullOrWhiteSpace(serviceId))
            {
                filters.Add(new ShopQueryFilterModel()
                {
                    FilterValueType = ShopQueryFilterValueType.ServiceId.ToString(),
                    Values          = new List <string>()
                    {
                        serviceId
                    },
                    JoinType = JoinType.And.ToString()
                });
            }
            var request = new ShopSearchRequest()
            {
                ProvinceName = province,
                CityName     = city,
                DistrictName = district,
                Lat          = latBegin,
                Lon          = lngBegin,
                Filters      = filters,
                SortTypes    = new List <ShopQuerySortModel>()
                {
                    new ShopQuerySortModel()
                    {
                        SortValueType = ShopQuerySortValueType.Default.ToString(),
                        ServiceType   = serviceType,
                        SortOrder     = sort
                    },
                },

                PageSize  = pageSize,
                PageIndex = pageIndex
            };

            #endregion

            IEnumerable <ShopSimpleDetailModel> shopSimpleDetails = null;
            Dictionary <int, decimal>           biResultDic       = null;
            using (var client = new ShopClient())
            {
                var searchResult = (await client.SearchShopIdsAsync(request))?.Result;
                var shopIds      = searchResult?.Source;

                page = searchResult?.Pager;
                if (shopIds != null && shopIds.Any())
                {
                    #region 获取BI综合值

                    ShopSearchRequest bIrequest = new ShopSearchRequest()
                    {
                        Lat     = latBegin,
                        Lon     = lngBegin,
                        Filters = new List <ShopQueryFilterModel>()
                        {
                            new ShopQueryFilterModel()
                            {
                                FilterValueType = ShopQueryFilterValueType.ShopId.ToString(),
                                Values          = shopIds.Select(x => x.ToString()).ToList(),
                                JoinType        = JoinType.Or.ToString()
                            }
                        },
                        SortTypes = new List <ShopQuerySortModel>()
                        {
                            new ShopQuerySortModel()
                            {
                                SortValueType = ShopQuerySortValueType.Default.ToString(),
                                ServiceType   = serviceType,
                            },
                        },
                        PageSize  = pageSize,
                        PageIndex = pageIndex
                    };
                    biResultDic = (await client.GetBiWeightByShopIdsAsync(bIrequest))?.Result;

                    #endregion

                    shopSimpleDetails = (await client.SelectShopSimpleDetailsAsync(shopIds))?.Result;
                }
            }
            IEnumerable <ShopSortModel> shops = null;
            if (shopSimpleDetails != null)
            {
                shops = shopSimpleDetails
                        .Select(t => Controls.ModelConvertHelper.ConvertToShopSortModel(t, serviceType))
                        .ToList();

                #region ShopSimpleDetailModel中不存在的字段进行单独处理

                shops.ForEach(x =>
                {
                    x.Distance = (latBegin != null && lngBegin != null && x.ShopLat != null && x.ShopLng != null)
                        ? Controls.MathHelper.GetDistance(latBegin.Value,
                                                          lngBegin.Value, x.ShopLat.Value, x.ShopLng.Value)
                        : 0;
                    x.ComprehensiveScore = biResultDic != null && biResultDic.ContainsKey(x.ShopId)
                        ? biResultDic[x.ShopId]
                        : 0;
                });

                #endregion
            }
            if (shops != null)
            {
                dic.Add("TotalPage", page?.TotalPage);
                dic["Code"] = "1";
                dic.Add("Shops", shops);
                dic.Add("Count", page?.Total);
            }
            return(Json(dic, JsonRequestBehavior.AllowGet));
        }