Пример #1
0
 public function updateAction()
 {
     $mobile = $this->_getParam('mobile');
     $email = $this->_getParam('email');
     $phone = $this->_getParam('phone');
     $passwd = $this->_getParam('passwd');
     $name = $this->_getParam('name');
     $avatar = $this->_getParam('avatar');
     $sex = $this->_getParam('sex');
     $job = $this->_getParam('job');
     $postcode = $this->_getParam('postcode');
     $idcard = $this->_getParam('idcard');
     $country = $this->_getParam('country');
     $address = $this->_getParam('address');
     $birthday = $this->_getParam('birthday');
     $auth = new Zend_Session_Namespace('auth');
     if ($this->_auth->userid && $this->_auth->role == 1) {
         $nuser = Application_Model_M_Nuser::find($this->_auth->userid);
         if ($nuser) {
             if (!$nuser->getMobile()) {
                 $validatorMobile = new Yy_Validate_Mobile();
                 if ($validatorMobile->isValid($mobile)) {
                     $bool = Application_Model_M_Nuser::fetchByMobile($mobile);
                     if (!$bool) {
                         $nuser->setMobile($mobile);
                     } else {
                         //将更新的手机号已经被注册
                         $out['errno'] = '2';
                         $out['msg'] = Yy_ErrMsg_User::getMsg('update', $out['errno']);
                         Yy_Utils::jsonOut($out);
                         return;
                     }
                 }
             }
             if (!$nuser->getEmail()) {
                 $validatorEmail = new Zend_Validate_EmailAddress();
                 if ($validatorEmail->isValid($email)) {
                     $bool = Application_Model_M_Nuser::fetchByEmail($email);
                     if (!$bool) {
                         $nuser->setEmail($email);
                     } else {
                         //将更新的邮箱已经被别人注册
                         $out['errno'] = '3';
                         $out['msg'] = Yy_ErrMsg_User::getMsg('update', $out['errno']);
                         Yy_Utils::jsonOut($out);
                         return;
                     }
                 }
             }
             if ($phone) {
                 $nuser->setPhone($phone);
             }
             if ($passwd) {
                 $nuser->setPasswd(md5($passwd));
             }
             if ($name) {
                 $nuser->setName($name);
             }
             //     			if($avatar){
             //     				$nuser->setAvatar($avatar);
             //     			}
             if ($sex) {
                 $nuser->setSex($sex);
             }
             if ($job) {
                 $nuser->setJob($job);
             }
             if ($postcode) {
                 $nuser->setPostcode($postcode);
             }
             if ($idcard) {
                 $nuser->setIdcard($idcard);
             }
             if ($country) {
                 $nuser->setCountry($country);
             }
             if ($address) {
                 $nuser->setAddress($address);
             }
             if ($birthday) {
                 $nuser->setBirthday($birthday);
             }
             try {
                 $out['errno'] = '0';
                 $nuser->save();
                 //保存用户头像
                 $adapter = new Zend_File_Transfer_Adapter_Http();
                 $wrdir = Yy_Utils::getWriteDir();
                 $adapter->setDestination($wrdir);
                 if (!$adapter->receive()) {
                     $messages = $adapter->getMessages();
                     //echo implode("\n", $messages);
                 }
                 $filename = $adapter->getFileName();
                 if (is_string($filename)) {
                     $handle = fopen($filename, 'rb');
                     $avatar = addslashes(fread($handle, filesize($filename)));
                     fclose($handle);
                     Application_Model_M_Nuser::updateAvatar($nuser->getId(), $avatar);
                 }
             } catch (Zend_Db_Exception $e) {
                 $out['errno'] = '1';
             }
         } else {
             $out['errno'] = '1';
         }
     } else {
         $out['errno'] = '200';
     }
     $out['msg'] = Yy_ErrMsg_User::getMsg('update', $out['errno']);
     Yy_Utils::jsonOut($out);
 }