public AppAgentSourceViewModel GetAgentSource(AppBaseRequest request, IEnumerable <KeyValuePair <string, string> > pairs, Uri uri) { var viewModel = new AppAgentSourceViewModel(); #region 参数校验 //校验返回值 var baseResponse = _appVerifyService.Verify(request, pairs); if (baseResponse.ErrCode != 1) { viewModel.BusinessStatus = baseResponse.ErrCode; viewModel.StatusMessage = baseResponse.ErrMsg; return(viewModel); } #endregion #region 业务逻辑 List <AgentCity> agentCity = _agentService.GetSourceList(string.Format("http://{0}:{1}/", uri.Host, uri.Port), request.Agent); if (agentCity.Any()) { viewModel.BusinessStatus = 1; viewModel.AgentCity = agentCity; } else { viewModel.BusinessStatus = -10002; viewModel.StatusMessage = "获取信息失败"; } #endregion return(viewModel); }
public HttpResponseMessage GetAgentSourceName([FromUri] GetAgentResourceRequest request) { _logInfo.Info(string.Format("微信获取代理人资源+名称接口请求串:{0}", Request.RequestUri)); var viewModel = new AppAgentSourceViewModel(); if (!ModelState.IsValid) { viewModel.BusinessStatus = -10000; string msg = ModelState.Values.Where(item => item.Errors.Count == 1).Aggregate(string.Empty, (current, item) => current + (item.Errors[0].ErrorMessage + "; ")); viewModel.StatusMessage = "输入参数错误," + msg; return(viewModel.ResponseToJson()); } var response = _agentService.GetAgentSource(request, Request.GetQueryNameValuePairs()); if (response.Status == HttpStatusCode.BadRequest || response.Status == HttpStatusCode.Forbidden) { viewModel.BusinessStatus = -10001; viewModel.StatusMessage = "参数校验错误,请检查您的校验码"; return(viewModel.ResponseToJson()); } if (response.Status == HttpStatusCode.ExpectationFailed) { viewModel.BusinessStatus = -10003; viewModel.StatusMessage = "服务发生异常"; } else { viewModel.SourceList = response.ComList.ConverToViewModel(); viewModel.BusinessStatus = 1; } return(viewModel.ResponseToJson()); }
public HttpResponseMessage GetAgentSource([FromUri] AppBaseRequest request) { _logAppInfo.Info(string.Format("获取代理渠道列表接口请求串:{0}", Request.RequestUri)); var viewModel = new AppAgentSourceViewModel(); if (!ModelState.IsValid) { viewModel.BusinessStatus = -10000; string msg = ModelState.Values.Where(item => item.Errors.Count == 1).Aggregate(string.Empty, (current, item) => current + (item.Errors[0].ErrorMessage + "; ")); viewModel.StatusMessage = "输入参数错误," + msg; return(viewModel.ResponseToJson()); } viewModel = _appAchieveService.GetAgentSource(request, Request.GetQueryNameValuePairs(), Request.RequestUri); //_logAppInfo.Info(string.Format("获取代理渠道列表接口返回值:{0}", viewModel.ToJson())); return(viewModel.ResponseToJson()); }
/// <summary> /// 获取渠道的source集合 /// </summary> /// <param name="url"></param> /// <param name="agentId">顶级代理Id</param> /// <returns></returns> public List <AgentCity> GetSourceList(string url, int agentId) { var viewModel = new AppAgentSourceViewModel(); //获取城市列表 var agentCityKey = string.Format("ExternalApi_{0}_ConfigCity_Find", agentId); var listTempCity = CacheProvider.Get <List <bx_agent_config> >(agentCityKey); var listCity = new List <int>(); if (listTempCity == null) { listTempCity = _agentConfig.FindNewCity(agentId); CacheProvider.Set(agentCityKey, listTempCity, 10800); } if (listTempCity != null) { listCity = listTempCity.Select(i => i.city_id.Value).Distinct().ToList(); } //获取所有source列表 var agentSourceKey = string.Format("agent_source_key_{0}", agentId); var listSource = CacheProvider.Get <List <bx_agent_config> >(agentSourceKey); if (listSource == null) { listSource = _agentConfig.Find(agentId).ToList(); CacheProvider.Set(agentSourceKey, listSource, 10800); } var citylist = new List <AgentCity>(); var agentCity = new AgentCity(); var sourcelist = new List <Source>(); var agentSource = new Source(); var tempSourceList = new List <bx_agent_config>(); //根据城市获取source列表 if (!listCity.Any()) { return(citylist); } foreach (var c in listCity) { tempSourceList = new List <bx_agent_config>(); tempSourceList = listSource.Where(i => i.city_id == c && i.source.HasValue).OrderBy(o => o.source.Value).Distinct().ToList(); sourcelist = new List <Source>(); if (tempSourceList.Any()) { foreach (var s in tempSourceList) { agentSource = new Source(); agentSource.Id = s.source.Value; agentSource.Name = s.source.Value.ToEnumDescriptionString(typeof(EnumSource)); agentSource.NewId = SourceGroupAlgorithm.GetNewSource(s.source.Value); agentSource.ImageUrl = string.Format("{0}/Images/company/{1}.png", url, s.source.Value); sourcelist.Add(agentSource); } } agentCity = new AgentCity(); agentCity.AgentSource = sourcelist; agentCity.CityId = c; agentCity.CityName = _iCityRepository.FindCity(c).city_name; citylist.Add(agentCity); } return(citylist); }