Ejemplo n.º 1
0
 public function staffAttrSyncAction()
 {
     $conn = $this->get("we_data_access");
     $conn_im = $this->get("we_data_access_im");
     $request = $this->getRequest();
     $appid = trim($request->get("appid"));
     $code = trim($request->get("code"));
     $openid = trim($request->get("openid"));
     $eno = trim($request->get("eno"));
     $staffattrlist = trim($request->get("attrs"));
     if (empty($appid)) {
         return $this->responseJson($request, array("returncode" => ReturnCode::$SYSERROR, "msg" => "应用ID不能为空。"));
     }
     if (empty($code)) {
         return $this->responseJson($request, array("returncode" => ReturnCode::$SYSERROR, "msg" => "动态授权码不能为空。"));
     }
     if (empty($staffattrlist)) {
         return $this->responseJson($request, 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 $this->responseJson($request, array("returncode" => ReturnCode::$SYSERROR, "msg" => "应用ID不正确。"));
     }
     $appkey = $data_app["dt"]["rows"][0]["appkey"];
     if (strtolower($code) != strtolower(MD5($appid . $appkey))) {
         return $this->responseJson($request, array("returncode" => ReturnCode::$SYSERROR, "msg" => "动态授权码不正确。"));
     }
     $attrObject = json_decode($staffattrlist, true);
     $nickname = isset($attrObject["NickName"]) ? $attrObject["NickName"] : null;
     $nickname = isset($attrObject["nickname"]) ? $attrObject["nickname"] : $nickname;
     $headportrait_url = isset($attrObject["HeadPortrait"]) ? $attrObject["HeadPortrait"] : null;
     $headportrait_url = isset($attrObject["headportrait"]) ? $attrObject["headportrait"] : $headportrait_url;
     $gender = isset($attrObject["Gender"]) ? $attrObject["Gender"] : null;
     $gender = isset($attrObject["gender"]) ? $attrObject["gender"] : $gender;
     $duty = isset($attrObject["Role"]) ? $attrObject["Role"] : null;
     $duty = isset($attrObject["role"]) ? $attrObject["role"] : $duty;
     $staff = new \Justsy\BaseBundle\Management\Staff($conn, $conn_im, $openid);
     if (!empty($headPortrait)) {
         $staff->SaveUserHead($headportrait_url);
     }
     $staff->checkAndUpdate($nick_name, null, null, $duty, null, $gender);
 }