Beispiel #1
0
        public JsonResult AddStores(Stores storesModel)
        {
            //var stores = strStores.FromJson<Stores>();

            IStoresService storesService = ServiceFactory.Create <IStoresService>();

            bool flage = storesService.Exists(t => t.ShopId == storesModel.ShopId && t.StoreName == storesModel.StoreName);

            if (flage)
            {
                return(Json(new Result(false, "已经存在同名门店请修改"), JsonRequestBehavior.AllowGet));
            }

            if (!string.IsNullOrWhiteSpace(storesModel.StoresImage))
            {
                storesModel.StoresImage = FileHelper.Move(storesModel.StoresImage, "/Upload/Reality/" + CurrentInfo.CurrentStore.ID + "/storeImage/");
            }
            if (!string.IsNullOrWhiteSpace(storesModel.ReceiptLogo))
            {
                string newRoute = ServiceHelper.GetCommonService.ThumbnailImage(storesModel.ReceiptLogo, CurrentInfo.CurrentStore.ID, 128, 128, "CUT", "ReceiptLogo");
                storesModel.ReceiptLogo = newRoute;
            }
            if (storesModel.LongitudeX == "NaN")
            {
                storesModel.LongitudeX = "0";
            }
            if (storesModel.LatitudeY == "NaN")
            {
                storesModel.LatitudeY = "0";
            }
            var data = storesService.AddEntity(storesModel);

            return(Json(new Result(data != null, ResultType.Add), JsonRequestBehavior.AllowGet));
        }
Beispiel #2
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);
        }