public JsonResult GetShopPermission(int id)
        {
            IRelationShopsModuleService relationShopsModuleService = ServiceFactory.Create <IRelationShopsModuleService>();
            List <int> moduleIDs = relationShopsModuleService.GetEntities(t => t.ShopID == id).Select(t => t.ModuleID).ToList();

            return(Json(moduleIDs, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 商家给门店分配菜单的方法
        /// </summary>
        /// <returns></returns>
        public ActionResult ShopPermissionMenu(int?storeID)
        {
            IShopsService shopsService = ServiceFactory.Create <IShopsService>();
            Shops         shop;

            //必须是管理员,才可以分配指定门店的权限
            if (storeID != null)
            {
                if (CurrentInfo.IsAdministrator)
                {
                    var singleStore = ServiceHelper.GetStoresService.GetEntity((int)storeID);
                    shop = shopsService.GetFirstOrDefault(t => t.ID == singleStore.ShopId);
                }
                else
                {
                    return(RedirectToAction("Error403", "Home", new { area = "Admin" }));
                }
            }
            else
            {
                shop = shopsService.GetFirstOrDefault(t => t.AdminUserID == CurrentInfo.CurrentUser.ID);
            }

            if (shop != null)
            {
                IRelationShopsModuleService relationShopsModuleService = ServiceFactory.Create <IRelationShopsModuleService>();
                //获取商家拥有的所有菜单
                var munes = relationShopsModuleService.GetEntities(t => t.ShopID == shop.ID).Select(t => t.Module);
                return(View(munes));
            }
            else
            {
                return(RedirectToAction("Error403", "Home", new { area = "Admin" }));
            }
        }
        /// <summary>
        /// 获取用户升级的广告图片,暂时无用
        /// </summary>
        private void GetUpgradeAdImg()
        {
            IRelationShopsModuleService relationShopsModuleService = ServiceHelper.GetRelationShopsModuleService;
            //是否有旗舰版
            //bool hasQJB = relationShopsModuleService.Exists(t => t.ShopID == CurrentInfo.CurrentShop.ID && t.Module.Controller == "BusinessSolution" && t.Module.Action == "FestivalRemind" && t.Module.Area == "Admin");

            //是否有聚客
            bool hasJKQ = relationShopsModuleService.Exists(t => t.ShopID == CurrentInfo.CurrentShop.ID && t.Module.Controller == "CashCoupon" && t.Module.Action == "CustomerCashCoupon" && t.Module.Area == "Admin");
            //是否有员工分红
            bool hasYGFH = relationShopsModuleService.Exists(t => t.ShopID == CurrentInfo.CurrentShop.ID && t.Module.Controller == "Shareholder" && t.Module.Action == "ShareholderList" && t.Module.Area == "Admin");
            //是否有众筹系统
            bool hasZCXT = relationShopsModuleService.Exists(t => t.ShopID == CurrentInfo.CurrentShop.ID && t.Module.Controller == "EmployeeWelfare" && t.Module.Action == "EmployeeWelfareList" && t.Module.Area == "Admin");

            CurrentInfo.HDImgUrl = "/Areas/Admin/Content/Img/shiyihuodong1.jpg";
            //高级功能都没有
            if (!hasJKQ && !hasYGFH && !hasZCXT)
            {
                CurrentInfo.HDImgUrl = "/Areas/Admin/Content/Img/shiyihuodong3.jpg";
            }
            else if (hasJKQ && !hasYGFH && !hasZCXT)//有聚客,没有众筹和员工
            {
                CurrentInfo.HDImgUrl = "/Areas/Admin/Content/Img/shiyihuodong2.jpg";
            }
            else
            {
                CurrentInfo.HDImgUrl = "/Areas/Admin/Content/Img/shiyihuodong1.jpg";
            }
            //ViewBag.UserIsIntention = CurrentInfo.CurrentUser.IsIntention == true ? "true" : "false";
        }
Ejemplo n.º 4
0
        public bool AddRelationShopModule(string IDs, string ModuleIDs, int createUserID = 0)
        {
            if (string.IsNullOrWhiteSpace(IDs) || string.IsNullOrWhiteSpace(ModuleIDs))
            {
                return(false);
            }

            if (createUserID == 0)
            {
                createUserID = CurrentInfo.CurrentUser.ID;
            }


            List <int> shopIDArr = IDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();
            List <int> moduleArr = ModuleIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();

            //把所有菜单的父菜单取出来,但是只能保证三级菜单,多级有可能有bug
            IModuleService moduleService = ServiceFactory.Create <IModuleService>();
            List <Module>  allListModule = new List <Module>();

            allListModule.AddRange(moduleService.GetEntities(t => moduleArr.Contains(t.ID)).ToList());


            for (int i = 0; i < allListModule.Count(); i++)
            {
                int    parentID     = allListModule[i].ParentID;
                Module parentModule = moduleService.GetFirstOrDefault(t => t.ID == parentID);
                if (parentModule != null)
                {
                    if (allListModule.Where(t => t.ID == parentModule.ID).Count() == 0)
                    {
                        allListModule.Add(parentModule);
                    }
                }
            }

            //从新生成菜单ID
            moduleArr = allListModule.Select(t => t.ID).ToList();

            IRelationShopsModuleService relationShopsModuleService = ServiceFactory.Create <IRelationShopsModuleService>();
            List <RelationShopsModule>  listRelationShopsModule    = new List <RelationShopsModule>();

            int addCount = 0;

            using (TransactionScope scope = TransactionScopeHelper.GetTran())
            {
                foreach (var shopID in shopIDArr)
                {
                    //删除当前人员的所有的权限,然后在添加新的权限
                    var roleModule = relationShopsModuleService.GetEntities(t => t.ShopID == shopID);
                    relationShopsModuleService.DeleteEntities(roleModule.ToList());
                    foreach (var moduleID in moduleArr)
                    {
                        RelationShopsModule model = new RelationShopsModule();
                        model.ShopID       = shopID;
                        model.ModuleID     = moduleID;
                        model.CreateUserID = createUserID;
                        model.CreateTime   = DateTime.Now;
                        listRelationShopsModule.Add(model);
                    }
                }
                addCount = relationShopsModuleService.AddEntities(listRelationShopsModule).Count();
                scope.Complete();
            }

            if (addCount > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public JsonResult AddRelationShopModule(string IDs, string ModuleIDs)
        {
            if (string.IsNullOrWhiteSpace(IDs) || string.IsNullOrWhiteSpace(ModuleIDs))
            {
                return(Json(new Result(false, "参数错误"), JsonRequestBehavior.AllowGet));
            }

            List <int> shopIDArr = IDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();
            List <int> moduleArr = ModuleIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();

            //把所有菜单的父菜单取出来,但是只能保证三级菜单,多级有可能有bug
            IModuleService moduleService = ServiceFactory.Create <IModuleService>();
            List <Module>  allListModule = new List <Module>();

            allListModule.AddRange(moduleService.GetEntities(t => moduleArr.Contains(t.ID)).ToList());

            //复制一份副本,用于循环使用
            Module[] tempAllListModule = new Module[allListModule.Count];
            allListModule.CopyTo(tempAllListModule);

            foreach (var item in tempAllListModule)
            {
                Module parentModule = moduleService.GetFirstOrDefault(t => t.ID == item.ParentID);
                if (parentModule != null)
                {
                    if (allListModule.Where(t => t.ID == parentModule.ID).Count() == 0)
                    {
                        allListModule.Add(parentModule);
                    }
                }
            }
            //从新生成菜单ID
            moduleArr = allListModule.Select(t => t.ID).ToList();

            IRelationShopsModuleService relationShopsModuleService = ServiceFactory.Create <IRelationShopsModuleService>();
            List <RelationShopsModule>  listRelationShopsModule    = new List <RelationShopsModule>();

            int addCount = 0;

            using (TransactionScope scope = TransactionScopeHelper.GetTran())
            {
                foreach (var shopID in shopIDArr)
                {
                    //删除当前人员的所有的权限,然后在添加新的权限
                    var roleModule = relationShopsModuleService.GetEntities(t => t.ShopID == shopID);
                    relationShopsModuleService.DeleteEntities(roleModule.ToList());
                    foreach (var moduleID in moduleArr)
                    {
                        RelationShopsModule model = new RelationShopsModule();
                        model.ShopID       = shopID;
                        model.ModuleID     = moduleID;
                        model.CreateUserID = CurrentInfo.CurrentUser.ID;
                        model.CreateTime   = DateTime.Now;
                        listRelationShopsModule.Add(model);
                    }
                }
                addCount = relationShopsModuleService.AddEntities(listRelationShopsModule).Count();
                scope.Complete();
            }

            return(Json(new Result(addCount > 0, "成功分配权限"), JsonRequestBehavior.AllowGet));
        }