public JsonResult GetUserAllRole(int UserID)
        {
            IRelationUserRoleService relationUserRoleService = ServiceFactory.Create <IRelationUserRoleService>();
            List <int> roleIDs = relationUserRoleService.GetEntities(t => t.UserID == UserID).Select(t => t.RoleID).ToList();

            return(Json(roleIDs, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 设置用户角色
        /// </summary>
        /// <param name="UserIDs"></param>
        /// <param name="RoleIDs"></param>
        /// <returns></returns>
        public JsonResult SetUserRole(string UserIDs, string RoleIDs)
        {
            if (string.IsNullOrWhiteSpace(UserIDs) || string.IsNullOrWhiteSpace(RoleIDs))
            {
                return(Json(new Result(false, "参数错误"), JsonRequestBehavior.AllowGet));
            }

            List <int> userIDArr = UserIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();
            List <int> roleIDArr = RoleIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();

            if (!CurrentInfo.IsAdministrator && userIDArr.Contains(1330))
            {
                return(Json(new Result(false, "拒绝修改"), JsonRequestBehavior.AllowGet));
            }

            IRelationUserRoleService relationUserRoleService = ServiceFactory.Create <IRelationUserRoleService>();
            List <RelationUserRole>  listRelationUserRole    = new List <RelationUserRole>();
            int addCount = 0;

            using (TransactionScope scope = TransactionScopeHelper.GetTran())
            {
                foreach (var userID in userIDArr)
                {
                    //删除当前人员的所有的权限,然后在添加新的权限
                    var userRoles = relationUserRoleService.GetEntities(t => t.UserID == userID);
                    relationUserRoleService.DeleteEntities(userRoles.ToList());
                    foreach (var roleID in roleIDArr)
                    {
                        RelationUserRole model = new RelationUserRole();
                        model.UserID       = userID;
                        model.RoleID       = roleID;
                        model.CreateUserID = CurrentInfo.CurrentUser.ID;
                        model.CreateTime   = DateTime.Now;
                        listRelationUserRole.Add(model);
                    }
                }
                addCount = relationUserRoleService.AddEntities(listRelationUserRole).Count();
                scope.Complete();
            }

            return(Json(new Result(addCount > 0, "成功分配用户角色"), JsonRequestBehavior.AllowGet));
        }
        protected void InitUserInfo(Users currentUser, Stores switchCurrentSore = null)
        {
            InitInfo initInfo = CurrentInfo;

            //当前用户
            //IUsersService usersService = ServiceFactory.Create<IUsersService>();
            //var currentUser = usersService.GetEntity(1);
            initInfo.CurrentUser = currentUser;

            //当前用户的所属门店
            IStoresService storesService = ServiceFactory.Create <IStoresService>();
            var            currentSore   = switchCurrentSore == null ? currentUser.Stores : switchCurrentSore;//soresService.GetEntity(1);

            initInfo.CurrentStore = currentSore;

            //当前商家
            initInfo.CurrentShop = currentUser.Stores.Shops;

            //该用户在当前门店下的所有角色
            var userAllRole = currentUser.RelationUserRole;
            //用户所有的门店
            List <Entity.Stores> allStore = null;

            List <Entity.Module> sidebar = new List <Entity.Module>();

            //如果是系统管理员,则默认加载所有的菜单//否则就加载用户拥有的权限菜单
            if (initInfo.IsAdministrator)//userAllRole.Any(t => t.RoleID == 1)
            {
                //当前用户使用的角色名称
                initInfo.CurrentRoleName = "超级管理员";
                //左侧菜单(全部获取)
                IModuleService moduleService = ServiceFactory.Create <IModuleService>();
                sidebar = moduleService.GetEntities(t => t.Disabled == false).ToList();

                //管理员可以查看所有门店
                allStore = storesService.GetEntities(t => t.ShopId == initInfo.CurrentShop.ID && t.Disabled == false).ToList();
                //initInfo.Sidebar = sidebar;
            }
            else if (initInfo.CurrentShop.AdminUserID == currentUser.ID)
            {
                //如果是商家,则获取商家的所有菜单
                ////当前用户使用的角色名称
                //initInfo.CurrentRoleName = "店铺管理员";
                //IRelationShopsModuleService relationShopsModuleService = ServiceFactory.Create<IRelationShopsModuleService>();
                //var shopAllModule = relationShopsModuleService.GetEntities(t => t.ShopID == initInfo.CurrentShop.ID).Select(t => t.Module).ToList();
                //foreach (var itemShopModule in shopAllModule)
                //{
                //    //菜单没有被禁用,并且之前没有添加到菜单列表里面
                //    if (!itemShopModule.Disabled && !sidebar.Any(t => t.ID == itemShopModule.ID))
                //    {
                //        sidebar.Add(itemShopModule);
                //    }
                //}

                //如果是商家,则获取商家的对应门店的所有菜单,因为商家下面的门店有可能购买的版本不一样
                //当前用户使用的角色名称
                initInfo.CurrentRoleName = "系统管理员";
                IRelationStoresModuleService relationStoresModuleService = ServiceFactory.Create <IRelationStoresModuleService>();
                var storeAllModule = relationStoresModuleService.GetEntities(t => t.StoresID == initInfo.CurrentStore.ID).Select(t => t.Module).ToList();
                foreach (var itemStoreModule in storeAllModule)
                {
                    if (!itemStoreModule.Disabled && !sidebar.Any(t => t.ID == itemStoreModule.ID))
                    {
                        sidebar.Add(itemStoreModule);
                    }
                }

                //商家管理员可以查看所有门店
                allStore = storesService.GetEntities(t => t.ShopId == initInfo.CurrentShop.ID && t.Disabled == false).ToList();
            }
            else
            {
                //根据角色获取到所有门店
                allStore = userAllRole.Select(t => t.Role.Stores).Where(t => t.Disabled == false).Distinct().ToList();

                IRelationUserRoleService relationUserRoleService = ServiceFactory.Create <IRelationUserRoleService>();

                //过滤出用户当前门店的所有角色
                var userCurrentStoreRole = userAllRole.Where(t => t.Role.StoreID == currentSore.ID);

                //当前用户使用的角色名称
                initInfo.CurrentRoleName = string.Join(",", userCurrentStoreRole.Select(t => t.Role.Name).ToList());

                //用户左侧菜单
                foreach (var itemUserRole in userCurrentStoreRole)
                {
                    //单个角色拥有的菜单
                    var singleRoleModule = itemUserRole.Role.RelationRoleModule;
                    foreach (var itemRoleModule in singleRoleModule)
                    {
                        Module singleModule = itemRoleModule.Module;
                        //菜单没有被禁用,并且之前没有添加到菜单列表里面
                        if (!singleModule.Disabled && !sidebar.Any(t => t.ID == singleModule.ID))
                        {
                            sidebar.Add(singleModule);
                        }
                    }
                }
            }

            //首先获取该用户下面的所有菜单
            IRelationUsersModuleService relationUsersModuleService = ServiceFactory.Create <IRelationUsersModuleService>();
            var userAllModule = relationUsersModuleService.GetEntities(t => t.UsersID == currentUser.ID).Select(t => t.Module).ToList();

            foreach (var itemUserModel in userAllModule)
            {
                //菜单没有被禁用,并且之前没有添加到菜单列表里面
                if (!itemUserModel.Disabled && !sidebar.Any(t => t.ID == itemUserModel.ID))
                {
                    sidebar.Add(itemUserModel);
                }
            }

            //System.Web.HttpContext.Current.Session["InitInfo"] = initInfo;
            //设置缓存2小时
            DataCache.SetCache(HttpContext.Session.SessionID, initInfo, TimeSpan.FromMinutes(1)); //
            //更新登录次数
            IUsersService userService = ServiceFactory.Create <IUsersService>();

            currentUser.LoginTimes    = currentUser.LoginTimes == null ? 1 : currentUser.LoginTimes + 1;
            currentUser.LastLoginTime = DateTime.Now;
            currentUser.LastLoginIP   = Request.UserHostAddress;

            //如果是意向客户,则查询一下IP在哪个城市
            if (currentUser.IsIntention == true)
            {
                currentUser.LastLoginArea = Common.IPHelper.GetAreaByIP(Request.UserHostAddress);
            }

            userService.UpdateEntity(currentUser);

            initInfo.AllStore = allStore;
            initInfo.Sidebar  = sidebar;
            initInfo.IsLogin  = true;

            ////确定当前用户显示的首页,如果有首页则显示,没有首页的话,默认显示微信聚客系统的介绍页
            //if (CurrentInfo.Sidebar.Exists(t =>
            //    t.Area != null && t.Area.ToLower() == "admin" &&
            //    t.Controller != null && t.Controller.ToLower() == "home" &&
            //    t.Action != null && t.Action.ToLower() == "index"))
            //{
            //    initInfo.HomeUrl = "/" + JeasuHelper.SubProjectName;
            //}
            //else
            //{
            //    initInfo.HomeUrl = "/Admin/CashCoupon/UseInstructions";
            //}

            initInfo.HomeUrl = "/Mobile/Home/DriftBottleList";
            #region 广告图片提示收年费
            if (string.IsNullOrWhiteSpace(CurrentInfo.HDImgUrl))
            {
            }

            #endregion

            InitSetting();
        }