public static AgentIdentityAndRateViewModel ConvertToViewModel(this GetAgentIdentityAndRateResponse response)
        {
            var model = new AgentIdentityAndRateViewModel();

            //model.Item = new AgentIdentityAndRateViewModel.AgentIdentityAndRate
            //{
            //    BizRate = response.BizRate,
            //    ForceRate = response.ForceRate,
            //    IsAgent = response.IsAgent,
            //    TaxRate = response.TaxRate
            //};
            model.Item         = new AgentIdentityAndRateViewModel.AgentIdentityAndRate();
            model.Item.IsAgent = response.IsAgent;
            if (response.IsAgent == 1)
            {
                if (response.AgentRate != null)
                {
                    model.Item.AgentRate = new AgentIdentityAndRateViewModel.Rate
                    {
                        BizRate   = response.AgentRate.BizRate,
                        ForceRate = response.AgentRate.ForceRate,
                        TaxRate   = response.AgentRate.TaxRate
                    };
                }
                else
                {
                    model.Item.AgentRate = new AgentIdentityAndRateViewModel.Rate();
                }

                model.Item.ZhiKeRate = new List <AgentIdentityAndRateViewModel.Rate>();
            }
            else
            {
                model.Item.AgentRate = new AgentIdentityAndRateViewModel.Rate();
                model.Item.ZhiKeRate = new List <AgentIdentityAndRateViewModel.Rate>();
                if (response.ZhiKeRate != null)
                {
                    for (int i = 0; i < response.ZhiKeRate.Count; i++)
                    {
                        model.Item.ZhiKeRate.Add(new AgentIdentityAndRateViewModel.Rate
                        {
                            BizRate = response.ZhiKeRate[i].BizRate,
                            Source  = response.ZhiKeRate[i].Source
                        });
                    }
                }
                else
                {
                    model.Item.ZhiKeRate = new List <AgentIdentityAndRateViewModel.Rate>();
                }
            }
            return(model);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="pairs"></param>
        /// <returns></returns>
        public GetAgentIdentityAndRateResponse GetAgent(GetAgentIdentityAndRateRequest request, IEnumerable <KeyValuePair <string, string> > pairs)
        {
            var response = new GetAgentIdentityAndRateResponse();

            try
            {
                //根据经纪人获取手机号
                bx_agent agentModel = GetAgent(request.Agent);
                //logInfo.Info("获取到的经纪人信息:"+agentModel.ToJson());
                //参数校验
                if (agentModel == null)
                {
                    response.Status = HttpStatusCode.Forbidden;
                    return(response);
                }

                if (!ValidateReqest(pairs, agentModel.SecretKey, request.SecCode))
                {
                    response.Status = HttpStatusCode.Forbidden;
                    return(response);
                }
                //当前经济人
                //var curAgent = _agentRepository.GetAgent(request.OpenId);
                var curAgent = request.ChildAgent;
                //_agentRepository.GetAgentByTopParentAgent(request.OpenId, request.ParentAgent);

                #region
                //直客身份
                if (curAgent == 0)
                {
                    response.IsAgent = 0;
                }
                else
                {
                    response.IsAgent = 1;


                    //var allids = _agentRepository.GetSonId(request.ParentAgent);
                    //var allsons = allids.Split(',');
                    var allsons = _agentRepository.GetSonsList(request.ParentAgent, true);

                    //modify.by.gpj.0419.判断操作重复
                    //当前试算人即是经纪人自己
                    //if (curAgent.Id == request.Agent)
                    //{
                    //看看是否是在这个顶级经纪人的归属下,才能按照经纪人身份展示,否则就按照直客处理

                    var isExist = allsons.Count(x => x == curAgent.ToString()) > 0;
                    if (isExist)
                    {
                        response.IsAgent = 1;
                    }
                    else
                    {
                        response.IsAgent = 0;
                    }

                    //}
                    //else
                    //{
                    //    //Request.Agent有可能是试算人的上级代理,是就按照经纪人身份处理,否则 按照直客处理
                    //    var isExist = allsons.Count(x => x == curAgent.Id.ToString()) > 0;
                    //    if (isExist)
                    //    {
                    //        response.IsAgent = 1;
                    //    }
                    //    else
                    //    {
                    //        response.IsAgent = 0;
                    //    }
                    //}
                }

                //后加逻辑
                //if (request.ParentAgent == request.Agent)
                //{
                //    response.IsAgent = 0;
                //}

                if (response.IsAgent == 0)
                {
                    using (var client = new HttpClient())
                    {
                        try
                        {
                            string method = string.Format("{0}/api/EnterpriseAgent/WechatZhiKeRate?agentid={1}&buid={2}", _rateCenter, request.Agent, request.Buid);
                            //string method = string.Format("{0}/api/EnterpriseAgent/WechatZhiKeRate?agentid={1}&buid={2}",_rateCenter, 102, 109154);
                            // logError.Info("获取费率请求串:" + method);
                            HttpResponseMessage responserate = client.GetAsync(method).Result;
                            var rrrate = responserate.Content.ReadAsStringAsync().Result;
                            //var resultrate = JsonConvert.DeserializeObject<ReturnRate>(rrrate);
                            var resultrate = rrrate.FromJson <List <ReturnRate> >();
                            if (resultrate != null)
                            {
                                response.ZhiKeRate = new List <Rate>();
                                for (var i = 0; i < resultrate.Count; i++)
                                {
                                    Rate rate = new Rate
                                    {
                                        //20160908兼容新旧source将0123->1248
                                        //Source = resultrate[i].Source,
                                        Source  = SourceGroupAlgorithm.GetNewSource((int)resultrate[i].Source),
                                        BizRate = resultrate[i].zhike_biz_rate
                                    };
                                    response.ZhiKeRate.Add(rate);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            logError.Info("获取费率发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException);
                        }
                    }
                }
                else
                {
                    //20160908兼容新旧source将1248->0123
                    var hebaoitem = _hebaoDianwei.Find(request.Buid, SourceGroupAlgorithm.GetOldSource(request.Source));
                    if (hebaoitem != null)
                    {
                        Rate rate = new Rate
                        {
                            BizRate   = hebaoitem.agent_biz_rate.HasValue ? hebaoitem.agent_biz_rate.Value : 0,
                            ForceRate = hebaoitem.agent_force_rate.HasValue ? hebaoitem.agent_force_rate.Value : 0,
                            TaxRate   = 0
                        };
                        response.AgentRate = rate;
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                logError.Info("发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException);
            }
            return(response);
        }