//获取订单列表根据二当家客户端编码
        public JsonResult GetOrdersByYXClientCode(string yxClientCode,int pageSize, int pageIndex, string clientID = "")
        {
            int totalCount=0, pageCount = 0;
            var list = OrdersBusiness.BaseBusiness.GetOrdersByYXCode(yxClientCode, clientID,pageSize, pageIndex, ref totalCount, ref pageCount);
            var objs=new List<Dictionary<string, object>>();
            foreach (var item in list) {
                Dictionary<string, object> obj = new Dictionary<string, object>();
                obj.Add("orderID", item.OrderID);
                obj.Add("goodsName", item.GoodsName);
                obj.Add("intGoodsCode", item.IntGoodsCode);
                obj.Add("finalPrice", item.FinalPrice);
                obj.Add("orderImage", item.OrderImage);
                obj.Add("orderImages", item.OrderImages);
                obj.Add("createTime", item.CreateTime);
                obj.Add("endTime", item.EndTime);
                obj.Add("clientID", item.ClientID);

                objs.Add(obj);
            }
            JsonDictionary.Add("orders",objs);
            JsonDictionary.Add("totalCount", totalCount);
            JsonDictionary.Add("pageCount", pageCount);

            return new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
        /// <summary>
        /// 验证手机验证码
        /// </summary>
        /// <param name="mobilePhone"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public JsonResult ValidateMobilePhoneCode(string mobilePhone, string code)
        {
            bool bl = Common.Common.ValidateMobilePhoneCode(mobilePhone, code);
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            JsonDictionary.Add("Result", bl ? 1 : 0);

            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
Beispiel #3
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);
            if (filterContext.HttpContext.Response.StatusCode == 401)
            {
                Dictionary<String, object> jsonDictionary = new Dictionary<string, object>();
                jsonDictionary.Add("error_code",401);

                filterContext.RequestContext.HttpContext.Response.Write( JsonConvert.SerializeObject(jsonDictionary).ToString() );
                filterContext.RequestContext.HttpContext.Response.End();

            }
        }
        /// <summary>
        /// 发送手机验证码
        /// </summary>
        /// <param name="mobilePhone">手机号码</param>
        /// <returns></returns>
        public JsonResult SendMobileMessage(string mobilePhone)
        {
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            Random rd = new Random();
            int code = rd.Next(100000, 1000000);

            bool flag = Common.MessageSend.SendMessage(mobilePhone, code);
            JsonDictionary.Add("Result", flag ? 1 : 0);

            if (flag)
            {
                Common.Common.SetCodeSession(mobilePhone, code.ToString());

                Common.Common.WriteAlipayLog(mobilePhone + " : " + code.ToString());

            }

            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
        public JsonResult GetAuthorizeInfo()
        {

            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            double remainderDays = 0;
            int authorizeType = 0;

            if (Session["ClientManager"] != null)
            {
                var CurrentUser = (IntFactoryEntity.Users)Session["ClientManager"];
                var agent = AgentsBusiness.GetAgentDetail(CurrentUser.AgentID);
                //Math.Ceiling((agent.EndTime - DateTime.Now).TotalDays)
                remainderDays = Math.Ceiling((agent.EndTime - DateTime.Now).TotalDays);
                authorizeType = agent.AuthorizeType;

            }

            JsonDictionary.Add("remainderDays", remainderDays);
            JsonDictionary.Add("authorizeType", authorizeType);

            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

        }
        public JsonResult GetOrdersOrTasksDataList(int filterType, string filterTime, 
           int moduleType, int orderType,int taskType,string userID,
           int pageSize, int pageIndex, int preFinishStatus) 
        {
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            var currentUser = (IntFactoryEntity.Users)Session["ClientManager"];
            string userid = currentUser.UserID;
            if (moduleType == 1)
            {
                //所有订单
                if (currentUser.Menus.FindAll(m => m.MenuCode == "102010300").Count > 0)
                {
                    userid = string.Empty;
                }
            }
            else
            {
                //所有任务
                if (currentUser.Menus.FindAll(m => m.MenuCode == "109010200").Count > 0)
                {
                    userid = string.Empty;
                }
            }
            if (!string.IsNullOrEmpty(userID))
            {
                userid = userID;
            }

            string startTime = string.Empty;
            int orderStatus = 0;
            int finishStatus = 0;
            if (!string.IsNullOrEmpty(filterTime))
            {
                startTime = filterTime;
                orderStatus = -1;
                finishStatus = -1;
            }
            else 
            {
                if (filterType != -1)
                {
                    orderStatus = -1;
                    finishStatus = -1;
                }
            }

            int getTotalCount = 0;
            int pageCount = 0;
            if (moduleType == 1)
            {
                var list = IntFactoryBusiness.OrdersBusiness.BaseBusiness.GetOrdersByPlanTime(startTime, startTime,
                    orderType, filterType, orderStatus,
                    userid, currentUser.ClientID, pageSize, pageIndex, ref getTotalCount, ref pageCount);
                JsonDictionary.Add("items", list);
            }
            else
            {
                var list = IntFactoryBusiness.TaskBusiness.GetTasksByEndTime(startTime, startTime,
                    orderType, filterType, finishStatus, preFinishStatus, taskType,
                    userid, currentUser.ClientID, pageSize, pageIndex, ref getTotalCount, ref pageCount);
                JsonDictionary.Add("items", list);
            }
            JsonDictionary.Add("getNeedTotalCount", getTotalCount);
            JsonDictionary.Add("pageCount", pageCount);
            if (!string.IsNullOrEmpty(filterTime))
            {
                JsonDictionary.Add("showTime", filterTime.Replace(".", "-") + "/" + YXERP.Common.Common.Week("周", (int)Convert.ToDateTime(filterTime).DayOfWeek));
            }

            return new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
        //获取订单详情
        public JsonResult GetOrderDetailByID(string orderID,string clientID)
        {
            var item = OrdersBusiness.BaseBusiness.GetOrderBaseInfoByID(orderID, clientID, clientID);
            Dictionary<string, object> obj = new Dictionary<string, object>();
            obj.Add("orderID", item.OrderID);
            obj.Add("goodsName", item.GoodsName);
            obj.Add("intGoodsCode", item.IntGoodsCode);
            obj.Add("finalPrice", item.FinalPrice);
            obj.Add("orderImage", item.OrderImage);
            obj.Add("orderImages", item.OrderImages);
            obj.Add("categoryID", item.CategoryID);
            obj.Add("categoryName", item.CategoryName);
            obj.Add("platemaking", item.Platemaking);
            obj.Add("createTime", item.CreateTime);
            obj.Add("endTime", item.EndTime);
            obj.Add("clientID", item.ClientID);

            //材料列表
            var details = new List<Dictionary<string, object>>();
            foreach (var d in item.Details) {
                Dictionary<string, object> detail = new Dictionary<string, object>();
                detail.Add("detailsCode", d.DetailsCode);
                detail.Add("imgS", d.ImgS);
                detail.Add("price", d.Price);
                detail.Add("unitName", d.UnitName);
                detail.Add("productCode", d.ProductCode);
                detail.Add("productName", d.ProductName);
                detail.Add("productImage", d.ProductImage);

                details.Add(detail);
            }
            obj.Add("details", details);
            //制版工艺
            var plateMakings = TaskBusiness.GetPlateMakings(orderID);
            var plates = new List<Dictionary<string, object>>();
            foreach (var p in plateMakings) {
                Dictionary<string, object> plate = new Dictionary<string, object>();
                plate.Add("plateID", p.PlateID);
                plate.Add("icon", p.Icon);
                plate.Add("title", p.Title);
                plate.Add("remark", p.Remark);
                plate.Add("type", p.Type);

                plates.Add(plate);
            }
            obj.Add("plateMakings", plates);
            //订单品类
            var category = new ProductsBusiness().GetOrderCategoryDetailsByID(item.CategoryID, item.OrderID);
            var attrLists = new List<Dictionary<string, object>>();
            var saleAttrs = new List<Dictionary<string, object>>();
            foreach (var attr in category.AttrLists) {
                Dictionary<string, object> attrObj= new Dictionary<string, object>();
                attrObj.Add("attrID", attr.AttrID);
                attrObj.Add("attrName", attr.AttrName);
                var attrValues = new List<Dictionary<string, object>>();
                foreach (var value in attr.AttrValues) {
                    Dictionary<string, object> valueObj = new Dictionary<string, object>();
                    valueObj.Add("valueID", value.ValueID);
                    valueObj.Add("valueName", value.ValueName);

                    attrValues.Add(valueObj);
                }
                attrObj.Add("attrValues", attrValues);
                attrLists.Add(attrObj);
            }
            foreach (var attr in category.SaleAttrs)
            {
                Dictionary<string, object> attrObj = new Dictionary<string, object>();
                attrObj.Add("attrID", attr.AttrID);
                attrObj.Add("attrName", attr.AttrName);
                var attrValues = new List<Dictionary<string, object>>();
                foreach (var value in attr.AttrValues)
                {
                    Dictionary<string, object> valueObj = new Dictionary<string, object>();
                    valueObj.Add("valueID", value.ValueID);
                    valueObj.Add("valueName", value.ValueName);

                    attrValues.Add(valueObj);
                }
                attrObj.Add("attrValues", attrValues);
                saleAttrs.Add(attrObj);
            }
            obj.Add("attrLists", attrLists);
            obj.Add("saleAttrs", saleAttrs);
            JsonDictionary.Add("order",obj);

            return new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
        /// <summary>
        /// 根据人数、年数获取最佳产品组合
        /// </summary>
        public JsonResult GetBestWay(int quantity, int years, int type)
        {
            int remainderMonths = 12;//剩余月份
            float discount = 1F;
            int pageCount = 0;
            int totalCount = 0;

            //购买人数
            if (type == 2)
            {
                remainderMonths = (CurrentAgent.EndTime.Year - DateTime.Now.Year) * 12 + (CurrentAgent.EndTime.Month - DateTime.Now.Month) - 1;
                if (CurrentAgent.EndTime.Day >= DateTime.Now.Day)
                    remainderMonths += 1;

                years = remainderMonths / 12 == 0 ? 1 : remainderMonths / 12;
                JsonDictionary.Add("PeriodQuantity", years);
            }

            List<ModulesProduct> list = ModulesProductBusiness.GetModulesProducts(string.Empty, int.MaxValue, 1, ref totalCount, ref pageCount);
            var way = ModulesProductBusiness.GetBestWay(quantity, list.OrderByDescending(m => m.UserQuantity).Where(m => m.PeriodQuantity == years).ToList());

            List<Dictionary<string, string>> products = new List<Dictionary<string, string>>();
            foreach (var p in way.Products)
            {
                Dictionary<string, string> product = new Dictionary<string, string>();
                product.Add("id", p.Key);
                product.Add("count", p.Value.ToString());
                products.Add(product);
            }

            JsonDictionary.Add("Items", products);
            JsonDictionary.Add("TotalMoney", way.TotalMoney);
            JsonDictionary.Add("TotalQuantity", way.TotalQuantity);


            //购买人数
            if (type == 2)
            {
                float remainderYears = (float)remainderMonths / (12 * years);
                JsonDictionary.Add("Amount", (float.Parse(way.TotalMoney.ToString()) * remainderYears).ToString("f2"));
            }

            if (!string.IsNullOrEmpty(CurrentUser.MDUserID))
            {
                if (type == 1 || type == 2)
                {
                    discount = 0.5F;
                }
                else
                {
                    discount = 0.88F;
                }

            }
            else
            {
                if (type == 1 || type == 2)
                {
                    discount = 0.5F;
                }
            }
            JsonDictionary.Add("Discount", discount);

            return new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);
            if (filterContext.HttpContext.Response.StatusCode == 401)
            {
                string source = HttpContext.Current.Request.QueryString["source"];
                if (!string.IsNullOrEmpty(source) && source == "md")
                {
                    filterContext.Result = new RedirectResult("/Home/MDLogin?ReturnUrl=" + HttpContext.Current.Request.Url);
                }
                else
                {
                    filterContext.Result = new RedirectResult("/Home/Login?ReturnUrl=" + HttpContext.Current.Request.Url);
                }
                return;
            }

            var controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower();
            var action = filterContext.ActionDescriptor.ActionName.ToLower();

            var currentUser = (IntFactoryEntity.Users)filterContext.HttpContext.Session["ClientManager"];

            if (currentUser.Client.GuideStep != 0)
            {
                if (controller != "default")
                {
                    filterContext.Result = new RedirectResult("/Default/Index");
                }
                return;
            }

            var agent = AgentsBusiness.GetAgentDetail(currentUser.AgentID);
            if (agent.EndTime < DateTime.Now)
            {
                if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
                {
                    Dictionary<string, string> result = new Dictionary<string, string>();
                    result.Add("result", "10001");
                    filterContext.Result = new JsonResult()
                    {
                        Data = result,
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                }
                else
                {
                    filterContext.Result = new RedirectResult("/Home/UseExpired");
                }

                return;
            }

            
            var menu = CommonBusiness.ClientMenus.Where(m => m.Controller.ToLower() == controller && m.View.ToLower() == action).FirstOrDefault();

            //需要判断权限
            if (menu != null && menu.IsLimit == 1)
            {
                if (currentUser.Menus.Where(m => m.MenuCode == menu.MenuCode).Count() <= 0)
                {
                    if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
                    {
                        Dictionary<string, string> result = new Dictionary<string, string>();
                        result.Add("result", "10001");
                        filterContext.Result = new JsonResult()
                        {
                            Data = result,
                            JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        };
                    }
                    else
                    {
                        var urlRequest = filterContext.RequestContext.HttpContext.Request;
                        throw new HttpException(403, urlRequest.UrlReferrer != null ? urlRequest.UrlReferrer.AbsoluteUri : urlRequest.Url.AbsoluteUri);
                    }
                }
            }

        }
        public JsonResult CreateOrder(string entity)
        {
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            IntFactoryEntity.OrderEntity model = serializer.Deserialize<IntFactoryEntity.OrderEntity>(entity);

            string orderid = OrdersBusiness.BaseBusiness.CreateOrder(model.CustomerID, model.GoodsCode, model.Title, model.PersonName, model.MobileTele, EnumOrderSourceType.SelfOrder,
                                                                    (EnumOrderType)model.OrderType, model.BigCategoryID, model.CategoryID, model.PlanPrice, model.PlanQuantity, model.PlanTime,
                                                                     model.OrderImage, model.CityCode, model.Address, model.ExpressCode, model.Remark, "", model.AgentID, model.ClientID);
            JsonDictionary.Add("id", orderid);
            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
        public JsonResult GetOrdersOrTasksReportData(int orderType, int filterTimeType, int moduleType, int taskType,string userID)
        {
            Dictionary<string, Object> resultObj = new Dictionary<string, object>();
            int result = 0;

            if (Session["ClientManager"] != null)
            {
                var currentUser = (IntFactoryEntity.Users)Session["ClientManager"];
                var nowDate=DateTime.Now;
                string beginTime = "";
                string endTime = "";
                if (filterTimeType == 0)
                {
                    beginTime = nowDate.Date.AddDays(-15).ToString();
                    endTime = nowDate.Date.AddDays(-1).ToString();
                    nowDate = nowDate.Date.AddDays(-15);
                }
                else if (filterTimeType == 1)
                {
                    beginTime = nowDate.Date.ToString();
                    endTime = nowDate.Date.AddDays(14).ToString();
                }
                else if (filterTimeType == 2)
                {
                    beginTime = nowDate.Date.AddDays(15).ToString();
                    endTime = nowDate.Date.AddDays(29).ToString();
                    nowDate = nowDate.Date.AddDays(15);
                }


                int getTotalCount=0;
                int pageCount = 0;
                string userid= currentUser.UserID;
                if (moduleType == 1)
                {
                    //所有订单
                    if (currentUser.Menus.FindAll(m => m.MenuCode == "102010300").Count > 0)
                    {
                        userid = string.Empty;
                    }
                }
                else
                {
                    //所有任务
                    if (currentUser.Menus.FindAll(m => m.MenuCode == "109010200").Count > 0)
                    {
                        userid = string.Empty;
                    }
                }
                if (!string.IsNullOrEmpty(userID)) {
                    userid = userID;
                }

                List<OrderEntity> orderItems=new List<OrderEntity>();
                List<IntFactoryEntity.Task.TaskEntity> taskItems = new List<IntFactoryEntity.Task.TaskEntity>();

                if (moduleType == 1)
                {
                    orderItems = IntFactoryBusiness.OrdersBusiness.BaseBusiness.GetOrdersByPlanTime(beginTime, endTime,
                                        orderType, -1, -1,
                                        userid, currentUser.ClientID, int.MaxValue, 1, ref getTotalCount, ref pageCount);
                }
                else 
                {
                    taskItems = IntFactoryBusiness.TaskBusiness.GetTasksByEndTime(beginTime, endTime,
                    orderType, -1, -1, -1, taskType,
                    userid, currentUser.ClientID, int.MaxValue, 1, ref getTotalCount, ref pageCount);
                }

                var totalExceedCount = 0;
                var totalWarnCount = 0;
                var totalWorkCount = 0;
                var totalFinishCount = 0;
                var totalSumCount = 0;
                var reportArr =new  List<Dictionary<string, Object>>();
                for (var i = 0; i < 15; i++) 
                {
                    var report = new Dictionary<string, Object>();
                    var nextDate = nowDate.AddDays(i);
                    
                    var exceedCount = 0;
                    var warnCount = 0;
                    var workCount = 0;
                    var finishCount = 0;
                    var totalCount = 0;

                    //订单操作
                    if (moduleType == 1)
                    {
                        var orderList = orderItems.FindAll(m => m.PlanTime.Date == nextDate.Date);
                        exceedCount = orderList.FindAll(m => m.PlanTime < DateTime.Now && m.OrderStatus == 1).Count;
                        for (var j = 0; j < orderList.Count; j++)
                        {
                            var order = orderList[j];
                            if (order.PlanTime > DateTime.Now && order.OrderStatus == 1)
                            {
                                if ((order.PlanTime - DateTime.Now).TotalHours * 3 < (order.PlanTime - order.OrderTime).TotalHours)
                                {
                                    warnCount++;
                                }
                                else
                                {
                                    workCount++;
                                }
                            }
                        }
                        finishCount = orderList.FindAll(m => m.OrderStatus == 2).Count;
                    }
                    //任务操作
                    else
                    {
                        var taskList = taskItems.FindAll(m => m.EndTime.Date == nextDate.Date);
                        exceedCount = taskList.FindAll(m => m.EndTime < DateTime.Now && m.FinishStatus == 1).Count;
                        for (var j = 0; j < taskList.Count; j++)
                        {
                            var task = taskList[j];
                            if (task.EndTime > DateTime.Now && task.FinishStatus == 1)
                            {
                                if ((task.EndTime - DateTime.Now).TotalHours * 3 < (task.EndTime - task.AcceptTime).TotalHours)
                                {
                                    warnCount++;
                                }
                                else
                                {
                                    workCount++;
                                }
                            }
                        }
                        finishCount = taskList.FindAll(m => m.FinishStatus == 2).Count;
                    }
                    report.Add("dateTime", nextDate.Date.ToString("yyyy.MM.dd"));
                    report.Add("date", nextDate.Date.ToString("MM.dd"));
                    report.Add("warnCount", warnCount);
                    report.Add("finishCount", finishCount);
                    report.Add("workCount", workCount);
                    report.Add("exceedCount", exceedCount);
                    totalCount=warnCount + finishCount + workCount + exceedCount;
                    report.Add("totalCount", totalCount);

                    totalExceedCount += exceedCount;
                    totalFinishCount += finishCount;
                    totalWarnCount += warnCount;
                    totalWorkCount += workCount;
                    totalSumCount += totalCount;
                    reportArr.Add(report);
                }

                result = 1;
                resultObj.Add("items", reportArr);
                resultObj.Add("totalExceedCount", totalExceedCount);
                resultObj.Add("totalFinishCount", totalFinishCount);
                resultObj.Add("totalWarnCount", totalWarnCount);
                resultObj.Add("totalWorkCount", totalWorkCount);
                resultObj.Add("totalSumCount", totalSumCount);
            }
            resultObj.Add("result", result);

            return new JsonResult()
            {
                Data=resultObj,
                JsonRequestBehavior=JsonRequestBehavior.AllowGet
            };
        }
        public JsonResult GetTaskOrOrderEcceedCount(int moduleType, int orderType, string userID)
        {
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            var currentUser = (IntFactoryEntity.Users)Session["ClientManager"];
            var total = 0;
            string userid = currentUser.UserID;
            if (moduleType == 1)
            {
                //所有订单
                if (currentUser.Menus.FindAll(m => m.MenuCode == "102010300").Count > 0)
                {
                    userid = string.Empty;
                }
            }
            else
            {
                //所有任务
                if (currentUser.Menus.FindAll(m => m.MenuCode == "109010200").Count > 0)
                {
                    userid = string.Empty;
                }
            }
            if (!string.IsNullOrEmpty(userID))
            {
                userid = userID;
            }

            if (moduleType == 1)
            {
                total = IntFactoryBusiness.OrdersBusiness.BaseBusiness.GetexceedOrderCount(userid, orderType, currentUser.ClientID);   
            }
            else
            {
                total = IntFactoryBusiness.TaskBusiness.GetexceedTaskCount(userid, orderType, currentUser.ClientID);
            }
            JsonDictionary.Add("result", total);

            return new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
 public JsonResult GetChildOrderCategorysByID(string categoryid, string clientid)
 {
     Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
     var list = new ProductsBusiness().GetClientCategorysByPID(categoryid, EnumCategoryType.Order, clientid);
     JsonDictionary.Add("Items", list);
     return new JsonResult
     {
         Data = JsonDictionary,
         JsonRequestBehavior = JsonRequestBehavior.AllowGet
     };
 }
        /// <summary>
        /// 重置用户密码
        /// </summary>
        /// <param name="loginName"></param>
        /// <param name="loginPwd"></param>
        /// <returns></returns>
        public JsonResult UpdateUserPwd(string loginName, string loginPwd, string code)
        {
            int result = 0;
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();

            bool bl = OrganizationBusiness.IsExistLoginName(loginName);
            if (bl)
            {
                bl = Common.Common.ValidateMobilePhoneCode(loginName, code);
                if (!bl)
                {
                    result = 3;
                }
                else
                {
                    bl = OrganizationBusiness.UpdateUserAccountPwd(loginName, loginPwd);
                    result = bl ? 1 : 0;

                    if (bl)
                    {
                        Common.Common.CachePwdErrorUsers.Remove(loginName);
                        Common.Common.ClearMobilePhoneCode(loginName);
                    }
                }
                
            }
            else
            {
                result = 2;
            }

            JsonDictionary.Add("Result",result);
            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
        /// <summary>
        /// 主动注册客户端
        /// </summary>
        /// <param name="name"></param>
        /// <param name="companyName"></param>
        /// <param name="loginName"></param>
        /// <param name="loginPWD"></param>
        /// <returns></returns>
        public JsonResult RegisterClient(string name, string companyName, string loginName, string loginPWD,string code)
        {
            int result = 0;
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();

            bool bl = OrganizationBusiness.IsExistLoginName(loginName);
            if (bl){
                result = 2;
            }
            else
            {
                bl = Common.Common.ValidateMobilePhoneCode(loginName, code);
                if (!bl){
                    result = 3;
                }
                else
                {
                    Clients client = new Clients() { CompanyName = companyName, ContactName = name, MobilePhone = loginName };
                    ClientBusiness.InsertClient(client, "", loginName, loginPWD, string.Empty, out result);

                    if (result == 1)
                    {
                        string operateip = Common.Common.GetRequestIP();
                        int outResult;
                        IntFactoryEntity.Users user = IntFactoryBusiness.OrganizationBusiness.GetUserByUserName(loginName, loginPWD, out outResult, operateip);
                        if (user != null){
                            Session["ClientManager"] = user;
                        }

                        Common.Common.ClearMobilePhoneCode(loginName);
                    }
                    else
                        result = 0;
                }
            }

            JsonDictionary.Add("Result", result);
            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
        /// <summary>
        /// 账号是否存在
        /// </summary>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public JsonResult IsExistLoginName(string loginName)
        {
            bool bl = OrganizationBusiness.IsExistLoginName(loginName);
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            JsonDictionary.Add("Result", bl?1:0);

            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
        //登录
        public JsonResult UserLogin(string userName, string pwd, string remember, int bindAccountType)
        {
            int result = 0;
            Dictionary<string, object> resultObj = new Dictionary<string, object>();
            YXERP.Common.PwdErrorUserEntity pwdErrorUser = null;

            if (Common.Common.CachePwdErrorUsers.ContainsKey(userName)) pwdErrorUser = Common.Common.CachePwdErrorUsers[userName];

            if (pwdErrorUser == null || (pwdErrorUser.ErrorCount < 10 && pwdErrorUser.ForbidTime<DateTime.Now) )
            {
                string operateip = Common.Common.GetRequestIP();
                int outResult;
                IntFactoryEntity.Users model = IntFactoryBusiness.OrganizationBusiness.GetUserByUserName(userName, pwd, out outResult, operateip);
                if (model != null)
                {
                    if (model.Status.Value ==1)
                    {
                        //保持登录状态
                        HttpCookie cook = new HttpCookie("cloudsales");
                        cook["username"] = userName;
                        cook["pwd"] = pwd;
                        cook["status"] = remember;
                        cook.Expires = DateTime.Now.AddDays(7);
                        Response.Cookies.Add(cook);

                        //将阿里账户绑定到已有账户
                        if (bindAccountType == 1) {
                            result=BindAliMember(model);
                        }
                        //将微信账户绑定到已有账户
                        else if (bindAccountType == 2) {
                            result = BindWeiXin(model);
                        }
                        else
                        {
                            Session["ClientManager"] = model;
                            result = 1;
                        }

                        Common.Common.CachePwdErrorUsers.Remove(userName);
                    }
                    else
                    {
                        if (model.Status.Value == 9){
                            result = 9;
                        }
                    }
                }
                else
                {
                    //密码错误
                    if (outResult==3)
                    {
                        if (pwdErrorUser == null){
                            pwdErrorUser = new Common.PwdErrorUserEntity();
                        }
                        else
                        {
                            if (pwdErrorUser.ErrorCount > 9)
                            {
                                pwdErrorUser.ErrorCount = 0;
                            }
                        }

                        pwdErrorUser.ErrorCount++;
                        if (pwdErrorUser.ErrorCount > 9)
                        {
                            pwdErrorUser.ForbidTime = DateTime.Now.AddHours(2);
                            result = 2;
                        }
                        else
                        {
                            resultObj.Add("errorCount", pwdErrorUser.ErrorCount);
                            result = 3;
                        }

                        Common.Common.CachePwdErrorUsers[userName] = pwdErrorUser;
                    }
                }
            }
            else
            {
                int forbidTime =(int)(pwdErrorUser.ForbidTime - DateTime.Now).TotalMinutes;
                resultObj.Add("forbidTime", forbidTime);
                result = -1;
            }
            resultObj.Add("result",result);

            return new JsonResult
            {
                Data = resultObj,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
        public JsonResult GetAgentActionData()
        {
            int customercount = 0, ordercount = 0;
            decimal totalmoney = 0;
            IntFactoryEntity.Users CurrentUser = (IntFactoryEntity.Users)Session["ClientManager"];
            var model = LogBusiness.BaseBusiness.GetClientActions(CurrentUser.ClientID, ref customercount, ref ordercount, ref totalmoney);

            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            JsonDictionary.Add("model", model);

            int myNeedOrders = 0;
            int cooperationNeedOrders = 0;
            int delegateNeedOrders = 0;

            int myFentOrder = 0;
            int doMyFentOrder = 0;
            int cooperationFentOrders = 0;
            int doCooperationFentOrders = 0;
            int delegateFentOrders = 0;
            int doDelegateFentOrders = 0;

            int myBulkOrder = 0;
            int doMyBulkOrder = 0;
            int cooperationBulkOrders = 0;
            int doCooperationBulkOrders = 0;
            int delegateBulkOrders = 0;
            int doDelegateBulkOrders = 0;
            foreach (var action in model.Actions) {
                if (action.OrderType == 1)
                {
                    if (action.Status == 0)
                    {
                        if (action.ObjectType == 6)
                        {
                            myNeedOrders += action.OrderCount;
                        }
                        else if (action.ObjectType == 5)
                        {
                            cooperationNeedOrders += action.OrderCount;
                        }
                        else if (action.ObjectType == 4)
                        {
                            delegateNeedOrders += action.OrderCount;
                        }
                    }
                    else
                    {

                        if (action.ObjectType == 6)
                        {
                            myFentOrder += action.OrderCount;
                            if (action.Status == 2)
                            {
                                doMyFentOrder += action.OrderCount;
                            }
                        }
                        else if (action.ObjectType == 5)
                        {
                            cooperationFentOrders += action.OrderCount;
                            if (action.Status == 2)
                            doCooperationFentOrders += action.OrderCount;
                        }
                        else if (action.ObjectType == 4)
                        {
                            delegateFentOrders += action.OrderCount;
                            if (action.Status == 2)
                            doDelegateFentOrders += action.OrderCount;
                        }

                    }
                }
                else
                {
                    if (action.Status == 0)
                    {
                        if (action.ObjectType == 6)
                        {
                            myNeedOrders += action.OrderCount;
                        }
                        else if (action.ObjectType == 5)
                        {
                            cooperationNeedOrders += action.OrderCount;
                        }
                        else if (action.ObjectType == 4)
                        {
                            delegateNeedOrders += action.OrderCount;
                        }
                    }
                    else
                    {
                        if (action.ObjectType == 6)
                        {
                            myBulkOrder += action.OrderCount;
                            if (action.Status == 2)
                            {
                                doMyBulkOrder += action.OrderCount;
                            }
                        }
                        else if (action.ObjectType == 5)
                        {
                            cooperationBulkOrders += action.OrderCount;
                            if (action.Status == 2)
                                doCooperationBulkOrders += action.OrderCount;
                        }
                        else if (action.ObjectType == 4)
                        {
                            delegateBulkOrders += action.OrderCount;
                            if (action.Status == 2)
                                doDelegateBulkOrders += action.OrderCount;
                        }
                    }
                }
            }

            JsonDictionary.Add("customercount", model.CustomerCount);
            JsonDictionary.Add("ordercount", model.OrderCount);
            JsonDictionary.Add("totalmoney", model.TotalMoney.ToString("C"));
            JsonDictionary.Add("myOrders", myNeedOrders);
            JsonDictionary.Add("cooperationOrders", cooperationNeedOrders);
            JsonDictionary.Add("delegateOrders", delegateNeedOrders);

            JsonDictionary.Add("myFentOrder", myFentOrder);
            JsonDictionary.Add("doMyFentOrder",doMyFentOrder);
            JsonDictionary.Add("cooperationFentOrders", cooperationFentOrders);
            JsonDictionary.Add("doCooperationFentOrders",doCooperationFentOrders);
            JsonDictionary.Add("delegateFentOrders", delegateFentOrders);
            JsonDictionary.Add("doDelegateFentOrders",doDelegateFentOrders);

            JsonDictionary.Add("myBulkOrder", myBulkOrder);
            JsonDictionary.Add("doMyBulkOrder",doMyBulkOrder);
            JsonDictionary.Add("cooperationBulkOrders", cooperationBulkOrders);
            JsonDictionary.Add("doCooperationBulkOrders",doCooperationBulkOrders);
            JsonDictionary.Add("delegateBulkOrders", delegateBulkOrders);
            JsonDictionary.Add("doDelegateBulkOrders",doDelegateBulkOrders);

            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }