示例#1
0
        // GET: Wo
        public ActionResult Index(string userId, string counts, string companyId)

        {
            log.AppenLog("我看看22");
            try
            {
                string userID      = "";
                string CompanyId   = "";
                string user_ticket = "";//成员票据,通过这个得到登陆进来的人的详情信息
                #region 得到userid和公司id
                //当是从别的页面回来时
                if (!string.IsNullOrWhiteSpace(userId))
                {
                    userID = Base64MIMA.JIE(userId);
                }
                if (!string.IsNullOrWhiteSpace(companyId))
                {
                    CompanyId = Base64MIMA.JIE(companyId);
                }
                if (userID == "")
                {
                    //通过code得到userid
                    string code1 = Request["code"];
                    if (code1 != "")
                    {
                        Tuple <bool, UserInfo> tu2 = BonusHelper.AccessTokenHelper.GetWechatUserInfo2(code1);//第三方应用
                        if (tu2.Item1 || Session["aaa"] != null)
                        {
                            if (Session["aaa"] == null)
                            {
                                log.AppenLog("if");
                                userID         = tu2.Item2.UserId;//得到userid
                                Session["aaa"] = userID;
                                // c.Value = tu2.Item2;
                            }
                            else
                            {
                                log.AppenLog("else");
                                userID = Session["aaa"].ToString();
                                //userid = c.Value;
                            }
                        }

                        try
                        {
                            userID      = userID.Replace('"', ' ');
                            userID      = userID.Trim();
                            CompanyId   = tu2.Item2.CorpId;
                            user_ticket = tu2.Item2.user_ticket;
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    else
                    {
                        //code为空,跳到错误页面
                        return(Redirect("/ErrorPage/Index"));
                    }
                }

                #endregion

                userID    = "lzc";
                CompanyId = "wx512ad5972960e003";
                //加密公司id和userid
                log.AppenLog("登陆进来userid:" + userId);
                ViewBag.CompanyID = Base64MIMA.JIA(CompanyId);
                ViewBag.userID    = Base64MIMA.JIA(userID);
                //工号
                ViewBag.SuserId = userID;
                #region 判断公司是否在有效期
                //在:看登陆进来的人是否是某个公司的负责人,如果是的话就把他的联系方式等填到相关公司表里,不是直接进入后台
                //不在:提示已经过了有效期,需要联系我们来审核
                string    sqlstr            = string.Format($"exec Proc_Wo 'IsValidComoany','{CompanyId}'");
                DataTable dt_IsValidComoany = sql.GetDataTableCommand(sqlstr);
                if (dt_IsValidComoany?.Rows.Count > 0)
                {
                    //通过user_ticket得到详细信息
                    string strResult = AccessTokenHelper.GetUserDetail2(user_ticket);
                    log.AppenLog("页面成员信息:" + strResult);
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(UserDetials));
                    MemoryStream ms  = new MemoryStream(Encoding.UTF8.GetBytes(strResult));
                    UserDetials  obj = (UserDetials)ser.ReadObject(ms);
                    //判断是否是某个公司的负责人
                    string    sqlstr2 = string.Format($"select * from Company where CompanyPrincipal='{userID}'");
                    DataTable dt2     = sql.GetDataTableCommand(sqlstr2);
                    if (dt2?.Rows.Count > 0)
                    {
                        //是某个公司负责人==>将他的信息放到公司列表里面去
                        string CompanyPhone = "";
                        string CompanyEmail = "";
                        string upCom        = "";
                        for (int i = 0; i < dt2?.Rows.Count; i++)
                        {
                            if (dt2.Rows[i]["CompanyPhone"].ToString() == "" || dt2.Rows[i]["CompanyEmail"].ToString() == "")
                            {
                                CompanyPhone = obj.mobile;
                                CompanyEmail = obj.email;
                                upCom       += string.Format($" update Company set CompanyPhone='{CompanyPhone}' where CompanyID={dt2.Rows[i]["CompanyID"].ToString()}");
                            }
                        }

                        if (upCom != "")
                        {
                            sql.EditDataCommand(upCom);
                        }
                    }
                    //更新对应人的信息
                    try
                    {
                        string py     = Pinyin.GetInitials(obj.name);                //简拼
                        string pinyin = Pinyin.GetPinyin(obj.name).Replace(" ", ""); //全拼
                        string upEmp  = string.Format($"exec Proc_Wo 'UpdateTouXiang','{obj.corpid}','{obj.userid}','{obj.avatar}','{obj.mobile}','{obj.email}','{pinyin}','{py}',{obj.gender}");
                        log.AppenLog("更新人员信息:" + upEmp);
                        string info_upEmp = sql.EditDataCommand(upEmp);
                        if (info_upEmp != "0")
                        {
                            return(Content("<script>alert('获取个人信息失败');history.go(-1);</script>"));
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                else
                {
                    //return Content("<script>alert('您的使用期限已过,请联系我们!8888888');history.go(-1);</script>");
                    return(Redirect("/Wo/EndIndex"));
                }
                #endregion

                #region 个人信息与个人奖金
                string  infosql = string.Format($"exec proc_Main 'SelectEmpDetialWo','{userID}','','{CompanyId}'");
                DataSet info    = sql.GetDataSetCommand(infosql);
                if (info?.Tables.Count > 0)
                {
                    //个人信息
                    if (info?.Tables[0].Rows.Count > 0)
                    {
                        //是否位超级管理员
                        if (info.Tables[0].Rows[0]["RoleID"].ToString() == "8EA2CC5C-308D-4538-A9D8-FCAD7CA6FEB0")
                        {
                            ViewBag.chaoji = 1;
                        }
                        else
                        {
                            ViewBag.chaoji = 0;
                        }

                        ViewBag.info = info.Tables[0];
                    }
                    else
                    {
                        ViewBag.info   = null;
                        ViewBag.chaoji = 0;
                    }
                    //个人奖金
                    if (info?.Tables[1].Rows.Count > 0)
                    {
                        ViewBag.SumMoney = info.Tables[1].Rows[0][0];
                    }
                    else
                    {
                        ViewBag.SumMoney = "0.00";
                    }
                }
                else
                {
                    ViewBag.info   = null;
                    ViewBag.chaoji = 0;
                }

                #endregion

                #region 部门奖金
                string    isDepartPri = string.Format($"exec proc_Main 'SelectDepJIangjin','{userID}','','{CompanyId}'");
                DataTable dss         = sql.GetDataTableCommand(isDepartPri);
                if (dss?.Rows.Count > 0)
                {
                    ViewBag.depSumMoney = dss;
                }
                else
                {
                    ViewBag.depSumMoney = null;
                }
                //string isDepartPri = string.Format("SELECT DepartID FROM dbo.Depart WHERE DepartPrincipal='{0}'", userID);
                //                string isDepartPri = string.Format("SELECT DepartID FROM dbo.Depart WHERE DepartPrincipal='{0}' AND CompanyID='{1}'", userID, CompanyId);
                //                DataTable dss = sql.GetDataTableCommand(isDepartPri);
                //                if (dss.Rows.Count > 0)
                //                {
                //                    //是部门负责人
                //                    //ViewBag.isDepartPri = "youarePri";
                //                    //部门奖金
                //                    string sqlDepart = string.Format(@"SELECT DepartID,DepartName,ISNULL(EarMoney,'0.00') Earmoney,EarMan FROM  dbo.Depart d  LEFT JOIN
                //(SELECT  SUM(EarMoney) EarMoney ,EarMan   FROM dbo.BonusData2 WHERE BonusType=0 AND IsGet=0 GROUP BY EarMan )
                // b ON d.DepartID=b.EarMan  WHERE   DepartPrincipal='{0}'  and CompanyID='{1}'", userID, CompanyId);
                //                    DataTable DepartName = sql.GetDataTableCommand(sqlDepart);
                //                    if (DepartName.Rows.Count > 0)
                //                    {

                //                        ViewBag.depSumMoney = DepartName;
                //                    }
                //                    else
                //                    {
                //                        ViewBag.depSumMoney = null;
                //                    }
                //                }
                //                else
                //                {
                //                    //ViewBag.isDepartPri = null;
                //                }
                #endregion

                #region 奖金项
                string isitp = string.Format(@"SELECT A.BonusItemID,A.BIName,RM,IM FROM (
SELECT RuleData.BonusItemID,BIName,SUM(RemainMoney)RM FROM dbo.RuleData 
INNER JOIN dbo.BonusItem ON BonusItem.BonusItemID = RuleData.BonusItemID
WHERE  RuleData.BonusItemID IN (SELECT BonusItemID FROM dbo.BonusImpower WHERE BIState=0 AND EmpID='{0}') AND CompanyID='{2}'
AND GETDATE()<EndDate
GROUP BY RuleData.BonusItemID,BIName) AS A
LEFT JOIN 
(SELECT b2.BonusItemID,BIName,SUM(b1.RemainMoney) IM FROM dbo.BonusImpower  b1
INNER JOIN dbo.BonusItem b2 ON b2.BonusItemID = b1.BonusItemID 
WHERE BIState=0 AND EmpID = '{1}' AND (ImpowerDate >= DATEADD(MM, DATEDIFF(MM, 0, GETDATE()), 0) and IsValid=0)
GROUP BY b2.BonusItemID, BIName) AS B ON A.BonusItemID=B.BonusItemID AND A.BIName=B.BIName", userID, userID, CompanyId);

                DataTable itp = sql.GetDataTableCommand(isitp);
                if (itp?.Rows.Count > 0)
                {
                    ViewBag.itp = itp;
                }
                else
                {
                    ViewBag.itp = null;
                }
                //自己负责的奖金项
                string    isitem = string.Format("SELECT dbo.RuleData.BonusItemID,dbo.BonusItem.BIName,SUM(RemainMoney) AllMoney FROM dbo.RuleData INNER JOIN dbo.BonusItem ON BonusItem.BonusItemID = RuleData.BonusItemID WHERE BIState=0 AND CompanyID='{1}' AND BIPrincipal = '{0}' AND CONVERT(VARCHAR(30), GETDATE(), 102) < EndDate GROUP BY dbo.RuleData.BonusItemID, dbo.BonusItem.BIName", userID, CompanyId);
                DataTable item   = sql.GetDataTableCommand(isitem);
                if (item?.Rows.Count > 0)
                {
                    for (int i = 0; i < item?.Rows.Count; i++)
                    {
                        Session["shit" + i] = sql.GetDataTableProcedure("proc_BonusData", item.Rows[i]["BonusItemID"].ToString(), "1");
                    }
                    ViewBag.item = item;
                }
                else
                {
                    ViewBag.item = null;
                }
                //查自己有没有奖金发放权限
                string    sqlsq = string.Format($@"
SELECT b2.BonusItemID, BIName, SUM(b1.RemainMoney) IM FROM dbo.BonusImpower  b1
INNER JOIN dbo.BonusItem b2 ON b2.BonusItemID = b1.BonusItemID
WHERE BIState = 0 AND EmpID = '{userID}' AND(ImpowerDate >= DATEADD(MM, DATEDIFF(MM, 0, GETDATE()), 0) and IsValid = 0)
GROUP BY b2.BonusItemID, BIName");
                DataTable dtsq  = sql.GetDataTableCommand(sqlsq);
                ViewBag.counts = dtsq.Rows.Count + item.Rows.Count;
                ViewBag.count  = Base64MIMA.JIA((dtsq.Rows.Count + item.Rows.Count).ToString());
                #endregion

                InitJsapi(Base64MIMA.JIA(CompanyId));
            }
            catch (Exception ex)
            {
                log.AppenLog("woIndex错误:" + ex.Message);
                return(Redirect("/ErrorPage/Index"));
            }
            return(View());
        }
示例#2
0
        /// <summary>
        /// 同步员工
        /// </summary>
        /// <param name="compid">加密后的公司id</param>
        /// <returns></returns>
        public ActionResult SelectEmp(string compid)
        {
            string accecctoken = GetQiyeToken.GetQiyeAttoken(compid);

            //应用须拥有指定部门的查看权限。
            //得到部门信息
            string    sqlstr   = string.Format("select * from Depart where PID=0 and CompanyID='{0}'", Base64MIMA.JIE(compid));
            DataTable dt       = sql.GetDataTableCommand(sqlstr);
            string    sqlUser2 = string.Format("select * from Employee where CompanyID='{0}'", Base64MIMA.JIE(compid));
            DataTable dtUser2  = sql.GetDataTableCommand(sqlUser2);

            if (dt?.Rows.Count > 0)
            {
                int    a       = 0;
                string sqlstr2 = "";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    a++;
                    int    depId     = int.Parse(dt.Rows[i]["DepartID"].ToString());
                    string url       = $"https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={accecctoken}&department_id={depId}&fetch_child=1";
                    string strResult = httpHelp.GetWebRequest(url);
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(strResult) && strResult.Substring(0, 1) == "{" && strResult.Substring(strResult.Length - 1, 1) == "}")
                        {
                            WechatReturnUser wrd = JSON.parse <WechatReturnUser>(strResult);
                            if (wrd.errcode == "0")
                            {
                                List <WechatUserList> listUser = wrd.userlist;


                                if (listUser.Count > 0)
                                {
                                    #region 如果微信那边没有,数据库中有,就把数据库中的删掉
                                    if (dtUser2.Rows.Count > 0)
                                    {
                                        var vupdel = (from s in dtUser2.AsEnumerable()
                                                      where !listUser.Any(x => x.userid == s.Field <string>("EmpID") && Base64MIMA.JIE(compid) == s.Field <string>("CompanyID"))
                                                      select s).ToList();
                                        if (vupdel.Count > 0)
                                        {
                                            foreach (var item in vupdel)
                                            {
                                                sqlstr2 += string.Format($"delete Employee where EmpID='{item.Field<string>("EmpID")}' and CompanyID='{Base64MIMA.JIE(compid)}' ");
                                            }
                                        }
                                    }


                                    #endregion
                                    foreach (var item in listUser)
                                    {
                                        //比较数据库中是否又这个人
                                        string      sqlUser    = string.Format($"select * from Employee where EmpID ='{item.userid}' and CompanyID='{Base64MIMA.JIE(compid)}'");
                                        DataTable   dtUser     = sql.GetDataTableCommand(sqlUser);
                                        string      url2       = $"https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token={accecctoken}&userid={item.userid}";
                                        string      strResult2 = httpHelp.GetWebRequest(url2);
                                        UserDetials ud         = JSON.parse <UserDetials>(strResult2);
                                        if (dtUser?.Rows.Count > 0)
                                        {
                                            //数据库又这个人不用同步
                                            if (ud.errcode == 0)
                                            {
                                                #region  微信那边的信息有没有更改,以微信为准
                                                int b = 0;

                                                bool Isok = int.TryParse(dtUser.Rows[0]["DepartID"].ToString(), out b);//部门id
                                                if (Isok)
                                                {
                                                    b = int.Parse(dtUser.Rows[0]["DepartID"].ToString());
                                                }
                                                if (ud.name != dtUser.Rows[0]["Name"].ToString() || item.department[0] != b)
                                                {
                                                    string JX = Pinyin.GetInitials(ud.name);                //简写
                                                    string QP = Pinyin.GetPinyin(ud.name).Replace(" ", ""); //全拼
                                                    sqlstr2 += string.Format($"update Employee set SpellQP='{QP}',SpellJX='{JX}',Name='{ud.name}',DepartID={item.department[0]} where EmpID='{ud.userid}' and CompanyID='{Base64MIMA.JIE(compid)}' ");
                                                }
                                                #endregion
                                            }
                                        }
                                        else
                                        {
                                            //获取这个人的详情信息

                                            if (ud.errcode == 0)
                                            {
                                                //循环添加到数据库中
                                                string JX = Pinyin.GetInitials(item.name);                //简写
                                                string QP = Pinyin.GetPinyin(item.name).Replace(" ", ""); //全拼
                                                sqlstr2 += $@"INSERT INTO dbo.Employee
                                            (EmpID, Name ,Sex,EmpTel ,EmpEmail 
                                            ,IsOut ,SpellJX,SpellQP ,DepartID,CompanyID,EmpPhotos)VALUES 
                                            ('{ud.userid}','{ud.name}',{ud.gender},'{ud.mobile}','{ud.email}'
                                             ,{0},'{JX}','{QP}','{item.department[0]}','{Base64MIMA.JIE(compid)}','{ud.avatar}') ";
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                return(Content("error:" + strResult));
                            }
                        }
                        else
                        {
                            return(Content("error:" + strResult));
                            //return new ReturnJson() { errmsg = string.IsNullOrWhiteSpace(strResult) ? "error" : strResult };
                        }
                    }
                    catch (Exception ex)
                    {
                        //log.AppenLog("从微信中读取数据失败:" + ex.Message);
                        return(Content("从微信中读取数据失败:" + ex.Message));
                    }
                }
                if (a == 0)
                {
                    return(Content("暂无需要同步的信息"));
                }
                else
                {
                    if (sqlstr2 == "")
                    {
                        return(Content("数据一致,不需要同步"));
                    }
                    string num = sql.EditDataCommand(sqlstr2);
                    if (num == "0")
                    {
                        return(Content("ok"));
                    }
                    else
                    {
                        return(Content("同步失败"));
                    }
                }
            }
            else
            {
                return(Content("请先同步部门"));
            }
        }