Ejemplo n.º 1
0
        public JsonResult SaveMember(HQ_Member entity)
        {
            #region 用户名、手机号码是否重复

            SearchModel sm = SearchEntity.FormSql<SearchModel>("select count(id) from hq_member where username=@uname and isnull(isdelete,0)=0 and id<>@id",
                new SqlParameter("uname", entity.UserName), new SqlParameter("id", entity.ID));
            int count = sm.LoadValue<int>();
            if (count > 0)
            {
                return ExController.JsonNet(new { ID = -1 });
            }
            sm = SearchEntity.FormSql<SearchModel>("select count(id) from hq_member where phonenum=@pnum and isnull(isdelete,0)=0 and id<>@id",
                new SqlParameter("pnum", entity.PhoneNum), new SqlParameter("id", entity.ID));
            count = sm.LoadValue<int>();
            if (count > 0)
            {
                return ExController.JsonNet(new { ID = -2 });
            }

            #endregion

            try
            {
                using (var scope = new TransactionScope())
                {
                    if (entity.ID == 0)
                    {
                        var password = "******";

                        #region 维护新增数据

                        entity.UserPsw = MD5.EncryptString(password);
                        entity.ShopPsw = entity.UserPsw;
                        entity.CreateBy = LoginInfo.Current.UserName;
                        entity.CreateOn = DateTime.Now;
                        if (entity.UserType == 2)
                        {
                            entity.OpenVipDate = DateTime.Now.Date;
                        }

                        #endregion

                        entity.Save();

                        HttpClient _httpClient = new HttpClient();
                        _httpClient.BaseAddress = new Uri("http://mall.chinalvju.com/");
                        var dic = new Dictionary<string, string>();
                        dic.Add("UserName", entity.PhoneNum);
                        dic.Add("NickName", entity.UserName);
                        dic.Add("Password", password);
                        dic.Add("ConfirmPassword", password);

                        _httpClient.PostAsync("Account/Register", new FormUrlEncodedContent(dic));
                    }
                    else
                    {
                        #region 维护修改数据

                        entity.EditBy = LoginInfo.Current.UserName;
                        entity.EditOn = DateTime.Now;
                        if (entity.UserType == 2)
                        {
                            entity.OpenVipDate = DateTime.Now.Date;
                        }

                        #endregion

                        sm = new SearchModel("uv_MemberWithAmount");
                        sm["id"] = entity.ID;
                        var oldMem = sm.LoadEntity<HQ_Member>();
                        if (oldMem.PhoneNum != entity.PhoneNum)
                        {
                            Shop_Member s_mem = new Shop_Member();
                            s_mem["UserID"] = oldMem.ShopUserID_G;
                            s_mem["UserName"] = entity.PhoneNum;
                            s_mem.Save();
                        }

                        entity.Save();
                    }

                    scope.Complete();
                }

                return ExController.JsonNet(entity);
            }
            catch
            {
                return ExController.JsonNet(new { ID = 0 });
            }
        }
Ejemplo n.º 2
0
        public long ChangeUserPhone(string phone, string yzm)
        {
            if (phone == null || phone.Length == 0 || !(Regex.Match(phone, @"^[1][3,5,8][0-9]{9}$", RegexOptions.Compiled).Success))
            {
                return -1;//手机号码错误
            }

            var omcode = base.HttpContext.Cache["msg-" + phone];
            if (omcode == null || omcode.ToString().Length == 0)
            {
                return -2;//已发送的短信验证码不存在
            }

            if (yzm == null || yzm.Length == 0 || !yzm.Equals(omcode.ToString()))
            {
                return -2;//输入的短信验证码错误
            }

            SearchModel sm = new SearchModel("uv_MemberWithAmount");
            sm["ID"] = LoginInfo.Current.UserID;
            sm.AddSearch("PhoneNum", "ShopUserID_G");
            var mem = sm.LoadEntity<HQ_Member>();

            try
            {
                using (var scope = new TransactionScope())
                {
                    if (mem.PhoneNum != phone)
                    {
                        Shop_Member s_mem = new Shop_Member();
                        s_mem["UserID"] = mem.ShopUserID_G;
                        s_mem["UserName"] = phone;
                        s_mem.Save();
                    }

                    HQ_Member user = new HQ_Member();
                    user["ID"] = LoginInfo.Current.UserID;
                    user.PhoneNum = phone;
                    user.Save();

                    scope.Complete();
                }
            }
            catch
            {
                return 0;
            }
            return 1;
        }
Ejemplo n.º 3
0
        public long ImportMember(string fpath)
        {
            fpath = Server.MapPath("~/" + fpath);
            if (!System.IO.File.Exists(fpath))
            {
                return 0;
            }

            var list = G.Util.Tool.ExcelHelper.Read<HQ_Member>(fpath, new string[] {
                "UserName","PhoneNum","MemberMedical"
                }, 1, (e) =>
                {
                    e.PhoneNum = e.PhoneNum;
                    e.UserPsw = e.PhoneNum.Substring(5);
                    e.UserType = (int)EnumUserType.Normal;
                    e.CreateBy = LoginInfo.Current.UserName;
                    e.CreateOn = DateTime.Now;
                });

            HttpClient _httpClient = new HttpClient();
            _httpClient.BaseAddress = new Uri("http://mall.chinalvju.com/");

            try
            {
                using (var scope = new TransactionScope())
                {
                    foreach (var l in list)
                    {
                        SearchModel se = new SearchModel("uv_MemberWithAmount");
                        se["UserName"] = l.UserName;
                        se.AddSearch("ID", "PhoneNum", "ShopUserID_G");
                        var member = se.LoadEntity<HQ_Member>();
                        if (member == null)
                        {
                            se = new SearchModel("HQ_Member");
                            se["PhoneNum"] = l.PhoneNum;
                            se.AddSearch("count(id)");
                            var memCount = se.LoadValue<int>();
                            if (memCount > 0)
                            {
                                continue;
                            }

                            var dic = new Dictionary<string, string>();
                            dic.Add("UserName", l.PhoneNum);
                            dic.Add("NickName", l.UserName);
                            dic.Add("Password", l.UserPsw);
                            dic.Add("ConfirmPassword", l.UserPsw);

                            _httpClient.PostAsync("Account/Register", new FormUrlEncodedContent(dic));

                            l.UserPsw = MD5.EncryptString(l.UserPsw);
                            l.ShopPsw = l.UserPsw;
                            l.Save();
                        }
                        else
                        {
                            if (!l.PhoneNum.Equals(member.PhoneNum))
                            {
                                //手机号码变化时,修改商城用户手机号码
                                Shop_Member s_mem = new Shop_Member();
                                s_mem["UserID"] = member.ShopUserID_G;
                                s_mem["UserName"] = l.PhoneNum;
                                s_mem.Save();
                            }

                            var mem = new HQ_Member();
                            mem["id"] = member.ID;
                            mem.PhoneNum = l.PhoneNum;
                            mem.MemberMedical = l.MemberMedical;
                            mem.Save();
                        }
                    }

                    scope.Complete();
                }
                return 1;
            }
            catch
            {
                return 0;
            }
        }
Ejemplo n.º 4
0
        public JsonResult ChangeUserName(string newName)
        {
            if (newName.Length == 0)
            {
                return this.JsonNet(new CommonResult() { ResultID = 0, Message = "新用户名不能为空!" });
            }
            if (newName == LoginInfo.Current.UserName)
            {
                return this.JsonNet(new CommonResult() { ResultID = 0, Message = "新用户名不能与旧用户名相同!" });
            }

            try
            {
                lock (changeUNameLockObj)
                {
                    SearchModel sm = new SearchModel("hq_member");
                    sm["username"] = newName;
                    sm.AddSearch("count(id)");
                    var mcount = sm.LoadValue<int>();
                    if (mcount > 0)
                    {
                        return this.JsonNet(new CommonResult() { ResultID = 0, Message = "新用户名已被其他用户使用!" });
                    }

                    using (var scope = new TransactionScope())
                    {
                        sm = new SearchModel("uv_MemberWithAmount");
                        sm["username"] = LoginInfo.Current.UserName;
                        sm.AddSearch("shopuserid_g");
                        var shopuserid = sm.LoadValue<int>();
                        Shop_Member smember = new Shop_Member();
                        smember["UserID"] = shopuserid;
                        smember["NickName"] = newName;
                        smember.Save();

                        HQ_Member mem = new HQ_Member();
                        mem["ID"] = LoginInfo.Current.UserID;
                        mem.UserName = newName;
                        mem.Save();

                        scope.Complete();
                    }
                }
            }
            catch
            {
                return this.JsonNet(new CommonResult() { ResultID = 0, Message = "修改用户名失败,请重试!" });
            }
            return this.JsonNet(new { ResultID = 1 });
        }