public JsonResult BatchAddSubmit(List <UserInfo> list)
        {
            var jsonm = new ResultJson();

            try
            {
                if (list.Count > 0)
                {
                    var userList = new List <UserInfo>();
                    foreach (var item in list)
                    {
                        if (!string.IsNullOrEmpty(item.UserPassword))
                        {
                            item.UserPassword = SHACryptHelper.SHA256Encrypt(item.UserPassword);
                        }

                        var umodel = new UserInfo();
                        umodel.UserAccount = item.UserAccount;
                        umodel.Mobile      = item.Mobile;
                        umodel.Email       = item.Email;
                        umodel.CreateTime  = DateTime.Now;

                        item.UserID     = umodel.UserID;
                        item.CreateTime = umodel.CreateTime;

                        userList.Add(umodel);
                    }



                    using (var db = SugarBase.GetIntance())
                    {
                        db.Insertable(userList).ExecuteCommand();
                    }
                }
            }
            catch (Exception ex)
            {
                jsonm.status = 500;
                jsonm.msg    = ex.Message;
                LogProvider.Error("批量添加用户", ex.StackTrace, ex.Message);
            }
            jsonm.data = list;
            return(Json(jsonm));
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="UserPassword"></param>
        /// <returns></returns>
        public JsonResult ChangePassSubmit(string QuotaID, string UserID, string UserPassword)
        {
            var      jsonm = new ResultJson();
            UserInfo model = new UserInfo();

            try
            {
                using (var db = SugarBase.GetIntance())
                {
                    if (!string.IsNullOrEmpty(UserID))
                    {
                        model = db.Queryable <UserInfo>().Where(m => m.UserID == UserID).First();
                        if (model != null)
                        {
                            if (model.UserID == UserID)
                            {
                                if (!string.IsNullOrEmpty(UserPassword))
                                {
                                    model.UserPassword = SHACryptHelper.SHA256Encrypt(UserPassword);
                                    db.Updateable(model).ExecuteCommand();
                                    jsonm.status = 200;
                                }
                                else
                                {
                                    jsonm.status = 300;
                                    jsonm.msg    = "请填写密码";
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogProvider.Error("修改密码", ex.StackTrace, ex.Message);

                jsonm.status = 500;
                jsonm.msg    = "保存失败";
            }
            return(Json(jsonm));
        }
        public JsonResult LoginSubmit(string username, string password, string vercode = "")
        {
            var jsonm = new ResultJson();

            try
            {
                ;
                var sessionid = CookieHelper.GetCookie("sessionid");
                var result    = false;

                if (RedisHelper.KeyExists("imgcode:" + sessionid))
                {
                    var code = RedisHelper.StringGet("imgcode:" + sessionid);

                    if (code.Trim().ToUpper() == vercode.Trim().ToUpper())
                    {
                        result = true;
                    }
                    else
                    {
                        jsonm.status = 500;
                        jsonm.msg    = "验证码错误";
                    }
                }

                if (result)
                {
                    using (var db = SugarBase.GetIntance())
                    {
                        if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
                        {
                            var model = db.Queryable <SysUser>().Where(m => m.Status == 1 && m.SysUserName.Equals(username.Trim()) && m.SysUserPwd.Equals(SHACryptHelper.SHA256Encrypt(password))).First();
                            if (model != null)
                            {
                                var userModel = new AccountToken();
                                userModel.UserID   = model.SysUserID;
                                userModel.UserName = model.SysNickName;

                                var menu_list = db.Queryable <SysModule, SysRoleModule, SysRole, SysUserRole>((sm, srm, sr, sur) => new object[] {
                                    JoinType.Left, sm.ID == srm.ModuleID,
                                    JoinType.Left, srm.RoleID == sr.RoleID,
                                    JoinType.Left, sr.RoleID == sur.RoleID,
                                })
                                                .Where((sm, srm, sr, sur) => sur.UserID == model.SysUserID && sm.Status)
                                                .OrderBy((sm, srm, sr, sur) => sm.Sort, OrderByType.Desc)
                                                .OrderBy((sm, srm, sr, sur) => sm.CreateTime, OrderByType.Asc)
                                                .Select(sm => new SysModule {
                                    ID = sm.ID, Href = sm.Href, Business = sm.Business, Icon = sm.Icon, Name = sm.Name, Sort = sm.Sort, Type = sm.Type, ParentID = sm.ParentID
                                }).ToList();

                                CookieHelper.WriteCookie("systoken", MD5CryptHelper.Encrypt(JsonConvert.Serialize(userModel)), 30);


                                var claims = new[] {
                                    new Claim("UserID", model.SysUserID),
                                    new Claim("UserName", model.SysNickName)
                                };
                                var             claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                                ClaimsPrincipal user           = new ClaimsPrincipal(claimsIdentity);

                                //var identity = new ClaimsIdentity();
                                //identity.AddClaim(new Claim(ClaimTypes.Sid, userModel.UserID));
                                //identity.AddClaim(new Claim(ClaimTypes.Name, userModel.UserName));
                                HttpContextHelper.Current.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, user);



                                userModel.MenuList = menu_list;


                                var daySpan = TimeSpan.FromMinutes(30);
                                RedisHelper.StringSet("system:SysToken:" + userModel.UserID, MD5CryptHelper.Encrypt(JsonConvert.Serialize(userModel)), daySpan);
                                setMenuCache();

                                SetSysLog("【系统登录】" + userModel.UserName, 1, 1);
                                //HttpContext.Session.SetString("SysToken", MD5CryptHelper.Encrypt(JsonConvert.Serialize(userModel)));
                                jsonm.status = 200;
                                jsonm.msg    = "登录成功";
                            }
                            else
                            {
                                jsonm.status = 500;
                                jsonm.msg    = "账号或密码错误";
                            }
                        }
                        else
                        {
                            jsonm.status = 500;
                            jsonm.msg    = "请填写账号信息";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                jsonm.status = 500;
                jsonm.msg    = "登录失败";
                LogProvider.Error("登录", ex.StackTrace, ex.Message);
            }
            return(Json(jsonm));
        }
        /// <summary>
        /// 添加/编辑  操作
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public JsonResult ChangeSubmit(SysUser Model)
        {
            var jsonm = new ResultJson();

            jsonm.data = Model;
            var model = new SysUser();

            try
            {
                using (var db = SugarBase.GetIntance())
                {
                    if (!string.IsNullOrEmpty(Model.SysUserID))
                    {
                        model = db.Queryable <SysUser>().Where(m => m.SysUserID == Model.SysUserID).First();
                    }
                    model.SysNickName = Model.SysNickName;
                    model.SysUserName = Model.SysUserName;
                    if (!string.IsNullOrEmpty(Model.SysUserPwd))
                    {
                        model.SysUserPwd = SHACryptHelper.SHA256Encrypt(Model.SysUserPwd);;
                    }


                    if (string.IsNullOrEmpty(Model.SysUserID))
                    {
                        db.Insertable(model).ExecuteCommand();
                        jsonm.status = 200;
                    }
                    else
                    {
                        db.Updateable(model).ExecuteCommand();
                        jsonm.status = 200;
                    }
                    db.Deleteable <SysUserRole>().Where(m => m.UserID == model.SysUserID).ExecuteCommand();
                    if (Model.RoleList != null)
                    {
                        List <SysUserRole> rel_list = new List <SysUserRole>();
                        foreach (var item in Model.RoleList)
                        {
                            if (!string.IsNullOrEmpty(item.RoleID))
                            {
                                var SysUserRoleModel = new SysUserRole();
                                SysUserRoleModel.RoleID = item.RoleID;
                                SysUserRoleModel.UserID = model.SysUserID;
                                rel_list.Add(SysUserRoleModel);
                            }
                        }
                        if (rel_list.Count > 0)
                        {
                            db.Insertable(rel_list).ExecuteCommand();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogProvider.Error("编辑系统用户", ex.StackTrace, ex.Message);

                jsonm.status = 500;
                jsonm.msg    = "保存失败";
            }


            return(Json(jsonm));
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="NickName"></param>
        /// <param name="FullName"></param>
        /// <param name="UserAccount"></param>
        /// <param name="UserPassword"></param>
        /// <param name="Email"></param>
        /// <param name="Mobile"></param>
        /// <param name="Remark"></param>
        /// <param name="Status"></param>
        /// <param name="State"></param>
        /// <param name="Gender"></param>
        /// <returns></returns>
        public JsonResult ChangeSubmit(UserInfo Model)
        {
            var      jsonm  = new ResultJson();
            UserInfo umodel = new UserInfo();
            UserInfo rmodel = new UserInfo();

            try
            {
                using (var db = SugarBase.GetIntance())
                {
                    if (!string.IsNullOrEmpty(Model.UserID))
                    {
                        umodel = db.Queryable <UserInfo>().Where(m => m.UserID == Model.UserID).First();
                    }
                    if (umodel == null)
                    {
                        umodel = new UserInfo();
                    }

                    if (!string.IsNullOrEmpty(umodel.UserAccount))
                    {
                        if (string.IsNullOrEmpty(Model.UserAccount))
                        {
                            Model.UserAccount = umodel.UserAccount;
                        }

                        if (umodel.UserAccount != Model.UserAccount)
                        {
                            Model.UserAccount = umodel.UserAccount;
                        }
                    }
                    var UserAccount2 = "";
                    if (string.IsNullOrEmpty(Model.UserAccount))
                    {
                        UserAccount2      = GetUserAccount(9, true, false, false);
                        Model.UserAccount = "zkey" + UserAccount2;
                    }

                    umodel.UserAccount = Model.UserAccount;
                    rmodel.UserAccount = Model.UserAccount;


                    if (!string.IsNullOrEmpty(Model.UserPassword))
                    {
                        rmodel.UserPassword = SHACryptHelper.SHA256Encrypt(Model.UserPassword);
                    }
                    else if (string.IsNullOrEmpty(rmodel.UserID))
                    {
                        jsonm.status = 500;
                        jsonm.msg    = "新添加用户,密码不能为空";
                        return(Json(jsonm));
                    }


                    umodel.FullName = Model.FullName;
                    umodel.Email    = Model.Email;
                    umodel.Mobile   = Model.Mobile;
                    umodel.Gender   = Model.Gender;
                    umodel.Remark   = Model.Remark;
                    umodel.Status   = Model.Status;


                    //每个站点对应的用户信息

                    var userCount = 0;
                    if (string.IsNullOrEmpty(Model.UserID))
                    {
                        userCount = db.Queryable <UserInfo>().Where(m => m.Mobile == rmodel.Mobile || m.Email == rmodel.Email).Count();

                        if (userCount <= 0)
                        {
                            umodel.CreateTime = DateTime.Now;

                            db.Insertable(umodel).ExecuteCommand();

                            jsonm.status = 200;
                        }
                        else
                        {
                            jsonm.status = 500;
                            jsonm.msg    = "手机号或邮箱已存在";
                        }
                    }
                    else
                    {
                        userCount = db.Queryable <UserInfo>().Where(m => (m.Mobile == rmodel.Mobile || m.Email == rmodel.Email) && m.UserID == rmodel.UserID).Count();
                        if (userCount > 1)
                        {
                            jsonm.status = 500;
                            jsonm.msg    = "用户已存在";
                        }
                        else
                        {
                            db.Updateable(umodel).ExecuteCommand();

                            jsonm.status = 200;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogProvider.Error("编辑用户", ex.StackTrace, ex.Message);

                jsonm.status = 500;
                jsonm.msg    = ex.Message;
            }
            return(Json(jsonm));
        }