public function mail_registerStaff($appid, $code, $eno, $stafflist) { $conn = $this->get("we_data_access"); $conn_im = $this->get("we_data_access_im"); $request = $this->getRequest(); //if(empty($appid)) return array("returncode"=>ReturnCode::$SYSERROR,"msg"=>"应用ID不能为空。"); //if(empty($code)) return array("returncode"=>ReturnCode::$SYSERROR,"msg"=>"动态授权码不能为空。"); if (empty($eno)) { return array("returncode" => ReturnCode::$SYSERROR, "msg" => "企业编号不能为空。"); } if (empty($stafflist)) { return array("returncode" => ReturnCode::$SYSERROR, "msg" => "注册人员不能为空,"); } $sql_app = "select appkey from we_appcenter_apps where appid=?"; $para_app = array($appid); $data_app = $conn->GetData("dt", $sql_app, $para_app); if ($data_app == null || count($data_app["dt"]["rows"]) == 0 || empty($data_app["dt"]["rows"][0]["appkey"])) { //return array("returncode"=>ReturnCode::$SYSERROR,"msg"=>"应用ID不正确。"); } // $appkey=$data_app["dt"]["rows"][0]["appkey"]; // if(strtolower($code)!=strtolower(MD5($appid.$appkey))){ // //return array("returncode"=>ReturnCode::$SYSERROR,"msg"=>"动态授权码不正确。"); // } //判断企业是否存在 $sql_eno = "select a.eno,a.eno_level,a.create_staff,b.auth_level,a.sys_manager,a.ename from we_enterprise a left join we_staff b on a.create_staff=b.login_account where a.eno=?"; $para_eno = array($eno); $data_eno = $conn->GetData("dt", $sql_eno, $para_eno); if ($data_eno == null || count($data_eno["dt"]["rows"]) == 0 || empty($data_eno["dt"]["rows"][0]["eno"])) { return array("returncode" => ReturnCode::$SYSERROR, "msg" => "企业编号不正确。"); } $stafflist = json_decode($stafflist, true); $create_staff = $data_eno["dt"]["rows"][0]["create_staff"]; if (empty($stafflist)) { return array("returncode" => ReturnCode::$SYSERROR, "msg" => "注册人员不正确。"); } $staffdata = array(); $staffreg = array(); $staffnoreg = array(); $json = array(); $ename = $data_eno["dt"]["rows"][0]['ename']; //企业名称 $eno_level = $data_eno["dt"]["rows"][0]['eno_level']; //企业属于什么角色 $auth_level = $data_eno["dt"]["rows"][0]['auth_level']; //企业创建者属于什么角色 $sys_manager = $data_eno["dt"]["rows"][0]['sys_manager']; //企业管理员 $mobileReg = new \Justsy\InterfaceBundle\Controller\MobileRegisterController(); $mobileReg->setContainer($this->container); for ($i = 0; $i < count($stafflist); $i++) { if (!empty($stafflist[$i]["reg_name"]) && !empty($stafflist[$i]["email"])) { //需要验证电子邮箱的合法性 $pattern = $this->checkmail(); $login_account = $stafflist[$i]['email']; $reg_name = $stafflist[$i]['reg_name']; $password = isset($stafflist[$i]["password"]) ? $stafflist[$i]["password"] : "******"; $ldap_uid = isset($stafflist[$i]["uid"]) ? $stafflist[$i]["uid"] : ""; $this->get("logger")->err("-----------------传入的ldap_uid:" . $ldap_uid); if (preg_match($pattern, $login_account)) { //验证通过 $sql_staff = "select eno,mobile,openid,nick_name,auth_level from we_staff where login_account=? "; $para_staff = array($login_account); $data_staff = $conn->GetData("dt", $sql_staff, $para_staff); if ($data_staff != null && count($data_staff["dt"]["rows"]) > 0 && !empty($data_staff["dt"]["rows"][0]["openid"])) { //成员已经存在 if ($data_staff["dt"]["rows"][0]["eno"] != $eno) { array_push($staffreg, array("openid" => "", "login_account" => $login_account, "reg_name" => $reg_name, "msg" => "注册人邮箱已注册,加入企业编号与【" . $eno . "】不是同一企业。")); } else { if ($data_staff["dt"]["rows"][0]["nick_name"] != $reg_name) { array_push($staffreg, array("openid" => "", "login_account" => $login_account, "reg_name" => $reg_name, "msg" => "注册人邮箱已注册,注册人姓名与【" . $reg_name . "】不一致。")); } else { //同一企业的同一用户需要修改权限 $mobile = $data_staff["dt"]["rows"][0]["mobile"]; $staff_auth_level = $data_staff["dt"]["rows"][0]["auth_level"]; //权限与管理员不一致,修改人员权限 if ($staff_auth_level != $auth_level) { try { $sql_upd = "update we_staff set auth_level=? where login_account=? "; $para_upd = array($staff_auth_level, $login_account); $conn->ExecSQL($sql_upd, $para_upd); $staffRole = new \Justsy\BaseBundle\Rbac\staffRole($conn, $conn_im, $this->container); $staffRole->UpdateStaffRoleByCode($login_account, $auth_level . $eno_level, $staff_auth_level . $eno_level, $eno); } catch (\Exception $e) { $this->get("logger")->err($e->getMessage()); } } $staffMgr = new \Justsy\BaseBundle\Management\Staff($conn, $conn_im, $login_account, $this->get("logger")); //和管理员相互添加好友 if (!empty($sys_manager)) { $sysmanager = explode(';', $sys_manager); //循环添加管理员为好友 for ($i = 0; $i < count($sysmanager); $i++) { $manager_staff = trim($sysmanager[$i]); try { if (!empty($manager_staff)) { $staffMgr->bothAddFriend($this->container, $manager_staff); } } catch (\Exception $e) { $this->get("logger")->err($e->getMessage()); } } } try { //和创建者相互添加好友 $staffMgr->bothAddFriend($this->container, $create_staff); } catch (\Exception $e) { $this->get("logger")->err($e->getMessage()); } array_push($staffreg, array("openid" => $data_staff["dt"]["rows"][0]["openid"], "login_account" => $login_account, "reg_name" => $reg_name, "msg" => "注册人邮箱已注册。")); } } } else { //手机号码未被注册 //获取企业名称 $sql = "select ename from we_enterprise where eno=?"; $params = array($eno); $ds = $conn->Getdata('enoname', $sql, $params); $ename = ''; $mailtype = ''; if ($ds['enoname']['recordcount'] > 0) { $ename = $ds['enoname']['rows'][0]['ename']; } $sql1 = "select 1 from we_public_domain where domain_name=?"; $params1 = array($this->getSubDomain($login_account)); $ds1 = $conn->Getdata('tt', $sql1, $params1); if ($ds1['tt']['recordcount'] > 0) { $mailtype = '0'; } else { $mailtype = '1'; } $active = new \Justsy\BaseBundle\Controller\ActiveController(); $active->setContainer($this->container); $active->doSave(array('account' => $login_account, 'realName' => $reg_name, 'passWord' => $password, 'eno' => $eno, 'ename' => $ename, 'isNew' => '0', 'mailtype' => $mailtype, 'ldap_uid' => $ldap_uid, 'import' => '1')); $sql = "select openid from we_staff where login_account=?"; $params = array($login_account); $ds = $conn->Getdata('op', $sql, $params); $openid = ''; if ($ds['op']['recordcount'] > 0) { $openid = $ds['op']['rows'][0]['openid']; } $res = array('openid' => $openid); if (!empty($res["openid"])) { //更改其他信息 array_push($staffdata, array("openid" => $res["openid"], "login_account" => $login_account)); //"reg_name"=>$reg_name, } else { //注册成员失败 $msg = "注册成员失败。"; if (!empty($res["msg"])) { $msg = $res["msg"]; } array_push($staffnoreg, array("login_account" => $login_account, "reg_name" => $reg_name, "msg" => $msg)); } } } else { //电子邮件格式不对 array_push($staffnoreg, array("login_account" => $login_account, "reg_name" => $reg_name, "msg" => "注册人帐号格式不正确。")); } } } //返回结果 if (empty($staffdata) && empty($staffreg) && empty($staffnoreg)) { $json = array("returncode" => ReturnCode::$SYSERROR, "msg" => "没有人员需要注册。"); } else { $json = array("returncode" => ReturnCode::$SUCCESS, "list" => $staffdata, "reg" => $staffreg, "noreg" => $staffnoreg); } return $json; }