Пример #1
0
 public function updateStaffAction()
 {
     $da = $this->get("we_data_access");
     $da_im = $this->get('we_data_access_im');
     $request = $this->getRequest();
     $state = $request->get("state");
     $im_deptid = $request->get("dept_id");
     //将im的部门id转化为sns里的部门id
     $deptInfo = $this->getDeptInfo($im_deptid);
     $sns_deptid = $deptInfo["deptid"];
     $login_account = $request->get("login_account");
     $e_mail = $request->get("e_mail");
     $nick_name = $request->get("nick_name");
     $password = $request->get("password");
     $sex = $request->get("sex");
     $duty = $request->get("duty");
     $duty = empty($duty) ? null : $duty;
     $mobile = $request->get("mobile");
     $mobile = empty($mobile) ? null : $mobile;
     $success = true;
     $msg = "";
     //判断手机号正误
     if (!empty($mobile)) {
         if (!Utils::validateMobile($mobile)) {
             $result = array("success" => false, "msg" => "手机账号格式错误!");
             $response = new Response(json_encode($result));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         } else {
             $sql = "";
             $para = array();
             if ($state == "add") {
                 $sql = "select count(*) number from we_staff where mobile_bind=?;";
                 array_push($para, (string) $mobile);
             } else {
                 $sql = "select count(*) number from we_staff where mobile_bind=? and login_account!=?;";
                 array_push($para, (string) $mobile, $login_account);
             }
             try {
                 $ds = $da->GetData("table", $sql, $para);
                 if ($ds && $ds["table"]["recordcount"] > 0) {
                     if ((int) $ds["table"]["rows"][0]["number"] > 0) {
                         $result = array("success" => false, "msg" => "已存在该手机号码!");
                         $response = new Response(json_encode($result));
                         $response->headers->set('Content-Type', 'text/json');
                         return $response;
                     }
                 }
             } catch (\Exception $e) {
                 $this->get("logger")->err($e->getMessage());
             }
         }
     }
     $user = $this->get('security.context')->getToken()->getUser();
     $deptMgr = new \Justsy\BaseBundle\Management\Dept($da, $da_im, $this->container);
     $staffMgr = new \Justsy\BaseBundle\Management\Staff($da, $da_im, $login_account, $this->container->get("logger"), $this->container);
     if ($state == "add") {
         if ($staffMgr->checkUser($mobile)) {
             $result = array("success" => false, "msg" => "用户账号已存在,请重新输入!");
             $response = new Response(json_encode($result));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         }
         //获得ldap_uid
         $login_array = explode("@", $login_account);
         if (count($login_array) < 2) {
             continue;
         }
         $ldap_uid = $login_array[0];
         //注册用户账号
         $register = new \Justsy\BaseBundle\Controller\ActiveController();
         $register->setContainer($this->container);
         $parameter = array("account" => $login_account, "realName" => $nick_name, "passWord" => $password, "ldap_uid" => $ldap_uid, "eno" => $user->eno, "ename" => $user->ename, "isNew" => '0', "mailtype" => "1", "import" => '1', "isSendMessage" => "N", "mobile" => $mobile, "duty" => $duty, "deptid" => $sns_deptid, "mutual" => "Y");
         $result = $register->doSave($parameter);
         if ($result["returncode"] == "0000") {
             $staffdata = $staffMgr->getInfo();
             //成功后统计人员
             $sql = "call dept_emp_stat(?)";
             $da_im->ExecSQL($sql, array((string) $staffdata["fafa_jid"]));
             //自动关注服务号
             $servicerMgr = new \Justsy\BaseBundle\Management\Service($this->container);
             $parameter = array("eno" => $user->eno, "deptid" => $im_deptid, "login_account" => $login_account);
             $servicerMgr->atten_service($parameter);
             $revJids = $staffMgr->getFriendAndColleagueJid();
             Utils::sendImMessage($user->fafa_jid, implode(",", $revJids), "newstaff", json_encode($staffMgr->getinfo()), $this->container, "", "", false, Utils::$systemmessage_code);
         } else {
             $success = false;
             $msg = "添加用户账号失败:" . $result["msg"];
         }
         $result = array("success" => $success, "msg" => $msg);
         $response = new Response(json_encode($result));
         $response->headers->set('Content-Type', 'text/json');
         return $response;
     } else {
         $staffinfo = $staffMgr->getInfo();
         $deptinfo = $deptMgr->getinfo($staffinfo["dept_id"]);
         //判断是否更改了性别
         if ($sex == $staffinfo["sex_id"]) {
             $sex = null;
         }
         //判断是否更改了职务
         if ($duty == $staffinfo["duty"]) {
             $duty = null;
         }
         //判断是否更改了姓名
         if ($nick_name == $staffinfo["nick_name"]) {
             $nick_name = null;
         }
         //判断是否更新了部门
         if ($sns_deptid == $deptinfo["dept_id"]) {
             $sns_deptid = null;
         }
         //判断是否更新了手机
         if ($mobile == $staffinfo["mobile_bind"]) {
             $mobile = null;
         }
         $uResult = $staffMgr->checkAndUpdate($nick_name, $mobile, $sns_deptid, $duty, null, $sex, null, $e_mail);
         $u_staff = null;
         $factory = null;
         //判断是否修改了密码
         if (!empty($password)) {
             $u_staff = new Staff($da, $da_im, $login_account, $this->get('logger'), $this->container);
             $factory = $this->get('security.encoder_factory');
             $targetStaffInfo = $u_staff->getInfo();
             $re = $u_staff->changepassword($targetStaffInfo["login_account"], $password, $factory);
             if ($re) {
                 //给自己发送一个staff-changepasswod的出席,通知在线客户端密码发生修改,需要新密码重新登录
                 Utils::sendImPresence($user->fafa_jid, $targetStaffInfo["fafa_jid"], "staff-changepasswod", "staff-changepasswod", $this->container, "", "", false, Utils::$systemmessage_code);
             }
         }
         //判断是否修改了帐号
         if ($e_mail != $login_account) {
             //判断邮件是否存在
             if (empty($u_staff)) {
                 $u_staff = new Staff($da, $da_im, $login_account, $this->get('logger'), $this->container);
             }
             if (empty($factory)) {
                 $factory = $this->get('security.encoder_factory');
             }
             $u_staff->changeLoginAccount($e_mail, $factory);
         }
         try {
             $revJids = $staffMgr->getFriendAndColleagueJid();
             if ($uResult && !empty($sns_deptid)) {
                 //部门变更时,需要通知手机端更新原部门和新部门数据
                 Utils::sendImMessage("", implode(",", $revJids), "staff-changedept", json_encode($deptinfo), $this->container, "", "", false, Utils::$systemmessage_code);
                 Utils::sendImMessage("", implode(",", $revJids), "staff-changedept", json_encode($deptMgr->getinfo($sns_deptid)), $this->container, "", "", false, Utils::$systemmessage_code);
                 $old_fafa_deptid = $deptinfo["fafa_deptid"];
                 $fafa_jid = $staffinfo["fafa_jid"];
                 //取消关注服务号
                 $servicerMgr = new \Justsy\BaseBundle\Management\Service($this->container);
                 $parameter = array("eno" => $user->eno, "deptid" => $old_fafa_deptid, "login_account" => $login_account);
                 $servicerMgr->cancel_atten($parameter);
                 //自动关注服务号
                 $parameter = array("eno" => $user->eno, "deptid" => $im_deptid, "login_account" => $login_account);
                 $servicerMgr->atten_service($parameter);
             }
         } catch (\Exception $e) {
             $this->get("logger")->err($e->getMessage());
             $success = false;
             $msg = "修改人员信息失败!";
         }
     }
     $result = array("success" => $success, "msg" => $msg);
     $response = new Response(json_encode($result));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
 public function deleteDeptAction()
 {
     $da = $this->get("we_data_access");
     $da_im = $this->get("we_data_access_im");
     $request = $this->getRequest();
     $deptid = $request->get("dept_id");
     //此处为fafa_deptid
     //返回参数
     $success = true;
     $msg = "";
     try {
         //判断是否有下级部门
         $sql = "select count(*) number from im_base_dept where pid=?";
         $ds = $da_im->GetData("table", $sql, array((string) $deptid));
         if ($ds && $ds["table"]["recordcount"] > 0) {
             $count = $ds["table"]["rows"][0]["number"];
             if ($count > 0) {
                 $success = false;
                 $msg = "不能删除具有下级部门的部门!";
             } else {
                 $sql = "select count(*) number from im_employee where deptid=?;";
                 $ds = $da_im->GetData("table", $sql, array((string) $deptid));
                 if ($ds && $ds["table"]["recordcount"] > 0) {
                     $count = $ds["table"]["rows"][0]["number"];
                     if ($count > 0) {
                         $success = false;
                         $msg = "该部门底下有人员,不允许删除 !";
                     } else {
                         $deptinfo = $this->getDeptInfo($deptid);
                         $deptMrg = new \Justsy\BaseBundle\Management\Dept($da, $da_im, $this->container);
                         $deptdata = $deptMrg->getinfo($deptinfo["deptid"]);
                         //删除部门数据
                         $sql = "delete from we_department where fafa_deptid=?";
                         $da->ExecSQL($sql, array((string) $deptid));
                         //删除im部门
                         $sql_pid = "select pid from im_base_dept where deptid=?;";
                         try {
                             $ds_pid = $da_im->GetData("table", $sql_pid, array((string) $deptid));
                             if ($ds_pid && $ds_pid["table"]["recordcount"] > 0) {
                                 $deptdata["pid"] = $ds_pid["table"]["rows"][0]["pid"];
                             }
                         } catch (\Exception $e) {
                             $deptdata["pid"] = "";
                         }
                         $sql = "delete from im_base_dept where deptid=?;";
                         $da_im->ExecSQL($sql, array((string) $deptid));
                         $msg = "删除部门数据成功!";
                         $parameter = array("flag" => "all", "title" => "removeDept", "message" => json_encode($deptdata), "container" => $this->container);
                         $sendMessage = new SendMessage($da, $da_im);
                         $sendMessage->sendImMessage($parameter);
                     }
                 }
             }
         } else {
             $success = false;
             $msg = "删除部门记录失败,请重试!";
         }
     } catch (\Exception $e) {
         $success = false;
         $this->get("logger")->err($e->getMessage());
         $msg = "删除部门记录失败,请重试!";
     }
     //返回的数据
     $result = array("success" => $success, "msg" => $msg);
     $response = new Response(json_encode($result));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
Пример #3
0
 public function changeStaffDeptAction($network_domain)
 {
     $res = $this->get("request");
     $account = trim($res->get("staff"));
     $deptid = trim($res->get("deptid"));
     if (empty($account) || empty($deptid)) {
         $response = new Response(json_encode(array("s" => 0, "msg" => "人员帐号或部门不能为空")));
         $response->headers->set('Content-Type', 'text/json');
         return $response;
     }
     try {
         $da = $this->get("we_data_access");
         $da_im = $this->get('we_data_access_im');
         $accountList = explode(",", $account);
         $user = $this->get('security.context')->getToken()->getUser();
         $deptmgr = new \Justsy\BaseBundle\Management\Dept($da, $da_im);
         $deptInfo = $deptmgr->getinfo($deptid);
         if ($deptInfo != null) {
             for ($i = 0; $i < count($accountList); $i++) {
                 $staffmgr = new \Justsy\BaseBundle\Management\Staff($da, $da_im, $accountList[$i]);
                 $result_jid = $staffmgr->moveToDept($deptid, $deptInfo["fafa_deptid"]);
                 //如果是其他人员更新了自己的部门,则向被移动的人员发条消息
                 if ($user->getUsername() != $accountList[$i]) {
                     try {
                         //发送即时消息
                         $message = "你的所属部门已变更为【" . $deptInfo["dept_name"] . "】";
                         Utils::sendImMessage($user->fafa_jid, $result_jid, "资料变更", $message, $this->container, "", "", false, Utils::$systemmessage_code);
                     } catch (\Exception $e) {
                         $this->get('logger')->err($e);
                     }
                 }
             }
             $response = new Response(json_encode(array("s" => 1, "msg" => "")));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         } else {
             $response = new Response(json_encode(array("s" => 0, "msg" => "部门编号无效")));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         }
     } catch (\Exception $e) {
         $this->get("logger")->err($e);
         $response = new Response(json_encode(array("s" => 0, "msg" => "数据操作失败")));
         $response->headers->set('Content-Type', 'text/json');
         return $response;
     }
 }
Пример #4
0
 public function sendDeptPresenceAction()
 {
     //判断请求域。是wefafa或子域则不验证授权令牌
     $isWeFaFaDomain = $this->checkWWWDomain();
     $res = $this->get("request");
     $da = $this->get("we_data_access");
     if (!$isWeFaFaDomain) {
         $token = $this->checkAccessToken($res, $da);
         if (!$token) {
             $response = new Response("{\"returncode\":\"9999\",\"code\":\"err1015\",\"msg\":\"参数Appid或Openid或Access_token未指定或无效.\"}");
             $response->headers->set('Content-Type', 'text/html');
             return $response;
         }
     }
     $depts = trim($res->get("deptid"));
     if (empty($depts)) {
         $response = new Response("{\"returncode\":\"9999\",\"code\":\"err1015\",\"msg\":\"参数deptid未指定或无效.\"}");
         $response->headers->set('Content-Type', 'text/html');
         return $response;
     }
     //获取部门人员
     $depts = trim($res->get("deptid"));
     if (empty($depts)) {
         $response = new Response("{\"returncode\":\"9999\",\"code\":\"err1015\",\"msg\":\"参数deptid未指定或无效.\"}");
         $response->headers->set('Content-Type', 'text/html');
         return $response;
     }
     $cctomail = $res->get("cctomail");
     $r = "{\"returncode\" : \"0000\"}";
     $depts = explode(",", $depts);
     $deptMgr = new \Justsy\BaseBundle\Management\Dept($da, $this->get("we_data_access_im"));
     for ($pos = 0; $pos < count($depts); $pos++) {
         if (empty($depts[$pos])) {
             continue;
         }
         $staffs = $deptMgr->getAllStaffJid($depts[$pos]);
         if (count($staffs) > 0) {
             $jids = array();
             for ($i = 0; $i < count($staffs); $i++) {
                 $jids[] = $staffs[$i]["jid"];
             }
             $r = $this->sendPresence($res->get("From") . $res->get("from"), implode(",", $jids), $res->get("Title") . $res->get("title"), $res->get("Message") . $res->get("message"), $res->get("Link") . $res->get("link"), $res->get("Linktext") . $res->get("Buttons") . $res->get("linktext") . $res->get("buttons"), false, trim($res->get("type")), $cctomail);
         }
     }
     $response = new Response($r);
     $response->headers->set('Content-Type', 'text/html');
     return $response;
 }
Пример #5
0
 private function getDeptId($eno)
 {
     $deptinfo = new \Justsy\BaseBundle\Management\Dept($this->get('we_data_access'), $this->get('we_data_access_im'));
     return $deptinfo->getDefaultDept($eno);
 }
Пример #6
0
 public function createstaff($parameter)
 {
     $deploy_mode = $this->container->getParameter('deploy_mode');
     $mobile_num = $parameter['account'];
     $mobile_pwd = $parameter['password'];
     $org_pwd = $mobile_pwd;
     //原始密码
     $deptid = isset($parameter['deptid']) ? $parameter['deptid'] : "";
     $eno = isset($parameter['eno']) ? $parameter['eno'] : $this->container->getParameter('ENO');
     $nick_name = $parameter['nick_name'];
     $ldap_uid = isset($parameter["ldap_uid"]) ? $parameter["ldap_uid"] : "";
     //优先采用第三方标识做为帐号,其次使用手机号做为帐号
     $login_account = empty($ldap_uid) ? $mobile_num : $ldap_uid;
     if (empty($login_account)) {
         return Utils::WrapResultError("请输入帐号!");
     }
     if (empty($mobile_pwd)) {
         return Utils::WrapResultError("请输入密码!");
     }
     if (empty($nick_name)) {
         return Utils::WrapResultError("请输入昵称!");
     }
     if (!strpos($login_account, "@")) {
         $domain = $this->container->getParameter('edomain');
         $login_account .= "@" . $domain;
     }
     $this->account = $login_account;
     $isHd = $this->getInfo();
     if (!empty($isHd)) {
         //已经注册,直接返回
         return Utils::WrapResultOK($isHd);
     }
     if (!empty($mobile_num) && Utils::validateMobile($mobile_num)) {
         if ($this->checkUser($mobile_num)) {
             return Utils::WrapResultError("该手机号已被绑定,请解绑后重试");
         }
     }
     $da = $this->conn;
     $da_im = $this->conn_im;
     try {
         //同步人员到业务系统
         $syncurl = null;
         try {
             //判断是否需要同步到其他系统
             $syspara = new \Justsy\BaseBundle\DataAccess\SysParam($this->container);
             $syncurl = $syspara->GetSysParam('staff_sync_url', '');
         } catch (\Exception $e) {
         }
         $cacheobj = new \Justsy\BaseBundle\Management\Enterprise($da, $this->logger, $this->container);
         //获取用户认证模块
         $authConfig = $cacheobj->getUserAuth();
         if (!empty($syncurl) && !empty($authConfig)) {
             try {
                 $classname = $authConfig["ssoauthmodule"];
                 if (!empty($classname)) {
                     $parameters = array("nick_name" => $nick_name, "mobile" => $login_account, "password" => $mobile_pwd);
                     $classname = "\\Justsy\\InterfaceBundle\\SsoAuth\\Sso" . $classname;
                     $re = call_user_func(array($classname, 'createUser'), $this->container, $parameters);
                     $ldap_uid = $re["ldap_uid"];
                     //该 属性必须由对应用户认证模块的方法createUser返回
                 }
             } catch (\Exception $e) {
                 $this->get("logger")->err($e);
                 return Utils::WrapResultError($e->getMessage());
             }
         }
         if (!empty($authConfig) && empty($eno)) {
             $eno = $authConfig["ENO"];
         }
         //验证企业号
         if (!empty($eno)) {
             $enterinfo = $cacheobj->getInfo($eno);
             if ($enterinfo == null) {
                 return Utils::WrapResultError("未找到您注册的企业!");
             }
             $edomain = $enterinfo['edomain'];
         }
         if (empty($deptid)) {
             $deptinfo = new \Justsy\BaseBundle\Management\Dept($da, $da_im);
             $deptid = $deptinfo->getDefaultDept($eno);
             $fafa_deptid = $deptid["deptid"];
             $deptid = $deptid["deptid"];
         } else {
             $deptinfo = new \Justsy\BaseBundle\Management\Dept($da, $da_im);
             $deptid = $deptinfo->getinfo($deptid);
             $fafa_deptid = $deptid["deptid"];
             $deptid = $deptid["deptid"];
         }
         $auth_level = "S";
         $eno_vip = $enterinfo['vip_level'];
         $eno_level = $enterinfo['eno_level'];
         $edomain = $enterinfo['edomain'];
         $circleId = $enterinfo['circle_id'];
         //注册jid
         $jid = SysSeq::GetSeqNextValue($da, "we_staff", "fafa_jid");
         $jid .= "-" . $eno . "@" . $edomain;
         //生成密码
         $user = new UserSession($login_account, $mobile_pwd, $login_account, array("ROLE_USER"));
         $factory = $this->container->get("security.encoder_factory");
         $encoder = $factory->getEncoder($user);
         $pwd = $encoder->encodePassword($mobile_pwd, $user->getSalt());
         $mobile_pwd = DES::encrypt($mobile_pwd);
         $istester = "";
         //是否是通过万能验证码激活的测试人员
         //插入人员、圈子信息
         $sqls[] = "insert into we_staff (dept_id,login_account,eno,password,nick_name,photo_path,state_id,fafa_jid,photo_path_small,photo_path_big,openid,register_date,active_date,t_code,auth_level,mobile,mobile_bind,ldap_uid,login_source) values (?,?,?,?,?,?,?,?,?,?,?,(select register_date from we_register where login_account=?),now(),?,?,?,?,?,?)";
         $sqls[] = "insert into we_circle_staff (circle_id,login_account,nick_name) values (?,?,?)";
         $sqls[] = "update we_register set state_id='3' where login_account=?";
         $paras[] = array((string) $deptid, (string) $login_account, (string) $eno, (string) $pwd, (string) $nick_name, (string) '', (string) "1", (string) $jid, (string) '', (string) '', (string) md5($eno . $login_account), (string) $login_account, (string) $mobile_pwd, (string) $auth_level, empty($mobile_num) ? null : (string) $mobile_num, empty($mobile_num) ? null : (string) $mobile_num, (string) $ldap_uid, $istester);
         $paras[] = array((string) $circleId, (string) $login_account, (string) $nick_name);
         $paras[] = array((string) $login_account);
         $da->ExecSQLs($sqls, $paras);
         //向RBAC跟新用户身份
         //$staffRole=new \Justsy\BaseBundle\Rbac\StaffRole($da,$da_im,$this->logger);
         //$staffRole->InsertStaffRoleByCode($login_account,$auth_level.$eno_vip,$eno);
     } catch (\Exception $e) {
         $this->logger->err($e);
         return Utils::WrapResultError($e->getMessage());
     }
     //写we_im库
     $sqls = array();
     $paras = array();
     try {
         //写入人员 如果$jid_old为空执行原有逻辑,否则更新旧jid数据
         if (empty($jid_old)) {
             $sqls = array();
             $paras = array();
             $pinyin = Utils::Pinyin($nick_name);
             $employeeid = SysSeq::GetSeqNextValue($da_im, "im_employee", "employeeid");
             $sqls[] = "insert into im_employee (employeeid, deptid, loginname, password, employeename,spell) values (?, ?, ?, ?, ?,?)";
             $paras[] = array((string) $employeeid, (string) $fafa_deptid, (string) $jid, (string) $mobile_pwd, (string) $nick_name, (string) $pinyin);
             $sqls[] = "insert into users (username, password, created_at) values (?, ?, now())";
             $paras[] = array((string) $jid, (string) $mobile_pwd);
             $sqls[] = "insert into im_b_msg_read (employeeid, lastid, readdatetime) values (?, (select max(id) from im_b_msg), now())";
             $paras[] = array((string) $jid);
             $da_im->ExecSQLs($sqls, $paras);
             try {
                 $da_im->ExecSQL("call dept_emp_stat(?)", array((string) $jid));
             } catch (\Exception $e) {
             }
             $this->syncAttrsToIM();
             $jid_old = $jid;
         }
     } catch (\Exception $e) {
         $this->logger->err($e);
         return Utils::WrapResultError($e->getMessage());
     }
     //关注自己所属企业的开放的内部公众号
     $mac = new \Justsy\BaseBundle\Management\MicroAccountMgr($da, $da_im, $login_account, $this->logger, $this->container);
     $mac->attenCompanyOpenAccount();
     //自动关注当前企业的开放公众号
     $re = $this->getInfo();
     return Utils::WrapResultOK($re);
 }