Esempio n. 1
0
        /// <summary>
        /// 微信绑定 旧用户
        /// </summary>
        public bool WXBindingCustomer(ah.Models.ViewModel.WechatBindingModel model)
        {
            if (!model.CustomerId.HasValue)
            {
                throw new Exception("没有选择绑定的用户");
            }

            foreach (var item in MainDbContext.CHIS_Code_Customer.Where(m => m.WXOpenId == model.openid))
            {
                item.WXOpenId = null;
            }
            MainDbContext.SaveChanges();

            var cus = MainDbContext.CHIS_Code_Customer.Find(model.CustomerId);

            cus.WXOpenId = model.openid;
            cus.WXPic    = model.WxPicUrl;
            MainDbContext.SaveChanges();
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// 微信注册 新用户
        /// </summary>
        public bool WXRegistCustomer(ah.Models.ViewModel.WechatBindingModel model)
        {
            var mobile = model.mobile;

            if (mobile.IsEmpty())
            {
                throw new Exception("手机号码为空");
            }
            if (model.openid.IsEmpty())
            {
                throw new Exception("微信openid为空");
            }
            if (!model.Gender.HasValue)
            {
                throw new Exception("没有选择性别");
            }
            if (model.CustomerName.IsEmpty())
            {
                throw new Exception("没有输入用户名");
            }
            if (!model.Birthday.HasValue)
            {
                throw new Exception("没有传入出生日期");
            }
            if (!(mobile.GetStringType().IsMobile))
            {
                throw new Exception("输入的账号非手机号码");
            }

            using (var tx = MainDbContext.Database.BeginTransaction())
            {
                try
                {
                    var cus = new CHIS_Code_Customer
                    {
                        NickName            = model.NickName,
                        CustomerName        = model.CustomerName,
                        Gender              = model.Gender,
                        Birthday            = model.Birthday,
                        WXPic               = model.WxPicUrl,
                        WXOpenId            = model.openid,
                        CustomerMobile      = mobile,
                        IsVIP               = false,
                        CustomerCreateDate  = DateTime.Now,
                        OpTime              = DateTime.Now,
                        sysLatestActiveTime = DateTime.Now
                    };

                    var count = MainDbContext.CHIS_Sys_Login.Where(m => m.Mobile == mobile).Count() + MainDbContext.CHIS_Code_Customer.Where(m => m.CustomerMobile == mobile).Count();
                    if (count > 0)
                    {
                        //强制清空手机账号
                        var find0 = MainDbContext.CHIS_Code_Customer.Where(m => m.CustomerMobile == mobile);
                        foreach (var fd0 in find0)
                        {
                            fd0.CustomerMobile = null;
                        }
                        var find1 = MainDbContext.CHIS_Sys_Login.Where(m => m.Mobile == mobile);
                        foreach (var fd1 in find1)
                        {
                            fd1.Mobile = null; fd1.MobileAuthenticatedTime = null; fd1.MobileIsAuthenticated = false;
                        }
                        MainDbContext.SaveChanges();
                    }

                    var add0 = MainDbContext.Add(cus).Entity;
                    MainDbContext.SaveChanges();
                    //增加注册用户
                    var login = MainDbContext.CHIS_Sys_Login.FirstOrDefault(m => m.Mobile == mobile);
                    if (login == null)
                    {
                        MainDbContext.Add(new CHIS_Sys_Login
                        {
                            Mobile     = mobile,
                            CustomerId = add0.CustomerID,
                            IsLock     = false
                        });
                        MainDbContext.SaveChanges();
                        cus = add0;
                    }

                    tx.Commit();
                }
                catch (Exception ex) { tx.Rollback(); throw ex; }
                return(true);
            }
        }