Ejemplo n.º 1
0
        public ActionResult SaveStore(int companyId, int storeId, string storename, string storetel, int cityId)
        {
            bool isnew = false;

            if (string.IsNullOrEmpty(storename) || companyId == 0)
            {
                return(Content("0"));
            }
            CompanyStore companystore = ncBase.CurrentEntities.CompanyStore.Where(o => o.StoreId == storeId).FirstOrDefault();

            if (companystore.IsNull())
            {
                isnew                = true;
                companystore         = new CompanyStore();
                companystore.Address = "";
            }
            companystore.CityID    = cityId;
            companystore.Tel       = storetel;
            companystore.CompanyId = companyId;
            companystore.StoreName = storename;

            if (isnew)
            {
                ncBase.CurrentEntities.AddToCompanyStore(companystore);
            }
            ncBase.CurrentEntities.SaveChanges();

            return(Content(companystore.StoreId.ToString()));
        }
Ejemplo n.º 2
0
        public JsonResult InviteRegister(int cityId, string info, string password, string from = "")
        {
            if (String.IsNullOrEmpty(info))
            {
                return(Json(new { status = -1, msg = "无效的参数" }));
            }
            UserModels userModels = new UserModels();

            info       = CryptoUtility.TripleDESDecrypt(info);
            userModels = JsonConvert.DeserializeObject <UserModels>(info);
            string tel = string.IsNullOrEmpty(userModels.Tel) ? "" : StringUtility.StripWhiteSpace(userModels.Tel.Replace("-", ""), false);

            if (tel.StartsWith("0"))
            {
                tel = tel.Substring(1);
            }
            userModels.Tel = tel;
            if (!StringUtility.ValidateMobile(userModels.Tel))
            {
                return(Json(new { status = -1, msg = "手机号码格式不正确" }));
            }
            PublicUser publicUser =
                ncBase.CurrentEntities.PublicUser.Where(o => o.Tel == userModels.Tel).FirstOrDefault();

            if (publicUser.IsNoNull())
            {
                return(Json(new { status = -1, msg = "该手机号码已经注册过了" }));
            }
            publicUser =
                ncBase.CurrentEntities.PublicUser.Where(o => o.Name == userModels.UserName).FirstOrDefault();
            string userName = userModels.UserName;

            if (publicUser.IsNoNull())
            {
                userModels.UserName = userModels.UserName + "_" + userModels.UserId + StringUtility.GetValiCode();
            }
            PublicUserModel user = new PublicUserModel();

            string  strCompany = string.IsNullOrEmpty(userModels.Company) ? userModels.Store : userModels.Company;
            string  strStore   = string.IsNullOrEmpty(userModels.Company) ? "" : userModels.Store;
            Company company    = ncBase.CurrentEntities.Company.Where(o => o.Name == strCompany && o.CityID == cityId).FirstOrDefault();

            if (company.IsNull())
            {
                company         = new Company();
                company.Name    = strCompany;
                company.Tel     = "";
                company.Address = "";
                company.CityID  = cityId;
                ncBase.CurrentEntities.AddToCompany(company);
                ncBase.CurrentEntities.SaveChanges();
            }


            CompanyStore companyStore = ncBase.CurrentEntities.CompanyStore.Where(o => o.StoreName == strStore && o.CompanyId == company.CompanyId).FirstOrDefault();

            if (!string.IsNullOrEmpty(strStore) && companyStore.IsNull())
            {
                companyStore           = new CompanyStore();
                companyStore.Address   = "";
                companyStore.CityID    = cityId;
                companyStore.CompanyId = company.CompanyId;
                companyStore.StoreName = strStore;
                companyStore.Tel       = "";
                ncBase.CurrentEntities.AddToCompanyStore(companyStore);
                ncBase.CurrentEntities.SaveChanges();
            }
            user.Tel         = userModels.Tel;
            user.Name        = userModels.UserName;
            user.Password    = password;
            user.CityID      = cityId;
            user.DistrictId  = 0;
            user.CompanyId   = company.CompanyId;
            user.StoreId     = companyStore.IsNoNull() ? companyStore.StoreId : 0;
            user.RegionId    = 0;
            user.VipType     = 2; //会员类型
            user.Portrait    = userModels.Portrait;
            user.Remarks     = !string.IsNullOrEmpty(from) ? "From:" + from : "";
            user.IP          = Request.UserHostAddress;
            user.LastLoginIP = Request.UserHostAddress;
            user.NickName    = userName;
            user.EnrolnName  = userName;

            #region 表单验证
            if (string.IsNullOrEmpty(user.Tel))
            {
                return(Json(new { status = 1, msg = "手机号不能为空" }));
            }

            if (string.IsNullOrEmpty(user.Name))
            {
                return(Json(new { status = 1, msg = "用户名不能为空" }));
            }
            if (string.IsNullOrEmpty(user.Password) || (user.Password != null && user.Password.Length < 6))
            {
                return(Json(new { status = 1, msg = "密码至少6位数" }));
            }
            if (user.CityID <= 0)
            {
                return(Json(new { status = 1, msg = "所属城市必填" }));
            }
            if (user.CompanyId <= 0)
            {
                return(Json(new { status = 1, msg = "所属公司必填" }));
            }

            #endregion

            UserBll userBll = new UserBll();
            int     userid  = userBll.addPublicUser(user);
            if (userid == -1)
            {
                return(Json(new { status = 1, msg = "用户名已经存在" }));
            }
            else if (userid == -2)
            {
                return(Json(new { status = 1, msg = "手机号已被注册" }));
            }
            if (userid > 0)//自动登录
            {
                try
                {
                    if (userModels.InviteUid.IsNoNull() && userModels.InviteUid > 0)
                    {
                        PublicUser publicUserInvite =
                            ncBase.CurrentEntities.PublicUser.Where(
                                o => o.UserID == userModels.InviteUid && o.Status == 1).FirstOrDefault();
                        if (publicUserInvite.IsNoNull())
                        {
                            int points = publicUserInvite.Points;
                            publicUserInvite.Points = points + 200;
                            ncBase.CurrentEntities.SaveChanges();

                            PublicUserPointsLog publicUserPointsLog = new PublicUserPointsLog();
                            publicUserPointsLog.Points        = 200;
                            publicUserPointsLog.UserId        = publicUserInvite.UserID;
                            publicUserPointsLog.AddTime       = DateTime.Now;
                            publicUserPointsLog.CurrentPoints = points + 200;
                            publicUserPointsLog.Description   = "手机用户" + user.Tel + "接受邀请注册加分";
                            ncBase.CurrentEntities.AddToPublicUserPointsLog(publicUserPointsLog);
                            ncBase.CurrentEntities.SaveChanges();
                            smsApi.SendSms(publicUserInvite.Tel, "手机用户" + user.Tel + "成功通过您的邀请链接注册房产盒子,系统赠送您200积分!", (Purpose)8, "【房产盒子】");
                        }
                    }
                    SendResult sendResult = smsApi.SendSms(user.Tel, "恭喜您成功开通房产盒子,帐号:" + user.Tel + " 密码:" + user.Password, (Purpose)8, "【房产盒子】");
                }
                catch (Exception)
                {
                    throw;
                }
                if (Session[user.Tel] != null)
                {
                    Session[user.Tel] = null;
                    Session.Remove(user.Tel);
                }
                PublicUserModel newUser = userBll.PublicUserLogin(user.Name, user.Password);
                String          saveKey = System.Configuration.ConfigurationManager.AppSettings["AuthSaveKey"];
                if (String.IsNullOrEmpty(saveKey))
                {
                    saveKey = "WXLoginedUser";
                }
                Session[saveKey] = newUser;
                HttpCookie loginUserCookie = new HttpCookie(saveKey, CryptoUtility.TripleDESEncrypt(newUser.UserID.ToString()));
                loginUserCookie.Expires = DateTime.Now.AddDays(10);
                HttpContext.Response.Cookies.Add(loginUserCookie);
            }
            return(Json(new { status = 0, msg = "注册成功" }));
        }