Пример #1
0
        /// <summary>
        /// 添加代理人信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="pairs"></param>
        /// <returns></returns>
        public GetAgentResponse AddAgent(PostAddAgentRequest request, IEnumerable <KeyValuePair <string, string> > pairs)
        {
            var      response = new GetAgentResponse();
            bx_agent agent    = new bx_agent();

            //备注:临时屏蔽,暂时先不上
            agent = _agentRepository.GetAgentIsTop(request.TopParentAgent);
            if (agent == null)
            {
                response.ErrCode = -4;//顶级代理人不存在
                return(response);
            }
            if (!_agentRepository.IsContainSon(request.TopParentAgent, request.AgentId))
            {
                response.ErrCode = -5;//顶级代理下面不包含子集代理
                return(response);
            }
            agent = new bx_agent();
            agent = _agentRepository.GetAgentByPhoneTopAgent(request.Mobile, request.TopParentAgent);
            if (agent != null)
            {
                response.ErrCode = -1;//手机号已存在
                return(response);
            }
            agent = new bx_agent();
            agent = _agentRepository.GetAgentByTopParentAgent(request.OpenId, request.TopParentAgent);
            if (agent != null)
            {
                response.ErrCode = -2;//OpenId已存在
                response.agent   = ToModel(agent, request.TopParentAgent);
                return(response);
            }
            int agentlevel = _agentRepository.GetAgentLevel(GetAgent(request.AgentId).ParentAgent);

            if (agentlevel > 2)
            {
                response.ErrCode = -3;//不允许新增下一级代理
                return(response);
            }
            //插入bx_agent
            bx_agent model = new bx_agent();

            model.AgentName   = request.AgentName;
            model.Mobile      = request.Mobile;
            model.OpenId      = request.OpenId;
            model.ParentAgent = request.AgentId;//有问题
            #region 分配默认值
            model.CreateTime     = DateTime.Now;
            model.IsBigAgent     = 1;
            model.CommissionType = 0;
            model.IsUsed         = 0;
            model.IsGenJin       = 0;
            model.IsDaiLi        = 0;
            model.IsShow         = 0;
            model.IsShowCalc     = 0;
            model.IsLiPei        = 0;
            model.AgentType      = 0;
            model.MessagePayType = 1; //发短信走当前代理人
            model.RegType        = 0; //小龙说默认走单店 暂无实际需要
            model.IsQuote        = 1;
            model.IsSubmit       = 1;
            #endregion
            long agentId = _agentRepository.Add(model);

            if (agentId > 0)
            {
                //根据agentId更新ShareCode
                int update = 0;
                update = _agentRepository.Update(agentId);
                if (update > 0)
                {
                    //存入缓存,并读取该记录
                    //string agentCacheKey = string.Format("agent_cacke_key-{0}-{1}", agentId, request.AgentId
                    //    );
                    var agentCache = _agentRepository.GetAgent((int)agentId);
                    //HttpRuntime.Cache.Insert(agentCacheKey, agentCache, null, DateTime.Now.AddHours(12), TimeSpan.Zero, CacheItemPriority.High, null);
                    response.agent = ToModel(agentCache, request.TopParentAgent);
                }
            }
            return(response);
        }
Пример #2
0
        public HttpResponseMessage AddAgent([FromBody] PostAddAgentRequest request)
        {
            _logInfo.Info(string.Format("微信添加代理人接口请求串:{0},参数:{1}", Request.RequestUri, request.ToJson()));
            var viewModel = new AgentViewModel();

            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.AddAgent(request, Request.GetQueryNameValuePairs());

            _logInfo.Info(string.Format("添加代理人接口返回值:{0}", response.ToJson()));
            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  = "服务发生异常";
                return(viewModel.ResponseToJson());
            }
            if (response.ErrCode == -1)
            {
                viewModel.BusinessStatus = -1;
                viewModel.StatusMessage  = "手机号已存在,请重新输入";
                return(viewModel.ResponseToJson());
            }
            else
            if (response.ErrCode == -2)
            {
                viewModel.Agent          = response.agent.ConverToViewModel();
                viewModel.BusinessStatus = -2;
                viewModel.StatusMessage  = "OpenId已存在,请重新输入";
                return(viewModel.ResponseToJson());
            }
            else if (response.ErrCode == -3)
            {
                viewModel.BusinessStatus = -3;
                viewModel.StatusMessage  = "当前用户是三级代理,不允许新增下一级代理";
                return(viewModel.ResponseToJson());
            }
            else if (response.ErrCode == -4)
            {
                viewModel.BusinessStatus = -4;
                viewModel.StatusMessage  = "顶级代理参数错误,无法创建下级代理";
                return(viewModel.ResponseToJson());
            }
            else if (response.ErrCode == -5)
            {
                viewModel.BusinessStatus = -5;
                viewModel.StatusMessage  = "顶级代理参数错误,顶级代理下无此子集代理";
                return(viewModel.ResponseToJson());
            }
            else
            {
                viewModel.Agent          = response.agent.ConverToViewModel();
                viewModel.BusinessStatus = 1;
            }
            return(viewModel.ResponseToJson());
        }