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); }
public function updateajaxAction() { $this->getResponse()->setHeader('Content-Type', 'application/json'); $this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout()->disableLayout(); $params = $this->_getAllParams(); //$id = $params['id']; //$nuser = Application_Model_M_Nuser::find($id); $nuser = new Application_Model_O_Nuser(); $validate = new Yy_Validate_Value(); if ($validate->isValid($params['id'])) { $nuser->setId($params['id']); } else { $nuser->setCtime(date('Y-m-d H:i:s')); } if ($validate->isValid($params['mobile'])) { $nuser->setMobile($params['mobile']); } if ($validate->isValid($params['email'])) { $nuser->setEmail($params['email']); } if ($validate->isValid($params['phone'])) { $nuser->setPhone($params['phone']); } if ($validate->isValid($params['passwd'])) { $nuser->setPasswd(md5($params['passwd'])); } if ($validate->isValid($params['name'])) { $nuser->setName($params['name']); } if ($validate->isValid($params['sex'])) { $nuser->setSex($params['sex']); } if ($validate->isValid($params['job'])) { $nuser->setJob($params['job']); } if ($validate->isValid($params['postcode'])) { $nuser->setPostcode($params['postcode']); } if ($validate->isValid($params['idcard'])) { $nuser->setIdcard($params['idcard']); } if ($validate->isValid($params['point'])) { $nuser->setPoint($params['point']); } if ($validate->isValid($params['country'])) { $nuser->setCountry($params['country']); } if ($validate->isValid($params['address'])) { $nuser->setAddress($params['address']); } if ($validate->isValid($params['birthday'])) { $nuser->setBirthday($params['birthday']); } if ($validate->isValid($params['status'])) { $nuser->setStatus($params['status']); } try { $nuser->save(); $id = $nuser->getId(); //保存用户头像 $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($id, $avatar); } $url = '/nuser/view?id=' . $id . '&from=update'; $this->redirect($url); } catch (Zend_Db_Exception $e) { //echo $e->getMessage();exit; $this->redirect('/error?message=' . $e->getMessage()); //$this->redirect('/error'); } }