예제 #1
0
파일: WXHelp.cs 프로젝트: jaysue/zyweb
        public QyJsonResult WX_AddTagMember(JH_Auth_UserRole Model)
        {
            var          role = new JH_Auth_RoleB().GetEntity(p => p.RoleCode == Model.RoleCode);
            QyJsonResult Ret  = new QyJsonResult();

            if (Qyinfo.IsUseWX == "Y")
            {
                string[] userList = { Model.UserName };
                int      bqid     = Int32.Parse(role.WXBQCode.ToString());
                Ret = MailListApi.AddTagMember(GetToken(), bqid, userList, null);
            }
            return(Ret);
        }
예제 #2
0
        public void REGISTERYS(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string       strXM    = P2;
            string       strPhone = P1;
            JH_Auth_User user1    = new JH_Auth_UserB().GetUserByUserName(10334, P1);

            if (user1 != null)
            {
                msg.ErrorMsg = "用户已存在";
                return;
            }
            JH_Auth_User user = new JH_Auth_User();

            user.UserName     = strPhone;
            user.mobphone     = strPhone;
            user.UserRealName = P2;
            user.UserPass     = CommonHelp.GetMD5("abc123");
            user.ComId        = 10334;
            user.BranchCode   = 1728;
            user.CRDate       = DateTime.Now;
            user.CRUser       = "******";
            user.logindate    = DateTime.Now;
            user.IsUse        = "Y";
            if (!new JH_Auth_UserB().Insert(user))
            {
                msg.ErrorMsg = "添加用户失败";
            }
            else
            {
                JH_Auth_QY QY = new JH_Auth_QYB().GetEntity(d => d.ComId == 10334);
                WXHelp     wx = new WXHelp(QY);
                wx.WX_CreateUser(user);

                //添加默认员工角色
                JH_Auth_UserRole Model = new JH_Auth_UserRole();
                Model.UserName = user.UserName;
                Model.RoleCode = 1219;
                Model.ComId    = user.ComId;
                new JH_Auth_UserRoleB().Insert(Model);
            }
        }
예제 #3
0
        /// <summary>
        /// 从企业微信同步到系统里
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void TBTXL(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            try
            {
                int bmcount = 0;
                int rycount = 0;
                if (P1 == "")
                {
                    msg.ErrorMsg = "请输入初始密码";
                    return;
                }
                WXHelp wx = new WXHelp(UserInfo.QYinfo);
                #region 更新部门
                GetDepartmentListResult bmlist = wx.WX_GetBranchList("");
                foreach (var wxbm in bmlist.department.OrderBy(d => d.parentid))
                {
                    var bm = new JH_Auth_BranchB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.WXBMCode == wxbm.id);
                    if (bm == null)
                    {
                        #region 新增部门
                        JH_Auth_Branch jab = new JH_Auth_Branch();
                        jab.WXBMCode  = int.Parse(wxbm.id.ToString());
                        jab.ComId     = UserInfo.User.ComId;
                        jab.DeptName  = wxbm.name;
                        jab.DeptDesc  = wxbm.name;
                        jab.DeptShort = int.Parse(wxbm.order.ToString());

                        if (wxbm.parentid == 0)//如果是跟部门,设置其跟部门为-1
                        {
                            jab.DeptRoot = -1;
                        }
                        else
                        {
                            var bm1 = new JH_Auth_BranchB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.WXBMCode == wxbm.parentid);
                            jab.DeptRoot = bm1.DeptCode;
                            jab.Remark1  = new JH_Auth_BranchB().GetBranchNo(UserInfo.User.ComId.Value, jab.DeptRoot);
                        }


                        new JH_Auth_BranchB().Insert(jab);
                        jab.Remark1 = new JH_Auth_BranchB().GetBranchNo(UserInfo.User.ComId.Value, jab.DeptRoot) + jab.DeptCode;
                        new JH_Auth_BranchB().Update(jab);


                        bmcount = bmcount + 1;
                        #endregion
                    }
                    else
                    {
                        //同步部门时放弃更新现有部门
                    }
                }
                #endregion

                #region 更新人员
                JH_Auth_Branch branchModel = new JH_Auth_BranchB().GetEntity(d => d.DeptRoot == -1 && d.ComId == UserInfo.User.ComId);

                GetDepartmentMemberInfoResult yg = wx.WX_GetDepartmentMemberInfo(branchModel.WXBMCode.Value);
                foreach (var u in yg.userlist)
                {
                    var user = new JH_Auth_UserB().GetUserByUserName(UserInfo.QYinfo.ComId, u.userid);
                    if (user == null)
                    {
                        #region 新增人员
                        JH_Auth_User jau = new JH_Auth_User();
                        jau.ComId        = UserInfo.User.ComId;
                        jau.UserName     = u.userid;
                        jau.UserPass     = CommonHelp.GetMD5(P1);
                        jau.UserRealName = u.name;
                        jau.Sex          = u.gender == 1 ? "男" : "女";
                        if (u.department.Length > 0)
                        {
                            int id  = int.Parse(u.department[0].ToString());
                            var bm1 = new JH_Auth_BranchB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.WXBMCode == id);
                            jau.BranchCode = bm1.DeptCode;
                            jau.remark     = bm1.Remark1.Split('-')[0];//用户得部门路径
                        }
                        jau.mailbox  = u.email;
                        jau.mobphone = u.mobile;
                        jau.zhiwu    = string.IsNullOrEmpty(u.position) ? "员工" : u.position;
                        jau.IsUse    = "Y";

                        if (u.status == 1 || u.status == 4)
                        {
                            jau.isgz = u.status.ToString();
                        }
                        jau.txurl = u.avatar;

                        new JH_Auth_UserB().Insert(jau);

                        rycount = rycount + 1;
                        #endregion

                        //为所有人增加普通员工的权限
                        JH_Auth_Role rdefault = new JH_Auth_RoleB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.isSysRole == "Y" && p.RoleName == "员工");//找到默认角色
                        if (rdefault != null)
                        {
                            JH_Auth_UserRole jaurdefault = new JH_Auth_UserRole();
                            jaurdefault.ComId    = UserInfo.User.ComId;
                            jaurdefault.RoleCode = rdefault.RoleCode;
                            jaurdefault.UserName = jau.UserName;
                            new JH_Auth_UserRoleB().Insert(jaurdefault);
                        }
                    }
                    else
                    {
                        //同步人员时放弃更新现有人员
                        #region 更新人员
                        user.UserRealName = u.name;
                        if (u.department.Length > 0)
                        {
                            int id  = int.Parse(u.department[0].ToString());
                            var bm1 = new JH_Auth_BranchB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.WXBMCode == id);
                            user.BranchCode = bm1.DeptCode;
                        }
                        user.mailbox  = u.email;
                        user.mobphone = u.mobile;
                        user.zhiwu    = string.IsNullOrEmpty(u.position) ? "员工" : u.position;
                        user.Sex      = u.gender == 1 ? "男" : "女";
                        if (u.status == 1 || u.status == 4)
                        {
                            user.IsUse = "Y";
                            user.isgz  = u.status.ToString();
                        }
                        else if (u.status == 2)
                        {
                            user.IsUse = "N";
                        }
                        user.txurl = u.avatar;

                        new JH_Auth_UserB().Update(user);
                        #endregion
                    }

                    #region 更新角色(职务)
                    if (!string.IsNullOrEmpty(u.position))
                    {
                        var r = new JH_Auth_RoleB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.RoleName == u.position);

                        if (r == null)
                        {
                            JH_Auth_Role jar = new JH_Auth_Role();
                            jar.ComId        = UserInfo.User.ComId;
                            jar.RoleName     = u.position;
                            jar.RoleDec      = u.position;
                            jar.PRoleCode    = 0;
                            jar.isSysRole    = "N";
                            jar.IsUse        = "Y";
                            jar.leve         = 0;
                            jar.DisplayOrder = 0;

                            new JH_Auth_RoleB().Insert(jar);

                            JH_Auth_UserRole jaur = new JH_Auth_UserRole();
                            jaur.ComId    = UserInfo.User.ComId;
                            jaur.RoleCode = jar.RoleCode;
                            jaur.UserName = u.userid;
                            new JH_Auth_UserRoleB().Insert(jaur);
                        }
                        else
                        {
                        }
                    }
                    #endregion
                }
                #endregion



                msg.Result1 = bmcount;
                msg.Result2 = rycount;
            }
            catch (Exception ex)
            {
                msg.ErrorMsg = ex.ToString();
            }
        }