Пример #1
0
 public function getfriendcardAction()
 {
     $re = array("returncode" => ReturnCode::$SUCCESS);
     $request = $this->getRequest();
     $uEno = "";
     $userJid = "";
     $currUser = $this->get('security.context')->getToken();
     if (!empty($currUser)) {
         $user = $currUser->getUser();
         $uEno = $user->eno;
         //当前登录人企业 号
         $userJid = $user->fafa_jid;
     } else {
         $ds = $this->getstaffinfo($request->get("Openid") . $request->get("openid"));
         if (empty($ds)) {
             $re = Utils::WrapResultError("当前操作人帐号无效");
             $response = new Response($request->get('jsoncallback') ? $request->get('jsoncallback') . "(" . json_encode($re) . ");" : json_encode($re));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         }
         $uEno = $ds["eno"];
         $userJid = $ds["jid"];
     }
     $staff = $request->get("staff");
     $ds = $this->getstaffinfo($staff);
     if (empty($ds)) {
         $re = Utils::WrapResultError("未查询到用户数据!");
     } else {
         $_source = $request->get("_source");
         //wefafa_bizproxy:业务代理
         if ($ds["eno"] != $uEno) {
             $da_im = $this->get('we_data_access_im');
             //判断该人员是否自己好友
             $dfriend = $da_im->GetData("f", "select count(1) from rosterusers where username=? and jid=? and subscription='B'", array((string) $userJid, (string) $ds["we_staff"]["rows"][0]["jid"]));
             if ($dfriend == null || count($dfriend["f"]["rows"]) == 0) {
                 $re = Utils::WrapResultError("没有权限查询该帐号的信息", ReturnCode::$NOTACCESS);
             } else {
                 if ("wefafa_bizproxy" != $_source) {
                     $re["staff_full"] = $ds;
                     $re["staff_full"]["pinyin"] = Utils::Pinyin($re["staff_full"]["nick_name"]);
                 } else {
                     $re = $ds;
                     $re["pinyin"] = Utils::Pinyin($re["nick_name"]);
                     $re["returncode"] = ReturnCode::$SUCCESS;
                 }
             }
         } else {
             if ("wefafa_bizproxy" != $_source) {
                 $re["staff_full"] = $ds;
                 $re["staff_full"]["pinyin"] = Utils::Pinyin($re["staff_full"]["nick_name"]);
             } else {
                 $re = $ds;
                 $re["pinyin"] = Utils::Pinyin($re["nick_name"]);
                 $re["returncode"] = ReturnCode::$SUCCESS;
             }
         }
     }
     $response = new Response($request->get('jsoncallback') ? $request->get('jsoncallback') . "(" . json_encode($re) . ");" : json_encode($re));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
Пример #2
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);
 }