public function saveAction($network_domain) { $conn = $this->get('we_data_access'); $conn_im = $this->get('we_data_access_im'); $userinfo = $this->get('security.context')->getToken()->getUser(); $logger = $this->get("logger"); $eno = $userinfo->getEno(); $login_account = $userinfo->getUsername(); $MicroAccountMgr = new MicroAccountMgr($conn, $conn_im, $userinfo, $logger, $this->container); $getRequest = $this->getRequest(); //$session = $this->get('session'); $filename120 = $getRequest->get("logo_path_big"); $filename48 = $getRequest->get("logo_path"); $filename24 = $getRequest->get("logo_path_small"); $dm = $this->get('doctrine.odm.mongodb.document_manager'); //if (!empty($filename120)) $filename120= $this->saveFile($filename120,$dm); //if (!empty($filename48)) $filename48= $this->saveFile($filename48,$dm); //if (!empty($filename24)) $filename24= $this->saveFile($filename24,$dm); //$session->remove("avatar_big"); //$session->remove("avatar_middle"); //$session->remove("avatar_small"); $factory = $this->get('security.encoder_factory'); $micro_id = $getRequest->get("id"); $number = $getRequest->get('micro_number'); $name = $getRequest->get('micro_name'); $type = $getRequest->get('type'); $introduction = $getRequest->get('introduction'); $concern_approval = $getRequest->get('concern_approval'); $salutatory = $getRequest->get('salutatory'); $level = $getRequest->get('send_status'); $password = $getRequest->get('password'); $micro_use = $getRequest->get('micro_use'); $appid = Utils::getAppid($eno, $login_account); $appkey = Utils::getAppkey(); if (empty($micro_id)) { $dataexec = $MicroAccountMgr->register($micro_id, $number, $name, $type, $micro_use, $introduction, $concern_approval, $salutatory, $level, $password, $filename48, $filename120, $filename24, $factory, $dm, $appid); } else { $dataexec = $MicroAccountMgr->register($micro_id, $number, $name, $type, $micro_use, $introduction, $concern_approval, $salutatory, $level, $password, $filename48, $filename120, $filename24, $factory, $dm); } $r = array("success" => false); if ($dataexec) { $r["success"] = true; if (empty($micro_id)) { try { $sql = "insert into we_appcenter_apps(appid,appkey,appname,state,appdeveloper,appdesc,apptype) values(?,?,?,?,?,?,?);"; $para = array($appid, $appkey, $name, 1, $eno, $name, '00'); $data = $conn->ExecSQL($sql, $para); } catch (Exception $e) { $this->get('logger')->err($e->getMessage()); } } } else { $r["msg"] = "帐号已经被使用"; } return $this->res(json_encode($r), 'text/html'); }
public function savemicroaccountAction($network_domain) { $conn = $this->get('we_data_access'); $conn_im = $this->get('we_data_access_im'); $userinfo = $this->get('security.context')->getToken()->getUser(); $logger = $this->get("logger"); $MicroAccountMgr = new MicroAccountMgr($conn, $conn_im, $userinfo, $logger, $this->container); $getRequest = $this->getRequest(); //$session = $this->get('session'); $filename120 = $getRequest->get("logo_path_big"); $filename48 = $getRequest->get("logo_path"); $filename24 = $getRequest->get("logo_path_small"); $dm = $this->get('doctrine.odm.mongodb.document_manager'); //if (!empty($filename120)) $filename120= $this->saveFile($filename120,$dm); //if (!empty($filename48)) $filename48= $this->saveFile($filename48,$dm); //if (!empty($filename24)) $filename24= $this->saveFile($filename24,$dm); //$session->remove("avatar_big"); //$session->remove("avatar_middle"); //$session->remove("avatar_small"); $factory = $this->get('security.encoder_factory'); $micro_id = $getRequest->get("id"); $number = $getRequest->get('micro_number'); $name = $getRequest->get('micro_name'); $type = $getRequest->get('type'); $introduction = $getRequest->get('introduction'); $concern_approval = $getRequest->get('concern_approval'); //var_dump($concern_approval);return; $salutatory = $getRequest->get('salutatory'); $level = $getRequest->get('send_status'); $password = $getRequest->get('password'); $micro_use = $getRequest->get('micro_use'); //var_dump(1222); $dataexec = $MicroAccountMgr->register($micro_id, $number, $name, $type, $micro_use, $introduction, $concern_approval, $salutatory, $level, $password, $filename48, $filename120, $filename24, $factory, $dm); //$dataexec =$MicroAccountMgr->register($request,"","",""); $r = array("success" => false); //var_dump($dataexec); if ($dataexec) { $r["success"] = true; //$r["id"] = $dataexec; //$r["logo_path"] = $this->container->getParameter('FILE_WEBSERVER_URL').$filename120; } else { $r["msg"] = "帐号已经被使用"; } return $this->res(json_encode($r), 'text/html'); }
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); }