public JsonResult GetShopVersionPermission(int id)
        {
            IRelationShopVersionModuleService relationShopVersionModuleService = ServiceFactory.Create <IRelationShopVersionModuleService>();
            List <int> moduleIDs = relationShopVersionModuleService.GetEntities(t => t.ShopVersionID == id).Select(t => t.ModuleID).ToList();

            return(Json(moduleIDs, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public JsonResult ResetShopVersion(int shopsID, int shopVersionID)
        {
            //如果不是管理员,拒绝调用此方法
            if (!CurrentInfo.IsAdministrator)
            {
                return(Json(new Result(false, ResultType.Update), JsonRequestBehavior.AllowGet));
            }

            //这边要取出这个版本所有菜单,然后加到用户菜单关系表 和 商家菜单关系表中
            IRelationShopVersionModuleService relationShopVersionModuleService = ServiceFactory.Create <IRelationShopVersionModuleService>();
            var listModuleID = relationShopVersionModuleService.GetEntities(t => t.ShopVersionID == shopVersionID).Select(t => t.ModuleID).ToList();
            var strModuleID  = string.Join(",", listModuleID.ToArray());

            IShopsService  shopsService    = ServiceHelper.GetShopsService;
            IStoresService storesService   = ServiceHelper.GetStoresService;
            var            modelStore      = storesService.GetTopEntities(1, t => t.ID, t => t.ShopId == shopsID, true).FirstOrDefault();
            int            shopAdminUserID = shopsService.GetEntity(shopsID).AdminUserID;
            Role           roleModel       = ServiceHelper.GetRoleService.GetFirstOrDefault(t => t.StoreID == modelStore.ID);

            //添加商家和菜单的关系
            AddRelationShopModule(shopsID.ToString(), strModuleID);
            //添加门店和菜单的关系
            AddRelationStoreModule(modelStore.ID.ToString(), strModuleID);
            //添加用户和菜单的关系
            AddRelationUsersModule(shopAdminUserID.ToString(), strModuleID);

            //如果店家有添加角色
            if (roleModel != null)
            {
                //添加角色和菜单的关系
                AddRelationRoleModule(roleModel.ID.ToString(), strModuleID);
            }

            //System.Threading.Thread.Sleep(2000);

            return(Json(new Result(true, ResultType.Update), JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        //public int nowAddShopID = 0;


        public Shops CreateShop(ShopModel shopModel, int createUserID = 0)
        {
            IUsersService  usersService  = ServiceFactory.Create <IUsersService>();
            IShopsService  shopsService  = ServiceFactory.Create <IShopsService>();
            IStoresService storesService = ServiceFactory.Create <IStoresService>();

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

            //bool saveSuccess = false;
            Shops shops = null;

            //用事务来添加一个商家
            using (TransactionScope scope = TransactionScopeHelper.GetTran(TransactionScopeOption.Required, TimeSpan.FromSeconds(20)))
            {
                //商家账号
                Users users = new Users();
                users.RealName = shopModel.RealName;
                users.UserName = shopModel.UserName;
                //添加账号PasswordSalt随机
                users.PasswordSalt = Common.TextFilter.GetPasswordSalt(); //Common.TextFilter.Substring(Guid.NewGuid().ToString("N"), 10, false);
                string endPassword = shopModel.Password + users.PasswordSalt;
                users.Password    = Common.SecureHelper.MD5(endPassword);
                users.NeedAccount = true;

                users.Idcard         = shopModel.Idcard;
                users.Phone          = shopModel.Phone;
                users.DefaultStoreID = null;
                users.CreateUserID   = createUserID;
                users.CreateTime     = DateTime.Now;
                users.Disabled       = shopModel.Disabled;

                users = usersService.AddEntity(users);

                //商家信息
                shops               = new Shops();
                shops.ShopName      = shopModel.ShopName;
                shops.Domain        = shopModel.Domain;
                shops.DomainName    = shopModel.DomainName;
                shops.DueDate       = shopModel.DueDate;
                shops.TotalMoney    = shopModel.TotalMoney;
                shops.Remark        = shopModel.Remark;
                shops.AdminUserID   = users.ID;
                shops.CreateUserID  = createUserID;
                shops.CreateTime    = DateTime.Now;
                shops.Disabled      = shopModel.Disabled;
                shops.ShopVersionID = shopModel.ShopVersionID;
                shops.ShopType      = shopModel.ShopType;
                shops.SalespersonID = shopModel.SalespersonID;
                shops.Deposit       = shopModel.Deposit;
                shops.FinalPayment  = shopModel.FinalPayment;
                shops.Province      = shopModel.Province;
                shops.ProvinceCode  = shopModel.ProvinceCode;
                shops.City          = shopModel.City;
                shops.CityCode      = shopModel.CityCode;
                shops.County        = shopModel.County;
                shops.CountyCode    = shopModel.CountyCode;
                shops.AfterSales    = shopModel.AfterSales;
                shops.LogoUrl       = shopModel.LogoUrl;
                shops.AnnualFee     = shopModel.AnnualFee;
                shops.SiteName      = shopModel.SiteName;

                //默认赋值
                {
                    shops.DueDate       = DateTime.MaxValue;
                    shops.TotalMoney    = 0;
                    shops.Disabled      = false;
                    shops.ShopVersionID = 1;
                }

                shops = shopsService.AddEntity(shops);

                //门店(开通商家的时候默认开通一号店)
                Stores stores = new Stores();
                stores.ShopId       = shops.ID;
                stores.StoreName    = "一号部门";
                stores.IsShare      = false;
                stores.IsShowWeiXin = false;
                stores.IsMainStore  = false;

                stores = storesService.AddEntity(stores);

                users.ShopsID        = shops.ID;
                users.DefaultStoreID = stores.ID;
                usersService.UpdateEntity(users);

                //Category categoryModel = new Category();
                //categoryModel.Name = "总仓";
                //categoryModel.Sort = 1;
                //categoryModel.CategoryType = 3;
                //categoryModel.Name = categoryModel.Name.Trim();
                //categoryModel.UserID = users.ID;
                //categoryModel.CreateTime = DateTime.Now;
                //categoryModel.StoreID = stores.ID;
                //categoryModel = categoryModel.Add();

                //Role roleModel = new Role();
                //roleModel.Name = "经理";
                //roleModel.Sort = 1;
                //roleModel.ShopsID = shops.ID;
                //roleModel.StoreID = stores.ID;
                //roleModel.CreateUserID = users.ID;
                //roleModel.CreateTime = DateTime.Now;
                //roleModel = roleModel.Add();


                //这边要取出这个版本所有菜单,然后加到用户菜单关系表 和 商家菜单关系表中
                IRelationShopVersionModuleService relationShopVersionModuleService = ServiceFactory.Create <IRelationShopVersionModuleService>();
                var listModuleID = relationShopVersionModuleService.GetEntities(t => t.ShopVersionID == shopModel.ShopVersionID).Select(t => t.ModuleID).ToList();
                var strModuleID  = string.Join(",", listModuleID.ToArray());

                //添加商家和菜单的关系
                AddRelationShopModule(shops.ID.ToString(), strModuleID, createUserID);
                //添加门店和菜单的关系
                AddRelationStoreModule(stores.ID.ToString(), strModuleID, createUserID);
                //添加用户和菜单的关系
                AddRelationUsersModule(users.ID.ToString(), strModuleID, createUserID);
                ////添加角色和菜单的关系
                //AddRelationRoleModule(roleModel.ID.ToString(), strModuleID, createUserID);
                scope.Complete();
            }

            return(shops);
        }
        public JsonResult AddRelationShopVersionModule(string IDs, string ModuleIDs)
        {
            if (string.IsNullOrWhiteSpace(IDs) || string.IsNullOrWhiteSpace(ModuleIDs))
            {
                return(Json(new Result(false, "参数错误"), JsonRequestBehavior.AllowGet));
            }

            List <int> shopVersionIDArr = 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();

            IRelationShopVersionModuleService relationShopVersionModuleService = ServiceFactory.Create <IRelationShopVersionModuleService>();
            List <RelationShopVersionModule>  listRelationShopVersionModule    = new List <RelationShopVersionModule>();

            int addCount = 0;

            using (TransactionScope scope = TransactionScopeHelper.GetTran())
            {
                foreach (var shopVersionID in shopVersionIDArr)
                {
                    //删除当版本的所有菜单,然后在添加新的菜单
                    var roleModule = relationShopVersionModuleService.GetEntities(t => t.ShopVersionID == shopVersionID);
                    relationShopVersionModuleService.DeleteEntities(roleModule.ToList());
                    foreach (var moduleID in moduleArr)
                    {
                        RelationShopVersionModule model = new RelationShopVersionModule();
                        model.ShopVersionID = shopVersionID;
                        model.ModuleID      = moduleID;
                        model.CreateUserID  = CurrentInfo.CurrentUser.ID;
                        model.CreateTime    = DateTime.Now;
                        listRelationShopVersionModule.Add(model);
                    }
                }
                addCount = relationShopVersionModuleService.AddEntities(listRelationShopVersionModule).Count();
                scope.Complete();
            }

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