コード例 #1
0
ファイル: Utils.php プロジェクト: 3116246/haolinju
 public static function resortjid($conn_im, &$staffLst)
 {
     if (empty($staffLst)) {
         return array();
     }
     if (count($staffLst) <= 1000) {
         return $staffLst;
     }
     //人员列表小于1000时,不用重排顺序
     if (empty($conn_im)) {
         throw new \Exception("未指定im库连接对象");
     }
     $online_jids = array();
     $onlinesql = "select distinct us from global_session";
     $onlinedata = $conn_im->GetData("online", $onlinesql, array());
     $onlinedata = $onlinedata["online"]["rows"];
     foreach ($onlinedata as $key => $value) {
         $online_jids[] = $value["us"];
     }
     unset($onlinedata);
     //在线的排数组前面
     $intersect = Utils::array_intersect_ex($online_jids, $staffLst);
     $diff = Utils::array_diff_ex($staffLst, $intersect);
     $staffLst = array_merge($intersect, $diff);
 }
コード例 #2
0
ファイル: GroupMgr.php プロジェクト: 3116246/haolinju
 public function addGroupEmployeeMulti($parameter)
 {
     $da_im = $this->conn_im;
     $sql = "";
     $para = array();
     $groupid = $parameter["groupid"];
     $deptid = $parameter["deptid"];
     //允许加入的部门
     $allow_jid = $parameter["allow_jid"];
     //允许加入的特定人员
     $user = $parameter["user"];
     $user_jid = $user->fafa_jid;
     $eno = $user->eno;
     $groupname = $parameter["groupname"];
     $sql = "select loginname,employeename from im_employee ";
     $condition = "";
     //取部门下的人员
     if (count($deptid) > 0) {
         $deptid = $this->getChildrenDept($eno, $deptid);
         $condition = " where deptid in(";
         for ($i = 0; $i < count($deptid); $i++) {
             $condition = $condition . "?,";
             array_push($para, (string) $deptid[$i]);
         }
         $condition = rtrim($condition, ",") . ")";
     }
     //允许人员
     if (!empty($allow_jid) && count($allow_jid) > 0) {
         $condition .= empty($condition) ? " where loginname in(" : " or loginname in(";
         for ($i = 0; $i < count($allow_jid); $i++) {
             $condition = $condition . "?,";
             array_push($para, (string) $allow_jid[$i]);
         }
         $condition = rtrim($condition, ",") . ")";
     }
     //总是将创建人员加入人员列表
     $condition .= empty($condition) ? " where loginname=?" : " or loginname=?";
     array_push($para, (string) $user_jid);
     $sql = $sql . $condition;
     $success = true;
     $msg = "";
     try {
         $ds = $da_im->GetData("table", $sql, $para);
         if ($ds && $ds["table"]["recordcount"] > 0) {
             $syspara = new \Justsy\BaseBundle\DataAccess\SysParam($this->container);
             $grouplimit = $syspara->GetSysParam('grouplimit', '1000');
             if ($ds["table"]["recordcount"] > (int) $grouplimit) {
                 return array('success' => false, 'msg' => '人数超过群成员最大限制' . $grouplimit);
             }
             $sql = "select employeeid from im_groupemployee where groupid=?";
             $old_ds = $da_im->GetData("members", $sql, array((string) $groupid));
             $oldMembers = array();
             foreach ($old_ds["members"]["rows"] as $key => $value) {
                 $oldMembers[] = $value['employeeid'];
             }
             $grouprole = "";
             $newJid = array();
             $newNick = array();
             foreach ($ds["table"]["rows"] as $key => $value) {
                 $newJid[] = $value['loginname'];
                 $newNick[$value['loginname']] = $value['employeename'];
             }
             //获取需要删除的人员。求差集
             $needSubLst = Utils::array_diff_ex($oldMembers, $newJid);
             //获取需要新加的人员
             $needJoinLst = Utils::array_diff_ex($newJid, $oldMembers);
             //获取未变动的人员
             $noticeLst = Utils::array_intersect_ex($newJid, $oldMembers);
             $sqls = array();
             foreach ($needSubLst as $key => $value) {
                 $sqls[] = 'delete from im_groupemployee where employeeid=\'' . $value . '\'';
             }
             $intSql = 'insert into im_groupemployee(employeeid,groupid,grouprole,employeenick)values';
             $values = array();
             foreach ($needJoinLst as $key => $value) {
                 if ($user_jid == $value) {
                     $grouprole = "owner";
                 } else {
                     $grouprole = "normal";
                 }
                 $values[] = '(\'' . $value . '\',\'' . $groupid . '\',\'' . $grouprole . '\',\'' . $newNick[$value] . '\')';
             }
             if (count($values) > 0) {
                 $sqls[] = $intSql . implode(',', $values);
             }
             $sqls[] = 'update im_group set number=(select count(1) from im_groupemployee where groupid=\'' . $groupid . '\') where groupid=\'' . $groupid . '\'';
             if (count($sqls) > 0) {
                 $da_im->ExecSQLs($sqls, array());
             }
             $groupinfo = $this->GetByIM($groupid);
             $groupinfo = array('groupname' => $groupinfo['groupname'], 'groupid' => $groupinfo['groupid'], 'logo' => $groupinfo['logo']);
             if (count($needSubLst) > 0) {
                 $iconUrl = $groupinfo['logo'];
                 $noticeinfo = Utils::WrapMessageNoticeinfo('你已退出企业群组 ' . $groupinfo['groupname'], $user->nick_name, null, $iconUrl);
                 $msg = Utils::WrapMessage("exit_group", $groupinfo, $noticeinfo);
                 Utils::sendImMessage($user_jid, $needSubLst, "exit_group", json_encode($msg), $this->container, "", "", false, Utils::$systemmessage_code);
             }
             if (count($needJoinLst) > 0) {
                 $iconUrl = $groupinfo['logo'];
                 $noticeinfo = Utils::WrapMessageNoticeinfo('你已受邀加入企业群组 ' . $groupinfo['groupname'], $user->nick_name, null, $iconUrl);
                 $msg = Utils::WrapMessage("join_group", $groupinfo, $noticeinfo);
                 //添加成员成功发送消息
                 Utils::sendImMessage($user_jid, $needJoinLst, "join_group", json_encode($msg), $this->container, "", "", false, '');
             }
             if (count($noticeLst) > 0) {
                 //通知这部分成员需要更新群信息
                 $noticeinfo = array();
                 $msg = Utils::WrapMessage("update_group", $groupinfo, $noticeinfo);
                 Utils::sendImMessage($user_jid, $noticeLst, "update_group", json_encode($msg), $this->container, "", "", false, '');
             }
         }
     } catch (\Exception $e) {
         $success = false;
         $msg = "";
     }
     return array("success" => $success, "msg" => $msg);
 }
コード例 #3
0
ファイル: Service.php プロジェクト: 3116246/haolinju
 public function register_service($parameter)
 {
     $nick_name = isset($parameter["name"]) ? $parameter["name"] : null;
     $micro_id = isset($parameter["micro_id"]) ? $parameter["micro_id"] : null;
     $login_account = isset($parameter["login_account"]) ? $parameter["login_account"] : null;
     $deptid = isset($parameter["deptid"]) ? $parameter["deptid"] : array();
     $fileid = isset($parameter["fileid"]) ? $parameter["fileid"] : null;
     $fileid = empty($fileid) ? null : $fileid;
     if (empty($login_account)) {
         $re = $this->serviceAccount($parameter);
         if (!empty($re)) {
             $login_account = $re['account'];
         }
     }
     //服务号密码自动生成
     $password = time();
     $staffid = isset($parameter["staffid"]) ? $parameter["staffid"] : array();
     $manager = isset($parameter["manager"]) ? $parameter["manager"] : array();
     $introduction = isset($parameter["desc"]) ? $parameter["desc"] : "";
     //简介
     $user = $parameter["user"];
     $success = true;
     $msg = "";
     $da = $this->conn;
     $type = "0";
     $micro_use = "0";
     $concern_approval = isset($parameter["concern_approval"]) ? $parameter["concern_approval"] : 1;
     //0  表示私密 1  表示开放
     $salutatory = null;
     $level = null;
     //注册服务员或修改服务号信息
     $factory = $this->container->get('security.encoder_factory');
     $dm = $this->container->get('doctrine.odm.mongodb.document_manager');
     $eno = $user->eno;
     $appid = Utils::getAppid($eno, $login_account);
     $appkey = Utils::getAppkey();
     $MicroAccountMgr = new MicroAccountMgr($this->conn, $this->conn_im, $user, $this->container->get("logger"), $this->container);
     $dataexec = $MicroAccountMgr->register($micro_id, $login_account, $nick_name, $type, $micro_use, $introduction, $concern_approval, $salutatory, $level, $password, $fileid, $fileid, $fileid, $factory, $dm, $appid);
     //修改im人员信息表
     $sqls = array();
     $paras = array();
     $fafa_jid = "";
     $staffMgr = new Staff($this->conn, $this->conn_im, $login_account, $this->container->get("logger"), $this->container);
     $ds = $staffMgr->getInfo();
     if (!empty($ds)) {
         $fafa_jid = $ds["fafa_jid"];
         $sql_im = "update im_employee set employeename=?,photo=? where loginname=?;";
         $para_im = array((string) $nick_name, (string) $fileid, (string) $fafa_jid);
         try {
             $this->conn_im->ExecSQL($sql_im, $para_im);
         } catch (\Exception $e) {
         }
     }
     //如果为修改时删除原来的相关记录
     if (!empty($micro_id)) {
         $sql = array("delete from we_service where login_account=?");
         $sql[] = "delete from we_staff_atten where atten_id=?";
         $this->conn->ExecSQLs($sql, array(array((string) $login_account), array((string) $login_account)));
         //$sql =array( "delete from im_microaccount_memebr where microaccount=?");
         //$sql[]="delete from im_microaccount_msg where microaccount=?";
         //$this->conn_im->ExecSQLs($sql,array(array((string)$fafa_jid),array((string)$fafa_jid)));
     }
     //部门的处理
     for ($j = 0; $j < count($deptid); $j++) {
         $sql = "insert into we_service(login_account,objid,`type`)values(?,?,1)";
         $para = array((string) $login_account, (string) $deptid[$j]);
         array_push($sqls, $sql);
         array_push($paras, $para);
     }
     //人员的处理
     for ($j = 0; $j < count($staffid); $j++) {
         $sql = "insert into we_service(login_account,objid,`type`)values(?,?,2)";
         $para = array((string) $login_account, (string) $staffid[$j]);
         array_push($sqls, $sql);
         array_push($paras, $para);
     }
     //管理人员的处理
     for ($j = 0; $j < count($manager); $j++) {
         $sql = "insert into we_service(login_account,objid,`type`)values(?,?,3)";
         $para = array((string) $login_account, (string) $manager[$j]);
         array_push($sqls, $sql);
         array_push($paras, $para);
     }
     try {
         $da->ExecSQLS($sqls, $paras);
         //菜单处理
         for ($j = 0; $j < count($manager); $j++) {
             $sql = "select 1 from mb_staff_menu where menu_id='service' and staff_id=?;";
             $ds = $this->conn->GetData("table", $sql, array((string) $manager[$j]));
             if ($ds && $ds["table"]["recordcount"] == 0) {
                 $sql = "insert into mb_staff_menu(staff_id,menu_id)values(?,'service');";
                 $this->conn->ExecSQL($sql, array((string) $manager[$j]));
             }
         }
         $memberSql = "select employeeid from im_microaccount_memebr where microaccount=?";
         $memberRs = $this->conn_im->getData("m", $memberSql, array((string) $fafa_jid));
         $memberList = array();
         for ($i = 0; $i < $memberRs["m"]["recordcount"]; $i++) {
             $memberList[] = $memberRs["m"]["rows"][$i]["employeeid"];
         }
         $account = $this->service_jid($login_account);
         $sqlffix = "insert into im_microaccount_memebr(employeeid,microaccount,lastreadid,subscribedate)values";
         //获取需要新加的帐号
         $needAdd = Utils::array_diff_ex($account, $memberList);
         //获取需要移除删除的帐号
         $needRemove = Utils::array_diff_ex($memberList, $account);
         //需要移除删除的帐号
         $sqls = array();
         if (count($needRemove) < 500) {
             if (count($needRemove) > 0) {
                 $this->conn_im->ExecSQL("delete from im_microaccount_memebr where employeeid in('" . implode("','", $needRemove) . "') and microaccount='" . $fafa_jid . "'", array());
             }
         } else {
             //使用另外的方式处理删除
             $keep = Utils::array_intersect_ex($account, $memberList);
             $this->conn_im->ExecSQL('delete from im_microaccount_memebr where microaccount=?', array((string) $fafa_jid));
             foreach ($keep as $key => $ac) {
                 $sqls[] = "('" . $ac . "','" . $fafa_jid . "',0,now())";
                 $paras[] = array();
                 if ($i > 0 && $i % 10000 == 0) {
                     try {
                         $this->conn_im->ExecSQL($sqlffix . implode(",", $sqls), array());
                     } catch (\Exception $e) {
                         $this->logger->err($e->getMessage());
                     }
                     $sqls = array();
                     $paras = array();
                 }
                 $i++;
             }
             if (count($sqls) > 0) {
                 try {
                     $this->conn_im->ExecSQL($sqlffix . implode(',', $sqls), array());
                 } catch (\Exception $e) {
                     $this->logger->err($e->getMessage());
                 }
             }
         }
         $sqls = array();
         $paras = array();
         $i = 0;
         //处理新增的帐号
         foreach ($needAdd as $key => $ac) {
             $sqls[] = "('" . $ac . "','" . $fafa_jid . "',0,now())";
             $paras[] = array();
             if ($i > 0 && $i % 10000 == 0) {
                 try {
                     $this->conn_im->ExecSQL($sqlffix . implode(",", $sqls), array());
                 } catch (\Exception $e) {
                     $this->logger->err($e->getMessage());
                 }
                 $sqls = array();
                 $paras = array();
             }
             $i++;
         }
         if (count($sqls) > 0) {
             try {
                 $this->conn_im->ExecSQL($sqlffix . implode(",", $sqls), array());
             } catch (\Exception $e) {
                 $this->logger->err($e->getMessage());
             }
         }
     } catch (\Exception $e) {
         $success = false;
         $msg = "更新用户信息失败!";
         $this->logger->err($e->getMessage());
     }
     return array("success" => $success, "msg" => $msg);
 }